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-md heading-lg heading-md heading-sm body-lg-medium body-md body-md-bold body-sm body-sm-bold body-xs inherit ``` ### 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 `FONT_WEIGHT` object from `./ui/helpers/constants/design-system.js` to change the font weight of the `Text` component. There are 3 font weights: - `FONT_WEIGHT.NORMAL` = `normal` || `400` - `FONT_WEIGHT.MEDIUM` = `medium` || `500` - `FONT_WEIGHT.BOLD` = `bold` || `700` ```jsx import { Text } from '../../component-library'; import { FONT_WEIGHT } from '../../../helpers/constants/design-system'; normal medium bold ``` ### Font Style Use the `fontStyle` prop and the `FONT_STYLE` object from `./ui/helpers/constants/design-system.js` to change the font style of the `Text` component. There are 2 font styles: - `FONT_STYLE.NORMAL` - `FONT_STYLE.ITALIC` ```jsx import { Text } from '../../component-library'; import { FONT_STYLE } from '../../../helpers/constants/design-system'; normal bold ``` ### Text Transform Use the `textTransform` prop and the `TEXT_TRANSFORM` object from `./ui/helpers/constants/design-system.js` to change the text alignment of the `Text` component ```jsx import { Text } from '../../component-library'; import { TEXT_TRANSFORM } from '../../../helpers/constants/design-system'; uppercase lowercase capitalize ``` ### Text Align Use the `textAlign` prop and the `TEXT_ALIGN` object from `./ui/helpers/constants/design-system.js` to change the text alignment of the `Text` component ```jsx import { Text } from '../../component-library'; import { TEXT_ALIGN } from '../../../helpers/constants/design-system'; left center right justify end ``` ### Overflow Wrap Use the `overflowWrap` prop and the `OVERFLOW_WRAP` object from `./ui/helpers/constants/design-system.js` to change the overflow wrap of the `Text` component ```jsx import { Text } from '../../component-library'; import { OVERFLOW_WRAP } from '../../../helpers/constants/design-system';
{OVERFLOW_WRAP.NORMAL}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d {OVERFLOW_WRAP.BREAK_WORD}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
; ``` ### Ellipsis Use the boolean `ellipsis` prop to change the if the `Text` component to have an ellipsis. ```jsx import { Text } from '../../component-library';
Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d No Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
; ``` ### 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'; dd div dt em h1 h2 h3 h4 h5 h6 li p span strong ``` Renders the html: ```html
dd
div
dt
em

h1

h2

h3

h4

h5
h6
  • li
  • p

    span strong ``` ### 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 and using the `TEXT_ALIGN` 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 ; ```