I am actually trying to add a button(icon) on the main storybook toolbar. Currently the toolbar has few actions as shown below,
Similar I want to append a button with some actions like below,
I see different examples online with latest versions of storybook but couldn't find something that works for my use case. Currently in our project we are using config.js
(which is preview.js
in new versions) file in which there is a configuration related to themes using addParameter
api. But when I tried adding the same to create a button on the toolbar, nothing seems to be working.
// config.js
// Below is the existing configuration
import { configure, addDecorator, addParameters } from '@storybook/react';
// other code
addParameters({
options: {
theme: myTheme
},
backgrounds: [
{ name: 'white', value: '#fff', default: true },
{ name: 'inverse', value: '#16325c' }
]
});
Is there a way to add one more action to the main toolbar and perform action based on click event?
Storybook version which I am currently using: v5
References:
in case the button you want to add will trigger some custom action, the best way to go (in storybook 6) is to write a very small addon:
.storybook/addons-myButtonAddon/register.js
:Please note that React is used here for Storybook only, since Storybook is build in React. This is independent of the actual framework you are building your components with.
.storybook/main.js
:@storybook/manager-webpack5
to your package.json. file vianpm i -D @storybook/manager-webpack5
Then the button should appear in the toolbar, executing the action defined in the click listener.
Instead of the button text you might add an SVG to have a nice icon on the button.
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> ... </svg>