Skip to content

Commit c73ab82

Browse files
siddharthkpSaraVieira
authored andcommitted
components: Text (codesandbox#3289)
* remove duplicate decorator * add parent styles to layout decorator * add min height to layout decorator * add common base element * use base element for other components * add all fontsizes + update example * add Text, mutedForeground token
1 parent bc56b76 commit c73ab82

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import styled from 'styled-components';
2+
import css from '@styled-system/css';
3+
import { Element } from '../Element';
4+
5+
const variants = {
6+
body: 'inherit',
7+
muted: 'mutedForeground',
8+
danger: 'errorForeground',
9+
};
10+
11+
export const Text = styled(Element).attrs({ as: 'span' })<{
12+
size?: number;
13+
align?: string;
14+
weight?: string;
15+
variant?: 'body' | 'muted' | 'danger';
16+
}>(({ size, align, weight, variant = 'body', ...props }) =>
17+
css({
18+
fontSize: size || 'inherit', // from theme.fontSizes
19+
fontWeight: weight || null, // from theme.fontWeights
20+
color: variants[variant],
21+
textAlign: align || 'left',
22+
})
23+
);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
import { Text } from '.';
3+
4+
export default {
5+
title: 'components/Text',
6+
component: Text,
7+
};
8+
9+
// replace the text inside with Text variants when available
10+
export const Basic = () => (
11+
<Text>This is a static template with no bundling</Text>
12+
);
13+
14+
export const Variants = () => (
15+
<>
16+
<Text variant="body">
17+
body is the default variant which inherits color from it&apos;s container
18+
</Text>
19+
<br />
20+
<br />
21+
<Text variant="muted">
22+
Use muted when you don&apos;t want to ask for too much attention
23+
</Text>
24+
<br />
25+
<br />
26+
<Text variant="danger">Now, we really want your atttention, hello!</Text>
27+
</>
28+
);
29+
30+
export const Weight = () => (
31+
<>
32+
<Text weight="thin">thin: These are all the weights Inter supports</Text>
33+
<br />
34+
<Text weight="light">light: These are all the weights Inter supports</Text>
35+
<br />
36+
<br />
37+
<Text weight="normal">
38+
normal (default): Most of our interface uses these 3 sizes
39+
</Text>
40+
<br />
41+
<Text weight="medium">
42+
medium: Most of our interface uses these 3 sizes
43+
</Text>
44+
<br />
45+
<Text weight="semibold">
46+
semibold: Most of our interface uses these 3 sizes
47+
</Text>
48+
<br />
49+
<br />
50+
<Text weight="bold">bold: These are all the weights Inter supports</Text>
51+
<br />
52+
<Text weight="extrabold">
53+
extrabold: These are all the weights Inter supports
54+
</Text>
55+
<br />
56+
<Text weight="black">black: These are all the weights Inter supports</Text>
57+
<br />
58+
</>
59+
);
60+
61+
export const Size = () => (
62+
<Text size={3}>Takes the size from fontSizes tokens</Text>
63+
);
64+
65+
export const Align = () => (
66+
<Text as="div" align="right">
67+
sometimes, just sometimes you need to align right
68+
</Text>
69+
);

packages/components/src/utils/polyfill-theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import deepmerge from 'deepmerge';
1414
// In that case, we should check if it exists before overriding it
1515
const polyfillTheme = vsCodeTheme =>
1616
deepmerge(vsCodeTheme, {
17+
mutedForeground: vsCodeTheme.foreground, // todo: find a way to fill this value
1718
sideBar: {
1819
hoverBackground: vsCodeTheme.sideBar.border,
1920
},

0 commit comments

Comments
 (0)