Integrate Vuetify and Storybook
Vuetify is a Vue-based component library designed with Google's Material Design spec. This recipe shows you how to get the most out of Vuetify in Storybook.
To get started, you'll need to add Vuetify’s fontloader and plugin to your Storybook configuration.
To do this, add the following to your
registerPlugins loads Vuetify’s fonts and registers all of its components with Storybook’s Vue app.
Next, you will need to wrap your stories in Vuetify's
v-app component in order to use some of its larger layout components like
To do this, create a component in
Now create a storybook decorator to wrap your stories in your StoryWrapper component.
Below I created a new file in
Now, give this decorator to Storybook in your
Vuetify comes out of the box with a light and dark theme that you can override or add to. To get the most out of your stories, you should have a way to toggle between all of your themes.
To add our switcher, declare a global type named
.storybook/preview.js and give it a list of supported themes to choose from.
This code will create a new toolbar menu to select your desired theme for your stories.
There needs to be a way to tell Vuetify to use the theme selected in the toolbar.
This can be done by updating our
StoryWrapper component and
themeName prop that it can give to
Now pass our global
theme variable to our
StoryWrapper component as a prop with our decorator
Now you're ready to use Vuetify with Storybook. 🎉 Check out the example repo for a quick start.