(useElement: ReturnType<DivOverlayHook<E, PropsWithoutRef<P>>>)
| 37 | } |
| 38 | |
| 39 | export function createDivOverlayComponent< |
| 40 | E extends DivOverlay, |
| 41 | P extends PropsWithChildren, |
| 42 | >(useElement: ReturnType<DivOverlayHook<E, PropsWithoutRef<P>>>) { |
| 43 | function OverlayComponent(props: PropsWithoutRef<P>, forwardedRef: Ref<E>) { |
| 44 | const [isOpen, setOpen] = useState(false) |
| 45 | const { instance } = useElement(props, setOpen).current |
| 46 | |
| 47 | useImperativeHandle(forwardedRef, () => instance) |
| 48 | // biome-ignore lint/correctness/useExhaustiveDependencies: update overlay when children change |
| 49 | useEffect( |
| 50 | function updateOverlay() { |
| 51 | if (isOpen) { |
| 52 | instance.update() |
| 53 | } |
| 54 | }, |
| 55 | [instance, isOpen, props.children], |
| 56 | ) |
| 57 | |
| 58 | // @ts-ignore _contentNode missing in type definition |
| 59 | const contentNode = instance._contentNode |
| 60 | return contentNode ? createPortal(props.children, contentNode) : null |
| 61 | } |
| 62 | |
| 63 | return forwardRef(OverlayComponent) |
| 64 | } |
| 65 | |
| 66 | export function createLeafComponent<E, P>( |
| 67 | useElement: ElementHook<E, PropsWithoutRef<P>>, |
no outgoing calls
no test coverage detected
searching dependent graphs…