Skip to content

Commit 10f2a86

Browse files
committed
add text variants
1 parent 941c1f8 commit 10f2a86

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed
23.1 KB
Loading

src/components/Text/Text.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,29 @@ type TextProps = {
2323
/** possible types of the css cursor property */
2424
cursor?: 'pointer' | 'default' | 'auto',
2525
/** modern text kinds */
26-
kind?: 'overline-2' | 'overline-1' | 'small-2' | 'small-1' | 'body' | 'subtitle',
26+
kind?: 'overline-2' | 'overline-1' | 'small-2' | 'small-1' | 'body' | 'subtitle' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5',
27+
};
28+
29+
const TAG_NAMES = {
30+
'overline-2': 'span',
31+
'overline-1': 'span',
32+
'small-2': 'span',
33+
'small-1': 'span',
34+
body: 'span',
35+
subtitle: 'span',
36+
h1: 'h1',
37+
h2: 'h2',
38+
h3: 'h3',
39+
h4: 'h4',
40+
h5: 'h5',
2741
};
2842

2943
function Text({
3044
text,
3145
children,
3246
...rest
3347
}: TextProps) {
34-
return <TextTag { ...rest } tagName="span">{ children || text }</TextTag>;
48+
return <TextTag { ...rest } tagName={ TAG_NAMES[rest.kind || 'body'] }>{ children || text }</TextTag>;
3549
}
3650

3751
Text.defaultProps = {

src/components/Text/Text.stories.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ common.story = {
3030

3131
export const withKindModifiers = () => (
3232
<Column>
33+
<Text kind="h1">H1 kind: { placeholderText }</Text>
34+
<Text kind="h2">H2 kind: { placeholderText }</Text>
35+
<Text kind="h3">H3 kind: { placeholderText }</Text>
36+
<Text kind="h4">H4 kind: { placeholderText }</Text>
37+
<Text kind="h5">H5 kind: { placeholderText }</Text>
3338
<Text kind="subtitle">Subtitle kind: { placeholderText }</Text>
3439
<Text kind="body">Body kind: { placeholderText }</Text>
3540
<Text kind="overline-1">Overline-1 kind: { placeholderText }</Text>

src/components/Text/Text.theme.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ const [TextTag, theme] = createThemeTag(name, ({ COLORS, FONTS }: *): * => ({
3030
subtitle: {
3131
...FONTS.SUBTITLE,
3232
},
33+
h1: {
34+
...FONTS.H1,
35+
},
36+
h2: {
37+
...FONTS.H2,
38+
},
39+
h3: {
40+
...FONTS.H3,
41+
},
42+
h4: {
43+
...FONTS.H4,
44+
},
45+
h5: {
46+
...FONTS.H5,
47+
},
3348
},
3449

3550
color: fp.mapValues(

0 commit comments

Comments
 (0)