diff --git a/packages/clay-color-picker/src/Hue.tsx b/packages/clay-color-picker/src/Hue.tsx index b8ef6e16ce..5eea768965 100644 --- a/packages/clay-color-picker/src/Hue.tsx +++ b/packages/clay-color-picker/src/Hue.tsx @@ -3,13 +3,11 @@ * SPDX-License-Identifier: BSD-3-Clause */ -import {Keys} from '@clayui/shared'; -import React, {useCallback} from 'react'; +import {ClayInput} from '@clayui/form'; +import ClaySlider from '@clayui/slider'; +import React from 'react'; import {LimitValue} from './Editor'; -import {usePointerPosition} from './hooks'; -import {hueToX, xToHue} from './util'; - type Props = { /** * Callback function for when the hue value changes @@ -22,90 +20,52 @@ type Props = { value: number; }; -const useIsomorphicLayoutEffect = - typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect; - /** * Renders Hue component */ const ClayColorPickerHue = ({value = 0, onChange = () => {}}: Props) => { - const containerRef = React.useRef(null); - const selectorActive = React.useRef(false); - - const {onPointerMove, setXY, x, y} = usePointerPosition(containerRef); - - const removeListeners = useCallback(() => { - selectorActive.current = false; - - window.removeEventListener('pointermove', onPointerMove); - window.removeEventListener('pointerup', removeListeners); - }, []); - - const onKeyDown = (event: React.KeyboardEvent) => { - event.preventDefault(); - - switch (event.key) { - case Keys.Left: - onChange(value - 1); - break; - case Keys.Right: - onChange(value + 1); - break; - default: - return; - } - }; - - useIsomorphicLayoutEffect(() => { - if (containerRef.current && selectorActive.current) { - onChange(xToHue(x, containerRef.current)); - } - }, [x]); - - React.useEffect(() => { - if (containerRef.current) { - setXY({x: hueToX(value, containerRef.current), y}); - } - }, [value]); - - React.useEffect(() => removeListeners, []); - return ( -
onKeyDown(event)} - onPointerDown={(event) => { - event.preventDefault(); - - selectorActive.current = true; - onPointerMove(event); - - (containerRef.current!.querySelector( - '.clay-color-range-pointer' - ) as HTMLElement)!.focus(); - - window.addEventListener('pointermove', onPointerMove); - window.addEventListener('pointerup', removeListeners); - }} - ref={containerRef} - role="slider" - tabIndex={0} - > -