Skip to content
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

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/components/src/panel/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import classnames from 'classnames';
*/
import { forwardRef } from '@wordpress/element';

const PanelRow = forwardRef( ( { className, children }, ref ) => (
const PanelRow = ( { className, children }, ref ) => (
Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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 🤷

<div
className={ classnames( 'components-panel__row', className ) }
ref={ ref }
>
{ children }
</div>
) );
);

export default PanelRow;
export default forwardRef( PanelRow );
142 changes: 62 additions & 80 deletions packages/components/src/panel/stories/index.js
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
*/
Expand All @@ -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">
Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these for simplicity. Placeholder can be particularly confusing because we have an actual wp-component called Placeholder.