npm i --save-dev @storybook/react @types/storybook__react awesome-typescript-loader react-docgen-typescript-webpack-plugin
See their for more.
Plugins
In Storybook we have something called addons.
Recommended plugins
actions: can be used to display data received by event handlers.
info: will show additional information for stories.
knobs: allow you to edit React props dynamically using the Storybook UI.
jsx: shows the JSX of the component.
All of them can be installed by running:
npm i --save-dev @storybook/addon-actions @types/storybook__addon-actions
npm i --save-dev @storybook/addon-info @types/storybook__addon-info
npm i --save-dev @storybook/addon-knobs @types/storybook__addon-knobs
npm i --save-dev storybook-addon-jsx
Configuration
We will proceed to create a config folder only for Storybook in the root of our project. It will look like this:
The config.js file will contain all the configuration. Is the one responsible to load all the stories:
import { configure, addDecorator, setAddon } from "@storybook/react";
import "../src/styles.css";
import { setOptions } from "@storybook/addon-options";
import { withKnobs } from "@storybook/addon-knobs";
import JSXAddon from 'storybook-addon-jsx';
setAddon(JSXAddon);
// Load all the stories
const req = require.context("../src/components", true, /\.story\.tsx$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
// Default decorators
addDecorator(withKnobs);
// Addon-options configuration
setOptions({
name: "shark-events-client",
addonPanelInRight: false,
sortStoriesByKind: true,
sidebarAnimations: false
});
configure(loadStories, module);
Finally, we will need to set our webpack.config.js file. Because we are using TypeScript, our info addon will need to import a plugin called react-docgen-typescript-webpack-plugin: