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.
## Props
The `Text` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
### Variant
Use the `variant` prop and the `TextVariant` enum from `./ui/helpers/constants/design-system.js` to change the font size of the component.
`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)
```jsx
import { Text } from '../../component-library';
import { TextVariant } from '../../../helpers/constants/design-system';
display-mdheading-lgheading-mdheading-smbody-lg-mediumbody-mdbody-md-boldbody-smbody-sm-boldbody-xsinherit
```
### Color
Use the `color` prop and the `TextColor` enum from `./ui/helpers/constants/design-system.js` to change the color of the `Text` component.
```jsx
import { Text } from '../../component-library';
import { TextColor, BackgroundColor } from '../../../helpers/constants/design-system';
text-default
text-alternative
text-muted
primary-default
primary-inverse
error-default
error-inverse
success-default
success-inverse
warning-default
warning-inverse
info-default
info-inverse
```
### Font Weight
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:
- `FontWeight.Normal` = `normal` || `400`
- `FontWeight.Medium` = `medium` || `500`
- `FontWeight.Bold` = `bold` || `700`
```jsx
import { Text } from '../../component-library';
import { FontWeight } from '../../../helpers/constants/design-system';
normal
medium
bold
```
### Font Style
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:
- `FontStyle.Normal`
- `FontStyle.Italic`
```jsx
import { Text } from '../../component-library';
import { FontStyle } from '../../../helpers/constants/design-system';
normal
bold
```
### Text Transform
Use the `textTransform` prop and the `TextTransform` enum from `./ui/helpers/constants/design-system.ts` to change the text alignment of the `Text` component
```jsx
import { Text } from '../../component-library';
import { TextTransform } from '../../../helpers/constants/design-system';
uppercase
lowercase
capitalize
```
### Text Align
Use the `textAlign` prop and the `TextAlign` enum from `./ui/helpers/constants/design-system.ts` to change the text alignment of the `Text` component
```jsx
import { Text } from '../../component-library';
import { TextAlign } from '../../../helpers/constants/design-system';
left
center
right
justify
end
```
### Overflow Wrap
Use the `overflowWrap` prop and the `OverflowWrap` enum from `./ui/helpers/constants/design-system.ts` to change the overflow wrap of the `Text` component
```jsx
import { Text } from '../../component-library';
import { OverflowWrap } from '../../../helpers/constants/design-system';
;
```
### Ellipsis
Use the boolean `ellipsis` prop to change the if the `Text` component to have an ellipsis.
```jsx
import { Text } from '../../component-library';
;
```
### As
Use the `as` prop to change the root html element of the `Text` component
You can also utilize the `ValidTag` enum from `./text.types` to ensure that you are using a valid html element
```jsx
import { Text } from '../../component-library';
dddivdtemh1h2h3h4h5h6lipspanstrong
```
Renders the html:
```html
dd
div
dt
em
h1
h2
h3
h4
h5
h6
li
p
spanstrong
```
### Text Direction
Use the `textDirection` prop and the `TextDirection` enum from `./text.types` to change the text direction of `Text`
```jsx
import { Text, TextDirection } from '../../component-library';
This is left to right (ltr) for English and most languages
This is right to left (rtl) for use with other laguanges such as Arabic. This Enlgish example is incorrect usage.
Let the user agent decide with the auto option
```
### Box Props
Use any valid box props [Box](/?path=/story/components-ui-box--default-story) component props to the Text component.
### Class Name
Adds an additional class to the `Text` component
### Children
The text content of the `Text` component
---
# 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';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo;
```
#### TypographyVariant.H2
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo;
```
#### TypographyVariant.H3
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo;
```
#### TypographyVariant.H4
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo;
```
#### TypographyVariant.H5
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo
;
```
#### TypographyVariant.H6
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo
;
```
#### TypographyVariant.Paragraph
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo;
```
#### TypographyVariant.H7
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo
;
```
#### TypographyVariant.H8
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo
;
```
#### TypographyVariant.H9
Requires `as="h6"` prop for 1:1 conversion
```jsx
// Before
import { TypographyVariant } from '../../../helpers/constants/design-system';
Demo;
// After
import { TextVariant } from '../../../helpers/constants/design-system';
Demo
;
```
### Align
The prop name `align` has been deprecated in favor of `textAlign`
Values using the `TextAlign` object from `./ui/helpers/constants/design-system.js` remain the same
```jsx
// Before
Demo;
// After
Demo;
```
### 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
Demo
;
// After
Demo
;
```