Skip to content

Commit

Permalink
Show text labels in block toolbars when option is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Oct 15, 2020
1 parent 7493226 commit 958944c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 8 deletions.
15 changes: 12 additions & 3 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Component } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { stack } from '@wordpress/icons';
import { withViewportMatch } from '@wordpress/viewport';

/**
* Internal dependencies
Expand Down Expand Up @@ -94,6 +95,7 @@ export class BlockSwitcher extends Component {
onTransform,
inserterItems,
hasBlockStyles,
isSmallScreen,
} = this.props;
const { hoveredClassName } = this.state;

Expand Down Expand Up @@ -128,22 +130,28 @@ export class BlockSwitcher extends Component {

const hasPossibleBlockTransformations = !! possibleBlockTransformations.length;

const blockTitle = getBlockType( hoveredBlock.name ).title;

if ( ! hasBlockStyles && ! hasPossibleBlockTransformations ) {
return (
<ToolbarGroup>
<ToolbarButton
disabled
className="block-editor-block-switcher__no-switcher-icon"
title={ __( 'Block icon' ) }
title={ blockTitle }
icon={ <BlockIcon icon={ icon } showColors /> }
/>
</ToolbarGroup>
);
}

const singleBlockLabel = isSmallScreen
? blockTitle
: `${ __( 'Change block type or style' ) } ( ${ blockTitle } )`;

const blockSwitcherLabel =
1 === blocks.length
? __( 'Change block type or style' )
? singleBlockLabel
: sprintf(
/* translators: %s: number of blocks. */
_n(
Expand Down Expand Up @@ -258,5 +266,6 @@ export default compose(
switchToBlockType( blocks, name )
);
},
} ) )
} ) ),
withViewportMatch( { isSmallScreen: '< small' } )
)( BlockSwitcher );
85 changes: 85 additions & 0 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,88 @@
opacity: 0;
transition: opacity 300ms;
}

.show-icon-labels {
.block-editor-block-toolbar {
.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);
}
}
}

// Padding overrides.

.components-accessible-toolbar .components-toolbar-group > div:first-child:last-child > .components-button.has-icon {
padding-left: 6px;
padding-right: 6px;
}

// Switcher overrides.
.block-editor-block-switcher {
border-right: 1px solid $gray-900;

.components-dropdown-menu__toggle {
margin-left: 0;
}
}

.block-editor-block-switcher .components-dropdown-menu__toggle,
.block-editor-block-switcher__no-switcher-icon {
.block-editor-block-icon {
width: 0 !important;
height: 0 !important;
}

&:focus::before {
right: $grid-unit-05 !important;
}
}

// Parent selector overrides

.block-editor-block-parent-selector__button {
.block-editor-block-icon {
width: 0;
}
}

// Mover overrides.
.block-editor-block-toolbar__block-controls .block-editor-block-mover {
margin-left: 0;
white-space: nowrap;
}

.block-editor-block-mover__drag-handle.has-icon {
padding-left: 6px !important;
padding-right: 6px !important;
border-right: 1px solid $gray-900;
}

.is-up-button {
border-bottom: 1px solid $gray-900;
}

.block-editor-block-contextual-toolbar .block-editor-block-mover.is-horizontal .block-editor-block-mover-button.block-editor-block-mover-button {
width: auto;
}

// Mobile adjustments
.components-toolbar,
.components-toolbar-group {
flex-shrink: 1;
}

.block-editor-format-toolbar {
.components-button + .components-button {
margin-left: 6px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ const FormatToolbar = () => {
{ ( toggleProps ) => (
<DropdownMenu
icon={ chevronDown }
label={ __(
'More rich text controls'
) }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'More formatting' ) }
toggleProps={ toggleProps }
controls={ orderBy(
fills.map(
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@
}
// Exception for drodpdown toggle buttons.
// Exception for the fullscreen mode button.
// Temporary exception for block toolbar (pending design).
.edit-post-header-toolbar__block-toolbar .components-button.has-icon,
.edit-post-fullscreen-mode-close.has-icon,
.components-button.has-icon.button-toggle {
svg {
Expand Down

0 comments on commit 958944c

Please sign in to comment.