-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeading.tsx
More file actions
213 lines (194 loc) · 5.27 KB
/
Copy pathHeading.tsx
File metadata and controls
213 lines (194 loc) · 5.27 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import React, {HTMLAttributes} from 'react'
import styled, {css} from 'styled-components'
import {device} from '../../theme/device'
type Props = {
className?: string
inline?: boolean
variant: Variant
color?: Color
align?: Align
normalWeight?: boolean
withAccentUnderline?: boolean
noWrap?: boolean
maxWidth?: string
uppercase?: boolean
} & HTMLAttributes<HTMLElement>
type Variant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
type Color = 'primary' | 'secondary' | 'accent'
type Align = 'left' | 'center' | 'right'
const Heading = ({
children,
className,
variant,
color,
align,
inline,
normalWeight,
withAccentUnderline,
noWrap,
maxWidth,
uppercase,
...props
}: Props) => {
const headingProps: Props = {
className,
variant,
color: color || 'secondary',
align: align || 'left',
inline: inline || false,
normalWeight,
withAccentUnderline,
noWrap,
maxWidth,
uppercase,
}
if (variant === 'h1') {
return (
<H1Styled {...headingProps} {...props}>
{children}
</H1Styled>
)
} else if (variant === 'h2') {
return (
<H2Styled {...headingProps} {...props}>
{children}
</H2Styled>
)
} else if (variant === 'h3') {
return (
<H3Styled {...headingProps} {...props}>
{children}
</H3Styled>
)
} else if (variant === 'h4') {
return (
<H4Styled {...headingProps} {...props}>
{children}
</H4Styled>
)
} else if (variant === 'h5') {
return (
<H5Styled {...headingProps} {...props}>
{children}
</H5Styled>
)
} else {
return (
<H6Styled {...headingProps} {...props}>
{children}
</H6Styled>
)
}
}
const styleValuesBasedOnDevice = {
XL: {
h1: {fontSize: '72px', lineHeight: '1.0'},
h2: {fontSize: '62px', lineHeight: '1.1'},
h3: {fontSize: '48px', lineHeight: '1.2'},
h4: {fontSize: '32px', lineHeight: '1.3'},
h5: {fontSize: '24px', lineHeight: '1.4'},
h6: {fontSize: '22px', lineHeight: '1.4'},
},
L: {
h1: {fontSize: '72px', lineHeight: '1.0'},
h2: {fontSize: '52px', lineHeight: '1.1'},
h3: {fontSize: '42px', lineHeight: '1.2'},
h4: {fontSize: '30px', lineHeight: '1.3'},
h5: {fontSize: '22px', lineHeight: '1.4'},
h6: {fontSize: '18px', lineHeight: '1.4'},
},
M: {
h1: {fontSize: '62px', lineHeight: '1.0'},
h2: {fontSize: '42px', lineHeight: '1.1'},
h3: {fontSize: '36px', lineHeight: '1.2'},
h4: {fontSize: '28px', lineHeight: '1.3'},
h5: {fontSize: '22px', lineHeight: '1.4'},
h6: {fontSize: '18px', lineHeight: '1.4'},
},
S: {
h1: {fontSize: '44px', lineHeight: '1.0'},
h2: {fontSize: '42px', lineHeight: '1.1'},
h3: {fontSize: '32px', lineHeight: '1.2'},
h4: {fontSize: '22px', lineHeight: '1.3'},
h5: {fontSize: '20px', lineHeight: '1.4'},
h6: {fontSize: '16px', lineHeight: '1.4'},
},
XS: {
h1: {fontSize: '38px', lineHeight: '1.0'},
h2: {fontSize: '36px', lineHeight: '1.1'},
h3: {fontSize: '32px', lineHeight: '1.2'},
h4: {fontSize: '22px', lineHeight: '1.3'},
h5: {fontSize: '20px', lineHeight: '1.4'},
h6: {fontSize: '16px', lineHeight: '1.4'},
},
}
const headingStyle = css<{
variant: Variant
color?: Color
align?: Align
inline?: boolean
normalWeight?: boolean
withAccentUnderline?: boolean
noWrap?: boolean
maxWidth?: string
uppercase?: boolean
}>`
display: ${(props) => (props.inline ? 'inline' : 'block')};
color: ${(props) => `var(--color-${props.color})`};
font-weight: ${(props) => (props.normalWeight ? 'normal' : 'bold')};
text-align: ${(props) => props.align};
border-bottom: ${(props) =>
props.withAccentUnderline ? `4px solid var(--color-accent)` : 'unset'};
white-space: ${(props) => (props.noWrap ? 'nowrap' : 'unset')};
max-width: ${(props) => props.maxWidth && props.maxWidth};
text-transform: ${(props) => (props.uppercase ? 'uppercase' : 'unset')};
@media ${device.XL} {
font-size: ${(props) =>
styleValuesBasedOnDevice['XL'][props.variant].fontSize};
line-height: ${(props) =>
styleValuesBasedOnDevice['XL'][props.variant].lineHeight};
}
@media ${device.L} {
font-size: ${(props) =>
styleValuesBasedOnDevice['L'][props.variant].fontSize};
line-height: ${(props) =>
styleValuesBasedOnDevice['L'][props.variant].lineHeight};
}
@media ${device.M} {
font-size: ${(props) =>
styleValuesBasedOnDevice['M'][props.variant].fontSize};
line-height: ${(props) =>
styleValuesBasedOnDevice['M'][props.variant].lineHeight};
}
@media ${device.S} {
font-size: ${(props) =>
styleValuesBasedOnDevice['S'][props.variant].fontSize};
line-height: ${(props) =>
styleValuesBasedOnDevice['S'][props.variant].lineHeight};
}
@media ${device.XS} {
font-size: ${(props) =>
styleValuesBasedOnDevice['XS'][props.variant].fontSize};
line-height: ${(props) =>
styleValuesBasedOnDevice['XS'][props.variant].lineHeight};
}
`
const H1Styled = styled.h1`
${headingStyle}
`
const H2Styled = styled.h2`
${headingStyle}
`
const H3Styled = styled.h3`
${headingStyle}
`
const H4Styled = styled.h4`
${headingStyle}
`
const H5Styled = styled.h5`
${headingStyle}
`
const H6Styled = styled.h6`
${headingStyle}
`
export default Heading