2022-08-18 19:51:53 +02:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import ActionableMessage from '../../ui/actionable-message';
import { Text } from './text';
# Text
> This Text (fka Typography) component has breaking changes in variant options and the line heights associated to each variant.
Good typography improves readability, legibility and hierarchy of information.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-text--default-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `Text` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-12-01 18:26:19 +01:00
2022-08-18 19:51:53 +02:00
<ArgsTable of={Text} />
### Variant
2023-02-10 01:09:33 +01:00
Use the `variant` prop and the `TextVariant` enum from `./ui/helpers/constants/design-system.js` to change the font size of the component.
2022-12-01 18:26:19 +01:00
2023-02-22 18:41:46 +01:00
`TextVariant` options:
- TextVariant.displayMd (default renders as `h1` tag)
- TextVariant.headingLg (default renders as `h2` tag)
- TextVariant.headingMd (default renders as `h3` tag)
- TextVariant.headingSm (default renders as `h4` tag)
- TextVariant.bodyLgMedium (default renders as `p` tag)
- TextVariant.bodyMd (default renders as `p` tag)
- TextVariant.bodyMdBold (default renders as `p` tag)
- TextVariant.bodySm (default renders as `p` tag)
- TextVariant.bodySmBold (default renders as `p` tag)
- TextVariant.bodyXs (default renders as `p` tag)
- TextVariant.inherit (default renders as `span` tag)
2022-08-18 19:51:53 +02:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-text--variant" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-02-02 21:15:26 +01:00
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.displayMd}>display-md</Text>
<Text variant={TextVariant.headingLg}>heading-lg</Text>
<Text variant={TextVariant.headingMd}>heading-md</Text>
<Text variant={TextVariant.headingSm}>heading-sm</Text>
<Text variant={TextVariant.bodyLgMedium}>body-lg-medium</Text>
<Text variant={TextVariant.bodyMd}>body-md</Text>
<Text variant={TextVariant.bodyMdBold}>body-md-bold</Text>
<Text variant={TextVariant.bodySm}>body-sm</Text>
<Text variant={TextVariant.bodySmBold}>body-sm-bold</Text>
<Text variant={TextVariant.bodyXs}>body-xs</Text>
<Text variant={TextVariant.inherit}>inherit</Text>
2022-08-18 19:51:53 +02:00
```
### Color
2023-04-03 19:42:37 +02:00
Use the `color` prop and the `TextColor` enum from `./ui/helpers/constants/design-system.js` to change the color of the `Text` component.
2022-08-18 19:51:53 +02:00
<Canvas>
2023-02-10 01:09:33 +01:00
<Story id="components-componentlibrary-text--color-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-02-02 21:15:26 +01:00
import { TextColor, BackgroundColor } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
2023-02-02 21:15:26 +01:00
<Text color={TextColor.textDefault}>
2022-08-18 19:51:53 +02:00
text-default
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.textAlternative}>
2022-08-18 19:51:53 +02:00
text-alternative
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.textMuted}>
2022-08-18 19:51:53 +02:00
text-muted
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.primaryDefault}>
2022-08-18 19:51:53 +02:00
primary-default
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.primaryInverse} backgroundColor={BackgroundColor.primaryDefault}>
2022-08-18 19:51:53 +02:00
primary-inverse
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.errorDefault}>
2022-08-18 19:51:53 +02:00
error-default
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.errorInverse} backgroundColor={BackgroundColor.errorDefault}>
2022-08-18 19:51:53 +02:00
error-inverse
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.successDefault}>
2022-08-18 19:51:53 +02:00
success-default
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.successInverse} backgroundColor={BackgroundColor.successDefault}>
2022-08-18 19:51:53 +02:00
success-inverse
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.warningDefault}>
warning-default
</Text>
<Text color={TextColor.warningInverse} backgroundColor={BackgroundColor.warningDefault}>
2022-08-18 19:51:53 +02:00
warning-inverse
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.infoDefault}>
2022-08-18 19:51:53 +02:00
info-default
</Text>
2023-02-02 21:15:26 +01:00
<Text color={TextColor.infoInverse} backgroundColor={BackgroundColor.infoDefault}>
2022-08-18 19:51:53 +02:00
info-inverse
</Text>
```
### Font Weight
2023-04-17 19:17:28 +02:00
Use the `fontWeight` prop and the `FontWeight` enum from `./ui/helpers/constants/design-system.js` to change the font weight of the `Text` component. There are 3 font weights:
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
- `FontWeight.Normal` = `normal` || `400`
- `FontWeight.Medium` = `medium` || `500`
- `FontWeight.Bold` = `bold` || `700`
2022-08-18 19:51:53 +02:00
<Canvas>
2023-05-25 19:35:38 +02:00
<Story id="components-componentlibrary-text--font-weight-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-04-17 19:17:28 +02:00
import { FontWeight } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
<Text fontWeight={FontWeight.Normal}>
2022-08-18 19:51:53 +02:00
normal
</Text>
2023-04-17 19:17:28 +02:00
<Text fontWeight={FontWeight.Medium}>
2022-08-18 19:51:53 +02:00
medium
</Text>
2023-04-17 19:17:28 +02:00
<Text fontWeight={FontWeight.Bold}>
2022-08-18 19:51:53 +02:00
bold
</Text>
```
### Font Style
2023-04-17 19:17:28 +02:00
Use the `fontStyle` prop and the `FontStyle` enum from `./ui/helpers/constants/design-system.js` to change the font style of the `Text` component. There are 2 font styles:
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
- `FontStyle.Normal`
- `FontStyle.Italic`
2022-08-18 19:51:53 +02:00
<Canvas>
2023-05-25 19:35:38 +02:00
<Story id="components-componentlibrary-text--font-style-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-04-17 19:17:28 +02:00
import { FontStyle } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
<Text fontStyle={FontStyle.Normal}>
2022-08-18 19:51:53 +02:00
normal
</Text>
2023-04-17 19:17:28 +02:00
<Text fontStyle={FontStyle.Italic}>
2022-08-18 19:51:53 +02:00
bold
</Text>
```
### Text Transform
2023-04-17 19:17:28 +02:00
Use the `textTransform` prop and the `TextTransform` enum from `./ui/helpers/constants/design-system.ts` to change the text alignment of the `Text` component
2022-08-18 19:51:53 +02:00
<Canvas>
2023-05-25 19:35:38 +02:00
<Story id="components-componentlibrary-text--text-transform-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-04-17 19:17:28 +02:00
import { TextTransform } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
<Text textAlign={TextTransform.Uppercase}>
2022-08-18 19:51:53 +02:00
uppercase
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextTransform.Lowercase}>
2022-08-18 19:51:53 +02:00
lowercase
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextTransform.Capitalize}>
2022-08-18 19:51:53 +02:00
capitalize
</Text>
```
### Text Align
2023-04-17 19:17:28 +02:00
Use the `textAlign` prop and the `TextAlign` enum from `./ui/helpers/constants/design-system.ts` to change the text alignment of the `Text` component
2022-08-18 19:51:53 +02:00
<Canvas>
2023-05-25 19:35:38 +02:00
<Story id="components-componentlibrary-text--text-align-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-04-17 19:17:28 +02:00
import { TextAlign } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.Left}>
2022-08-18 19:51:53 +02:00
left
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.Center}>
2022-08-18 19:51:53 +02:00
center
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.Right}>
2022-08-18 19:51:53 +02:00
right
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.Justify}>
2022-08-18 19:51:53 +02:00
justify
</Text>
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.End}>
2022-08-18 19:51:53 +02:00
end
</Text>
```
### Overflow Wrap
2023-04-17 19:17:28 +02:00
Use the `overflowWrap` prop and the `OverflowWrap` enum from `./ui/helpers/constants/design-system.ts` to change the overflow wrap of the `Text` component
2022-08-18 19:51:53 +02:00
<Canvas>
2023-05-25 19:35:38 +02:00
<Story id="components-componentlibrary-text--overflow-wrap-story" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2023-04-17 19:17:28 +02:00
import { OverflowWrap } from '../../../helpers/constants/design-system';
2022-08-18 19:51:53 +02:00
<div
style={{
width: 250,
border: '1px solid var(--color-error-default)',
display: 'block',
}}
>
2023-04-17 19:17:28 +02:00
<Text overflowWrap={OverflowWrap.Normal}>
{OverflowWrap.Normal}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
2022-08-18 19:51:53 +02:00
</Text>
2023-04-17 19:17:28 +02:00
<Text overflowWrap={OverflowWrap.BreakWord}>
{OverflowWrap.BreakWord}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
2022-08-18 19:51:53 +02:00
</Text>
</div>;
```
### Ellipsis
Use the boolean `ellipsis` prop to change the if the `Text` component to have an ellipsis.
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-text--ellipsis" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2022-08-18 19:51:53 +02:00
<div
style={{
width: 250,
border: '1px solid var(--color-error-default)',
display: 'block',
}}
>
<Text ellipsis>Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d</Text>
<Text>No Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d</Text>
</div>;
```
### As
Use the `as` prop to change the root html element of the `Text` component
2023-04-03 19:42:37 +02:00
You can also utilize the `ValidTag` enum from `./text.types` to ensure that you are using a valid html element
2022-08-18 19:51:53 +02:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-text--as" />
2022-08-18 19:51:53 +02:00
</Canvas>
```jsx
2023-01-25 20:54:08 +01:00
import { Text } from '../../component-library';
2022-08-18 19:51:53 +02:00
<Text as="dd">dd</Text>
<Text as="div">div</Text>
<Text as="dt">dt</Text>
<Text as="em">em</Text>
<Text as="h1">h1</Text>
<Text as="h2">h2</Text>
<Text as="h3">h3</Text>
<Text as="h4">h4</Text>
<Text as="h5">h5</Text>
<Text as="h6">h6</Text>
<Text as="li">li</Text>
<Text as="p">p</Text>
<Text as="span">span</Text>
<Text as="strong">strong</Text>
2022-10-19 20:09:38 +02:00
<Text as="input" placeholder="input"></Text>
2022-08-18 19:51:53 +02:00
```
Renders the html:
```html
<dd>dd</dd>
<div>div</div>
<dt>dt</dt>
<em>em</em>
<h1>h1</h1>
<h2>h2</h2>
<h3>h3</h3>
<h4>h4</h4>
<h5>h5</h5>
<h6>h6</h6>
<li>li</li>
<p>p</p>
<span>span</span>
<strong>strong</strong>
2022-10-19 20:09:38 +02:00
<input placeholder="input" />
2022-08-18 19:51:53 +02:00
```
2022-12-15 19:49:47 +01:00
### Text Direction
2023-04-03 19:42:37 +02:00
Use the `textDirection` prop and the `TextDirection` enum from `./text.types` to change the text direction of `Text`
2022-12-15 19:49:47 +01:00
<Canvas>
2023-04-03 19:42:37 +02:00
<Story id="components-componentlibrary-text--text-direction-story" />
2022-12-15 19:49:47 +01:00
</Canvas>
```jsx
2023-04-03 19:42:37 +02:00
import { Text, TextDirection } from '../../component-library';
2022-12-15 19:49:47 +01:00
2023-04-03 19:42:37 +02:00
<Text textDirection={TextDirection.LeftToRight}>
2022-12-15 19:49:47 +01:00
This is left to right (ltr) for English and most languages
</Text>
2023-04-03 19:42:37 +02:00
<Text textDirection={TextDirection.RightToLeft}>
2022-12-15 19:49:47 +01:00
This is right to left (rtl) for use with other laguanges such as Arabic. This Enlgish example is incorrect usage.
</Text>
2023-04-03 19:42:37 +02:00
<Text textDirection={TextDirection.Auto}>
2022-12-15 19:49:47 +01:00
Let the user agent decide with the auto option
</Text>
```
2023-04-26 21:46:03 +02:00
### Strong
Using the `as` prop with the value of `strong` will render the `Text` component as a `strong` element and any `strong` emlements used within a `Text` component will be supported with bold styles.
<Canvas>
<Story id="components-componentlibrary-text--strong" />
</Canvas>
```jsx
import { Text } from '../../component-library';
<Text as="strong">
This is an as="strong" demo.
</Text>
<Text>
This is a <strong>strong element</strong> demo.
</Text>
```
2022-08-18 19:51:53 +02:00
### Box Props
2023-01-25 20:51:25 +01:00
Use any valid box props [Box](/?path=/story/components-ui-box--default-story) component props to the Text component.
2022-08-18 19:51:53 +02:00
### Class Name
Adds an additional class to the `Text` component
### Children
The text content of the `Text` component
2023-02-22 18:41:46 +01:00
---
# Converting from `Typography` to `Text`
The `Typography` component has been deprecated in favor of the `Text` component. Below are code examples converting from `Typography` to `Text`.
### Variant
Table below is the 1:1 mapping of `TypographyVariant` to `TextVariant` and the html element that needs to be rendered.
The new `Text` component does not have matching default elements for `TypographyVariant.H5`, `TypographyVariant.H6`, `TypographyVariant.H7` or `TypographyVariant.H8` or `TypographyVariant.H9` variant.
If you need to use these variants, please use the `as` prop to render the correct html element.
| TypographyVariant | Typography Tag | TextVariant | Text Default Tag |
| ---------------------------------------------------------- | -------------- | --------------------- | ---------------- |
| [TypographyVariant.H1](#typographyvarianth1) | h1 | TextVariant.displayMd | h1 |
| [TypographyVariant.H2](#typographyvarianth2) | h2 | TextVariant.headingLg | h2 |
| [TypographyVariant.H3](#typographyvarianth3) | h3 | TextVariant.headingMd | h3 |
| [TypographyVariant.H4](#typographyvarianth4) | h4 | TextVariant.headingSm | h4 |
| [TypographyVariant.H5](#typographyvarianth5) | h5 | TextVariant.bodyMd | p |
| [TypographyVariant.H6](#typographyvarianth6) | h6 | TextVariant.bodySm | p |
| [TypographyVariant.Paragraph](#typographyvariantparagraph) | p | TextVariant.bodyMd | p |
| [TypographyVariant.H7](#typographyvarianth7) | h6 | TextVariant.bodySm | p |
| [TypographyVariant.H8](#typographyvarianth8) | h6 | TextVariant.bodyXs | p |
| [TypographyVariant.H9](#typographyvarianth9) | h6 | TextVariant.bodyXs | p |
#### TypographyVariant.H1
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typography variant={TypographyVariant.H1}>Demo</Typography>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.displayMd}>Demo</Text>;
```
#### TypographyVariant.H2
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H2}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.headingLg}>Demo</Text>;
```
#### TypographyVariant.H3
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H3}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.headingMd}>Demo</Text>;
```
#### TypographyVariant.H4
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H4}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.headingSm}>Demo</Text>;
```
#### TypographyVariant.H5
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H5}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodyMd} as="h6">
Demo
</Text>;
```
#### TypographyVariant.H6
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H6}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodySm} as="h6">
Demo
</Text>;
```
#### TypographyVariant.Paragraph
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.Paragraph}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodyMd}>Demo</Text>;
```
#### TypographyVariant.H7
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H7}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodySm} as="h6">
Demo
</Text>;
```
#### TypographyVariant.H8
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H8}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodyXs} as="h6">
Demo
</Text>;
```
#### TypographyVariant.H9
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
<Typograpghy variant={TypographyVariant.H9}>Demo</Typograpghy>;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
<Text variant={TextVariant.bodyXs} as="h6">
Demo
</Text>;
```
### Align
The prop name `align` has been deprecated in favor of `textAlign`
2023-04-17 19:17:28 +02:00
Values using the `TextAlign` object from `./ui/helpers/constants/design-system.js` remain the same
2023-02-22 18:41:46 +01:00
```jsx
// Before
2023-04-17 19:17:28 +02:00
<Typography align={TEXT_ALIGN.CENTER}>Demo</Typography>;
2023-02-22 18:41:46 +01:00
// After
2023-04-17 19:17:28 +02:00
<Text textAlign={TextAlign.Center}>Demo</Text>;
2023-02-22 18:41:46 +01:00
```
### Box Props
Box props are now integrated with the `Text` component. Valid box props: [Box](/?path=/story/components-ui-box--default-story)
You no longer need to pass these props as an object through `boxProps`
```jsx
// Before
<Typography
boxProps={{
backgroundColor: Color.infoMuted,
borderColor: Color.infoDefault,
padding: 4,
borderRadius: 4,
}}
color={Color.textDefault}
>
Demo
</Typography>;
// After
<Text
backgroundColor={Color.infoMuted}
borderColor={Color.infoDefault}
padding={4}
borderRadius={4}
color={Color.textDefault}
>
Demo
</Text>;
```