-
Notifications
You must be signed in to change notification settings - Fork 98
chore(demo): refactor storybook #1265
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
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
7fbcf73
Refactor `new` script
jzempel 2d976e7
Update template stories
jzempel 3ec686e
Update template element components
jzempel 2bb693c
Add template subcomponent
jzempel 3ff6e39
Update template tests
jzempel 3ef3ee9
Merge branch 'main' into jzempel/enhance-new
jzempel 5882deb
Fix prettier format check
jzempel d2c722b
Merge branch 'jzempel/enhance-new' into jzempel/refactor-storybook
jzempel f700179
Configure storybook to process package "demo" folders
jzempel aa976f0
Initial accordion stories
jzempel d0a6735
Refactor accordion and stepper stories
jzempel 75b8d9c
Refactor timeline story demo
jzempel 0272d63
Update template
jzempel 34a94f6
Update template
jzempel a440d4c
Update formatting/linting
jzempel 59eb499
Refactor tooltip demo stories
jzempel 5e82f6b
Remove refactored stories
jzempel 7207114
Refactor breadcrumb demo stories
jzempel 39611ba
Categorize stories under "Packages"
jzempel fe8038f
Fix invalid role applied to component SVGs
jzempel 62c529c
Refactor button demo stories
jzempel 9460c0b
Fix import
jzempel d35afcf
Switch from useState to useArgs for controlled examples
jzempel 8583cf3
Refactor colorpicker demo stories
jzempel b383e89
Refactor datepicker demo stories
jzempel f7ffa97
Fix readme sort order
jzempel acfa3ec
Initial refactor for typography demo stories
jzempel 03a95fe
Refine template mdx
jzempel bb31a6e
Finesse story automation
jzempel b2948e1
Refactor blockquote demo story
jzempel 8cb9dd0
Merge branch 'main' into jzempel/refactor-storybook
jzempel 3018456
Update size snapshots
jzempel 0ee13b4
Remove unwanted merge files
jzempel ed5bee9
Expose typography interfaces
jzempel 7d7d066
Refactor typography demo stories
jzempel 1d4a276
Refactor notification demo stories
jzempel fcc693e
Merge branch 'main' into jzempel/refactor-storybook
jzempel 56680fa
Initial refactor of loaders demo stories
jzempel 1f3b3d9
Fix tsc
jzempel 1d5bdd4
Add control for number of skelton loaders
jzempel cc8c11c
Refactor avatar demo stories
jzempel 89e9afc
Add avatar-chrome pattern controls
jzempel d594ac5
Add background color story control
jzempel 745a915
Refactor menu demo stories
jzempel ef2604f
Refactor dropdown select demo stories
jzempel 86dc841
Refactor modal demo story
jzempel fd45036
Refactor DrawerModal demo stories
jzempel 0177083
Upgrade to latest storybook
jzempel 3444e04
Add figma designs to storybook
jzempel 0b76896
Refactor tooltip modal demo story
jzempel 9b59c75
Refactor loader demo stories
jzempel c5d63f1
Refactor tags demo stories
jzempel 47dc87a
Refactor pagination demo stories
jzempel 0a3401f
Refactor tabs demo stories
jzempel 53c325e
Refactor table demo stories
jzempel 32f4637
Refactor chrome demo stories
jzempel 51d6ba7
Add CollapsibleSubNavItem demo stories
jzempel 82d5d0d
Demonstrate Sheet.Footer isCompact
jzempel 03324ce
Refactor grid demo stories
jzempel 48021b8
Grid demo refinements
jzempel 8d9fac3
Initial refactor of forms demo stories
jzempel 4eb3298
Continued forms demo stories refactor
jzempel ce256ea
Continued refactor form demo stories; reconfigure "patterns" stories
jzempel 6dc9a45
Refactor InpuGroup demo stories
jzempel 79393bb
Remove refactored forms stories
jzempel 763d293
Resolve storybook static-dirs deprecation
jzempel 8a3f3de
Abstract dropdown demo stories
jzempel 82561ad
Refactor dropdowns demo stories
jzempel 6cc5490
Fix type
jzempel 1f07566
Refactor theming demo stories
jzempel 2670c93
Add demo documenation
jzempel b66a606
Merge branch 'main' into jzempel/refactor-storybook
jzempel f9e0a64
Fix lint error
jzempel fe49dd3
Fix svgo configuration
jzempel 595e2d3
Update size snapshots based on SVGO changes
jzempel c7cfb32
Zero out padding to make box-sizing differences more obvious
jzempel fa8baab
Address comments from @Francois-Esquire
jzempel 862e979
Remove unused static images
jzempel c31bae4
Recategorize Sheet controls
jzempel 6bcf661
Restore missing `isPrimary` control
jzempel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ module.exports = { | |
focusable: false | ||
}, | ||
{ | ||
role: 'presentation' | ||
'aria-hidden': true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This clears out SVG errors seen in Storybook's a11y tab and applies the correct accessibility semantics for visually decorative Garden icons. See https://css-tricks.com/accessible-svgs/#example-2-standalone-icon-decorative for details. |
||
} | ||
] | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
# Garden demos | ||
|
||
Garden leverages [Storybook](https://storybook.js.org/) for generating component | ||
demos with story controls. Run `yarn start` to build and serve package demos in | ||
development mode (with hot reloading). | ||
|
||
The development goal for demos is to render components in isolation with the | ||
least amount of structural scaffolding together with the greatest amount of | ||
control for content and flexibility. Along with global toolbar items (preview | ||
size, locale direction, CSS Bedrock, etc), controls should stress every aspect | ||
of a component's layout and behavior. | ||
|
||
## Best practice | ||
|
||
The following list of dos and don'ts outline demo code expectations. | ||
|
||
### Do this | ||
|
||
- Expose controls for all essentials βΒ inherent props, conditional subcomponent | ||
renders, child content | ||
- Allow natural component layout β full width for block, partial width for inline | ||
- Use the Garden `Grid` to manage layout for components that respond to | ||
placement values (start, end, top, bottom, etc) | ||
- Rely on `useArgs` from Storybook's client API in order to keep component state | ||
connected with it's associated Storybook control | ||
Francois-Esquire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Not this | ||
|
||
- Avoid `styled-components`. The addition of demo CSS is an indicator that the | ||
underlying component may not offer comprehensive styling. | ||
- Refrain from adding component documentation. The Storybook demos are not a | ||
substitute for the [garden.zendesk.com](https://garden.zendesk.com/) website. | ||
The website is the source of truth for component documenation. | ||
- Avoid `useState`; prefer Storybook `useArgs` instead | ||
- Do not write "Default" vs "Advanced" stories. A well-written component story | ||
will render as expected with defaults and offer controls to push into advanced | ||
component capabilities. See the [patterns](#patterns) section below for cases | ||
that extend beyond the consideration of an isolated component. | ||
- Do not use numeric file naming. By following the [naming](#naming) conventions | ||
listed below, component stories will be naturally sorted alphabetically. | ||
|
||
## Conventions | ||
|
||
Stick to the following conventions for authoring demo stories that are | ||
consistent with the existing codebase. You may find that running `yarn new` is | ||
helpful for auto-generating component demo scaffolding. | ||
|
||
### Structure | ||
|
||
- Place MDX stories under the package `demo` directory. | ||
- All `Story` TSX files are placed under a `demo/stories` directory. | ||
- Move all boilerplate data constants (i.e. control data for a component's | ||
`children`) into `demo/stories/data.ts` | ||
- Capture all types and interfaces specific to story data under | ||
`demo/stories/types.ts` | ||
- If a package has patterns (see [section](#patterns) below), tuck all pattern | ||
demo code under a `demo/~patterns` directory β repeating the directory structure | ||
as needed for `Story` TSX, `data.ts`, and `types.ts` files noted above. Prefix | ||
with a tilde to ensure these stories are ordered last. | ||
|
||
### Meta | ||
|
||
Story meta appears in the MDX file with the following structure: | ||
|
||
```mdx | ||
<Meta | ||
title="Packages/Package/Component" | ||
component={Component} | ||
subcomponents={{...}} /> | ||
``` | ||
|
||
- The `Component` is the element-level component that this story is focused on | ||
- Use the optional `subcomponents` object whenever subcomponents exist in | ||
support of the main element component. Keep this list in alphabetical order. | ||
|
||
### ArgsTable | ||
|
||
The next simple section of MDX generates prop tables for the component and | ||
subcomponents identied by the story meta. These tables can be viewed under the | ||
Storybook "Docs" tab. | ||
|
||
```mdx | ||
# API | ||
|
||
<ArgsTable /> | ||
``` | ||
|
||
### Canvas story (or stories) | ||
|
||
The canvas story specifies a name, args, argTypes, parameters, and the rendered | ||
story itself. In its most basic form: | ||
|
||
```mdx | ||
# Demo | ||
|
||
<Canvas> | ||
<Story name="Component">{args => <Component {...args} />}</Story> | ||
</Canvas> | ||
``` | ||
|
||
Often a single story is enough to fulfill the development goal for an isolated | ||
and flexible component demo. But sometimes, in the case of uncontrolled vs. | ||
controlled, there is a need to render multiple stories. In this case, the basic | ||
MDX form is modified to be: | ||
|
||
```mdx | ||
# Demo | ||
|
||
## Uncontrolled | ||
|
||
<Canvas> | ||
<Story name="Uncontrolled">{args => <ComponentStory {...args} />}</Story> | ||
</Canvas> | ||
|
||
## Controlled | ||
|
||
<Canvas> | ||
<Story name="Controlled"> | ||
{args => { | ||
const updateArgs = useArgs()[1]; | ||
const handleEvent = argName => updateArgs({ argName }); | ||
return <ComponentStory {...args} onEvent={handleEvent} />; | ||
}} | ||
Francois-Esquire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Story> | ||
</Canvas> | ||
``` | ||
|
||
Note how the `ComponentStory` is reused for both canvas stories. See | ||
[Story](#story) below for additional details. Be sure to move common `args`, | ||
`argTypes`, and `parameters` under the MDX `<Meta>` rather than repeating these | ||
under each story. | ||
|
||
#### Story `args` | ||
|
||
- Storybook automatically provides main component props as `args`. Usually there | ||
is no need to specify these values (double-check for missing prop controls). One | ||
notable exception is for Garden boolean prop values that default to `true`. In | ||
this case, the `args` should be specified to match. | ||
- Select smart defaults for the remaining subcomponent or "Story" `args`. | ||
Sometimes the best choice is to leave an arg undefined. | ||
|
||
#### Story `argTypes` | ||
|
||
Standard convention for `argTypes` exists across dozens of existing stories. | ||
Study demo code for details. Most importantly, main component props that are | ||
_not_ auto-generated must be properly categorized. The two acceptable story | ||
categories are: | ||
|
||
- Subcomponent. All subcomponent props (including `children`) are specified | ||
under the associated subcomponent name. | ||
- "Story". This category includes all ancillary controls that are needed to | ||
stress the full flexibility of the rendered component(s). | ||
|
||
#### Story `parameters` | ||
|
||
Currently, story `parameters` are used to link to the Figma page(s) or frame(s) | ||
that best exhibits associated component designs. Note that the parameter URLs | ||
are internal-only and point to designs that exist in the main Garden Figma | ||
branch. Therefore, `parameters` may need to be added as a follow-on for new | ||
components. | ||
|
||
### Story | ||
|
||
A `Story` type component is the best way to develop demo code for non-trivial | ||
Garden components. Doing so removes complexity of coding in MDX, placing | ||
component rendering and application of story args into TypeScript where code can | ||
be properly maintained. In its basic form, a `Story` looks like this: | ||
|
||
```tsx | ||
import React from 'react'; | ||
import { Story } from '@storybook/react'; | ||
import { Component, IComponentProps } from '@zendeskgarden/react-package'; | ||
|
||
interface IArgs extends IComponentProps { | ||
/* Subcomponent and "Story" arg definitions go here */ | ||
} | ||
|
||
export const ComponentStory: Story<IArgs> = args => <Component {...args} />; | ||
``` | ||
|
||
Take time to ensure Story `args` and `argTypes` are defined well. Often you will | ||
find that the majority of demo development time is spent on `args` and | ||
`argTypes` and the `Story` itself essentially falls out of the goal to | ||
demonstrate component flexibility in isolation. | ||
|
||
## Naming | ||
|
||
- Follow the existing Storybook naming hierarcy: | ||
`Packages/{{PackageName}}/{{ComponentName}}` | ||
Francois-Esquire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- The first story in every package demo should be a `#readme.stories.mdx` file | ||
that renders the package's README.md. Prefix with a hashtag to ensure this story | ||
is ordered first. | ||
- Subsequent component story files are named `componentName.stories.mdx` | ||
(camelCase) | ||
- Use Garden's standard prop naming for story args (i.e. isXxx/hasXxx for | ||
boolean args), but use `argTypes` to rename with subcomponent notation. For | ||
example: | ||
|
||
```js | ||
args={{ | ||
hasHint: true | ||
}} | ||
argTypes={{ | ||
hasHint: { name: Hint, table: { category: 'Story' } } | ||
}} | ||
``` | ||
|
||
## Patterns | ||
|
||
A pattern is a demo story that highlights a component's ability to work together | ||
with other Garden components or in conjunction with external libraries. | ||
Oftentimes, a pattern ends up violating the best practice of duplicating example | ||
documentation that belongs on the website. However, due to component development | ||
sequencing or a need to persist a visual test, a pattern can be a helpful tool | ||
for (temporarily) demonstrating component layout or behavior that supercedes the | ||
isolation of the component itself. | ||
|
||
Follow [structure](#structure) conventions to keep patterns collected in a | ||
(potentially) short-lived location. It is the component developer's | ||
responsibility to track example pattern movement to the website and subsequently | ||
remove the pattern from Storybook βΒ keeping the website as the focal source of | ||
truth. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This default layout makes better UX sense for component-controls testing.