Skip to content

Commit

Permalink
Border Controls: Display color indicator and check selected color (#3…
Browse files Browse the repository at this point in the history
…4467)

* Fix border panel color indicator

* Pass color value rather than slug as prop, to fix preset color preview

* Lazily initialize state
  • Loading branch information
stacimc authored Sep 8, 2021
1 parent 5d21c21 commit e3ebc6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/block-editor/src/hooks/border-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import classnames from 'classnames';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -48,8 +49,18 @@ export function BorderColorEdit( props ) {
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const disableCustomColors = ! useSetting( 'color.custom' );
const disableCustomGradients = ! useSetting( 'color.customGradient' );
const [ colorValue, setColorValue ] = useState(
() =>
getColorObjectByAttributeValues(
colors,
borderColor,
style?.border?.color
)?.color
);

const onChangeColor = ( value ) => {
setColorValue( value );

const colorObject = getColorObjectByColorValue( colors, value );
const newStyle = {
...style,
Expand All @@ -71,7 +82,7 @@ export function BorderColorEdit( props ) {
return (
<ColorGradientControl
label={ __( 'Color' ) }
value={ borderColor || style?.border?.color }
colorValue={ colorValue }
colors={ colors }
gradients={ undefined }
disableCustomColors={ disableCustomColors }
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/sidebar/border-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function BorderPanel( {
{ hasBorderColor && (
<ColorGradientControl
label={ __( 'Color' ) }
value={ borderColor }
colorValue={ borderColor }
colors={ colors }
gradients={ undefined }
disableCustomColors={ disableCustomColors }
Expand Down

0 comments on commit e3ebc6d

Please sign in to comment.