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

navigation-menu: apply colors correctly in edition mode #18172

Merged
merged 10 commits into from
Nov 6, 2019
23 changes: 7 additions & 16 deletions packages/block-library/src/navigation-menu-item/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,17 @@
.wp-block-navigation-menu-item {
&:not(.is-editing) {
font-family: inherit;
font-size: inherit;
background-color: var(--background-color-menu-link);
color: var(--color-menu-link);
width: inherit;

.components-external-link {
color: var(--color-menu-link);
}
font-size: $text-editor-font-size;
font-weight: bold;
}

&.is-editing .components-text-control__input {
retrofox marked this conversation as resolved.
Show resolved Hide resolved
width: inherit;
background-color: var(--background-color-menu-link);
color: var(--color-menu-link);

.components-external-link {
color: var(--color-menu-link);
&:focus {
color: var(--color-menu-link);
}
background-color: inherit;
color: inherit;

&:focus {
color: inherit;
}
}

Expand Down
48 changes: 33 additions & 15 deletions packages/block-library/src/navigation-menu/block-colors-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,42 @@ const ColorSelectorSVGIcon = () => (
/**
* Color Selector Icon component.
*
* @param {Object} colorControlProps colorControl properties.
* @return {*} React Icon component.
*/
const ColorSelectorIcon = ( { style } ) =>
<div className="block-library-colors-selector__icon-container">
<div
className="block-library-colors-selector__state-selection"
style={ style }
>
<ColorSelectorSVGIcon />
const ColorSelectorIcon = ( { backgroundColor, textColor } ) => {
const iconStyle = {};
if ( textColor && ! textColor.class ) {
iconStyle.color = textColor.color;
}

if ( backgroundColor && ! backgroundColor.class ) {
iconStyle.backgroundColor = backgroundColor.color;
}

const iconClasses = classnames( 'block-library-colors-selector__state-selection', {
'has-background-color': backgroundColor && backgroundColor.color,
'has-text-color': backgroundColor && backgroundColor.color,
[ backgroundColor.class ]: backgroundColor && backgroundColor.class,
[ textColor.class ]: textColor && textColor.class,
} );

return (
<div className="block-library-colors-selector__icon-container">
<div className={ iconClasses } style={ iconStyle }>
<ColorSelectorSVGIcon />
</div>
</div>
</div>;
);
};

/**
* Renders the Colors Selector Toolbar with the icon button.
*
* @param {Object} style - Colors style object.
* @param {Object} colorControlProps colorControl properties.
* @return {*} React toggle button component.
*/
const renderToggleComponent = ( style ) => ( { onToggle, isOpen } ) => {
const renderToggleComponent = ( { backgroundColor, textColor } ) => ( { onToggle, isOpen } ) => {
const openOnArrowDown = ( event ) => {
if ( ! isOpen && event.keyCode === DOWN ) {
event.preventDefault();
Expand All @@ -55,7 +72,7 @@ const renderToggleComponent = ( style ) => ( { onToggle, isOpen } ) => {
label={ __( 'Open Colors Selector' ) }
onClick={ onToggle }
onKeyDown={ openOnArrowDown }
icon={ <ColorSelectorIcon style={ style } /> }
icon={ <ColorSelectorIcon backgroundColor={ backgroundColor } textColor={ textColor } /> }
/>
</Toolbar>
);
Expand Down Expand Up @@ -91,11 +108,12 @@ const renderContent = ( { backgroundColor, textColor, onColorChange = noop } ) =
);
} );

export default ( { style, className, ...colorControlProps } ) =>
export default ( colorControlProps ) => (
<Dropdown
position="bottom right"
className={ classnames( 'block-library-colors-selector', className ) }
className="block-library-colors-selector"
contentClassName="block-library-colors-selector__popover"
renderToggle={ renderToggleComponent( style ) }
renderToggle={ renderToggleComponent( colorControlProps ) }
renderContent={ renderContent( colorControlProps ) }
/>;
/>
);
16 changes: 8 additions & 8 deletions packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ function NavigationMenu( {
[ pages ]
);

const navigationMenuStyles = {};
if ( textColor.color ) {
navigationMenuStyles[ '--color-menu-link' ] = textColor.color;
const navigationMenuInlineStyles = {};
if ( textColor ) {
navigationMenuInlineStyles.color = textColor.color;
}

if ( backgroundColor.color ) {
navigationMenuStyles[ '--background-color-menu-link' ] = backgroundColor.color;
if ( backgroundColor ) {
navigationMenuInlineStyles.backgroundColor = backgroundColor.color;
}

const navigationMenuClasses = classnames(
'wp-block-navigation-menu', {
'has-text-color': textColor.color,
'has-background-color': backgroundColor.color,
[ attributes.backgroundColorCSSClass ]: attributes && attributes.backgroundColorCSSClass,
[ attributes.textColorCSSClass ]: attributes && attributes.textColorCSSClass,
}
);

Expand Down Expand Up @@ -121,8 +123,6 @@ function NavigationMenu( {
{ navigatorToolbarButton }
</Toolbar>
<BlockColorsStyleSelector
style={ navigationMenuStyles }
className={ navigationMenuClasses }
backgroundColor={ backgroundColor }
textColor={ textColor }
onColorChange={ setColorType }
Expand All @@ -147,7 +147,7 @@ function NavigationMenu( {
</PanelBody>
</InspectorControls>

<div className={ navigationMenuClasses } style={ navigationMenuStyles }>
<div className={ navigationMenuClasses } style={ navigationMenuInlineStyles }>
{ isRequesting && <><Spinner /> { __( 'Loading Navigation…' ) } </> }
{ pages &&
<InnerBlocks
Expand Down
12 changes: 4 additions & 8 deletions packages/block-library/src/navigation-menu/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
}
}


.wp-block-navigation-menu .block-editor-block-list__layout,
.wp-block-navigation-menu {
display: flex;
Expand Down Expand Up @@ -123,13 +122,10 @@ $colors-selector-size: 22px;
line-height: ($colors-selector-size - 2);
padding: 2px;

background-color: var(--background-color-menu-link);
color: var(--color-menu-link);
}

&:not(.has-background-color) .block-library-colors-selector__state-selection {
background-image: linear-gradient(135deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.08) 50%, rgba(0, 0, 0, 0.08) 75%, transparent 75%, transparent 100%);
background-size: 12px 12px;
&:not(.has-background-color) {
background-image: linear-gradient(135deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.08) 50%, rgba(0, 0, 0, 0.08) 75%, transparent 75%, transparent 100%);
background-size: 12px 12px;
}
}
}

Expand Down