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

Archives Block: Refactor setting panel #67841

Merged
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
122 changes: 86 additions & 36 deletions packages/block-library/src/archives/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* WordPress dependencies
*/
import {
PanelBody,
ToggleControl,
SelectControl,
Disabled,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
Expand All @@ -17,55 +18,104 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
displayAsDropdown: false,
showLabel: false,
showPostCounts: false,
type: 'monthly',
} );
} }
>
<ToolsPanelItem
label={ __( 'Display as dropdown' ) }
checked={ displayAsDropdown }
onChange={ () =>
setAttributes( {
displayAsDropdown: ! displayAsDropdown,
} )
isShownByDefault
hasValue={ () => displayAsDropdown }
onDeselect={ () =>
setAttributes( { displayAsDropdown: false } )
}
/>
{ displayAsDropdown && (
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show label' ) }
checked={ showLabel }
label={ __( 'Display as dropdown' ) }
checked={ displayAsDropdown }
onChange={ () =>
setAttributes( {
showLabel: ! showLabel,
displayAsDropdown: ! displayAsDropdown,
} )
}
/>
</ToolsPanelItem>

{ displayAsDropdown && (
<ToolsPanelItem
label={ __( 'Show label' ) }
isShownByDefault
hasValue={ () => showLabel }
onDeselect={ () =>
setAttributes( { showLabel: false } )
}
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show label' ) }
checked={ showLabel }
onChange={ () =>
setAttributes( {
showLabel: ! showLabel,
} )
}
/>
</ToolsPanelItem>
) }
<ToggleControl
__nextHasNoMarginBottom

<ToolsPanelItem
label={ __( 'Show post counts' ) }
checked={ showPostCounts }
onChange={ () =>
setAttributes( {
showPostCounts: ! showPostCounts,
} )
isShownByDefault
hasValue={ () => showPostCounts }
onDeselect={ () =>
setAttributes( { showPostCounts: false } )
}
/>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show post counts' ) }
checked={ showPostCounts }
onChange={ () =>
setAttributes( {
showPostCounts: ! showPostCounts,
} )
}
/>
</ToolsPanelItem>

<ToolsPanelItem
label={ __( 'Group by' ) }
options={ [
{ label: __( 'Year' ), value: 'yearly' },
{ label: __( 'Month' ), value: 'monthly' },
{ label: __( 'Week' ), value: 'weekly' },
{ label: __( 'Day' ), value: 'daily' },
] }
value={ type }
onChange={ ( value ) =>
setAttributes( { type: value } )
isShownByDefault
hasValue={ () => !! type }
onDeselect={ () =>
setAttributes( { type: 'monthly' } )
}
/>
</PanelBody>
>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Group by' ) }
options={ [
{ label: __( 'Year' ), value: 'yearly' },
{ label: __( 'Month' ), value: 'monthly' },
{ label: __( 'Week' ), value: 'weekly' },
{ label: __( 'Day' ), value: 'daily' },
] }
value={ type }
onChange={ ( value ) =>
setAttributes( { type: value } )
}
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<div { ...useBlockProps() }>
<Disabled>
Expand Down
Loading