Skip to content

Commit

Permalink
Global styles: move custom CSS to ellipsis menu if no custom CSS pres…
Browse files Browse the repository at this point in the history
…ent yet (#47371)
  • Loading branch information
glendaviesnz authored Jan 29, 2023
1 parent b97255d commit 2ceba81
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { isRTL, __ } from '@wordpress/i18n';
import { chevronLeft, chevronRight } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { experiments as blockEditorExperiments } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -24,8 +25,12 @@ import { IconWithCurrentColor } from './icon-with-current-color';
import { NavigationButtonAsItem } from './navigation-button';
import ContextMenu from './context-menu';
import StylesPreview from './preview';
import { unlock } from '../../experiments';

function ScreenRoot() {
const { useGlobalStyle } = unlock( blockEditorExperiments );
const [ customCSS ] = useGlobalStyle( 'css' );

const { variations, canEditCSS } = useSelect( ( select ) => {
const {
getEntityRecord,
Expand Down Expand Up @@ -110,7 +115,7 @@ function ScreenRoot() {
</ItemGroup>
</CardBody>

{ canEditCSS && (
{ canEditCSS && !! customCSS && (
<>
<CardDivider />
<CardBody>
Expand Down
50 changes: 47 additions & 3 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {
__experimentalNavigatorProvider as NavigatorProvider,
__experimentalNavigatorScreen as NavigatorScreen,
__experimentalUseNavigator as useNavigator,
createSlotFill,
DropdownMenu,
} from '@wordpress/components';
import { getBlockTypes, store as blocksStore } from '@wordpress/blocks';

import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { experiments as blockEditorExperiments } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { moreVertical } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -31,6 +36,43 @@ import { ScreenVariation } from './screen-variations';
import ScreenBorder from './screen-border';
import StyleBook from '../style-book';
import ScreenCSS from './screen-css';
import { unlock } from '../../experiments';

const SLOT_FILL_NAME = 'GlobalStylesMenu';
const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } =
createSlotFill( SLOT_FILL_NAME );

function GlobalStylesActionMenu() {
const { toggle } = useDispatch( preferencesStore );
const { useGlobalStylesReset } = unlock( blockEditorExperiments );
const [ canReset, onReset ] = useGlobalStylesReset();
const { goTo } = useNavigator();
const loadCustomCSS = () => goTo( '/css' );
return (
<GlobalStylesMenuFill>
<DropdownMenu
icon={ moreVertical }
label={ __( 'More Styles actions' ) }
controls={ [
{
title: __( 'Reset to defaults' ),
onClick: onReset,
isDisabled: ! canReset,
},
{
title: __( 'Welcome Guide' ),
onClick: () =>
toggle( 'core/edit-site', 'welcomeGuideStyles' ),
},
{
title: __( 'Additional CSS' ),
onClick: loadCustomCSS,
},
] }
/>
</GlobalStylesMenuFill>
);
}

function GlobalStylesNavigationScreen( { className, ...props } ) {
return (
Expand Down Expand Up @@ -289,8 +331,10 @@ function GlobalStylesUI( { isStyleBookOpened, onCloseStyleBook } ) {
{ isStyleBookOpened && (
<GlobalStylesStyleBook onClose={ onCloseStyleBook } />
) }

<GlobalStylesActionMenu />
</NavigatorProvider>
);
}

export { GlobalStylesMenuSlot };
export default GlobalStylesUI;
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
/**
* WordPress dependencies
*/
import {
DropdownMenu,
FlexItem,
FlexBlock,
Flex,
Button,
} from '@wordpress/components';
import { FlexItem, FlexBlock, Flex, Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { styles, moreVertical, seen } from '@wordpress/icons';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
import { styles, seen } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';

import { useState, useEffect } from '@wordpress/element';
import { experiments as blockEditorExperiments } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import DefaultSidebar from './default-sidebar';
import { GlobalStylesUI } from '../global-styles';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../experiments';

const { useGlobalStylesReset } = unlock( blockEditorExperiments );
import { GlobalStylesMenuSlot } from '../global-styles/ui';

export default function GlobalStylesSidebar() {
const [ canReset, onReset ] = useGlobalStylesReset();
const { toggle } = useDispatch( preferencesStore );
const [ isStyleBookOpened, setIsStyleBookOpened ] = useState( false );
const editorMode = useSelect(
( select ) => select( editSiteStore ).getEditorMode(),
[]
);

useEffect( () => {
if ( editorMode !== 'visual' ) {
setIsStyleBookOpened( false );
Expand Down Expand Up @@ -67,25 +57,7 @@ export default function GlobalStylesSidebar() {
/>
</FlexItem>
<FlexItem>
<DropdownMenu
icon={ moreVertical }
label={ __( 'More Styles actions' ) }
controls={ [
{
title: __( 'Reset to defaults' ),
onClick: onReset,
isDisabled: ! canReset,
},
{
title: __( 'Welcome Guide' ),
onClick: () =>
toggle(
'core/edit-site',
'welcomeGuideStyles'
),
},
] }
/>
<GlobalStylesMenuSlot />
</FlexItem>
</Flex>
}
Expand Down

1 comment on commit 2ceba81

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 2ceba81.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4039048992
📝 Reported issues:

Please sign in to comment.