Convert Figma logo to code with AI

storybookjs logostorybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation

83,945
9,214
83,945
2,006

Top Related Projects

Easy to maintain open source documentation websites.

Isolated React component development environment with a living style guide

23,600

✍ It has never been so easy to document your things!

Sandbox for developing and testing UI components in isolation

Quick Overview

Storybook is an open-source tool for developing UI components in isolation for React, Vue, Angular, and more. It makes building stunning UIs organized and efficient by allowing developers to browse a component library, view the different states of each component, and interactively develop and test components.

Pros

  • Enhances component-driven development workflow
  • Provides a sandbox to build components in isolation
  • Supports multiple frontend frameworks and libraries
  • Offers a rich ecosystem of addons for extended functionality

Cons

  • Can add complexity to the development setup
  • Learning curve for new users
  • May increase build times for large projects
  • Some addons may not be compatible with all frameworks

Code Examples

  1. Basic Storybook story for a React button component:
import React from 'react';
import { Button } from './Button';

export default {
  title: 'Components/Button',
  component: Button,
};

export const Primary = () => <Button primary>Primary Button</Button>;
export const Secondary = () => <Button>Secondary Button</Button>;
  1. Using args to control component props:
import React from 'react';
import { Button } from './Button';

export default {
  title: 'Components/Button',
  component: Button,
  argTypes: {
    backgroundColor: { control: 'color' },
  },
};

const Template = (args) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
  primary: true,
  label: 'Button',
};
  1. Adding actions to track events:
import React from 'react';
import { Button } from './Button';
import { action } from '@storybook/addon-actions';

export default {
  title: 'Components/Button',
  component: Button,
};

export const WithAction = () => (
  <Button onClick={action('button-click')}>
    Click me!
  </Button>
);

Getting Started

To get started with Storybook:

  1. Install Storybook in your project:

    npx sb init
    
  2. Run Storybook:

    npm run storybook
    
  3. Create a new story file (e.g., Button.stories.js) in the stories directory:

    import React from 'react';
    import { Button } from './Button';
    
    export default {
      title: 'Components/Button',
      component: Button,
    };
    
    export const Primary = () => <Button primary>Primary Button</Button>;
    
  4. View your story in the Storybook UI by running the Storybook development server.

Competitor Comparisons

Easy to maintain open source documentation websites.

Pros of Docusaurus

  • Easier to set up and configure for documentation-focused projects
  • Built-in search functionality and internationalization support
  • Better suited for creating full documentation websites with multiple pages

Cons of Docusaurus

  • Less flexible for showcasing UI components and design systems
  • Limited customization options compared to Storybook's extensive addon ecosystem
  • Primarily focused on documentation, lacking advanced component development features

Code Comparison

Docusaurus configuration (docusaurus.config.js):

module.exports = {
  title: 'My Project',
  tagline: 'A website for my project',
  url: 'https://myproject.com',
  baseUrl: '/',
  onBrokenLinks: 'throw',
  favicon: 'img/favicon.ico',
  organizationName: 'myorg',
  projectName: 'myproject',
};

Storybook configuration (.storybook/main.js):

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
  framework: '@storybook/react',
};

Both tools serve different purposes: Docusaurus excels at creating documentation websites, while Storybook is better suited for developing and showcasing UI components. Choose based on your project's primary focus and requirements.

Isolated React component development environment with a living style guide

Pros of React Styleguidist

  • Simpler setup and configuration process
  • Better support for documenting React components with Markdown
  • Automatic prop type documentation generation

Cons of React Styleguidist

  • Less extensive ecosystem and addon support
  • Limited support for non-React frameworks
  • Fewer built-in features for testing and accessibility checks

Code Comparison

React Styleguidist:

import React from 'react';
import Button from './Button';

export default function ButtonExample() {
  return <Button>Click me</Button>;
}

Storybook:

import React from 'react';
import { Button } from './Button';

export default {
  title: 'Example/Button',
  component: Button,
};

const Template = (args) => <Button {...args} />;
export const Primary = Template.bind({});
Primary.args = {
  children: 'Click me',
};

React Styleguidist focuses on creating a styleguide with examples and documentation, while Storybook provides a more structured approach to component development and testing. Styleguidist's setup is generally simpler, but Storybook offers more advanced features and broader framework support. The code examples show how Styleguidist uses standard React components for examples, while Storybook employs a specific story format with additional configuration options.

23,600

✍ It has never been so easy to document your things!

Pros of Docz

  • Simpler setup and configuration process
  • Built-in support for MDX, allowing easy mixing of documentation and live code examples
  • Lightweight and faster build times for smaller projects

Cons of Docz

  • Less extensive ecosystem and plugin support
  • Fewer built-in features and customization options
  • Limited theming capabilities compared to Storybook's robust theming system

Code Comparison

Docz configuration:

// doczrc.js
export default {
  title: 'My Component Library',
  description: 'Documentation for my React components',
  base: '/docs',
}

Storybook configuration:

// .storybook/main.js
module.exports = {
  stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
};

Both Storybook and Docz are popular tools for documenting and showcasing components, but they cater to different needs. Storybook offers a more comprehensive solution with extensive features and a large ecosystem, making it suitable for complex projects and teams. Docz, on the other hand, provides a simpler, more lightweight approach that can be beneficial for smaller projects or those primarily focused on documentation with code examples.

Sandbox for developing and testing UI components in isolation

