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

Author Block: Refactor Settings panel to use Toolspanel #67965

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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
200 changes: 136 additions & 64 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
} from '@wordpress/block-editor';
import {
ComboboxControl,
PanelBody,
SelectControl,
ToggleControl,
__experimentalVStack as VStack,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -100,84 +101,155 @@ function PostAuthorEdit( {
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<VStack
spacing={ 4 }
className="wp-block-post-author__inspector-settings"
<VStack
spacing={ 4 }
className="wp-block-post-author__inspector-settings"
>
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
avatarSize: 48,
showAvatar: true,
isLink: false,
linkTarget: '_self',
} );
} }
>
{ showAuthorControl &&
( ( showCombobox && (
<ComboboxControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Author' ) }
options={ authorOptions }
value={ authorId }
onChange={ handleSelect }
allowReset={ false }
/>
) ) || (
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Author' ) }
value={ authorId }
options={ authorOptions }
onChange={ handleSelect }
/>
) ) }
<ToggleControl
__nextHasNoMarginBottom
{ showAuthorControl && (
<ToolsPanelItem
label={ __( 'Author' ) }
isShownByDefault
hasValue={ () => authorId }
onDeselect={ () =>
setAttributes( { authorId: null } )
}
>
{ ( showCombobox && (
<ComboboxControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Author' ) }
options={ authorOptions }
value={ authorId }
onChange={ handleSelect }
allowReset={ false }
/>
) ) || (
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Author' ) }
value={ authorId }
options={ authorOptions }
onChange={ handleSelect }
/>
) }
</ToolsPanelItem>
) }
<ToolsPanelItem
label={ __( 'Show avatar' ) }
checked={ showAvatar }
onChange={ () =>
setAttributes( { showAvatar: ! showAvatar } )
isShownByDefault
hasValue={ () => showAvatar }
onDeselect={ () =>
setAttributes( { showAvatar: true } )
}
/>
{ showAvatar && (
<SelectControl
__next40pxDefaultSize
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Avatar size' ) }
value={ attributes.avatarSize }
options={ avatarSizes }
onChange={ ( size ) => {
label={ __( 'Show avatar' ) }
checked={ showAvatar }
onChange={ () =>
setAttributes( {
avatarSize: Number( size ),
} );
} }
showAvatar: ! showAvatar,
} )
}
/>
</ToolsPanelItem>
{ showAvatar && (
<ToolsPanelItem
label={ __( 'Avatar size' ) }
isShownByDefault
hasValue={ () => attributes.avatarSize }
onDeselect={ () =>
setAttributes( { avatarSize: 48 } )
}
>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Avatar size' ) }
value={ attributes.avatarSize }
options={ avatarSizes }
onChange={ ( size ) => {
setAttributes( {
avatarSize: Number( size ),
} );
} }
/>
</ToolsPanelItem>
) }
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanelItem
label={ __( 'Show bio' ) }
checked={ showBio }
onChange={ () =>
setAttributes( { showBio: ! showBio } )
isShownByDefault
hasValue={ () => showBio }
onDeselect={ () =>
setAttributes( { showBio: true } )
}
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Link author name to author page' ) }
checked={ isLink }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show bio' ) }
checked={ showBio }
onChange={ () =>
setAttributes( { showBio: ! showBio } )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
label={ __( 'Link author name' ) }
isShownByDefault
hasValue={ () => isLink }
onDeselect={ () =>
setAttributes( { isLink: false } )
}
/>
{ isLink && (
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
label={ __(
'Link author name to author page'
) }
checked={ isLink }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
{ isLink && (
<ToolsPanelItem
label={ __( 'Link target' ) }
isShownByDefault
hasValue={ () => linkTarget }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value
? '_blank'
: '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
) }
</VStack>
</PanelBody>
</ToolsPanel>
</VStack>
</InspectorControls>

<BlockControls group="block">
Expand Down
Loading