Skip to content

Commit

Permalink
Try toggle instead of dropdown to show stylebook. (WordPress#67810)
Browse files Browse the repository at this point in the history
* Try toggle instead of dropdown to show stylebook.

* Use button instead of actual toggle

* Make button icon except if text labels are enabled
  • Loading branch information
tellthemachines authored and yogeshbhutkar committed Dec 18, 2024
1 parent cbd4514 commit 8c94287
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
8 changes: 1 addition & 7 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library
import { useCallback, useMemo } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as preferencesStore } from '@wordpress/preferences';
import { decodeEntities } from '@wordpress/html-entities';
import { Icon, arrowUpLeft } from '@wordpress/icons';
import { store as blockEditorStore } from '@wordpress/block-editor';
Expand Down Expand Up @@ -130,21 +129,18 @@ export default function EditSiteEditor( { isPostsList = false } ) {
const { postType, postId, context } = entity;
const {
supportsGlobalStyles,
showIconLabels,
editorCanvasView,
currentPostIsTrashed,
hasSiteIcon,
} = useSelect( ( select ) => {
const { getEditorCanvasContainerView } = unlock(
select( editSiteStore )
);
const { get } = select( preferencesStore );
const { getCurrentTheme, getEntityRecord } = select( coreDataStore );
const siteData = getEntityRecord( 'root', '__unstableBase', undefined );

return {
supportsGlobalStyles: getCurrentTheme()?.is_block_theme,
showIconLabels: get( 'core', 'showIconLabels' ),
editorCanvasView: getEditorCanvasContainerView(),
currentPostIsTrashed:
select( editorStore ).getCurrentPostAttribute( 'status' ) ===
Expand Down Expand Up @@ -267,9 +263,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
postId={ postWithTemplate ? context.postId : postId }
templateId={ postWithTemplate ? postId : undefined }
settings={ settings }
className={ clsx( 'edit-site-editor__editor-interface', {
'show-icon-labels': showIconLabels,
} ) }
className="edit-site-editor__editor-interface"
styles={ styles }
customSaveButton={
_isPreviewingTheme && <SaveButton size="compact" />
Expand Down
13 changes: 12 additions & 1 deletion packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { PluginArea } from '@wordpress/plugins';
import { store as noticesStore } from '@wordpress/notices';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand Down Expand Up @@ -70,6 +71,15 @@ function Layout() {
triggerAnimationOnChange: routeKey + '-' + canvas,
} );

const { showIconLabels } = useSelect( ( select ) => {
return {
showIconLabels: select( preferencesStore ).get(
'core',
'showIconLabels'
),
};
} );

const [ backgroundColor ] = useGlobalStyle( 'color.background' );
const [ gradientValue ] = useGlobalStyle( 'color.gradient' );
const previousCanvaMode = usePrevious( canvas );
Expand All @@ -93,6 +103,7 @@ function Layout() {
navigateRegionsProps.className,
{
'is-full-canvas': canvas === 'edit',
'show-icon-labels': showIconLabels,
}
) }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { __ } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useViewportMatch } from '@wordpress/compose';
import {
Button,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { Button } from '@wordpress/components';
import { addQueryArgs } from '@wordpress/url';
import { seen } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -21,44 +19,21 @@ import StyleBook from '../style-book';
import { STYLE_BOOK_COLOR_GROUPS } from '../style-book/constants';

const { useLocation, useHistory } = unlock( routerPrivateApis );
const { Menu } = unlock( componentsPrivateApis );

const GlobalStylesPageActions = ( {
isStyleBookOpened,
setIsStyleBookOpened,
} ) => {
return (
<Menu
trigger={
<Button __next40pxDefaultSize variant="tertiary" size="compact">
{ __( 'Preview' ) }
</Button>
}
>
<Menu.RadioItem
value
checked={ isStyleBookOpened }
name="styles-preview-actions"
onChange={ () => setIsStyleBookOpened( true ) }
defaultChecked
>
<Menu.ItemLabel>{ __( 'Style book' ) }</Menu.ItemLabel>
<Menu.ItemHelpText>
{ __( 'Preview blocks and styles.' ) }
</Menu.ItemHelpText>
</Menu.RadioItem>
<Menu.RadioItem
value={ false }
checked={ ! isStyleBookOpened }
name="styles-preview-actions"
onChange={ () => setIsStyleBookOpened( false ) }
>
<Menu.ItemLabel>{ __( 'Site' ) }</Menu.ItemLabel>
<Menu.ItemHelpText>
{ __( 'Preview your site.' ) }
</Menu.ItemHelpText>
</Menu.RadioItem>
</Menu>
<Button
isPressed={ isStyleBookOpened }
icon={ seen }
label={ __( 'Style Book' ) }
onClick={ () => {
setIsStyleBookOpened( ! isStyleBookOpened );
} }
size="compact"
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@
color: $gray-900;
}
}

.show-icon-labels {
.edit-site-styles .edit-site-page-content {
.edit-site-page-header__actions {
.components-button.has-icon {
width: auto;
padding: 0 $grid-unit-10;

// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
font-size: $helptext-font-size;
}
}

}
}
}

0 comments on commit 8c94287

Please sign in to comment.