You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the Storybook docs: "a story is a component with a set of arguments that define how the component should render. “Args” are Storybook’s mechanism for defining those arguments in a single JavaScript object."
Storybook provides users with the possibility of settings default args on the Meta, and local overrides on each individual StoryObj.
The problem
Currently, the addon doesn't provide any mechanism to declare Story Args.
Proposal and API
Based on the discussions held on #73 the proposal to support this feature would involve both a global macro, and local args override.
<scriptsetuplang="ts">const openModal1 =ref(false);const openModal2 =ref(true);// Global args definition inherited by all Story componentsdefineArgs<typeofDialog>({ label: "Label"});</script>
<template>
<Stories :component="Dialog">
<!-- Args are exposed to the template via scoped slots -->
<Storyv-slot="{ args }">
<Dialogv-model="openModal1" :label="args.label" /> <!-- the value here is "Label"-->
</Story>
<!-- Args can be overridden locally by passing them to the Story component -->
<Storyv-slot="{ args }" :args="{ label:'Custom Label'}">
<Dialogv-model="openModal2" :label="args.label"/> <!-- the value here is "Custom Label"-->
</Story>
<Stories>
</template>
Types
For the first iteration, this proposal would only provide types and autocompletion via the generic signature of function defineArgs<T>(): Args<T>.
Once #70 is resolved, and defineArgTypes will be used to provide type information to the <Story /> component, the local :args prop override will expose type information, alongside the scoped slot v-slot="{ args }".
Pending to define
What happens when there are multiple defineArgs functions invoked within a single script context? Do we only parse the last one, or do we parse each individual one and merge the results?
There should be no need to define multiple defineArgs in a script context, and therefore my suggestion would be to ignore all calls but the last one.
How to pass Components as args ?
Often components need to be rendered with dynamic component passed as args within their supported slots:
From the Storybook docs: "a story is a component with a set of arguments that define how the component should render. “Args” are Storybook’s mechanism for defining those arguments in a single JavaScript object."
Storybook provides users with the possibility of settings default
args
on the Meta, and local overrides on each individualStoryObj
.The problem
Currently, the addon doesn't provide any mechanism to declare Story Args.
Proposal and API
Based on the discussions held on #73 the proposal to support this feature would involve both a global macro, and local args override.
Types
For the first iteration, this proposal would only provide types and autocompletion via the generic signature of
function defineArgs<T>(): Args<T>
.Once #70 is resolved, and
defineArgTypes
will be used to provide type information to the<Story />
component, the local:args
prop override will expose type information, alongside the scoped slotv-slot="{ args }"
.Pending to define
defineArgs
functions invoked within a singlescript
context? Do we only parse the last one, or do we parse each individual one and merge the results?There should be no need to define multiple
defineArgs
in a script context, and therefore my suggestion would be to ignore all calls but the last one.args
?Often components need to be rendered with dynamic component passed as
args
within their supported slots:For such cases, do we want to support components as
args
(like the above proposals) or would clients need to opt out and render that themselves?defineArgs
conflict with any other macros?Should we create a special prefix or unique ID in the name to only this addon?
defineStorybookArgs
?The text was updated successfully, but these errors were encountered: