Skip to content

Commit

Permalink
Merge header and label props for ToolsPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Sep 2, 2021
1 parent b101ce6 commit 16d3c0a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ const BlockInspectorSingleBlock = ( {
<InspectorControls.Slot
__experimentalGroup="dimensions"
bubblesVirtually={ false }
header={ __( 'Dimensions' ) }
label={ __( 'Dimensions options' ) }
label={ __( 'Dimensions' ) }
/>
<div>
<AdvancedControls bubblesVirtually={ bubblesVirtually } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default function InspectorControlsSlot( {
__experimentalGroup: group = 'default',
bubblesVirtually = true,
label,
header,
...props
} ) {
const Slot = groups[ group ]?.Slot;
Expand All @@ -29,13 +28,9 @@ export default function InspectorControlsSlot( {
return null;
}

if ( header ) {
if ( label ) {
return (
<BlockSupportToolsPanel
group={ group }
header={ header }
label={ label }
>
<BlockSupportToolsPanel group={ group } label={ label }>
<Slot { ...props } bubblesVirtually={ bubblesVirtually } />
</BlockSupportToolsPanel>
);
Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/tools-panel/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ export const _default = () => {
return (
<PanelWrapperView>
<Panel>
<ToolsPanel
header="Tools Panel"
label="Display options"
resetAll={ resetAll }
>
<ToolsPanel label="Tools Panel" resetAll={ resetAll }>
<ToolsPanelItem
className="single-column"
hasValue={ () => !! height }
Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/tools-panel/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const resetAll = jest.fn();

// Default props for the tools panel.
const defaultProps = {
header: 'Panel header',
label: 'Display options',
label: 'Panel header',
resetAll,
};

Expand Down Expand Up @@ -231,9 +230,9 @@ describe( 'ToolsPanel', () => {
expect( menuItems[ 1 ] ).toHaveAttribute( 'aria-checked', 'false' );
} );

it( 'should render panel header', () => {
it( 'should render panel label as header text', () => {
renderPanel();
const header = screen.getByText( defaultProps.header );
const header = screen.getByText( defaultProps.label );

expect( header ).toBeInTheDocument();
} );
Expand Down
11 changes: 3 additions & 8 deletions packages/components/src/tools-panel/tools-panel-header/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ This component is generated automatically by its parent

## Props

### `header`: `string`
### `label`: `string`

Text to be displayed within the panel header.
Text to be displayed within the panel header. It is also passed along as the
`label` for the panel header's `DropdownMenu`.

- Required: Yes

### `menuLabel`: `string`

This is passed along as the `label` for the panel header's `DropdownMenu`.

- Required: No

### `resetAll`: `function`

The `resetAll` prop provides the callback to execute when the "Reset all" menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ import { contextConnect } from '../../ui/context';
const ToolsPanelHeader = ( props, forwardedRef ) => {
const {
hasMenuItems,
header,
label: labelText,
menuItems,
menuLabel,
resetAll,
toggleItem,
...headerProps
} = useToolsPanelHeader( props );

if ( ! header ) {
if ( ! labelText ) {
return null;
}

return (
<h2 { ...headerProps } ref={ forwardedRef }>
{ header }
{ labelText }
{ hasMenuItems && (
<DropdownMenu icon={ moreVertical } label={ menuLabel }>
<DropdownMenu icon={ moreVertical } label={ labelText }>
{ ( { onClose } ) => (
<>
<MenuGroup label={ __( 'Display options' ) }>
Expand Down
15 changes: 3 additions & 12 deletions packages/components/src/tools-panel/tools-panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ export function DimensionPanel( props ) {
};

return (
<ToolsPanel
header={ __( 'Dimensions' ) }
label={ __( 'Dimensions options' ) }
resetAll={ resetAll }
>
<ToolsPanel label={ __( 'Dimensions' ) } resetAll={ resetAll }>
{ ! isPaddingDisabled && (
<ToolsPanelItem
hasValue={ () => hasPaddingValue( props ) }
Expand All @@ -71,15 +67,10 @@ export function DimensionPanel( props ) {

## Props

### `header`: `string`

Text to be displayed within the panel's header.

- Required: Yes

### `label`: `string`

The label for the panel's dropdown menu.
Text to be displayed within the panel's header and as the aria label for the
panel's dropdown menu.

- Required: Yes

Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/tools-panel/tools-panel/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { contextConnect } from '../../ui/context';
const ToolsPanel = ( props, forwardedRef ) => {
const {
children,
header,
label,
panelContext,
resetAllItems,
Expand All @@ -22,8 +21,7 @@ const ToolsPanel = ( props, forwardedRef ) => {
<View { ...toolsPanelProps } ref={ forwardedRef }>
<ToolsPanelContext.Provider value={ panelContext }>
<ToolsPanelHeader
header={ header }
menuLabel={ label }
label={ label }
resetAll={ resetAllItems }
toggleItem={ toggleItem }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ export default function DimensionsPanel( { context, getStyle, setStyle } ) {
};

return (
<ToolsPanel
label={ __( 'Dimensions options' ) }
header={ __( 'Dimensions' ) }
resetAll={ resetAll }
>
<ToolsPanel label={ __( 'Dimensions' ) } resetAll={ resetAll }>
{ showPaddingControl && (
<ToolsPanelItem
hasValue={ hasPaddingValue }
Expand Down

0 comments on commit 16d3c0a

Please sign in to comment.