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

Function ColorLoupe

packages/@react-spectrum/s2/src/ColorHandle.tsx:112–200  ·  view source on GitHub ↗
({isExiting, onExited, containerRef, loupeRef, getPosition, color}: any)

Source from the content-addressed store, hash-verified

110}
111
112function ColorLoupe({isExiting, onExited, containerRef, loupeRef, getPosition, color}: any) {
113 let patternId = useId();
114
115 // Get the bounding rectangle of the container (e.g. ColorArea/ColorSlider).
116 let [containerRect, setContainerRect] = useState({top: 0, left: 0, width: 0, height: 0});
117 useLayoutEffect(() => {
118 let rect = containerRef.current?.getBoundingClientRect();
119 setContainerRect({
120 top: rect?.top || 0,
121 left: rect?.left || 0,
122 width: rect?.width || 0,
123 height: rect?.height || 0
124 });
125 }, [containerRef]);
126
127 // Compute the pixel position of the thumb.
128 let {x: thumbLeft, y: thumbTop} = getPosition();
129 thumbTop *= containerRect.height;
130 thumbLeft *= containerRect.width;
131
132 let enterAnimation = keyframes(`
133 from {
134 transform: translateY(8px);
135 opacity: 0;
136 }
137 `);
138
139 let exitAnimation = keyframes(`
140 to {
141 transform: translateY(8px);
142 opacity: 0;
143 }
144 `);
145
146 return (
147 <svg
148 style={{
149 // Position relative to the viewport.
150 position: 'fixed',
151 top: containerRect.top + thumbTop,
152 left: containerRect.left + thumbLeft,
153 marginTop: -LOUPE_HEIGHT - LOUPE_BORDER_WIDTH * 2 - HANDLE_SIZE / 2 - LOUPE_OFFSET,
154 marginLeft: -LOUPE_WIDTH / 2 - LOUPE_BORDER_WIDTH,
155 animationName: isExiting ? exitAnimation : enterAnimation
156 }}
157 className={style({
158 filter: 'elevated',
159 pointerEvents: 'none',
160 animationDuration: 125,
161 animationFillMode: 'forwards',
162 animationTimingFunction: 'in-out',
163 isolation: 'isolate'
164 })}
165 onAnimationEnd={e => {
166 if (e.animationName === exitAnimation) {
167 onExited();
168 }
169 }}

Callers

nothing calls this directly

Calls 5

useIdFunction · 0.90
keyframesFunction · 0.90
onExitedFunction · 0.85
toStringMethod · 0.65
getPositionFunction · 0.50

Tested by

no test coverage detected