Skip to content

Commit

Permalink
Block Library: Normalize theme block toolbars (#31952)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
priethor and ntsekouras authored May 19, 2021
1 parent d64f586 commit 3b551c4
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 143 deletions.
6 changes: 3 additions & 3 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
InspectorControls,
RichText,
Expand Down Expand Up @@ -117,8 +117,8 @@ function PostAuthorEdit( { isSelected, context, attributes, setAttributes } ) {
</PanelBody>
</InspectorControls>

<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/post-comments-count/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
Warning,
useBlockProps,
Expand Down Expand Up @@ -51,8 +51,8 @@ export default function PostCommentsCountEdit( {

return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/post-comments-form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
Warning,
useBlockProps,
Expand Down Expand Up @@ -36,8 +36,8 @@ export default function PostCommentsFormEdit( {

return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/post-comments-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
Warning,
useBlockProps,
Expand Down Expand Up @@ -82,8 +82,8 @@ function PostCommentsLinkEdit( { context, attributes, setAttributes } ) {

return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/post-comments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
*/
import { useSelect } from '@wordpress/data';
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
Warning,
useBlockProps,
Expand Down Expand Up @@ -68,8 +68,8 @@ export default function PostCommentsEdit( {

return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
27 changes: 12 additions & 15 deletions packages/block-library/src/post-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import { useEntityProp } from '@wordpress/core-data';
import { useState } from '@wordpress/element';
import { __experimentalGetSettings, dateI18n } from '@wordpress/date';
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
InspectorControls,
useBlockProps,
} from '@wordpress/block-editor';
import {
ToolbarGroup,
ToolbarButton,
ToggleControl,
Popover,
Expand Down Expand Up @@ -91,26 +90,24 @@ export default function PostDateEdit( { attributes, context, setAttributes } ) {
}
return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>

{ date && (
<ToolbarGroup>
<ToolbarButton
icon={ edit }
title={ __( 'Change Date' ) }
onClick={ () =>
setIsPickerOpen(
( _isPickerOpen ) => ! _isPickerOpen
)
}
/>
</ToolbarGroup>
<ToolbarButton
icon={ edit }
title={ __( 'Change Date' ) }
onClick={ () =>
setIsPickerOpen(
( _isPickerOpen ) => ! _isPickerOpen
)
}
/>
) }
</BlockControls>

Expand Down
27 changes: 10 additions & 17 deletions packages/block-library/src/post-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ import classnames from 'classnames';
*/
import { useSelect, useDispatch } from '@wordpress/data';
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
InspectorControls,
useBlockProps,
PlainText,
} from '@wordpress/block-editor';
import {
ToolbarGroup,
ToggleControl,
TextControl,
PanelBody,
} from '@wordpress/components';
import { ToggleControl, TextControl, PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';

Expand Down Expand Up @@ -104,16 +99,14 @@ export default function PostTitleEdit( {

return (
<>
<BlockControls>
<ToolbarGroup>
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</ToolbarGroup>
<AlignmentToolbar
<BlockControls group="block">
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
21 changes: 9 additions & 12 deletions packages/block-library/src/query-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import classnames from 'classnames';
*/
// import { useSelect, useDispatch } from '@wordpress/data';
import {
AlignmentToolbar,
AlignmentControl,
BlockControls,
useBlockProps,
Warning,
} from '@wordpress/block-editor';
import { ToolbarGroup } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -52,16 +51,14 @@ export default function QueryTitleEdit( {
}
return (
<>
<BlockControls>
<ToolbarGroup>
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</ToolbarGroup>
<AlignmentToolbar
<BlockControls group="block">
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/site-tagline/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
*/
import { useEntityProp } from '@wordpress/core-data';
import {
AlignmentToolbar,
AlignmentControl,
useBlockProps,
BlockControls,
RichText,
Expand All @@ -29,8 +29,8 @@ export default function SiteTaglineEdit( { attributes, setAttributes } ) {
} );
return (
<>
<BlockControls>
<AlignmentToolbar
<BlockControls group="block">
<AlignmentControl
onChange={ ( newAlign ) =>
setAttributes( { textAlign: newAlign } )
}
Expand Down
92 changes: 41 additions & 51 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ import {
__experimentalUseInnerBlocksProps as useInnerBlocksProps,
useBlockProps,
InspectorControls,
JustifyToolbar,
JustifyContentControl,
ContrastChecker,
PanelColorSettings,
withColors,
} from '@wordpress/block-editor';
import {
DropdownMenu,
MenuGroup,
MenuItem,
PanelBody,
ToggleControl,
ToolbarItem,
ToolbarGroup,
ToolbarDropdownMenu,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';
Expand Down Expand Up @@ -114,8 +112,8 @@ export function SocialLinksEdit( props ) {

return (
<Fragment>
<BlockControls>
<JustifyToolbar
<BlockControls group="block">
<JustifyContentControl
allowedControls={ [
'left',
'center',
Expand All @@ -131,51 +129,43 @@ export function SocialLinksEdit( props ) {
isAlternate: true,
} }
/>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
label={ __( 'Size' ) }
text={ __( 'Size' ) }
icon={ null }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
>
{ ( { onClose } ) => (
<MenuGroup>
{ sizeOptions.map( ( entry ) => {
return (
<MenuItem
icon={
( size ===
entry.value ||
( ! size &&
entry.value ===
'has-normal-icon-size' ) ) &&
check
}
isSelected={
size === entry.value
}
key={ entry.value }
onClick={ () => {
setAttributes( {
size: entry.value,
} );
} }
onClose={ onClose }
role="menuitemradio"
>
{ entry.name }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</DropdownMenu>
) }
</ToolbarItem>
</ToolbarGroup>
</BlockControls>
<BlockControls group="other">
<ToolbarDropdownMenu
label={ __( 'Size' ) }
text={ __( 'Size' ) }
icon={ null }
popoverProps={ POPOVER_PROPS }
>
{ ( { onClose } ) => (
<MenuGroup>
{ sizeOptions.map( ( entry ) => {
return (
<MenuItem
icon={
( size === entry.value ||
( ! size &&
entry.value ===
'has-normal-icon-size' ) ) &&
check
}
isSelected={ size === entry.value }
key={ entry.value }
onClick={ () => {
setAttributes( {
size: entry.value,
} );
} }
onClose={ onClose }
role="menuitemradio"
>
{ entry.name }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Link settings' ) }>
Expand Down
Loading

0 comments on commit 3b551c4

Please sign in to comment.