Let's see we have the simple component ToggleButton
:
const ButtonComponent = Vue.component('ButtonComponent', {
props: {
value: Boolean
},
methods: {
handleClick() {
this.$emit('toggle');
}
},
template: `
<button
:class="value ? 'on' : 'off'"
@click="handleClick"
>
Toggle
</button>`
});
And the story for that component:
import ToggleButton from './ToggleButton.vue';
export default {
title: 'ToggleButton',
component: ToggleButton,
argTypes: {
onToggle: {
action: 'toggle' // <-- instead of logging "toggle" I'd like to mutate `args.value` here
}
}
};
export const Default = (_args, { argTypes }) => ({
components: { ToggleButton },
props: Object.keys(argTypes),
template: `
<ToggleButton
:value="value"
:toggle="onToggle"
/>
`
});
Default.args = {
value: false
}
What I want to achieve is to handle toggle
action inside the story and change value
that I've used in Default.args
object to change the button style by changing the class name from .off
to .on
.
ButtonComponent.stories.ts
, let's sayconst ControlComponent = Vue.component('ControlComponent', { components: { ButtonComponent } });
with dynamic properties inside that's being mutated byButtonComponent
. And then have used it instead ofButtonComponent
. – Papilla