storybook: Vue + Vuetify theme not working
Bug or support request summary
Calling Vue.use (Vuetify {theme: { primary: <color>, etc.}}) is not working - a component that tries to use that theme does not take on the color, for instance.
Please provide issue details here - What did you expect to happen? What happened instead?
Component should use theme color in rendering. It does not.
Steps to reproduce
- Create a minimal project with Vue cli (2 or 3)
- in the config, import Vue and Vuetify
- add a Vue.use() line, specifying a theme
- create a component (VBtn works), that uses a color in the theme (primary, for instance))
- create a story to invoke the button.
VBtn doesn’t take on the color. (in my test app, it does when run from dev/serve)
Please specify which version of Storybook and optionally any affected addons that you’re running
- @storybook/vue 3.4.11
- @storybook/addons 3.4.11
- @storybook/addon-actions 3.4.11
- @storybook/addon-links 3.4.11
Affected platforms
- _If UI related, please indicate:
- chrome 69.0.3497.100 (Official Build) (64-bit), MacOS High Sierra
- _If dependency related, please include relevant version numbers
- vue - latest version (2.5.17)
- vuetify - latest version (1.2.5)
Screenshots / Screencast / Code Snippets (Optional)
Example component:
<template>
<v-btn round
color="primary">
<slot></slot>
</v-btn>
</template>
<script>
export default {
name: "test-button",
}
</script>
App file invoking the component:
<v-app>
<v-layout column justify-center>
<v-layout row justify-center align-center>
<test-button @click="testBtnClicked">
Click It
</test-button>
</v-layout>
</v-layout>
</v-app>
Vue/Vuetify setup in config.js:
import Vue from 'vue';
import 'vuetify/dist/vuetify.min.css';
import Vuetify from "vuetify";
import colors from 'vuetify/es5/util/colors';
Vue.use(Vuetify, {
theme: {
primary: colors.indigo.base,
info: colors.blue.lighten2,
accent: colors.green.lighten1,
error: colors.red.darken2
}
});
Story for the TestButton:
import { storiesOf } from "@storybook/vue";
import TestButton from "./TestButton.vue";
storiesOf("TestButton", module)
.add("default", () => ({
template: '<test-button>Click Me</test-button>',
components: {TestButton}
}))
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (3 by maintainers)
I have the problem too.
After reading vuetify’s code, seems the generation of CSS, and injection of the theme is made in the
VAppmixinapp-themelocated here.So, I think the problem is not linked to storybook, but vuetify instead.
By wrapping the component I wish to test with a
v-app, it’s ok.So, for now, please try to add a decorator in your
config.jslike this :Sounds ok for you ?
I think you just need add
<v-app>tag inside Story.I have the whole storybook + vuetify + vue cli working perfectly, including scoped css. I post my setup here for whoever needs some help. My setup include 5 files:
main.js This is the storybook config file (I set up here webpack options)
preview.js This is the storybook file where I define the vuetify decorator.
preview-head.html This is used to import web font from google
vuetify_storybook.js This file contains the vuetify configuration, in order to have the vuetify components, the themes and my icons working in storybook.
vuetify_style.scss This file is used to modify the min-height in v-application, in order to avoid the story canvas to extend to end of the page, but just as big as the component is.
Hope this helps…cheers guys!
@mrtwinkler for me this works with storybook 6.0.13 and vuetify 2.3.9 with https://storybook.nuxtjs.org/manual-setup/ after running
npx nuxt storybook ejectstorybook/preview.js:
I found this : https://github.com/nidkil/vuetify-with-storybook
maybe it can help you ?
I also am experiencing this