-
Notifications
You must be signed in to change notification settings - Fork 350
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
Conversation
Size Change: +907 B (+0.11%) Total Size: 858 kB
ℹ️ View Unchanged
|
2918590
to
f43ed66
Compare
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (d6c8b22) 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 |
2f4f7b1
to
06a90b5
Compare
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
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.
Looked through all the storybook pages updated and they are 10x better with the ability to see an interact with the props. Let's ship!
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 IS SO EXCITING! 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉
I'm requesting changes to make sure the actions work everywhere that's specified before shipping this, but everything else looks awesome.
I also had one question about why the action props are all removed from the control panel, but that's nonblocking. (Usually in wonder blocks, we keep all the function props in the table, but we set the control type to null so they're not interactable. But it's clear that they're still props on the component.)
packages/perseus/src/components/__stories__/input-with-examples.stories.tsx
Outdated
Show resolved
Hide resolved
packages/perseus/src/components/__stories__/input-with-examples.stories.tsx
Show resolved
Hide resolved
packages/perseus/src/components/__stories__/text-list-editor.stories.tsx
Outdated
Show resolved
Hide resolved
packages/perseus/src/components/__stories__/text-list-editor.stories.tsx
Outdated
Show resolved
Hide resolved
packages/perseus/src/components/__stories__/zoomable.stories.tsx
Outdated
Show resolved
Hide resolved
…s.stories.tsx Co-authored-by: Nisha Yerunkar <nisha@khanacademy.org>
20b6e0f
to
c7a34cd
Compare
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.
Yayyyy thanks for the updates! This is SO EXCITING! And I learned a ton from your PR too 🎉
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
)