-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Storybook: Improve TypeScript performance for slow stories #63388
Changes from all commits
c3c7e03
67ac6ff
a34e5d4
24569a5
96d59ec
1c03480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -43,39 +43,42 @@ const meta: Meta< typeof DropdownMenu > = { | |
}; | ||
export default meta; | ||
|
||
const Template: StoryFn< typeof DropdownMenu > = ( props ) => ( | ||
<div style={ { height: 150 } }> | ||
<DropdownMenu { ...props } /> | ||
</div> | ||
); | ||
|
||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
label: 'Select a direction.', | ||
icon: menu, | ||
controls: [ | ||
{ | ||
title: 'First Menu Item Label', | ||
icon: arrowUp, | ||
// eslint-disable-next-line no-console | ||
onClick: () => console.log( 'up!' ), | ||
}, | ||
{ | ||
title: 'Second Menu Item Label', | ||
icon: arrowDown, | ||
// eslint-disable-next-line no-console | ||
onClick: () => console.log( 'down!' ), | ||
}, | ||
export const Default: StoryObj< typeof DropdownMenu > = { | ||
decorators: [ | ||
( Story ) => ( | ||
<div style={ { height: 150 } }> | ||
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. I noticed these explicit heights are no longer necessary due to #53889, because popovers are now rendering at the end of the document rather than within the each story div, which used to cut them off visually. I'll do a separate cleanup PR. 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. Cleanup at #63480 |
||
<Story /> | ||
</div> | ||
), | ||
], | ||
args: { | ||
label: 'Select a direction.', | ||
icon: menu, | ||
controls: [ | ||
{ | ||
title: 'First Menu Item Label', | ||
icon: arrowUp, | ||
// eslint-disable-next-line no-console | ||
onClick: () => console.log( 'up!' ), | ||
}, | ||
{ | ||
title: 'Second Menu Item Label', | ||
icon: arrowDown, | ||
// eslint-disable-next-line no-console | ||
onClick: () => console.log( 'down!' ), | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const WithChildren = Template.bind( {} ); | ||
// Adding custom source because Storybook is not able to show the contents of | ||
// the `children` prop correctly in the code snippet. | ||
WithChildren.parameters = { | ||
docs: { | ||
source: { | ||
code: `<DropdownMenu label="Select a direction." icon={ more }> | ||
export const WithChildren: StoryObj< typeof DropdownMenu > = { | ||
...Default, | ||
mirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Adding custom source because Storybook is not able to show the contents of | ||
// the `children` prop correctly in the code snippet. | ||
parameters: { | ||
docs: { | ||
source: { | ||
code: `<DropdownMenu label="Select a direction." icon={ more }> | ||
<MenuGroup> | ||
<MenuItem icon={ arrowUp } onClick={ onClose }> | ||
Move Up | ||
|
@@ -90,29 +93,30 @@ WithChildren.parameters = { | |
</MenuItem> | ||
</MenuGroup> | ||
</DropdownMenu>`, | ||
language: 'jsx', | ||
type: 'auto', | ||
language: 'jsx', | ||
type: 'auto', | ||
}, | ||
}, | ||
}, | ||
}; | ||
WithChildren.args = { | ||
label: 'Select a direction.', | ||
icon: more, | ||
children: ( { onClose } ) => ( | ||
<> | ||
<MenuGroup> | ||
<MenuItem icon={ arrowUp } onClick={ onClose }> | ||
Move Up | ||
</MenuItem> | ||
<MenuItem icon={ arrowDown } onClick={ onClose }> | ||
Move Down | ||
</MenuItem> | ||
</MenuGroup> | ||
<MenuGroup> | ||
<MenuItem icon={ trash } onClick={ onClose }> | ||
Remove | ||
</MenuItem> | ||
</MenuGroup> | ||
</> | ||
), | ||
args: { | ||
label: 'Select a direction.', | ||
icon: more, | ||
children: ( { onClose } ) => ( | ||
<> | ||
<MenuGroup> | ||
<MenuItem icon={ arrowUp } onClick={ onClose }> | ||
Move Up | ||
</MenuItem> | ||
<MenuItem icon={ arrowDown } onClick={ onClose }> | ||
Move Down | ||
</MenuItem> | ||
</MenuGroup> | ||
<MenuGroup> | ||
<MenuItem icon={ trash } onClick={ onClose }> | ||
Remove | ||
</MenuItem> | ||
</MenuGroup> | ||
</> | ||
), | ||
}, | ||
}; |
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.
Switched to an uncontrolled story for simplicity.