From 45796901d7b6e424e466c37bb6728074c8e4eae0 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 17 Nov 2021 16:05:42 +1000 Subject: [PATCH] Update border color to display multiple color palette origins --- .../use-common-single-multiple-selects.js | 3 +-- .../block-editor/src/hooks/border-color.js | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js b/packages/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js index a76c849a8f126..6a538a33de44e 100644 --- a/packages/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js +++ b/packages/block-editor/src/components/colors-gradients/use-common-single-multiple-selects.js @@ -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' ), diff --git a/packages/block-editor/src/hooks/border-color.js b/packages/block-editor/src/hooks/border-color.js index 30f7d15233dd9..6c7e00a08c597 100644 --- a/packages/block-editor/src/hooks/border-color.js +++ b/packages/block-editor/src/hooks/border-color.js @@ -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, @@ -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 @@ -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: { @@ -87,12 +93,10 @@ export function BorderColorEdit( props ) { ); }