Text
Text provides an ergonomic API for rendering text. It includes built-in support for Canvas type tokens.
Usage Guidance
Coming soon!
Examples
Basic Example
Text
is built on top of Box
and supports a multitude of
style props including spacing props such
as margin
and padding
, as well as text styling props such as fontSize
and fontWeight
.
Text
renders a <span>
element by default. You may override the rendered element using the as
prop.
Text as h4
Text styled using style props
Text styled using type token level
Type Level and Variant
Text
includes built-in support for Canvas type tokens via the typeLevel
and
variant
props.
typeLevel
hooks into the Canvas type hierarchy.
Small Body level text
variant
allows you to layer additional styling to aid users'
understanding of the text being rendered.
Error text
Component API
Text
This is a generic base component intended to render any text. It's built on top of the
component. It also has
typeLevel
and variant
style props that simplify navigating
our type hierarchy and using Canvas type
tokens. By default, it renders a semantic
span
element, but you can adjust this as needed with the as
prop.
The type hierarchy is organized into four levels, which correspond to our Canvas type levels.
title
: Intended to be used for large page titles.heading
: Intended to be used for headings and large text.body
: Intended to be used for standard body text.subtext
: Intended to be used for small subtext content or in tight spaces.
Each level has three sizes: large
, medium
, and small
.
You can provide any level and size to the typeLevel
prop, and it will apply the correct styles
accordingly. In the example below we're providing the subtext
level and small
size to the
component with the value subtext.small
.
import { Text } from '@workday/canvas-kit-react/text';const CustomErrorText = () => (<Text typeLevel="subtext.small" variant="error">Error Text</Text>);
Layout Component
Text
supports all props from thelayout component.
Props
Props extend from span. Changing the as
prop will change the element interface.
Name | Type | Description | Default |
---|---|---|---|
typeLevel | | Type token as string with level and size separated by dot. These values map to our Canvas type levels.
| |
variant | keyof | Type variant token names:
| |
children | ReactNode | ||
as | React.ElementType | Optional override of the default element used by the component. Any valid tag or Component. If you provided a Component, this component should forward the ref using Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care. | span |
ref | React.Ref | Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If |
Can't Find What You Need?
Check out our FAQ section which may help you find the information you're looking for.
FAQ Section