(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 keyboardUpdate = (cb, inputRef: RefObject<HTMLInputElement | null>, input: 'x' | 'y') => { |
| 115 | state.setDragging(true); |
| 116 | setValueChangedViaKeyboard(true); |
| 117 | cb(); |
| 118 | state.setDragging(false); |
| 119 | focusInput(inputRef); |
| 120 | setFocusedInput(input); |
| 121 | }; |
| 122 | |
| 123 | let {keyboardProps} = useKeyboard({ |
| 124 | shortcuts: { |
| 125 | PageUp: () => { |
| 126 | return keyboardUpdate( |
| 127 | () => { |
| 128 | state.incrementY(state.yChannelPageStep); |
| 129 | }, |
| 130 | inputYRef, |
| 131 | 'y' |
| 132 | ); |
| 133 | }, |
| 134 | PageDown: () => { |
no test coverage detected