MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useColorWheel

Function useColorWheel

packages/react-aria/src/color/useColorWheel.ts:56–380  ·  view source on GitHub ↗
(
  props: AriaColorWheelOptions,
  state: ColorWheelState,
  inputRef: RefObject<HTMLInputElement | null>
)

Source from the content-addressed store, hash-verified

54 * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
55 */
56export 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 },

Callers 4

ColorWheelFunction · 0.90
ColorWheel.tsxFile · 0.90
ColorWheel.tsxFile · 0.90
ColorWheelFunction · 0.90

Calls 15

useGlobalListenersFunction · 0.90
focusWithoutScrollingFunction · 0.90
useFormResetFunction · 0.90
useKeyboardFunction · 0.90
useMoveFunction · 0.90
mergePropsFunction · 0.90
useLocaleFunction · 0.90
useLabelsFunction · 0.90
useVisuallyHiddenFunction · 0.90
getEventTargetFunction · 0.90
onTrackDownFunction · 0.85
circlePathFunction · 0.85

Tested by 1

ColorWheelFunction · 0.72