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

Add support for the Show button text labels preference to the Widgets editor #68531

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NavigableToolbar } from '@wordpress/block-editor';
import { listView, plus } from '@wordpress/icons';
import { useCallback } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -25,6 +26,7 @@ function DocumentTools() {
isListViewOpen,
inserterSidebarToggleRef,
listViewToggleRef,
showIconLabels,
} = useSelect( ( select ) => {
const {
isInserterOpened,
Expand All @@ -37,6 +39,10 @@ function DocumentTools() {
isListViewOpen: isListViewOpened(),
inserterSidebarToggleRef: getInserterSidebarToggleRef(),
listViewToggleRef: getListViewToggleRef(),
showIconLabels: select( preferencesStore ).get(
'core',
'showIconLabels'
),
};
}, [] );
const { setIsInserterOpened, setIsListViewOpened } =
Expand All @@ -52,6 +58,13 @@ function DocumentTools() {
[ setIsInserterOpened, isInserterOpen ]
);

/* translators: Button label text should, if possible, be under 16 characters. */
const longLabel = _x(
'Block Inserter',
'Generic label for block inserter button'
);
const shortLabel = ! isInserterOpen ? __( 'Add' ) : __( 'Close' );

return (
<NavigableToolbar
className="edit-widgets-header-toolbar"
Expand All @@ -69,18 +82,23 @@ function DocumentTools() {
} }
onClick={ toggleInserterSidebar }
icon={ plus }
/* translators: button label text should, if possible, be under 16
characters. */
label={ _x(
'Block Inserter',
'Generic label for block inserter button'
) }
label={ showIconLabels ? shortLabel : longLabel }
size="compact"
showTooltip={ ! showIconLabels }
aria-expanded={ isInserterOpen }
/>
{ isMediumViewport && (
<>
<ToolbarItem as={ UndoButton } />
<ToolbarItem as={ RedoButton } />
<ToolbarItem
as={ UndoButton }
showTooltip={ ! showIconLabels }
variant={ showIconLabels ? 'tertiary' : undefined }
/>
<ToolbarItem
as={ RedoButton }
showTooltip={ ! showIconLabels }
variant={ showIconLabels ? 'tertiary' : undefined }
/>
<ToolbarItem
as={ Button }
className="edit-widgets-header-toolbar__list-view-toggle"
Expand All @@ -91,6 +109,8 @@ function DocumentTools() {
onClick={ toggleListView }
ref={ listViewToggleRef }
size="compact"
showTooltip={ ! showIconLabels }
variant={ showIconLabels ? 'tertiary' : undefined }
/>
</>
) }
Expand Down
52 changes: 52 additions & 0 deletions packages/edit-widgets/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,58 @@
}
}

/**
* Show icon labels.
*/
.show-icon-labels .edit-widgets-header {
.components-button.has-icon {
width: auto;

// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
white-space: nowrap;
}
&[aria-disabled="true"] {
background-color: transparent;
}
}
.is-tertiary {
&:active {
box-shadow: 0 0 0 1.5px var(--wp-admin-theme-color);
background-color: transparent;
}
}
// Exception for drodpdown toggle buttons.
.components-button.has-icon.button-toggle {
svg {
display: block;
}
&::after {
content: none;
}
}

// Don't hide MenuItemsChoice check icons
.components-menu-items-choice .components-menu-items__item-icon.components-menu-items__item-icon {
display: block;
}
.editor-document-tools__inserter-toggle.editor-document-tools__inserter-toggle,
.interface-pinned-items .components-button {
padding-left: $grid-unit;
padding-right: $grid-unit;

@include break-small {
padding-left: $grid-unit-15;
padding-right: $grid-unit-15;
}
}
}

.edit-widgets-header__navigable-toolbar-wrapper {
display: flex;
align-items: center;
Expand Down
25 changes: 23 additions & 2 deletions packages/edit-widgets/src/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { PluginArea } from '@wordpress/plugins';
import { store as noticesStore } from '@wordpress/notices';
import { __unstableUseNavigateRegions as useNavigateRegions } from '@wordpress/components';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -32,14 +38,29 @@ function Layout( { blockEditorSettings } ) {
);
}

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

const navigateRegionsProps = useNavigateRegions();

return (
<ErrorBoundary>
<div
className={ navigateRegionsProps.className }
{ ...navigateRegionsProps }
ref={ navigateRegionsProps.ref }
className={ clsx(
'edit-widgets-layout',
navigateRegionsProps.className,
{
'show-icon-labels': showIconLabels,
}
) }
>
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
Expand Down
14 changes: 13 additions & 1 deletion packages/edit-widgets/src/components/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import {
import { useState } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { external, moreVertical } from '@wordpress/icons';
import { PreferenceToggleMenuItem } from '@wordpress/preferences';
import {
PreferenceToggleMenuItem,
store as preferencesStore,
} from '@wordpress/preferences';
import { displayShortcut } from '@wordpress/keycodes';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -36,6 +40,12 @@ export default function MoreMenu() {

const isLargeViewport = useViewportMatch( 'medium' );

const showIconLabels = useSelect(
( select ) =>
select( preferencesStore ).get( 'core', 'showIconLabels' ),
[]
);

return (
<>
<DropdownMenu
Expand All @@ -48,6 +58,8 @@ export default function MoreMenu() {
toggleProps={ {
tooltipPosition: 'bottom',
size: 'compact',
showTooltip: ! showIconLabels,
...( showIconLabels && { variant: 'tertiary' } ),
} }
>
{ ( onClose ) => (
Expand Down
Loading