MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useColorArea

Function useColorArea

packages/react-aria/src/color/useColorArea.ts:77–581  ·  view source on GitHub ↗
(props: AriaColorAreaOptions, state: ColorAreaState)

Source from the content-addressed store, hash-verified

75 * gradient background.
76 */
77export 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';

Callers 2

ColorArea.tsxFile · 0.90
ColorArea.tsxFile · 0.90

Calls 15

useGlobalListenersFunction · 0.90
useLocaleFunction · 0.90
focusWithoutScrollingFunction · 0.90
useFormResetFunction · 0.90
useKeyboardFunction · 0.90
useMoveFunction · 0.90
useFocusWithinFunction · 0.90
mergePropsFunction · 0.90
useFocusFunction · 0.90
useLabelsFunction · 0.90
useVisuallyHiddenFunction · 0.90

Tested by

no test coverage detected