({ className, children }: MeasuredChartFrameProps)
| 16 | * during route transitions, so gate chart mounting on a measured frame. |
| 17 | */ |
| 18 | export function MeasuredChartFrame({ className, children }: MeasuredChartFrameProps) { |
| 19 | const ref = useRef<HTMLDivElement | null>(null) |
| 20 | const [size, setSize] = useState<ChartFrameSize | null>(null) |
| 21 | |
| 22 | useEffect(() => { |
| 23 | const el = ref.current |
| 24 | if (!el) return |
| 25 | |
| 26 | const measure = () => { |
| 27 | const rect = el.getBoundingClientRect() |
| 28 | setSize(rect.width > 0 && rect.height > 0 |
| 29 | ? { width: Math.floor(rect.width), height: Math.floor(rect.height) } |
| 30 | : null) |
| 31 | } |
| 32 | |
| 33 | measure() |
| 34 | const ro = new ResizeObserver(measure) |
| 35 | ro.observe(el) |
| 36 | return () => ro.disconnect() |
| 37 | }, []) |
| 38 | |
| 39 | return ( |
| 40 | <div ref={ref} className={className}> |
| 41 | {size ? (typeof children === 'function' ? children(size) : children) : null} |
| 42 | </div> |
| 43 | ) |
| 44 | } |
nothing calls this directly
no test coverage detected