|
| 1 | +--- |
| 2 | +section: Typography |
| 3 | +title: Text |
| 4 | +slug: /docs/text/ |
| 5 | +--- |
| 6 | + |
| 7 | +# Text |
| 8 | + |
| 9 | +Utilities for controlling the all typography of an element. |
| 10 | + |
| 11 | +<carbon-ad /> |
| 12 | + |
| 13 | +| React props | CSS Properties | |
| 14 | +| ------------- | -------------- | |
| 15 | +| `text={size}` | Mixed | |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +Text is similar to [`fontSize`](/docs/font-size/), except it also specify according [`lineHeight`](/docs/line-height/). |
| 20 | + |
| 21 | +By extending theme, `text` can be used to define all text variants of your application. |
| 22 | + |
| 23 | +```jsx preview color=violet |
| 24 | +<> |
| 25 | + <template preview> |
| 26 | + <> |
| 27 | + {[ |
| 28 | + 'xs', |
| 29 | + 'sm', |
| 30 | + 'base', |
| 31 | + 'lg', |
| 32 | + 'xl', |
| 33 | + '2xl', |
| 34 | + '3xl', |
| 35 | + '4xl', |
| 36 | + '5xl', |
| 37 | + '6xl', |
| 38 | + '7xl', |
| 39 | + '8xl', |
| 40 | + '9xl', |
| 41 | + ].map((size) => ( |
| 42 | + <x.dl |
| 43 | + key={size} |
| 44 | + display="flex" |
| 45 | + alignItems="baseline" |
| 46 | + color="violet-600" |
| 47 | + overflow="hidden" |
| 48 | + > |
| 49 | + <x.dt w={16} flexShrink={0} text="sm" opacity={0.8} fontFamily="mono"> |
| 50 | + {size} |
| 51 | + </x.dt> |
| 52 | + <x.dd text={size} fontWeight="medium"> |
| 53 | + Computers have lots of memory but no imagination. |
| 54 | + </x.dd> |
| 55 | + </x.dl> |
| 56 | + ))} |
| 57 | + </> |
| 58 | + </template> |
| 59 | + <x.p text="xs">Computers have lots ...</x.p> |
| 60 | + <x.p text="sm">Computers have lots ...</x.p> |
| 61 | + <x.p text="base">Computers have lots ...</x.p> |
| 62 | + <x.p text="lg">Computers have lots ...</x.p> |
| 63 | + <x.p text="xl">Computers have lots ...</x.p> |
| 64 | + <x.p text="2xl">Computers have lots ...</x.p> |
| 65 | + <x.p text="3xl">Computers have lots ...</x.p> |
| 66 | + <x.p text="4xl">Computers have lots ...</x.p> |
| 67 | + <x.p text="5xl">Computers have lots ...</x.p> |
| 68 | + <x.p text="6xl">Computers have lots ...</x.p> |
| 69 | + <x.p text="7xl">Computers have lots ...</x.p> |
| 70 | + <x.p text="8xl">Computers have lots ...</x.p> |
| 71 | + <x.p text="9xl">Computers have lots ...</x.p> |
| 72 | +</> |
| 73 | +``` |
| 74 | + |
| 75 | +## Responsive |
| 76 | + |
| 77 | +To control the space between elements at a specific breakpoint, use responsive object notation. For example, adding the property `text={{ md: "xl" }}` to an element would apply the `text="xl"` utility at medium screen sizes and above. |
| 78 | + |
| 79 | +```jsx |
| 80 | +<x.p text={{ xs: 'sm', md: 'xl' }}>{/* ... */}</x.p> |
| 81 | +``` |
| 82 | + |
| 83 | +For more information about xstyled's responsive design features, check out [Responsive Design](/docs/responsive-design/) documentation. |
| 84 | + |
| 85 | +## Customizing |
| 86 | + |
| 87 | +### Texts |
| 88 | + |
| 89 | +If you'd like to customize your values for texts, use the `theme.texts` section of your theme. Every typography utilities are authorized, not only `fontSize` and `lineHeight`. You can literally define all your texts style using this utility. |
| 90 | + |
| 91 | +```diffjs |
| 92 | + // theme.js |
| 93 | + export const theme = { |
| 94 | + texts: { |
| 95 | + title: { |
| 96 | + fontSize: '30px', |
| 97 | + lineHeight: '45px', |
| 98 | + fontWeight: 'bold' |
| 99 | + }, |
| 100 | + hint: { |
| 101 | + fontSize: 10, |
| 102 | + lineHeight: 1.4, |
| 103 | + color: 'gray-300', |
| 104 | + } |
| 105 | + }, |
| 106 | + } |
| 107 | +``` |
| 108 | + |
| 109 | +If you don't want to customize it, a set of `fontSizes` is already defined in default theme: |
| 110 | + |
| 111 | +```js |
| 112 | +const defaultTheme = { |
| 113 | + // ... |
| 114 | + fontSizes: { |
| 115 | + xs: { fontSize: 'xs', lineHeight: 'xs' }, |
| 116 | + sm: { fontSize: 'sm', lineHeight: 'sm' }, |
| 117 | + default: { fontSize: 'default', lineHeight: 'default' }, |
| 118 | + lg: { fontSize: 'lg', lineHeight: 'lg' }, |
| 119 | + xl: { fontSize: 'xl', lineHeight: 'xl' }, |
| 120 | + '2xl': { fontSize: '2xl', lineHeight: '2xl' }, |
| 121 | + '3xl': { fontSize: '3xl', lineHeight: '3xl' }, |
| 122 | + '4xl': { fontSize: '4xl', lineHeight: '4xl' }, |
| 123 | + '5xl': { fontSize: '5xl', lineHeight: '5xl' }, |
| 124 | + '6xl': { fontSize: '6xl', lineHeight: '6xl' }, |
| 125 | + '7xl': { fontSize: '7xl', lineHeight: '7xl' }, |
| 126 | + '8xl': { fontSize: '8xl', lineHeight: '8xl' }, |
| 127 | + '9xl': { fontSize: '9xl', lineHeight: '9xl' }, |
| 128 | + }, |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +Values are defined in `fontSizes` and `lineHeights` theme section. It means if you modify a `fontSize` it will automatically reflects change on `text` and `fontSize` utility. |
0 commit comments