From 327725e794c9ef600b6555138e36d00551e4e010 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 3 Dec 2021 20:01:24 +0000 Subject: [PATCH] Update: Make the color popover on the gradient picker appear as expected --- .../components/colors-gradients/control.js | 3 ++ .../components/src/color-palette/index.js | 23 ++++++--- .../test/__snapshots__/index.js.snap | 49 ++++++++++--------- .../src/custom-gradient-bar/constants.js | 5 -- .../src/custom-gradient-bar/control-points.js | 47 +++++++++++++++--- .../src/custom-gradient-bar/index.js | 8 +++ .../src/custom-gradient-picker/index.js | 9 +++- .../components/src/gradient-picker/index.js | 4 ++ packages/components/src/palette-edit/index.js | 1 + 9 files changed, 106 insertions(+), 43 deletions(-) diff --git a/packages/block-editor/src/components/colors-gradients/control.js b/packages/block-editor/src/components/colors-gradients/control.js index 783b35a6a5c221..4be2e4b1f083b1 100644 --- a/packages/block-editor/src/components/colors-gradients/control.js +++ b/packages/block-editor/src/components/colors-gradients/control.js @@ -132,6 +132,9 @@ function ColorGradientControlInner( { __experimentalHasMultipleOrigins={ __experimentalHasMultipleOrigins } + __experimentalIsRenderedInSidebar={ + __experimentalIsRenderedInSidebar + } clearable={ clearable } /> ) } diff --git a/packages/components/src/color-palette/index.js b/packages/components/src/color-palette/index.js index 64778a449f2c2d..39ec5ebfc09c3d 100644 --- a/packages/components/src/color-palette/index.js +++ b/packages/components/src/color-palette/index.js @@ -110,6 +110,20 @@ function MultiplePalettes( { ); } +export function CustomColorPickerDropdown( { isRenderedInSidebar, ...props } ) { + return ( + + ); +} + export default function ColorPalette( { clearable = true, className, @@ -139,13 +153,8 @@ export default function ColorPalette( { return ( { ! disableCustomColors && ( - ( - - + + + + { + const result = { + className: + 'components-custom-gradient-picker__color-picker-popover', + position: 'top', + }; + if ( isRenderedInSidebar ) { + result.anchorRef = gradientPickerDomRef.current; + result.position = isRTL() ? 'bottom right' : 'bottom left'; + result.__unstableForcePosition = true; + } + return result; + }, [ gradientPickerDomRef.current, isRenderedInSidebar ] ); + return ( + + ); +} + function ControlPoints( { disableRemove, disableAlpha, @@ -83,6 +109,7 @@ function ControlPoints( { onChange, onStartControlPointChange, onStopControlPointChange, + __experimentalIsRenderedInSidebar, } ) { const controlPointMoveState = useRef(); @@ -134,7 +161,9 @@ function ControlPoints( { const initialPosition = point?.position; return ( ignoreMarkerPosition !== initialPosition && ( - ( @@ -244,7 +273,6 @@ function ControlPoints( { ) } ) } - popoverProps={ COLOR_POPOVER_PROPS } /> ) ); @@ -258,10 +286,14 @@ function InsertPoint( { onCloseInserter, insertPosition, disableAlpha, + __experimentalIsRenderedInSidebar, + gradientPickerDomRef, } ) { const [ alreadyInsertedPoint, setAlreadyInsertedPoint ] = useState( false ); return ( - { onCloseInserter(); @@ -314,7 +346,6 @@ function InsertPoint( { } } /> ) } - popoverProps={ COLOR_POPOVER_PROPS } /> ); } diff --git a/packages/components/src/custom-gradient-bar/index.js b/packages/components/src/custom-gradient-bar/index.js index 823e3d00992a32..87b14cac434d67 100644 --- a/packages/components/src/custom-gradient-bar/index.js +++ b/packages/components/src/custom-gradient-bar/index.js @@ -78,6 +78,7 @@ export default function CustomGradientBar( { onChange, disableInserter = false, disableAlpha = false, + __experimentalIsRenderedInSidebar, } ) { const gradientPickerDomRef = useRef(); @@ -134,6 +135,10 @@ export default function CustomGradientBar( { { ! disableInserter && ( isMovingInserter || isInsertingControlPoint ) && ( ) } { ); }; -export default function CustomGradientPicker( { value, onChange } ) { +export default function CustomGradientPicker( { + value, + onChange, + __experimentalIsRenderedInSidebar, +} ) { const gradientAST = getGradientAstWithDefault( value ); // On radial gradients the bar should display a linear gradient. // On radial gradients the bar represents a slice of the gradient from the center until the outside. @@ -121,6 +125,9 @@ export default function CustomGradientPicker( { value, onChange } ) { return (
onChange( undefined ), [ onChange, @@ -136,6 +137,9 @@ export default function GradientPicker( { content={ ! disableCustomGradients && ( diff --git a/packages/components/src/palette-edit/index.js b/packages/components/src/palette-edit/index.js index ddd8903b7a6b90..b4de9800c9ecec 100644 --- a/packages/components/src/palette-edit/index.js +++ b/packages/components/src/palette-edit/index.js @@ -127,6 +127,7 @@ function Option( { ) } { isGradient && ( onChange( {