-
Notifications
You must be signed in to change notification settings - Fork 12
Conversation
Co-authored-by: Alex Sanders <alex@sndrs.dev>
docs/10-stories.md
Outdated
}; | ||
|
||
export const NoValue = (args: MyComponentProps) => ( | ||
<MyComponent {...args} label="Label"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not passing default args
via the NoValue.args = {...}
pattern, is it useful to spread the args into the component like this? Is it doing anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, good point. The only thing that we need is to pass an arg into the function so that Storybook generates the source for the docs page. We could instead do:
export const NoValue = (_: MyComponentProps) => (
<MyComponent label="Label"/>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, that's unusual. So if you don't specifically define an argument, the docs don't get generated? You couldn't simply do:
export const NoValue = () => (
<MyComponent label="Label"/>
)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct - for example:
With Args
export const LegendSupportingTextLight = (args: RadioGroupProps) => (
<RadioGroup
{...args}
name="colours"
label="Select your preferred colour"
supporting="You can always change it later"
>
{radiosOneSelected.map((radio, index) =>
React.cloneElement(radio, { key: index }),
)}
</RadioGroup>
);
or
export const LegendSupportingTextLight = (_: RadioGroupProps) => (
<RadioGroup
name="colours"
label="Select your preferred colour"
supporting="You can always change it later"
>
{radiosOneSelected.map((radio, index) =>
React.cloneElement(radio, { key: index }),
)}
</RadioGroup>
);
Without Args
export const LegendSupportingTextLight = () => (
<RadioGroup
name="colours"
label="Select your preferred colour"
supporting="You can always change it later"
>
{radiosOneSelected.map((radio, index) =>
React.cloneElement(radio, { key: index }),
)}
</RadioGroup>
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storybook must be able to introspect useful info from you explicitly giving the args type, even if you don't use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we happy with this then?
export const LegendSupportingTextLight = (_: RadioGroupProps) => (
<RadioGroup
name="colours"
label="Select your preferred colour"
supporting="You can always change it later"
>
{radiosOneSelected.map((radio, index) =>
React.cloneElement(radio, { key: index }),
)}
</RadioGroup>
);
Co-authored-by: Simon Adcock <simonadcock2@gmail.com>
Co-authored-by: Alex Sanders <alex@sndrs.dev>
Hmm... I thought I agreed with this but then I had a play with the |
is it useful though to style the demo? i feel like that should show us what you get out the box, rather than an example of using it? |
Yeah, maybe for the Demo it should always just be the component on it's own. I'll update the recommendations to include that. I'd argue that some of the styling is useful for stories that are used for visual regression testing as it can test them in context or test multiple instances of the component in one story. I've posted a couple more ideas for how to improve those code blocks in the |
that's a good point – maybe we just don't want code for the chromatic examples? only the demo with the knobs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it!
Amazing work, thanks @sndrs and @jamie-lynch 💎 |
* Add doc with best practice for story configuration * Update docs/10-stories.md Co-authored-by: Alex Sanders <alex@sndrs.dev> * include Editorial in stories title pattern * Update docs/10-stories.md Co-authored-by: Simon Adcock <simonadcock2@gmail.com> * standardise configuration approach * update story file name recommendation * add stories doc link to README * Add note about using ignore to remove args completely * update example to match updated recommendations * Update docs/10-stories.md Co-authored-by: Alex Sanders <alex@sndrs.dev> * add recommendations about styling * update recommendations * replace tabs with spaces * update the string | JSX.Element tip Co-authored-by: Alex Sanders <alex@sndrs.dev> Co-authored-by: Simon Adcock <simonadcock2@gmail.com>
What is the purpose of this change?
This PR adds a document which sets out a guide for writing stories to help ensure consistency and best practice.
Background
This document is being added during the migration of API docs from theguardian.design into Storybook. I have written this up whilst working on #902 so that PR is a good example of the guidelines in action.
I'm adding it now so that as we continue with the migration and find even more ways to improve the documentation we can record these explicitly for the future, but also so that we can have the discussion around best practice for stories in one place, rather than split across multiple PRs throughout the migration.