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

Adds a default text label to the block appender when it can only insert a single block type #22293

Merged
merged 2 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
58 changes: 35 additions & 23 deletions packages/block-editor/src/components/button-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { Icon, create } from '@wordpress/icons';
*/
import Inserter from '../inserter';

function AddTooltipForIconButton( { hasTooltip, tooltipLabel, button } ) {
draganescu marked this conversation as resolved.
Show resolved Hide resolved
if ( hasTooltip ) {
return <Tooltip text={ tooltipLabel }> { button } </Tooltip>;
}
return button;
}

function ButtonBlockAppender(
{
rootClientId,
Expand Down Expand Up @@ -52,30 +59,35 @@ function ButtonBlockAppender(
);
}
const isToggleButton = ! hasSingleBlockType;
return (
<Tooltip text={ label }>
<Button
ref={ ref }
onFocus={ onFocus }
tabIndex={ tabIndex }
className={ classnames(
className,
'block-editor-button-block-appender'
) }
onClick={ onToggle }
aria-haspopup={
isToggleButton ? 'true' : undefined
}
aria-expanded={
isToggleButton ? isOpen : undefined
}
disabled={ disabled }
label={ label }
>

const inserterButton = (
<Button
ref={ ref }
onFocus={ onFocus }
tabIndex={ tabIndex }
className={ classnames(
className,
'block-editor-button-block-appender'
) }
onClick={ onToggle }
aria-haspopup={ isToggleButton ? 'true' : undefined }
aria-expanded={ isToggleButton ? isOpen : undefined }
disabled={ disabled }
label={ label }
>
{ ! hasSingleBlockType && (
<VisuallyHidden as="span">{ label }</VisuallyHidden>
<Icon icon={ create } />
</Button>
</Tooltip>
) }
<Icon icon={ create } />
{ hasSingleBlockType && <span>{ label } </span> }
</Button>
);
return (
<AddTooltipForIconButton
draganescu marked this conversation as resolved.
Show resolved Hide resolved
hasTooltip={ ! hasSingleBlockType }
tooltipLabel={ label }
button={ inserterButton }
/>
);
} }
isAppender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@

// This variant is used in inline situations, like Buttons, Social Links, Navigation Menu.
&.block-list-appender__toggle {
background: $dark-gray-primary;
color: $white;
display: flex;
flex-direction: row;
color: $dark-gray-primary;
box-shadow: none;
width: 24px;
height: 24px;
padding: 0;
margin-left: $grid-unit-10;

&:active {
color: $white;
}

& > svg {
width: 24px;
background-color: $dark-gray-primary;
color: $white;
}

& > span {
draganescu marked this conversation as resolved.
Show resolved Hide resolved
display: block;
margin-left: $grid-unit-10;
}
}
}