Pros of React Cosmos

  • Lightweight and faster to set up compared to Storybook
  • Better integration with React's context API and hooks
  • More flexible fixture system for component testing

Cons of React Cosmos

  • Smaller community and ecosystem than Storybook
  • Less extensive documentation and fewer learning resources
  • Fewer built-in addons and integrations

Code Comparison

React Cosmos:

// cosmos.decorator.js
import { Decorator } from 'react-cosmos/react';

export default ({ children }) => (
  <ThemeProvider theme={lightTheme}>{children}</ThemeProvider>
);

Storybook:

// preview.js
import { ThemeProvider } from 'styled-components';
import { lightTheme } from './themes';

export const decorators = [
  (Story) => (
    <ThemeProvider theme={lightTheme}>
      <Story />
    </ThemeProvider>
  ),
];

Both React Cosmos and Storybook are powerful tools for developing and testing UI components in isolation. React Cosmos offers a more lightweight and flexible approach, particularly well-suited for React-specific projects. It excels in working with React's context and hooks, and provides a versatile fixture system.

Storybook, on the other hand, boasts a larger community, more extensive documentation, and a wider range of addons and integrations. It's generally considered more feature-rich and has better support for various frameworks beyond React.

The code comparison shows how both tools allow for similar functionality in terms of applying global decorators or wrappers to components, with slight differences in syntax and configuration.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Storybook

Build bulletproof UI components faster


Build Status on CircleCI codecov License
Storybook Community Backers on Open Collective Sponsors on Open Collective Official Twitter Handle OpenSSF Scorecard

Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and documentation. Find out more at https://storybook.js.org!

View README for:
latest next

Table of contents

Getting Started

Visit Storybook's website to learn more about Storybook and to get started.

Documentation

Documentation can be found on Storybook's docs site.

Examples

View Component Encyclopedia to see how leading teams use Storybook.

Use storybook.new to quickly create an example project in Stackblitz.

Storybook comes with a lot of addons for component design, documentation, testing, interactivity, and so on. Storybook's API makes it possible to configure and extend in various ways. It has even been extended to support React Native, Android, iOS, and Flutter development for mobile.

Community

For additional help, share your issue in the repo's GitHub Discussions.

Projects

Supported Frameworks

RendererDemo
ReactStorybook demoReact
AngularStorybook demoAngular
Vue 3Storybook demoVue 3
Web componentsStorybook demoSvelte
React NativeReact Native
HTMLStorybook demoHTML
EmberEmber
SvelteStorybook demoSvelte
PreactStorybook demoPreact
QwikQwik
SolidJSSolidJS
Android, iOS, FlutterNative

Addons

Addons
a11yTest components for user accessibility in Storybook
actionsLog actions as users interact with components in the Storybook UI
backgroundsLet users choose backgrounds in the Storybook UI
cssresourcesDynamically add/remove CSS resources to the component iframe
design assetsView images, videos, and weblinks alongside your story
docsAdd high quality documentation to your components
eventsInteractively fire events to components that respond to EventEmitter
google-analyticsReports google analytics on stories
graphqlQuery a GraphQL server within Storybook stories
jestView the results of components' unit tests in Storybook
linksCreate links between stories
measureVisually inspect the layout and box model within the Storybook UI
outlineVisually debug the CSS layout and alignment within the Storybook UI
query paramsMock query params
storysourceView the code of your stories within the Storybook UI
viewportChange display sizes and layouts for responsive components using Storybook

See Addon / Framework Support Table

To continue improving your experience, we have to eventually deprecate or remove certain addons in favor of new and better tools.

If you're using info/notes, we highly recommend you migrate to docs instead, and here is a guide to help you.

If you're using contexts, we highly recommend you migrate to toolbars and here is a guide to help you.

If you're using addon-storyshots, we highly recommend you migrate to the Storybook test-runner and here is a guide to help you.

Badges & Presentation materials

We have a badge! Link it to your live Storybook example.

Storybook

[![Storybook](https://cdn.jsdelivr.net/gh/storybookjs/brand@main/badge/badge-storybook.svg)](link to site)

If you're looking for material to use in your Storybook presentation, such as logos, video material, and the colors we use, you can find it all on our brand repo.

Community

Contributing

Contributions to Storybook are always welcome!

  • 📥 Pull requests and 🌟 Stars are always welcome.
  • Read our contributing guide to get started, or find us on Discord, we will take the time to guide you.

Looking for a first issue to tackle?

  • We tag issues with Good First Issue when we think they are well suited for people who are new to the codebase or OSS in general.
  • Talk to us, we'll find something that suits your skills and learning interest.

Development scripts

Storybook is organized as a monorepo. Useful scripts include:

yarn start

Runs a sandbox template storybook with test stories

yarn task

As above, but gives you options to customize the sandbox (e.g. selecting other frameworks)

yarn lint

boolean check if code conforms to linting rules - uses remark & eslint

  • yarn lint:js - will check js
  • yarn lint:md - will check markdown + code samples
  • yarn lint:js --fix - will automatically fix js

yarn test

boolean check if unit tests all pass - uses jest

  • yarn run test --core --watch - will run core tests in watch-mode

Sponsors

Become a sponsor to have your logo and website URL on our README on Github. [Become a sponsor]

Backers

By making a recurring donation, you can support us and our work. [Become a backer]

License

MIT

-the end-

NPM DownloadsLast 30 Days