DEV Community

Alex Spinov
Alex Spinov

Posted on

Storybook Has a Free UI Development Environment — Build and Test Components in Isolation

Why Storybook?

Storybook lets you develop UI components in isolation — outside your app. Each component gets a "story" showing its states. Perfect for design systems.

npx storybook@latest init
npm run storybook
Enter fullscreen mode Exit fullscreen mode

Write a Story

// Button.stories.tsx
import type { Meta, StoryObj } from '@storybook/react'
import { Button } from './Button'

const meta: Meta<typeof Button> = {
  component: Button,
  tags: ['autodocs'],
}
export default meta

type Story = StoryObj<typeof Button>

export const Primary: Story = {
  args: { variant: 'primary', children: 'Click me' },
}

export const Secondary: Story = {
  args: { variant: 'secondary', children: 'Cancel' },
}

export const Disabled: Story = {
  args: { variant: 'primary', children: 'Submit', disabled: true },
}

export const Loading: Story = {
  args: { variant: 'primary', children: 'Saving...', loading: true },
}
Enter fullscreen mode Exit fullscreen mode

Interactive Tests

import { within, userEvent, expect } from '@storybook/test'

export const ClickTest: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement)
    const button = canvas.getByRole('button')
    await userEvent.click(button)
    await expect(button).toHaveTextContent('Clicked!')
  },
}
Enter fullscreen mode Exit fullscreen mode

Auto-Generated Docs

Storybook reads your TypeScript props and generates documentation automatically — every prop, every type, every default value.

Visual Regression Testing

npm install @storybook/addon-storyshots
Enter fullscreen mode Exit fullscreen mode

Capture screenshots of every story. On next run, compare pixel-by-pixel.

Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.

Top comments (0)