@wordpress/components
Version:
UI components for WordPress.
33 lines (32 loc) • 1.2 kB
JavaScript
// packages/components/src/slot-fill/bubbles-virtually/fill.tsx
import { useObservableValue } from "@wordpress/compose";
import { useContext, useRef, useEffect, createPortal } from "@wordpress/element";
import SlotFillContext from "./slot-fill-context";
import StyleProvider from "../../style-provider";
import { jsx as _jsx } from "react/jsx-runtime";
function Fill({
name,
children
}) {
var _slot$fillProps;
const registry = useContext(SlotFillContext);
const slot = useObservableValue(registry.slots, name);
const instanceRef = useRef({});
useEffect(() => {
const instance = instanceRef.current;
registry.registerFill(name, instance);
return () => registry.unregisterFill(name, instance);
}, [registry, name]);
if (!slot || !slot.ref.current) {
return null;
}
const wrappedChildren = /* @__PURE__ */ _jsx(StyleProvider, {
document: slot.ref.current.ownerDocument,
children: typeof children === "function" ? children((_slot$fillProps = slot.fillProps) !== null && _slot$fillProps !== void 0 ? _slot$fillProps : {}) : children
});
return createPortal(wrappedChildren, slot.ref.current);
}
export {
Fill as default
};
//# sourceMappingURL=fill.js.map