UNPKG

@wordpress/components

Version:
76 lines (68 loc) 2.26 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement, Fragment } from "@wordpress/element"; // @ts-nocheck /** * WordPress dependencies */ import { forwardRef } from '@wordpress/element'; /** * Internal dependencies */ 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'; export { default as useSlot } from './bubbles-virtually/use-slot'; export { default as useSlotFills } from './bubbles-virtually/use-slot-fills'; export function Fill(props) { // We're adding both Fills here so they can register themselves before // their respective slot has been registered. Only the Fill that has a slot // will render. The other one will return null. return createElement(Fragment, null, createElement(BaseFill, props), createElement(BubblesVirtuallyFill, props)); } export const Slot = forwardRef((_ref, ref) => { let { bubblesVirtually, ...props } = _ref; if (bubblesVirtually) { return createElement(BubblesVirtuallySlot, _extends({}, props, { ref: ref })); } return createElement(BaseSlot, props); }); export function Provider(_ref2) { let { children, ...props } = _ref2; return createElement(SlotFillProvider, props, createElement(BubblesVirtuallySlotFillProvider, null, children)); } export function createSlotFill(key) { const baseName = typeof key === 'symbol' ? key.description : key; const FillComponent = props => createElement(Fill, _extends({ name: key }, props)); FillComponent.displayName = `${baseName}Fill`; const SlotComponent = props => createElement(Slot, _extends({ name: key }, props)); SlotComponent.displayName = `${baseName}Slot`; SlotComponent.__unstableName = key; return { Fill: FillComponent, Slot: SlotComponent }; } export const createPrivateSlotFill = name => { const privateKey = Symbol(name); const privateSlotFill = createSlotFill(privateKey); return { privateKey, ...privateSlotFill }; }; //# sourceMappingURL=index.js.map