Skip to content

Commit

Permalink
ToolsPanel: Update panel readme and stories (#36557)
Browse files Browse the repository at this point in the history
* Update ToolsPanel readme illustrating non-panel-item display
* Add ToolsPanel story for non menu item
  • Loading branch information
aaronrobertshaw authored Nov 17, 2021
1 parent 88fd9d3 commit b5f267f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/components/src/tools-panel/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,56 @@ export const _default = () => {
);
};

export const WithNonToolsPanelItems = () => {
const [ height, setHeight ] = useState();
const [ width, setWidth ] = useState();

const resetAll = () => {
setHeight( undefined );
setWidth( undefined );
};

return (
<PanelWrapperView>
<Panel>
<ToolsPanel
label="ToolsPanel (with non-menu items)"
resetAll={ resetAll }
>
<IntroText>
This text illustrates not all items must be wrapped in a
ToolsPanelItem and represented in the panel menu.
</IntroText>
<SingleColumnItem
hasValue={ () => !! width }
label="Width"
onDeselect={ () => setWidth( undefined ) }
isShownByDefault={ true }
>
<UnitControl
label="Width"
value={ width }
onChange={ ( next ) => setWidth( next ) }
/>
</SingleColumnItem>
<SingleColumnItem
hasValue={ () => !! height }
label="Height"
onDeselect={ () => setHeight( undefined ) }
isShownByDefault={ true }
>
<UnitControl
label="Height"
value={ height }
onChange={ ( next ) => setHeight( next ) }
/>
</SingleColumnItem>
</ToolsPanel>
</Panel>
</PanelWrapperView>
);
};

export const WithOptionalItemsPlusIcon = () => {
const [ height, setHeight ] = useState();
const [ width, setWidth ] = useState();
Expand Down Expand Up @@ -229,3 +279,7 @@ const PanelWrapperView = styled.div`
const SingleColumnItem = styled( ToolsPanelItem )`
grid-column: span 1;
`;

const IntroText = styled.div`
grid-column: span 2;
`;
9 changes: 9 additions & 0 deletions packages/components/src/tools-panel/tools-panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ displaying by default through the `isShownByDefault` prop. Determining whether a
child has a value is done via the `hasValue` function provided through the
child's props.

Components that are not wrapped within a `ToolsPanelItem` are still rendered
however they will not be represented within, or controlled by, the `ToolsPanel`
menu. An example scenario that benefits from this could be displaying
introduction or help text within a panel.

## Usage

```jsx
Expand All @@ -51,6 +56,10 @@ export function DimensionPanel( props ) {

return (
<ToolsPanel label={ __( 'Dimensions' ) } resetAll={ resetAll }>
<p>
Select dimensions or spacing related settings from the menu for
additional controls.
</p>
{ ! isPaddingDisabled && (
<ToolsPanelItem
hasValue={ () => hasPaddingValue( props ) }
Expand Down

0 comments on commit b5f267f

Please sign in to comment.