DEV Community

James
James

Posted on

Typescript design token docs in Storybook

Storybook is great for documenting UI components but what about data structures such as a themes and design tokens? Here's a super quick way to add design token documentation into your Storybook.

Using MDX and ArgsTable

In designtoken.stories.mdx:

import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs/blocks';
import { Theme, Breakpoints } from './helpers';

<Meta title="Design Tokens/Theme" />

### Theme

<ArgsTable of={Theme} />

#### Breakpoint Device Types

<ArgsTable of={Breakpoints} />

<Canvas>
  <Story name="Theme">
    <span>See Docs tab</span>
  </Story>
</Canvas>
Enter fullscreen mode Exit fullscreen mode

Where helper.tsx is:

import { ThemeType, theme } from '../DesignTokens';

export const Theme: (Theme: ThemeType) => void = () => {};

export const Breakpoints: (Breakpoints: typeof theme.Breakpoints) => void = () => {};
Enter fullscreen mode Exit fullscreen mode

This super simple approach allows us describe important contracts throughout our design system implementation, without the need to manually write and maintain that documentation. Below is a screenshot of how that might look.

Screenshot of Storybook documentation showing properties and type information

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay