-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] defineArgTypes
macro to set argTypes
for all stories
#70
Comments
Looks like a nice proposal. The args can also be specified only for a single story, right? So maybe adding a <script setup lang="ts">
import BButton from "./b-button.vue";
const args = defineArgs<typeof BButton>({
variant: {
options: ["primary", "secondary"],
control: "select",
},
label: {
control: "text",
description: "This is the text displayed on the button."
},
});
</script>
<template>
<Stories title="Components/Button" :component="BButton" :args="args">
<Story title="Primary" :args="args">
<BButton variant="primary" label="Click"/>
</Story>
<Story title="Secondary">
<BButton variant="secondary" label="Click" />
</Story>
</Stories>
</template> Maybe call it |
Yes, that would be a great experience. To consider creating custom However, as I revisit my original idea, there is some consideration about the API that could lead to a simpler/cleaner approach. Currently, clients of The Therefore, since the library doesn't yet support any custom macros, and I haven't seen any discussion of anything in the pipeline that could lead to a similar implementation, we might be better off simplifying the approach and be consistent, with this type of API: <script setup lang="ts">
import BButton from "./b-button.vue";
// this is just a static object
// Question: could we provide just the types, but not the macros,
// to help with ts autocomplete?
const argTypes /* : ArgTypes<typeof BButton>*/ = {
variant: {
options: ["primary", "secondary"],
control: "select",
},
label: {
control: "text",
description: "This is the text displayed on the button."
},
};
</script>
<template>
<Stories title="Components/Button" :component="BButton" :arg-types="argsTypes">
<Story title="Primary">
<BButton variant="primary" label="Click"/>
</Story>
<Story title="Secondary">
<BButton variant="secondary" label="Click" />
</Story>
</Stories>
</template> This approach would remove the complexity of creating/maintaining a macro, which would only have the convenience to expose the schema with types inferred from its generic. We can achieve the same type if we treat the schema as static object that will be parsed by our What do you think? |
In my head the For the implementation, you need to get the args prop of the story at storybook-vue-addon/src/core/parser.ts Lines 66 to 70 in 02839f9
storybook-vue-addon/src/core/transform.ts Lines 105 to 112 in 02839f9
component .
|
@tobiasdiez so are we going to create a dedicated macro function (and a dedicated prop) for each part of the We have to support I am wondering whether it makes more sense to support these features one by one by dedicated identify function, or whether we should maintain consistency with the CSF approach and provide something like We might have these two approaches: Supporting each
|
@tobiasdiez I opened a draft #73 it's going to be easy to discuss some proposal, API design and edge-cases with some concrete examples. |
The issue
Currently, in Storybook you have the possibility to define
argTypes
either via automatic inference or by manually setting the properties..Manually setting
argTypes
brings the benefit to allow for a specific value to be selected within the controls, or overriding/customizing descriptions.Syntax proposal
The text was updated successfully, but these errors were encountered: