-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Panel: Remove knobs from stories #46958
Changes from all commits
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,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { boolean, text } from '@storybook/addon-knobs'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -18,88 +13,75 @@ import { wordpress } from '@wordpress/icons'; | |
export default { | ||
title: 'Components/Panel', | ||
component: Panel, | ||
subcomponents: { PanelRow, PanelBody }, | ||
argTypes: { | ||
children: { control: { type: null } }, | ||
}, | ||
parameters: { | ||
knobs: { disable: false }, | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
|
||
export const _default = () => { | ||
const bodyTitle = text( 'Body Title', 'My Block Settings' ); | ||
const opened = boolean( 'Opened', true ); | ||
const rowText = text( 'Row Text', 'My Panel Inputs and Labels' ); | ||
return ( | ||
<Panel header="My Panel"> | ||
<PanelBody title={ bodyTitle } opened={ opened }> | ||
<PanelRow>{ rowText }</PanelRow> | ||
const Template = ( props ) => <Panel { ...props } />; | ||
|
||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
header: 'My panel', | ||
children: ( | ||
<> | ||
<PanelBody title="First section"> | ||
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. Changed the default story to have multiple bodies so it looks more like a Panel. |
||
<PanelRow> | ||
<div | ||
style={ { | ||
background: '#ddd', | ||
height: 100, | ||
width: '100%', | ||
} } | ||
/> | ||
</PanelRow> | ||
</PanelBody> | ||
<PanelBody title="Second section" initialOpen={ false }> | ||
<PanelRow> | ||
<div | ||
style={ { | ||
background: '#ddd', | ||
height: 100, | ||
width: '100%', | ||
} } | ||
/> | ||
</PanelRow> | ||
</PanelBody> | ||
</Panel> | ||
); | ||
</> | ||
), | ||
}; | ||
|
||
export const multipleBodies = () => { | ||
return ( | ||
<ScrollableContainer> | ||
<Panel header="My Panel"> | ||
<PanelBody title="First Settings"> | ||
<PanelRow> | ||
<Placeholder height={ 250 } /> | ||
</PanelRow> | ||
</PanelBody> | ||
<PanelBody title="Second Settings" initialOpen={ false }> | ||
<PanelRow> | ||
<Placeholder height={ 400 } /> | ||
</PanelRow> | ||
</PanelBody> | ||
<PanelBody title="Third Settings" initialOpen={ false }> | ||
<PanelRow> | ||
<Placeholder height={ 600 } /> | ||
</PanelRow> | ||
</PanelBody> | ||
<PanelBody title="Fourth Settings" initialOpen={ false }> | ||
<PanelRow> | ||
<Placeholder /> | ||
</PanelRow> | ||
</PanelBody> | ||
<PanelBody | ||
title="Disabled Settings" | ||
initialOpen={ false } | ||
buttonProps={ { disabled: true } } | ||
/> | ||
</Panel> | ||
</ScrollableContainer> | ||
); | ||
export const DisabledSection = Template.bind( {} ); | ||
DisabledSection.args = { | ||
...Default.args, | ||
children: ( | ||
<PanelBody | ||
title="Disabled section" | ||
initialOpen={ false } | ||
buttonProps={ { disabled: true } } | ||
/> | ||
), | ||
}; | ||
|
||
export const withIcon = () => { | ||
const bodyTitle = text( 'Body Title', 'My Block Settings' ); | ||
const rowText = text( 'Row Text', 'My Panel Inputs and Labels' ); | ||
const icon = boolean( 'Icon', true ) ? wordpress : undefined; | ||
const opened = boolean( 'Opened', true ); | ||
return ( | ||
<Panel header="My Panel"> | ||
<PanelBody title={ bodyTitle } opened={ opened } icon={ icon }> | ||
<PanelRow>{ rowText }</PanelRow> | ||
</PanelBody> | ||
</Panel> | ||
); | ||
export const WithIcon = Template.bind( {} ); | ||
WithIcon.args = { | ||
...Default.args, | ||
children: ( | ||
<PanelBody title="Section title" icon={ wordpress }> | ||
<PanelRow> | ||
<div | ||
style={ { | ||
background: '#ddd', | ||
height: 100, | ||
width: '100%', | ||
} } | ||
/> | ||
</PanelRow> | ||
</PanelBody> | ||
), | ||
}; | ||
|
||
function ScrollableContainer( { children } ) { | ||
return ( | ||
<div | ||
style={ { | ||
width: 300, | ||
height: '100vh', | ||
overflowY: 'auto', | ||
margin: 'auto', | ||
boxShadow: '0 0 0 1px #ddd inset', | ||
} } | ||
> | ||
{ children } | ||
</div> | ||
); | ||
} | ||
|
||
function Placeholder( { height = 200 } ) { | ||
return <div style={ { background: '#ddd', height, width: '100%' } } />; | ||
} | ||
Comment on lines
-87
to
-105
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. Removed these for simplicity. |
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.
Tweaked the export so the displayName isn't borked.
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.
Interesting that this is enough! I though we had to name-export
PanelRow
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 was super weird, because the original code would show the display name as
[object Object]
😕 I don't think I've ever seen that before.Aside from that, I'm still unclear on why behavior seems inconsistent between "named but unexported" and "named and exported". Sometimes it works without an export, sometimes it doesn't 🤷