import type { Meta, StoryObj } from '@storybook/react' import { tokens } from '../../theme/tokens/tokens' import { viewports } from '../../utils/viewports' import { colorVariants } from './foregroundColors' import { Typography } from './Typography' import { allVariants, typographyVariants } from './variants' const colorVariantsKeys = Object.keys(colorVariants) const variantsKeys = Object.keys(allVariants) const findTokenValue = (tokenName: string) => { for (const category of Object.values(tokens)) { if (category[tokenName]) { return { light: category[tokenName].light.replace('var(--', '').replace(')', ''), dark: category[tokenName].dark.replace('var(--', '').replace(')', ''), } } } return null } const meta: Meta = { component: Typography, title: 'Typography/Typography', parameters: { chromatic: { viewports: [viewports.all] }, }, argTypes: { variant: { description: 'Defines the style of the text, such as header, body, code, or display.
Available variants:', control: { type: 'select', labels: variantsKeys, }, value: 'body', options: variantsKeys, table: { type: { summary: variantsKeys.join(' | ') }, defaultValue: { summary: 'body' }, }, }, children: { control: 'text', description: 'The content to be rendered. Can be a string, or a React element when `asChild` is true.', table: { type: { summary: 'string | React.ReactNode' }, }, }, color: { description: 'Allows you to set the text color. The values for this prop correspond to blocks design system tokens.
Available colors:', control: { type: 'select', labels: colorVariantsKeys, }, value: 'foreground', options: colorVariantsKeys, table: { type: { summary: colorVariantsKeys.join(' | ') }, defaultValue: { summary: 'foreground' }, }, }, asChild: { description: 'Renders the Typography component as the specified child element, allowing more control over the rendered HTML element.', control: false, table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, }, } export default meta type Story = StoryObj export const Default: Story = { args: { children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', }, } export const Display: Story = { render: (_args) => (
Display XL Display L Display M Display S Display XS
), } export const Headers: Story = { render: (_args) => (
TypographyH1 TypographyH2 TypographyH3 TypographyH4 TypographyH5 TypographyH6
), } export const Body: Story = { render: (_args) => (
Body XL Body Semi XL Body L Body Semi L Body M Body Semi M Body S Body Semi S Body XS Body Semi XS
), } export const Code: Story = { render: (_args) => (
Code XXL Code XL Code L Code Code S Code XS
), } export const Composition = (_args: any) => (
This is a h2 styled span using the asChild prop This is a h2 styled span using the typographyVariants helper This is a body-xl styled link colored anchor tag using the asChild prop This is a body-xl styled link colored anchor tag using the typographyVariants helper
) export const Colors = (_args: any) => ( <> Foreground Link Brand Muted Muted More Success Error Warning Progress ) export const AllColors = (_args: any) => (
{Object.entries(colorVariants).map(([key, value]) => { const tokenName = value.replace('text-', '') const tokenValue = findTokenValue(tokenName) if (!tokenValue) { return null } return (
{key} --{tokenName} {tokenValue && (
Light {tokenValue.light}
Dark {tokenValue.dark}
)}
) })}
) Colors.parameters = { themes: { defaultTheme: 'light', disable: true, }, } export const Muted: Story = { args: { ...Default.args, color: 'muted', children: 'This is a muted paragraph.', }, } export const AsDiv: Story = { args: { ...Default.args, asChild: true, variant: 'h5', children:
16
, }, } export const AsSpan: Story = { args: { ...Default.args, asChild: true, children: ( This looks like a paragraph, but it is actually a span. ), }, } export const AllVariants: Story = { render: (_args) => (
TypographyH1 TypographyH2 TypographyH3 TypographyH4 TypographyH5 TypographyH6 Body XL Body Semi XL Body L Body Semi L Body M Body Semi M Body S Body Semi S Body XS Body Semi XS Code XXL Code XL Code L Code Code S Code XS
), }