@wordpress/components
Version:
UI components for WordPress.
84 lines (83 loc) • 2.35 kB
JavaScript
// packages/components/src/slot-fill/index.tsx
import { forwardRef, useContext } from "@wordpress/element";
import BaseFill from "./fill";
import BaseSlot from "./slot";
import BubblesVirtuallyFill from "./bubbles-virtually/fill";
import BubblesVirtuallySlot from "./bubbles-virtually/slot";
import BubblesVirtuallySlotFillProvider from "./bubbles-virtually/slot-fill-provider";
import SlotFillProvider from "./provider";
import SlotFillContext from "./bubbles-virtually/slot-fill-context";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { default as default2 } from "./bubbles-virtually/use-slot";
import { default as default3 } from "./bubbles-virtually/use-slot-fills";
function Fill(props) {
return /* @__PURE__ */ _jsxs(_Fragment, {
children: [/* @__PURE__ */ _jsx(BaseFill, {
...props
}), /* @__PURE__ */ _jsx(BubblesVirtuallyFill, {
...props
})]
});
}
function UnforwardedSlot(props, ref) {
const {
bubblesVirtually,
...restProps
} = props;
if (bubblesVirtually) {
return /* @__PURE__ */ _jsx(BubblesVirtuallySlot, {
...restProps,
ref
});
}
return /* @__PURE__ */ _jsx(BaseSlot, {
...restProps
});
}
var Slot = forwardRef(UnforwardedSlot);
function Provider({
children,
passthrough = false
}) {
const parent = useContext(SlotFillContext);
if (!parent.isDefault && passthrough) {
return /* @__PURE__ */ _jsx(_Fragment, {
children
});
}
return /* @__PURE__ */ _jsx(SlotFillProvider, {
children: /* @__PURE__ */ _jsx(BubblesVirtuallySlotFillProvider, {
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 = (props) => /* @__PURE__ */ _jsx(Slot, {
name: key,
...props
});
SlotComponent.displayName = `${baseName}Slot`;
SlotComponent.__unstableName = key;
return {
name: key,
Fill: FillComponent,
Slot: SlotComponent
};
}
export {
Fill,
Provider,
Slot,
UnforwardedSlot,
createSlotFill,
default2 as useSlot,
default3 as useSlotFills
};
//# sourceMappingURL=index.js.map