-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathBody.tsx
More file actions
102 lines (99 loc) · 3.4 KB
/
Copy pathBody.tsx
File metadata and controls
102 lines (99 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from 'react';
import { Typography, TypographyProps } from '@mui/material';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
import { colors } from 'styles/Theme';
/**
* A component that displays body text with customizable styles.
* It supports different font weights (bold, thin) and sizes (small, regular, large).
* @param {Object} props - The component props.
* @param {boolean} [props.bold] - If true, the text will be bold.
* @param {boolean} [props.thin] - If true, the text will be thin.
* @param {string} [props.size='regular'] - The size of the text, can be 'small', 'regular', or 'large'.
* @param {React.ReactNode} props.children - The content to display within the body text.
* @returns {JSX.Element} A styled Typography component with the specified text styles.
* @example
* <BodyText thin size="large">This is large thin text.</BodyText>
* <BodyText bold size="small">This is small bold text.</BodyText>
* <BodyText>This is regular text.</BodyText>
*/
export const BodyText = ({
bold,
thin,
size = 'regular',
children,
...props
}: {
bold?: boolean;
thin?: boolean;
size?: 'small' | 'regular' | 'large';
children: React.ReactNode;
} & TypographyProps) => {
const fontSize = {
small: '14px',
regular: '16px',
large: '18px',
}[size];
const lineHeight = {
small: '22px',
regular: '24px',
large: '24px',
}[size];
const fontWeight = () => {
if (bold) {
return 700;
}
if (thin) {
return 300;
}
return 400;
};
return (
<Typography fontWeight={fontWeight()} fontSize={fontSize} lineHeight={lineHeight} {...props}>
{children}
</Typography>
);
};
/**
* Displays an error message with an icon.
* If no error message is provided, it returns null.
* @param {Object} props - The component props.
* @param {string} [props.error] - The error message to display.
* @returns {JSX.Element|null} A styled error message or null if no error is provided.
* @example
* <ErrorMessage error="Maximum length exceeded." />
* <ErrorMessage error="Invalid input." />
*/
export const ErrorMessage = ({ error }: { error?: string }) => {
if (!error) return null;
return (
<BodyText bold size="small" sx={{ color: colors.notification.error.shade, lineHeight: '24px' }}>
<FontAwesomeIcon
icon={faExclamationCircle}
style={{ marginRight: '8px', fontSize: '18px', position: 'relative', top: '2px' }}
/>
{error}
</BodyText>
);
};
/**
* A component that displays eyebrow text, typically used for headings or introductory text.
* It uses a larger font size and a lighter font weight for emphasis.
* @param {Object} props - The component props.
* @param {React.ReactNode} props.children - The content to display within the eyebrow text.
* @returns {JSX.Element} A styled Typography component with eyebrow text styles.
* @example
* <EyebrowText>This is eyebrow text.</EyebrowText>
*/
export const EyebrowText = ({
children,
...props
}: {
children: React.ReactNode;
} & TypographyProps) => {
return (
<Typography variant="body1" fontSize="24px" lineHeight="normal" fontWeight={300} {...props}>
{children}
</Typography>
);
};