Open Kezhich opened 3 years ago
Do you have any palliative solutions to this situation?
I've come up with a solution to this, though being new to storybook I can't guarantee it's correct.
I added https://storybook.js.org/addons/@socheatsok78/storybook-addon-vuetify/ to my vue project, but importantly where those instructions tell you to edit .storybook/<file>.js
you actually need to edit config/storybook/<file.js>
because that's the new directory that vue cli storybook plugin uses for the config when building storybook.
What I did to make it work was:
First, edit config/storybook/main.js
(the new central config file) to add in the veutify addon:
module.exports = {
stories: ['../../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-links',
'@socheatsok78/storybook-addon-vuetify',
]
};
Then create a config/storybook/preview.js
with:
import { withVuetify } from '@socheatsok78/storybook-addon-vuetify/dist/decorators'
export const decorators = [
withVuetify
];
Then testing with a Veutify based component started rendering the component correctly.
As an additional potential solution, I've made this decorator, where AppDecorator
is a component that will render <v-app>
and <v-main>
, among other implementation specific global needs:
import Vue, { VueConstructor } from "vue";
import { makeDecorator } from "@storybook/addons";
import vuetify from "@/plugins/vuetify";
import AppDecorator from "@/components/AppDecorator.vue";
export default makeDecorator({
name: "withVuetify",
parameterName: "vuetify",
wrapper: (storyFn, context, { parameters = {} }) => {
const WrappedComponent = storyFn(context) as VueConstructor<Vue>;
return Vue.extend({
vuetify,
components: { AppDecorator, WrappedComponent },
template: `<app-decorator><wrapped-component /></app-decorator>`,
});
},
});
For me, the thing I see different from the original decorator is the use of the wrapper creating a wrapped vue component along with injecting it into the decorator vue component. It was my understanding that the default template will be rendered with react, so I imaging that the original implementation would be throwing errors for unknown custom components.
Hi. I'm stuck with adding vuetify to my stories. I'm using vue CLI 4.5.7 with vue 2.6.11
Most of the components dont work correctly and i can't access vuetify global variables.
I have these errors in console:
Any idea on how to fix this?
My current package.json chunk:
My vuetify plugin config:
Storybook config main.js:
Storybook config preview.js: