# Storybook ![Storybook logo](/shared/storybook-logo.png) Storybook is a development environment for UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components. ## How to Use Storybook in an Nx Repo ### Add the Storybook plugin ```bash yarn add --dev @nrwl/storybook ``` ### Generating Storybook Configuration You can generate Storybook configuration for an individual project with this command: ```bash nx g @nrwl/react:storybook-configuration project-name ``` If there's no `.storybook` folder at the root of the workspace, one is created. ```treeview / ├── .storybook/ │ ├── main.js │ ├── tsconfig.json │ └── webpack.config.js ├── apps/ ├── libs/ ├── nx.json ├── package.json ├── README.md └── etc... ``` Also, a project-specific `.storybook` folder is added in the root of the project. ```treeview / ├── .storybook/ │ ├── main.js │ ├── config.js │ ├── tsconfig.json │ └── webpack.config.js ├── src/ ├── README.md ├── tsconfig.json └── etc... ``` ### Running Storybook Serve Storybook using this command: ```bash nx run project-name:storybook ``` ### Run Cypress Tests Against a Storybook Instance Both `storybook-configuration` generator gives the option to set up an e2e Cypress app that is configured to run against the project's Storybook instance. To launch Storybook and run the Cypress tests against the iframe inside of Storybook: ```bash nx run project-name-e2e:e2e ``` The url that Cypress points to should look like this: `'/iframe.html?id=buttoncomponent--primary&args=text:Click+me!;padding;style:default'` - `buttoncomponent` is a lowercase version of the `Title` in the `*.stories.ts` file. - `primary` is the name of an individual story. - `style=default` sets the `style` arg to a value of `default`. Changing args in the url query parameters allows your Cypress tests to test different configurations of your component. You can [read the documentation](https://storybook.js.org/docs/react/writing-stories/args#setting-args-through-the-url) for more information. ### Example Files **\*.stories.tsx file** ```typescript import { Story, Meta } from '@storybook/react'; import { Button, ButtonProps } from './button'; export default { component: Button, title: 'Button', } as Meta; const Template: Story = (args) =>