Logo

dev-resources.site

for different kinds of informations.

Manual setup for a minimal Storybook

Published at
5/13/2024
Categories
storybook
react
designsystem
typescript
Author
dannyhw
Author
7 person written this
dannyhw
open
Manual setup for a minimal Storybook

If you're having issues with the cli or you just want to know what you're installing then this is for you. I've put together what I consider the minimal setup. From there you can browse addons and docs to see how to enhance your setup.

Heres a video of me following the same steps:

I'll use bun here but replace with any package manager.

Also this example uses react with vite. If you're using a different framework you can swap @storybook/react and @storybook/react-vite for the alternative.

Packages

Heres the minimal packages you'll need to get started with a react storybook.



bun add @storybook/react @storybook/react-vite @storybook/addon-essentials storybook


Enter fullscreen mode Exit fullscreen mode

Scripts

Add to your scripts in package.json



"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"


Enter fullscreen mode Exit fullscreen mode

Configuration files

Add a .storybook folder with a main.ts and preview.ts.

main.ts

Find the docs here



// .storybook/main.ts
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
  stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
  addons: ["@storybook/addon-essentials"],
  framework: {
    name: "@storybook/react-vite",
    options: {},
  },
  docs: {
    autodocs: "tag",
  },
};
export default config;


Enter fullscreen mode Exit fullscreen mode

preview.ts

Start here to learn about the preview



// .storybook/preview.ts
import type { Preview } from "@storybook/react";

const preview: Preview = {
  parameters: {
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
  },
};

export default preview;


Enter fullscreen mode Exit fullscreen mode

Example story

Lets add a component file



// src/Button.tsx
export const Button = ({ text }: { text: string }) => {
  return <button>{text}</button>;
};



Enter fullscreen mode Exit fullscreen mode

Then we create a stories file and import it there.

Look here to learn about writing stories



// src/Button.stories.tsx
import { Button } from "./Button";

export default {
  component: Button,
};

export const Primary = {
  args: {
    text: "Primary Button",
  },
};



Enter fullscreen mode Exit fullscreen mode

Run it!

Now run this to see your storybook in action.



bun run storybook


Enter fullscreen mode Exit fullscreen mode

The final product should look like this:

screenshot of the final storybook

All done!

Thats the basics, now I recommend you explore the docs to learn more about how to customize storybook for your needs. Especially look into interactions they are really nice.

Find me here:
twitter: @Danny_H_W
github: dannyhw

storybook Article's
30 articles in total
Favicon
Integrate Storybook with VueJS
Favicon
Run Storybook with NX Expo and React Native Paper
Favicon
Storybook for UI Components: Build, Test, and Document Your React Components in Isolation
Favicon
Integrating Storybook into an existing next.js project
Favicon
How to customize storybook (custom theme and layout option)?
Favicon
How to add custom fonts and viewports in storybook?
Favicon
Made AI-Powered Interactive Storybook Generator with Next.js, Gemini and Elevenlabs ️‍🔥
Favicon
Storybook: The Workshop for Modern Frontends
Favicon
SanS-UI v0.0.1 Quick Start!
Favicon
SanS-UI Released v0.0.1
Favicon
Using Storybook with Angular and Vite 🎨
Favicon
Documentation of components in React with TypeScript using Storybook
Favicon
Documentação de componentes em React com Typescript usando Storybook
Favicon
Tutorial de utilização Storybook
Favicon
Component Driven Development with Storybook React Native
Favicon
Storybook: Stories for Smart Components
Favicon
Tutorial de instalação do Storybook com Tailwind
Favicon
📚 How to Handle Multiple MSW Handlers in Storybook Stories
Favicon
Beginner Guide to React Storybook
Favicon
Comparing Vue Component Documentation tools
Favicon
How to stop Storybook opening a new webpage on start (automatically with zsh)
Favicon
Manual setup for a minimal Storybook
Favicon
Setup Your Universal App with React Native, Expo Router, Tamagui, and Storybook
Favicon
Configuring Storybook in Your Nuxt Project
Favicon
Documentando seus componentes no Storybook
Favicon
Build component library using Storybook
Favicon
Integrating Storybook with PrimeNG and TailwindCSS in an Nx Workspace
Favicon
Storybook setup: Virtual Screen Reader with Web Components
Favicon
Simple setup: Virtual Screen Reader in Storybook
Favicon
Using fonts in Storybook for Next.JS and Tailwind Projects

Featured ones: