| 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 | onKeyDown(e) { |
| 79 | // these are the cases that useMove doesn't handle |
| 80 | if (!/^(PageUp|PageDown)$/.test(e.key)) { |
| 81 | e.continuePropagation(); |
| 82 | return; |
| 83 | } |
| 84 | // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us |
| 85 | e.preventDefault(); |
| 86 | // remember to set this and unset it so that onChangeEnd is fired |
| 87 | state.setDragging(true); |
| 88 | switch (e.key) { |
| 89 | case 'PageUp': |
| 90 | e.preventDefault(); |
| 91 | state.increment(state.pageStep); |
| 92 | break; |
| 93 | case 'PageDown': |
| 94 | e.preventDefault(); |
| 95 | state.decrement(state.pageStep); |
| 96 | break; |
| 97 | } |
| 98 | state.setDragging(false); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | let moveHandler = { |
| 103 | onMoveStart() { |
| 104 | currentPosition.current = null; |
| 105 | state.setDragging(true); |
| 106 | }, |
| 107 | onMove({deltaX, deltaY, pointerType, shiftKey}) { |
| 108 | if (currentPosition.current == null) { |
| 109 | currentPosition.current = state.getThumbPosition(thumbRadius); |
| 110 | } |
| 111 | currentPosition.current.x += deltaX; |
| 112 | currentPosition.current.y += deltaY; |
| 113 | if (pointerType === 'keyboard') { |