Skip to content

Commit

Permalink
Global styles: split styles menus in revisions and everything else (W…
Browse files Browse the repository at this point in the history
…ordPress#51318)

* Switching items in the dropdown in GlobalStylesMenu to MenuItems

* Icons and stuff

* Simplify aria labels on style actions menus and add role to surrounding header.

* Grouping menuitems

* Removing icons and shortening the copy for text view

* Need to close the menu after some actions

* Remove flex item so that the text labels sit more neatly in "text labels" preferences mode

* changelog

* Update e2e selectors
  • Loading branch information
ramonjd authored and sethrubenstein committed Jul 13, 2023
1 parent cf8d6fe commit aad4dd5
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 51 deletions.
1 change: 1 addition & 0 deletions packages/edit-site/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements
- Site editor sidebar: add home template details and controls [#51223](https://github.com/WordPress/gutenberg/pull/51223).
- Site editor sidebar: add footer to template part and ensure nested template areas display [#51669](https://github.com/WordPress/gutenberg/pull/51669).
- Global styles: split styles menus into revisions and other styles actions ([#51318](https://github.com/WordPress/gutenberg/pull/51318)).

## 5.12.0 (2023-06-07)

Expand Down
11 changes: 11 additions & 0 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@
.edit-site-global-styles-sidebar__panel .block-editor-block-icon svg {
fill: currentColor;
}

[class][class].edit-site-global-styles-sidebar__revisions-count-badge {
align-items: center;
background: $gray-800;
border-radius: 2px;
color: $white;
display: inline-flex;
justify-content: center;
min-height: $icon-size;
min-width: $icon-size;
}
140 changes: 95 additions & 45 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -7,16 +12,18 @@ import {
__experimentalUseNavigator as useNavigator,
createSlotFill,
DropdownMenu,
MenuGroup,
MenuItem,
} from '@wordpress/components';
import { getBlockTypes, store as blocksStore } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import {
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __, sprintf, _n } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { moreVertical } from '@wordpress/icons';
import { backup, moreVertical } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect } from '@wordpress/element';

Expand Down Expand Up @@ -47,8 +54,7 @@ const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } =

function GlobalStylesActionMenu() {
const { toggle } = useDispatch( preferencesStore );
const { setIsListViewOpened } = useDispatch( editSiteStore );
const { canEditCSS, revisionsCount } = useSelect( ( select ) => {
const { canEditCSS } = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );

Expand All @@ -60,6 +66,63 @@ function GlobalStylesActionMenu() {
return {
canEditCSS:
!! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false,
};
}, [] );
const { goTo } = useNavigator();
const loadCustomCSS = () => goTo( '/css' );

return (
<GlobalStylesMenuFill>
<DropdownMenu icon={ moreVertical } label={ __( 'More' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ canEditCSS && (
<MenuItem onClick={ loadCustomCSS }>
{ __( 'Additional CSS' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
toggle(
'core/edit-site',
'welcomeGuideStyles'
);
onClose();
} }
>
{ __( 'Welcome Guide' ) }
</MenuItem>
</MenuGroup>
) }
</DropdownMenu>
</GlobalStylesMenuFill>
);
}

function RevisionsCountBadge( { className, children } ) {
return (
<span
className={ classnames(
className,
'edit-site-global-styles-sidebar__revisions-count-badge'
) }
>
{ children }
</span>
);
}
function GlobalStylesRevisionsMenu() {
const { setIsListViewOpened } = useDispatch( editSiteStore );
const { revisionsCount } = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );

const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;

return {
revisionsCount:
globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0,
};
Expand All @@ -70,7 +133,6 @@ function GlobalStylesActionMenu() {
const { setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);
const loadCustomCSS = () => goTo( '/css' );
const loadRevisions = () => {
setIsListViewOpened( false );
goTo( '/revisions' );
Expand All @@ -80,46 +142,33 @@ function GlobalStylesActionMenu() {

return (
<GlobalStylesMenuFill>
<DropdownMenu
icon={ moreVertical }
label={ __( 'Styles actions' ) }
controls={ [
{
title: __( 'Reset to defaults' ),
onClick: onReset,
isDisabled: ! canReset,
},
{
title: __( 'Welcome Guide' ),
onClick: () =>
toggle( 'core/edit-site', 'welcomeGuideStyles' ),
},
...( canEditCSS
? [
{
title: __( 'Additional CSS' ),
onClick: loadCustomCSS,
},
]
: [] ),
...( hasRevisions
? [
{
title: sprintf(
/* translators: %d: number of revisions */
_n(
'%d Revision',
'%d Revisions',
revisionsCount
),
revisionsCount
),
onClick: loadRevisions,
},
]
: [] ),
] }
/>
<DropdownMenu icon={ backup } label={ __( 'Revisions' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ hasRevisions && (
<MenuItem
onClick={ loadRevisions }
icon={
<RevisionsCountBadge>
{ revisionsCount }
</RevisionsCountBadge>
}
>
{ __( 'Revision history' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! canReset }
>
{ __( 'Reset to defaults' ) }
</MenuItem>
</MenuGroup>
) }
</DropdownMenu>
</GlobalStylesMenuFill>
);
}
Expand Down Expand Up @@ -357,6 +406,7 @@ function GlobalStylesUI() {
<GlobalStylesStyleBook />
) }

<GlobalStylesRevisionsMenu />
<GlobalStylesActionMenu />
<GlobalStylesBlockLink />
<GlobalStylesEditorCanvasContainerLink />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export default function GlobalStylesSidebar() {
closeLabel={ __( 'Close Styles' ) }
panelClassName="edit-site-global-styles-sidebar__panel"
header={
<Flex className="edit-site-global-styles-sidebar__header">
<Flex
className="edit-site-global-styles-sidebar__header"
role="menubar"
aria-label={ __( 'Styles actions' ) }
>
<FlexBlock style={ { minWidth: 'min-content' } }>
<strong>{ __( 'Styles' ) }</strong>
</FlexBlock>
Expand All @@ -87,9 +91,7 @@ export default function GlobalStylesSidebar() {
} }
/>
</FlexItem>
<FlexItem>
<GlobalStylesMenuSlot />
</FlexItem>
<GlobalStylesMenuSlot />
</Flex>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ class UserGlobalStylesRevisions {

async openRevisions() {
await this.page
.getByRole( 'button', { name: 'Styles actions' } )
.getByRole( 'menubar', { name: 'Styles actions' } )
.click();
await this.page.getByRole( 'button', { name: 'Revisions' } ).click();
await this.page
.getByRole( 'menuitem', { name: /^Revision history/ } )
.click();
await this.page.getByRole( 'menuitem', { name: 'Revisions' } ).click();
}

async openStylesPanel() {
Expand Down

0 comments on commit aad4dd5

Please sign in to comment.