@@ -8,8 +8,8 @@ import { colord } from 'colord';
88 * WordPress dependencies
99 */
1010import { useInstanceId } from '@wordpress/compose' ;
11- import { useEffect , useRef , useState } from '@wordpress/element' ;
12- import { __ , sprintf } from '@wordpress/i18n' ;
11+ import { useEffect , useRef , useState , useMemo } from '@wordpress/element' ;
12+ import { __ , sprintf , isRTL } from '@wordpress/i18n' ;
1313import { plus } from '@wordpress/icons' ;
1414import { LEFT , RIGHT } from '@wordpress/keycodes' ;
1515
@@ -18,8 +18,8 @@ import { LEFT, RIGHT } from '@wordpress/keycodes';
1818 */
1919import Button from '../button' ;
2020import { ColorPicker } from '../color-picker' ;
21- import Dropdown from '../dropdown' ;
2221import { VisuallyHidden } from '../visually-hidden' ;
22+ import { CustomColorPickerDropdown } from '../color-palette' ;
2323
2424import {
2525 addControlPoint ,
@@ -31,7 +31,6 @@ import {
3131 getHorizontalRelativeGradientPosition ,
3232} from './utils' ;
3333import {
34- COLOR_POPOVER_PROPS ,
3534 GRADIENT_MARKERS_WIDTH ,
3635 MINIMUM_SIGNIFICANT_MOVE ,
3736 KEYBOARD_CONTROL_POINT_VARIATION ,
@@ -74,6 +73,33 @@ function ControlPointButton( { isOpen, position, color, ...additionalProps } ) {
7473 ) ;
7574}
7675
76+ function GradientColorPickerDropdown ( {
77+ isRenderedInSidebar,
78+ gradientPickerDomRef,
79+ ...props
80+ } ) {
81+ const popoverProps = useMemo ( ( ) => {
82+ const result = {
83+ className :
84+ 'components-custom-gradient-picker__color-picker-popover' ,
85+ position : 'top' ,
86+ } ;
87+ if ( isRenderedInSidebar ) {
88+ result . anchorRef = gradientPickerDomRef . current ;
89+ result . position = isRTL ( ) ? 'bottom right' : 'bottom left' ;
90+ result . __unstableForcePosition = true ;
91+ }
92+ return result ;
93+ } , [ gradientPickerDomRef . current , isRenderedInSidebar ] ) ;
94+ return (
95+ < CustomColorPickerDropdown
96+ isRenderedInSidebar = { isRenderedInSidebar }
97+ popoverProps = { popoverProps }
98+ { ...props }
99+ />
100+ ) ;
101+ }
102+
77103function ControlPoints ( {
78104 disableRemove,
79105 disableAlpha,
@@ -83,6 +109,7 @@ function ControlPoints( {
83109 onChange,
84110 onStartControlPointChange,
85111 onStopControlPointChange,
112+ __experimentalIsRenderedInSidebar,
86113} ) {
87114 const controlPointMoveState = useRef ( ) ;
88115
@@ -134,7 +161,9 @@ function ControlPoints( {
134161 const initialPosition = point ?. position ;
135162 return (
136163 ignoreMarkerPosition !== initialPosition && (
137- < Dropdown
164+ < GradientColorPickerDropdown
165+ gradientPickerDomRef = { gradientPickerDomRef }
166+ isRenderedInSidebar = { __experimentalIsRenderedInSidebar }
138167 key = { index }
139168 onClose = { onStopControlPointChange }
140169 renderToggle = { ( { isOpen, onToggle } ) => (
@@ -244,7 +273,6 @@ function ControlPoints( {
244273 ) }
245274 </ >
246275 ) }
247- popoverProps = { COLOR_POPOVER_PROPS }
248276 />
249277 )
250278 ) ;
@@ -258,10 +286,14 @@ function InsertPoint( {
258286 onCloseInserter,
259287 insertPosition,
260288 disableAlpha,
289+ __experimentalIsRenderedInSidebar,
290+ gradientPickerDomRef,
261291} ) {
262292 const [ alreadyInsertedPoint , setAlreadyInsertedPoint ] = useState ( false ) ;
263293 return (
264- < Dropdown
294+ < GradientColorPickerDropdown
295+ gradientPickerDomRef = { gradientPickerDomRef }
296+ isRenderedInSidebar = { __experimentalIsRenderedInSidebar }
265297 className = "components-custom-gradient-picker__inserter"
266298 onClose = { ( ) => {
267299 onCloseInserter ( ) ;
@@ -314,7 +346,6 @@ function InsertPoint( {
314346 } }
315347 />
316348 ) }
317- popoverProps = { COLOR_POPOVER_PROPS }
318349 />
319350 ) ;
320351}
0 commit comments