Skip to content

Commit

Permalink
Refactor "Settings" panel of Table block to use ToolsPanel instead of…
Browse files Browse the repository at this point in the history
… PanelBody (WordPress#67896)

Co-authored-by: Sukhendu2002 <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent cff73d4 commit 8d6b8c5
Showing 1 changed file with 54 additions and 20 deletions.
74 changes: 54 additions & 20 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import {
import { __ } from '@wordpress/i18n';
import {
Button,
PanelBody,
Placeholder,
TextControl,
ToggleControl,
ToolbarDropdownMenu,
__experimentalHasSplitBorders as hasSplitBorders,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import {
alignLeft,
Expand Down Expand Up @@ -473,33 +474,66 @@ function TableEdit( {
</>
) }
<InspectorControls>
<PanelBody
title={ __( 'Settings' ) }
className="blocks-table-settings"
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
hasFixedLayout: true,
head: [],
foot: [],
} );
} }
>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanelItem
hasValue={ () => hasFixedLayout !== true }
label={ __( 'Fixed width table cells' ) }
checked={ !! hasFixedLayout }
onChange={ onChangeFixedLayout }
/>
onDeselect={ () =>
setAttributes( { hasFixedLayout: true } )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Fixed width table cells' ) }
checked={ !! hasFixedLayout }
onChange={ onChangeFixedLayout }
/>
</ToolsPanelItem>
{ ! isEmpty && (
<>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanelItem
hasValue={ () => head && head.length }
label={ __( 'Header section' ) }
checked={ !! ( head && head.length ) }
onChange={ onToggleHeaderSection }
/>
<ToggleControl
__nextHasNoMarginBottom
onDeselect={ () =>
setAttributes( { head: [] } )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Header section' ) }
checked={ !! ( head && head.length ) }
onChange={ onToggleHeaderSection }
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => foot && foot.length }
label={ __( 'Footer section' ) }
checked={ !! ( foot && foot.length ) }
onChange={ onToggleFooterSection }
/>
onDeselect={ () =>
setAttributes( { foot: [] } )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Footer section' ) }
checked={ !! ( foot && foot.length ) }
onChange={ onToggleFooterSection }
/>
</ToolsPanelItem>
</>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
{ ! isEmpty && (
<table
Expand Down

0 comments on commit 8d6b8c5

Please sign in to comment.