Spaces:
Running
Running
File size: 1,812 Bytes
391a73c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { createPortal } from 'react-dom';
import { LeafletContext } from './context.js';
export function createContainerComponent(useElement) {
function ContainerComponent(props, forwardedRef) {
const { instance, context } = useElement(props).current;
useImperativeHandle(forwardedRef, ()=>instance);
const { children } = props;
return children == null ? null : /*#__PURE__*/ React.createElement(LeafletContext, {
value: context
}, children);
}
return /*#__PURE__*/ forwardRef(ContainerComponent);
}
export function createDivOverlayComponent(useElement) {
function OverlayComponent(props, forwardedRef) {
const [isOpen, setOpen] = useState(false);
const { instance } = useElement(props, setOpen).current;
useImperativeHandle(forwardedRef, ()=>instance);
// biome-ignore lint/correctness/useExhaustiveDependencies: update overlay when children change
useEffect(function updateOverlay() {
if (isOpen) {
instance.update();
}
}, [
instance,
isOpen,
props.children
]);
// @ts-ignore _contentNode missing in type definition
const contentNode = instance._contentNode;
return contentNode ? /*#__PURE__*/ createPortal(props.children, contentNode) : null;
}
return /*#__PURE__*/ forwardRef(OverlayComponent);
}
export function createLeafComponent(useElement) {
function LeafComponent(props, forwardedRef) {
const { instance } = useElement(props).current;
useImperativeHandle(forwardedRef, ()=>instance);
return null;
}
return /*#__PURE__*/ forwardRef(LeafComponent);
}
|