packages/grafana-ui/src/components/Text/Text.mdx
import { Meta, Canvas, ArgTypes } from '@storybook/blocks'; import { Text } from './Text'; import { TextLink } from '../Link/TextLink.tsx'; import { Basic } from './Text.story.tsx'; import { Tooltip } from '../Tooltip/Tooltip'; import { ExampleFrame } from '../../utils/storybook/ExampleFrame';
<Meta title="MDX|Text" component={Text} />The Text component can be used to apply typography styles in a simple way, without the need of extra css.
In this documentation you can find:
variant prop to modify its style instead.tabular prop when numbers should have a fixed width, such as in tables.element prop because of its appearance, use it to organize the structure of the page.error, success, disabled and so on.code variant for anything other than code snippets.The content of the text should be written according to the Grafana writing style guide.
The following is the default behaviour and so, it will be applied according to its type.
The Text component is mainly comprised by itself. In occasions, the Text component can have another Text or TextLink component as a child.
<ExampleFrame> <Text color="primary" element="p"> {'If you need more help of how to write in Grafana you can go to our '} <TextLink href="https://grafana.com/docs/writers-toolkit/" external> {'Writer’s Toolkit'} </TextLink> </Text> </ExampleFrame> <ExampleFrame> <Text color="primary" element="p"> {'And Forrest Gump said: '} <Text italic>{"Life is like a box of chocolates. You never know what you're gonna get."}</Text> </Text> </ExampleFrame>The Text component can be truncated. However, the Text component element rendered by default (no value set in element prop) is a <span>. As this is an inline container that must have a parent, which can be another Text component or not, the truncation must be applied to this parent element.
overflow: hidden, text-overflow: ellipsis and whiteSpace: 'nowrap' to it. In this case, the user should wrap up this container with a Tooltip, so when the text is truncated its content can still be seen hovering on the text.h1 heading per page.h1 has the rank 1 while h6 heading has the rank 6. For example, h1 can be used in the page heading, h2 for the titles of the sections and h3 for the subsections.h2 should not be followed by an h5 but an h2 can follow an h5 if this is closing the previous section. Skipping heading ranks should be avoided where possible as it can be confusing.