Skip to content

Commit

Permalink
Update border color to display multiple color palette origins
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw authored and stacimc committed Nov 24, 2021
1 parent 30210e1 commit 4579690
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Expand Up @@ -3,8 +3,7 @@
*/
import useSetting from '../use-setting';

export default
function useCommonSingleMultipleSelects() {
export default function useCommonSingleMultipleSelects() {
return {
disableCustomColors: ! useSetting( 'color.custom' ),
disableCustomGradients: ! useSetting( 'color.customGradient' ),
Expand Down
22 changes: 13 additions & 9 deletions packages/block-editor/src/hooks/border-color.js
Expand Up @@ -15,6 +15,7 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import ColorGradientControl from '../components/colors-gradients/control';
import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
import {
getColorClassName,
getColorObjectByColorValue,
Expand Down Expand Up @@ -50,13 +51,15 @@ export function BorderColorEdit( props ) {
attributes: { borderColor, style },
setAttributes,
} = props;
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const disableCustomColors = ! useSetting( 'color.custom' );
const disableCustomGradients = ! useSetting( 'color.customGradient' );
const colorGradientSettings = useMultipleOriginColorsAndGradients();
const availableColors = colorGradientSettings.colors.reduce(
( colors, origin ) => colors.concat( origin.colors ),
[]
);
const [ colorValue, setColorValue ] = useState(
() =>
getColorObjectByAttributeValues(
colors,
availableColors,
borderColor,
style?.border?.color
)?.color
Expand All @@ -65,7 +68,10 @@ export function BorderColorEdit( props ) {
const onChangeColor = ( value ) => {
setColorValue( value );

const colorObject = getColorObjectByColorValue( colors, value );
const colorObject = getColorObjectByColorValue(
availableColors,
value
);
const newStyle = {
...style,
border: {
Expand All @@ -87,12 +93,10 @@ export function BorderColorEdit( props ) {
<ColorGradientControl
label={ __( 'Color' ) }
colorValue={ colorValue }
colors={ colors }
gradients={ undefined }
disableCustomColors={ disableCustomColors }
disableCustomGradients={ disableCustomGradients }
onColorChange={ onChangeColor }
clearable={ false }
__experimentalHasMultipleOrigins
{ ...colorGradientSettings }
/>
);
}
Expand Down

0 comments on commit 4579690

Please sign in to comment.