(props: AriaColorAreaOptions, state: ColorAreaState)
| 75 | * gradient background. |
| 76 | */ |
| 77 | export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState): ColorAreaAria { |
| 78 | let { |
| 79 | isDisabled, |
| 80 | inputXRef, |
| 81 | inputYRef, |
| 82 | containerRef, |
| 83 | 'aria-label': ariaLabel, |
| 84 | xName, |
| 85 | yName, |
| 86 | form |
| 87 | } = props; |
| 88 | let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/color'); |
| 89 | |
| 90 | let {addGlobalListener, removeGlobalListener} = useGlobalListeners(); |
| 91 | |
| 92 | let {direction, locale} = useLocale(); |
| 93 | |
| 94 | let [focusedInput, setFocusedInput] = useState<'x' | 'y' | null>(null); |
| 95 | let focusInput = useCallback( |
| 96 | (inputRef: RefObject<HTMLInputElement | null> = inputXRef) => { |
| 97 | if (inputRef.current) { |
| 98 | focusWithoutScrolling(inputRef.current); |
| 99 | } |
| 100 | }, |
| 101 | [inputXRef] |
| 102 | ); |
| 103 | |
| 104 | useFormReset(inputXRef, state.defaultValue, state.setValue); |
| 105 | |
| 106 | let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = useState(false); |
| 107 | let [valueChangedViaInputChangeEvent, setValueChangedViaInputChangeEvent] = useState(false); |
| 108 | let {xChannel, yChannel, zChannel} = state.channels; |
| 109 | let xChannelStep = state.xChannelStep; |
| 110 | let yChannelStep = state.yChannelStep; |
| 111 | |
| 112 | let currentPosition = useRef<{x: number; y: number} | null>(null); |
| 113 | |
| 114 | let {keyboardProps} = useKeyboard({ |
| 115 | onKeyDown(e) { |
| 116 | // these are the cases that useMove doesn't handle |
| 117 | if (!/^(PageUp|PageDown|Home|End)$/.test(e.key)) { |
| 118 | e.continuePropagation(); |
| 119 | return; |
| 120 | } |
| 121 | // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us |
| 122 | e.preventDefault(); |
| 123 | // remember to set this and unset it so that onChangeEnd is fired |
| 124 | state.setDragging(true); |
| 125 | setValueChangedViaKeyboard(true); |
| 126 | let dir; |
| 127 | switch (e.key) { |
| 128 | case 'PageUp': |
| 129 | state.incrementY(state.yChannelPageStep); |
| 130 | dir = 'y'; |
| 131 | break; |
| 132 | case 'PageDown': |
| 133 | state.decrementY(state.yChannelPageStep); |
| 134 | dir = 'y'; |
no test coverage detected