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

Navigation Submenu Block: Refactor settings panel to use ToolsPanel #67969

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
167 changes: 110 additions & 57 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import clsx from 'clsx';
*/
import { useSelect, useDispatch } from '@wordpress/data';
import {
PanelBody,
TextControl,
TextareaControl,
ToolbarButton,
ToolbarGroup,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -382,67 +383,119 @@ export default function NavigationSubmenuEdit( {
</BlockControls>
{ /* Warning, this duplicated in packages/block-library/src/navigation-link/edit.js */ }
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ label || '' }
onChange={ ( labelValue ) => {
setAttributes( { label: labelValue } );
} }
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
label: '',
url: '',
description: '',
title: '',
rel: '',
} );
} }
>
<ToolsPanelItem
label={ __( 'Text' ) }
autoComplete="off"
/>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ url || '' }
onChange={ ( urlValue ) => {
setAttributes( { url: urlValue } );
} }
isShownByDefault
hasValue={ () => !! label }
onDeselect={ () => setAttributes( { label: '' } ) }
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ label || '' }
onChange={ ( labelValue ) => {
setAttributes( { label: labelValue } );
} }
label={ __( 'Text' ) }
autoComplete="off"
/>
</ToolsPanelItem>

<ToolsPanelItem
label={ __( 'Link' ) }
autoComplete="off"
/>
<TextareaControl
__nextHasNoMarginBottom
value={ description || '' }
onChange={ ( descriptionValue ) => {
setAttributes( {
description: descriptionValue,
} );
} }
isShownByDefault
hasValue={ () => !! url }
onDeselect={ () => setAttributes( { url: '' } ) }
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ url || '' }
onChange={ ( urlValue ) => {
setAttributes( { url: urlValue } );
} }
label={ __( 'Link' ) }
autoComplete="off"
/>
</ToolsPanelItem>

<ToolsPanelItem
label={ __( 'Description' ) }
help={ __(
'The description will be displayed in the menu if the current theme supports it.'
) }
/>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ title || '' }
onChange={ ( titleValue ) => {
setAttributes( { title: titleValue } );
} }
isShownByDefault
hasValue={ () => !! description }
onDeselect={ () =>
setAttributes( { description: '' } )
}
>
<TextareaControl
__nextHasNoMarginBottom
value={ description || '' }
onChange={ ( descriptionValue ) => {
setAttributes( {
description: descriptionValue,
} );
} }
label={ __( 'Description' ) }
help={ __(
'The description will be displayed in the menu if the current theme supports it.'
) }
/>
</ToolsPanelItem>

<ToolsPanelItem
label={ __( 'Title attribute' ) }
autoComplete="off"
help={ __(
'Additional information to help clarify the purpose of the link.'
) }
/>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ rel || '' }
onChange={ ( relValue ) => {
setAttributes( { rel: relValue } );
} }
isShownByDefault
hasValue={ () => !! title }
onDeselect={ () => setAttributes( { title: '' } ) }
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ title || '' }
onChange={ ( titleValue ) => {
setAttributes( { title: titleValue } );
} }
label={ __( 'Title attribute' ) }
autoComplete="off"
help={ __(
'Additional information to help clarify the purpose of the link.'
) }
/>
</ToolsPanelItem>

<ToolsPanelItem
label={ __( 'Rel attribute' ) }
autoComplete="off"
help={ __(
'The relationship of the linked URL as space-separated link types.'
) }
/>
</PanelBody>
isShownByDefault
hasValue={ () => !! rel }
onDeselect={ () => setAttributes( { rel: '' } ) }
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ rel || '' }
onChange={ ( relValue ) => {
setAttributes( { rel: relValue } );
} }
label={ __( 'Rel attribute' ) }
autoComplete="off"
help={ __(
'The relationship of the linked URL as space-separated link types.'
) }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<div { ...blockProps }>
{ /* eslint-disable jsx-a11y/anchor-is-valid */ }
Expand Down
Loading