UNPKG

3.33 kBMarkdownView Raw
1---
2title: Text
3storybookPath: typography-text--default
4isExperimentalPackage: false
5---
6
7Constrained, purposeful text styles as a component.
8
9## Examples
10
11```jsx live
12const textSizes = ['large', 'standard', 'small', 'xsmall'];
13
14return (
15 <Columns collapseBelow="tablet" gap="xlarge">
16 <Stack gap="large">
17 {textSizes.map(textSize => (
18 <Text key={textSize} size={textSize} weight="regular">
19 Text {textSize} regular
20 </Text>
21 ))}
22 </Stack>
23 <Stack gap="large">
24 {textSizes.map(textSize => (
25 <Text key={textSize} size={textSize} weight="semibold">
26 Text {textSize} regular
27 </Text>
28 ))}
29 </Stack>
30 </Columns>
31);
32```
33
34### Align
35
36Text can be aligned with the `align` prop.
37
38```jsx live
39<Stack gap="large" dividers>
40 <Text align="left">Left (default)</Text>
41 <Text align="center">Center</Text>
42 <Text align="right">Right</Text>
43</Stack>
44```
45
46### Overflow strategy
47
48Use the `overflowStrategy` prop to manage how `Text` behaves with regard to
49overflow.
50
51```jsx live
52const overflowStrategies = ['truncate', 'nowrap', 'breakword'];
53
54return (
55 <Stack gap="large" style={{ width: 200 }}>
56 <Stack gap="small">
57 <Text weight="semibold">Default</Text>
58 <Text>The quick brown fox jumps over the lazy dog.</Text>
59 </Stack>
60 {overflowStrategies.map(overflowStrategy => (
61 <Stack key={overflowStrategy} gap="small">
62 <Text weight="semibold">{overflowStrategy}</Text>
63 <Text overflowStrategy={overflowStrategy}>
64 The quick brown fox jumps over the lazy dog.
65 </Text>
66 </Stack>
67 ))}
68 </Stack>
69);
70```
71
72### Tone
73
74The foreground colour of text can be set by applying a `tone`. In addition to
75the foundation tones, “muted” provides a way to de-emphasise text.
76
77```jsx live
78const textTones = [
79 'neutral', // Default
80 'accent',
81 'caution',
82 'critical',
83 'disabled',
84 'fieldAccent',
85 'info',
86 'link',
87 'muted',
88 'placeholder',
89 'positive',
90 'primary',
91 'primaryActive',
92 'primaryHover',
93 'secondary',
94 'secondaryActive',
95 'secondaryHover',
96];
97
98return (
99 <Columns collapseBelow="tablet" gap="large" template={[1, 1]}>
100 {textTones.map(tone => (
101 <Text key={tone} tone={tone}>
102 {tone}
103 </Text>
104 ))}
105 </Columns>
106);
107```
108
109### Weight
110
111Text is available in two weight: `regular` and `semibold`.
112
113```jsx live
114<Inline gap="small">
115 <Text weight="regular">Regular</Text>
116 <Text weight="semibold">Semibold</Text>
117</Inline>
118```
119
120### Contrast
121
122To ensure text has sufficient contrast, when on a dark background the foreground
123tones “neutral” and “muted” will be inverted.
124
125```jsx live
126<Inline gap="large">
127 <Box background="neutral" padding="small" borderRadius="small">
128 <Text>neutral</Text>
129 </Box>
130 <Box background="neutral" padding="small" borderRadius="small">
131 <Text tone="muted">muted</Text>
132 </Box>
133</Inline>
134```
135
136## Props
137
138<PropsTable displayName="Text" />
139
140Extra props are also passed into the underlying [`Box`](/package/box) component.
141
142[brighte-theme]:
143 https://github.com/brighte-labs/spark-web/blob/e503bea4f7668d187ec7a78f99c5ed374417588b/packages/theme/src/makeTheme.ts#L158
144[data-attribute-map]:
145 https://github.com/brighte-labs/spark-web/blob/e7f6f4285b4cfd876312cc89fbdd094039aa239a/packages/utils/src/internal/buildDataAttributes.ts#L1