({isExiting, onExited, containerRef, loupeRef, getPosition, color}: any)
| 110 | } |
| 111 | |
| 112 | function 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 | }} |
nothing calls this directly
no test coverage detected