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

Function onColorAreaDown

packages/react-aria/src/color/useColorArea.ts:288–324  ·  view source on GitHub ↗
(
    colorArea: Element,
    id: number | null | undefined,
    clientX: number,
    clientY: number
  )

Source from the content-addressed store, hash-verified

286 };
287
288 let onColorAreaDown = (
289 colorArea: Element,
290 id: number | null | undefined,
291 clientX: number,
292 clientY: number
293 ) => {
294 let rect = colorArea.getBoundingClientRect();
295 let {width, height} = rect;
296 let x = (clientX - rect.x) / width;
297 let y = (clientY - rect.y) / height;
298 if (direction === 'rtl') {
299 x = 1 - x;
300 }
301 if (
302 x >= 0 &&
303 x <= 1 &&
304 y >= 0 &&
305 y <= 1 &&
306 !state.isDragging &&
307 currentPointer.current === undefined
308 ) {
309 isOnColorArea.current = true;
310 setValueChangedViaKeyboard(false);
311 currentPointer.current = id;
312 state.setColorFromPoint(x, y);
313
314 focusInput();
315 state.setDragging(true);
316
317 if (typeof PointerEvent !== 'undefined') {
318 addGlobalListener(window, 'pointerup', onColorAreaUp, false);
319 } else {
320 addGlobalListener(window, 'mouseup', onColorAreaUp, false);
321 addGlobalListener(window, 'touchend', onColorAreaUp, false);
322 }
323 }
324 };
325
326 let onColorAreaUp = e => {
327 let id = e.pointerId ?? e.changedTouches?.[0].identifier;

Callers 1

useColorAreaFunction · 0.85

Calls 2

setColorFromPointMethod · 0.80
setDraggingMethod · 0.65

Tested by

no test coverage detected