| 54 | * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track. |
| 55 | */ |
| 56 | export function useColorWheel( |
| 57 | props: AriaColorWheelOptions, |
| 58 | state: ColorWheelState, |
| 59 | inputRef: RefObject<HTMLInputElement | null> |
| 60 | ): ColorWheelAria { |
| 61 | let {isDisabled, innerRadius, outerRadius, 'aria-label': ariaLabel, name, form} = props; |
| 62 | |
| 63 | let {addGlobalListener, removeGlobalListener} = useGlobalListeners(); |
| 64 | |
| 65 | let thumbRadius = (innerRadius + outerRadius) / 2; |
| 66 | |
| 67 | let focusInput = useCallback(() => { |
| 68 | if (inputRef.current) { |
| 69 | focusWithoutScrolling(inputRef.current); |
| 70 | } |
| 71 | }, [inputRef]); |
| 72 | |
| 73 | useFormReset(inputRef, state.defaultValue, state.setValue); |
| 74 | |
| 75 | let currentPosition = useRef<{x: number; y: number} | null>(null); |
| 76 | |
| 77 | let {keyboardProps} = useKeyboard({ |
| 78 | shortcuts: { |
| 79 | PageUp: () => { |
| 80 | state.setDragging(true); |
| 81 | state.increment(state.pageStep); |
| 82 | state.setDragging(false); |
| 83 | }, |
| 84 | PageDown: () => { |
| 85 | state.setDragging(true); |
| 86 | state.decrement(state.pageStep); |
| 87 | state.setDragging(false); |
| 88 | } |
| 89 | }, |
| 90 | allowRepeats: true |
| 91 | }); |
| 92 | |
| 93 | let moveHandler = { |
| 94 | onMoveStart() { |
| 95 | currentPosition.current = null; |
| 96 | state.setDragging(true); |
| 97 | }, |
| 98 | onMove({deltaX, deltaY, pointerType, shiftKey}) { |
| 99 | if (currentPosition.current == null) { |
| 100 | currentPosition.current = state.getThumbPosition(thumbRadius); |
| 101 | } |
| 102 | currentPosition.current.x += deltaX; |
| 103 | currentPosition.current.y += deltaY; |
| 104 | if (pointerType === 'keyboard') { |
| 105 | if (deltaX > 0 || deltaY < 0) { |
| 106 | state.increment(shiftKey ? state.pageStep : state.step); |
| 107 | } else if (deltaX < 0 || deltaY > 0) { |
| 108 | state.decrement(shiftKey ? state.pageStep : state.step); |
| 109 | } |
| 110 | } else { |
| 111 | state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius); |
| 112 | } |
| 113 | }, |