UNPKG

@wordpress/components

Version:
56 lines (55 loc) • 2 kB
import { forwardRef, useContext } from "@wordpress/element"; import Fill from "./fill.mjs"; import BaseSlot from "./slot.mjs"; import BubblesVirtuallySlot from "./bubbles-virtually/slot.mjs"; import SlotFillProvider from "./provider.mjs"; import SlotFillContext from "./context.mjs"; import { Fragment, jsx } from "react/jsx-runtime"; import useSlot from "./bubbles-virtually/use-slot.mjs"; import useSlotFills from "./bubbles-virtually/use-slot-fills.mjs"; // packages/components/src/slot-fill/index.tsx /** * `Slot` marks a location where content rendered by matching `Fill` components * elsewhere will appear. Use it to allow a component to define UI areas that * can be extended from other parts of the application. */ const Slot = forwardRef((props, ref) => { const { bubblesVirtually, ...restProps } = props; if (bubblesVirtually) return /* @__PURE__ */ jsx(BubblesVirtuallySlot, { ...restProps, ref }); return /* @__PURE__ */ jsx(BaseSlot, { ...restProps }); }); Slot.displayName = "Slot"; function Provider({ children, passthrough = false }) { if (!useContext(SlotFillContext).isDefault && passthrough) return /* @__PURE__ */ jsx(Fragment, { children }); return /* @__PURE__ */ jsx(SlotFillProvider, { children }); } Provider.displayName = "SlotFillProvider"; function createSlotFill(key) { const baseName = typeof key === "symbol" ? key.description : key; const FillComponent = (props) => /* @__PURE__ */ jsx(Fill, { name: key, ...props }); FillComponent.displayName = `${baseName}Fill`; const SlotComponent = forwardRef((props, ref) => /* @__PURE__ */ jsx(Slot, { name: key, ref, ...props })); SlotComponent.displayName = `${baseName}Slot`; /** * @deprecated 6.8.0 * Please use `slotFill.name` instead of `slotFill.Slot.__unstableName`. */ SlotComponent.__unstableName = key; return { name: key, Fill: FillComponent, Slot: SlotComponent }; } export { Fill, Provider, Slot, createSlotFill, useSlot, useSlotFills }; //# sourceMappingURL=index.mjs.map