-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHeadings.tsx
More file actions
186 lines (177 loc) · 6.01 KB
/
Copy pathHeadings.tsx
File metadata and controls
186 lines (177 loc) · 6.01 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import React from 'react';
import { Typography, TypographyProps } from '@mui/material';
type HeadingWeight = 'bold' | 'regular' | 'thin';
type HeadingProps = {
children: React.ReactNode;
weight?: HeadingWeight;
bold?: boolean;
component?: React.ElementType;
} & TypographyProps;
const fontWeight = (weight?: string | number) => {
switch (weight) {
case 'bold':
return 700;
case 'regular':
return 400;
case 'thin':
return 200;
default:
return weight;
}
};
/**
* Heading1 component for rendering a primary heading.
* This component uses the MUI Typography component to render a heading with customizable styles.
* @param {props.children} - The content of the heading.
* @param {props.weight} - The font weight of the heading, can be 'bold', 'regular', or 'thin'.
* @param {props.bold} - Shortcut for setting font weight to bold, takes precedence over the weight prop if both are provided.
* @param {props.component} - The HTML element to use for the heading, defaults to 'h1'.
* @param {props} - Additional props to pass to the Typography component.
* @returns JSX.Element: A styled heading element.
*/
export const Heading1 = ({ children, weight, bold, component, ...props }: HeadingProps) => {
return (
<Typography
component={component || 'h1'}
variant="h1"
lineHeight="1.5"
fontSize="2rem"
marginBottom="1.5rem"
marginTop="1.5rem"
fontWeight={bold ? 'bold' : fontWeight(weight)}
{...props}
>
{children}
</Typography>
);
};
/**
* Heading2 component for rendering a secondary heading.
* This component uses the MUI Typography component to render a heading with optional decoration and customizable styles.
* @param {props.children} - The content of the heading.
* @param {props.decorated} - Whether to add a decorative line above the heading.
* @param {props.weight} - The font weight of the heading, can be 'bold', 'regular', or 'thin'.
* @param {props.bold} - Shortcut for setting font weight to bold, takes precedence over the weight prop if both are provided.
* @param {props.component} - The HTML element to use for the heading, defaults to 'h2'.
* @param {props} - Additional props to pass to the Typography component.
* @returns JSX.Element: A styled heading element with optional decoration.
*/
export const Heading2 = ({
children,
decorated = false,
weight,
bold,
component,
...props
}: HeadingProps & {
decorated?: boolean;
}) => {
return (
<Typography
variant="h2"
component={component || 'h2'}
lineHeight="1.5"
fontSize="1.5rem"
mb="1.5rem"
mt="0.5rem"
fontWeight={bold ? 'bold' : fontWeight(weight)}
{...props}
sx={[
{
'&::before': decorated
? {
backgroundColor: 'gold.60',
content: '""',
display: 'block',
width: '40px',
height: '4px',
position: 'relative',
bottom: '4px',
}
: {},
},
...(Array.isArray(props.sx) ? props.sx : [props.sx]),
]}
>
{children}
</Typography>
);
};
/**
* Heading3 component for rendering a tertiary heading.
* This component uses the MUI Typography component to render a heading with customizable styles.
* @param {props.children} - The content of the heading.
* @param {props.weight} - The font weight of the heading, can be 'bold', 'regular', or 'thin'.
* @param {props.bold} - Shortcut for setting font weight to bold, takes precedence over the weight prop if both are provided.
* @param {props.component} - The HTML element to use for the heading, defaults to 'h3'.
* @param {props} - Additional props to pass to the Typography component.
* @returns JSX.Element: A styled heading element.
*/
export const Heading3 = ({
children,
weight,
bold,
component,
...props
}: {
children: React.ReactNode;
weight?: HeadingWeight;
component?: React.ElementType;
} & HeadingProps) => {
return (
<Typography
component={component || 'h3'}
variant="h3"
lineHeight={1.5}
fontSize="1.25rem"
fontStyle="normal"
fontWeight={bold ? 'bold' : fontWeight(weight)}
{...props}
>
{children}
</Typography>
);
};
/**
* Heading4 component for rendering a quaternary heading.
* This component uses the MUI Typography component to render a heading with customizable styles.
* @param {Object} props - Additional props to pass to the Typography component.
* @param {React.ReactNode} props.children - The content of the heading.
* @param {string} props.weight - The font weight of the heading, can be 'bold', 'regular', or 'thin'.
* @param {boolean} props.bold - Whether to apply bold styling to the heading.
* @param {React.ElementType} props.component - The HTML element to use for the heading, defaults to 'h4'.
* @returns JSX.Element: A styled heading element.
*/
export const Heading4 = ({
children,
weight = 'bold',
bold,
component,
...props
}: {
children: React.ReactNode;
weight?: HeadingWeight;
bold?: boolean;
component?: React.ElementType;
} & TypographyProps) => {
return (
<Typography
component={component || 'h4'}
variant="h4"
lineHeight="1.5"
fontSize="1.125rem"
fontStyle="normal"
fontWeight={bold ? 'bold' : fontWeight(weight)}
{...props}
>
{children}
</Typography>
);
};
const Headers = {
Heading1,
Heading2,
Heading3,
Heading4,
};
export default Headers;