-
Notifications
You must be signed in to change notification settings - Fork 351
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
Modernize Perseus' components folder stories #1802
Draft
jeremywiebe
wants to merge
11
commits into
main
Choose a base branch
from
jer/storybook-modernize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains 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
Size Change: +617 B (+0.07%) Total Size: 867 kB
ℹ️ View Unchanged
|
jeremywiebe
force-pushed
the
jer/storybook-modernize
branch
from
October 25, 2024 16:14
2918590
to
f43ed66
Compare
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (2f4f7b1) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1802 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1802 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
I spent some of Hackathon 2024 looking into a Storybook upgrade (unfinished). During this time, I read up on how Storybook recommends writing stories. The new format (CSF) makes Typescript understand the stories much better.
So, it turns out, with a few changes, the Storybook tooling becomes a bunch more helpful and reduces how much code we need to write in our stories. I'll outline the types of changes this PR contains so that it's easy to follow if you want to adjust other stories in this repo.
Here is what a very, simple, modern Storybook file looks like:
Always define the default export as:
Two things are important here:
Meta
(from@storybook/react
). This enables Storybook to infer the props this component has and enables "intellisense" on the different parameters tometa
.as Meta
on this object definition. I'm unclear why, but that doesn't seem to work as well as the example above.Always define a type in the file as
type Story = StoryObj<typeof MyComponent>
. (again, theStoryObj<T>
type comes from@storybook/react
.Define stories as
export const MyStory: Story = {}
. By defining stories as simple data objects we get better type checking on the args we provide and reduce alot of boilerplate that our stories typically had.Use
render
and/ordecorators
to reduce duplication. Often times we need to wrap our component in order for it to behave properly or to look better in Storybook. Instead of writing each story with this wrapper, move the common wrapping code into themeta
object'srender
key. (note: I'm not 100% clear when to use therender
key and when to use thedecorators
. I was able to accomplish similar things with both. I suspectdecorators
is more useful if you have multiple things you want to adorn the component with but do not want to merge them together into a singlerender
function.Issue: "none"
Test plan:
Review the stories in
Perseus/components
(yarn start; open http://localhost:6006/?path=/docs/perseus-components-button-group--docs
)