@wordpress/components
Version:
UI components for WordPress.
1 lines • 3.54 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/slot-fill/index.tsx"],"sourcesContent":["import type { ForwardedRef } from 'react';\nimport { forwardRef, useContext } from '@wordpress/element';\nimport Fill from './fill';\nimport BaseSlot from './slot';\nimport BubblesVirtuallySlot from './bubbles-virtually/slot';\nimport SlotFillProvider from './provider';\nimport SlotFillContext from './context';\nimport type { WordPressComponentProps } from '../context';\nexport { default as useSlot } from './bubbles-virtually/use-slot';\nexport { default as useSlotFills } from './bubbles-virtually/use-slot-fills';\nimport type {\n\tDistributiveOmit,\n\tFillComponentProps,\n\tSlotComponentProps,\n\tSlotFillProviderProps,\n\tSlotKey,\n} from './types';\n\nexport { Fill };\n\n/**\n * `Slot` marks a location where content rendered by matching `Fill` components\n * elsewhere will appear. Use it to allow a component to define UI areas that\n * can be extended from other parts of the application.\n */\nexport const Slot = forwardRef(\n\t(\n\t\tprops: SlotComponentProps &\n\t\t\tOmit< WordPressComponentProps< {}, 'div' >, 'className' >,\n\t\tref: ForwardedRef< any >\n\t) => {\n\t\tconst { bubblesVirtually, ...restProps } = props;\n\t\tif ( bubblesVirtually ) {\n\t\t\treturn <BubblesVirtuallySlot { ...restProps } ref={ ref } />;\n\t\t}\n\t\treturn <BaseSlot { ...restProps } />;\n\t}\n);\nSlot.displayName = 'Slot';\n\nexport function Provider( {\n\tchildren,\n\tpassthrough = false,\n}: SlotFillProviderProps ) {\n\tconst parent = useContext( SlotFillContext );\n\tif ( ! parent.isDefault && passthrough ) {\n\t\treturn <>{ children }</>;\n\t}\n\treturn <SlotFillProvider>{ children }</SlotFillProvider>;\n}\nProvider.displayName = 'SlotFillProvider';\n\nexport function createSlotFill( key: SlotKey ) {\n\tconst baseName = typeof key === 'symbol' ? key.description : key;\n\tconst FillComponent = ( props: Omit< FillComponentProps, 'name' > ) => (\n\t\t<Fill name={ key } { ...props } />\n\t);\n\tFillComponent.displayName = `${ baseName }Fill`;\n\n\t// Wrap SlotComponent with forwardRef to support ref forwarding\n\tconst SlotComponent = forwardRef(\n\t\t(\n\t\t\tprops: DistributiveOmit< SlotComponentProps, 'name' >,\n\t\t\tref: ForwardedRef< any >\n\t\t) => <Slot name={ key } ref={ ref } { ...props } />\n\t) as React.ForwardRefExoticComponent<\n\t\tDistributiveOmit< SlotComponentProps, 'name' > &\n\t\t\tReact.RefAttributes< any >\n\t> & {\n\t\t__unstableName: SlotKey;\n\t};\n\tSlotComponent.displayName = `${ baseName }Slot`;\n\t/**\n\t * @deprecated 6.8.0\n\t * Please use `slotFill.name` instead of `slotFill.Slot.__unstableName`.\n\t */\n\tSlotComponent.__unstableName = key;\n\n\treturn {\n\t\tname: key,\n\t\tFill: FillComponent,\n\t\tSlot: SlotComponent,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,MAAa,OAAO,YAElB,OAEA,QACI;CACJ,MAAM,EAAE,kBAAkB,GAAG,cAAc;CAC3C,IAAK,kBACJ,OAAO,oBAAC,sBAAD;EAAsB,GAAK;EAAkB;CAAO,CAAA;CAE5D,OAAO,oBAAC,UAAD,EAAU,GAAK,UAAa,CAAA;AACpC,CACD;AACA,KAAK,cAAc;AAEnB,SAAgB,SAAU,EACzB,UACA,cAAc,SACY;CAE1B,IAAK,CADU,WAAY,eACf,CAAC,CAAC,aAAa,aAC1B,OAAO,oBAAA,UAAA,EAAI,SAAY,CAAA;CAExB,OAAO,oBAAC,kBAAD,EAAoB,SAA4B,CAAA;AACxD;AACA,SAAS,cAAc;AAEvB,SAAgB,eAAgB,KAAe;CAC9C,MAAM,WAAW,OAAO,QAAQ,WAAW,IAAI,cAAc;CAC7D,MAAM,iBAAkB,UACvB,oBAAC,MAAD;EAAM,MAAO;EAAM,GAAK;CAAS,CAAA;CAElC,cAAc,cAAc,GAAI,SAAU;CAG1C,MAAM,gBAAgB,YAEpB,OACA,QACI,oBAAC,MAAD;EAAM,MAAO;EAAY;EAAM,GAAK;CAAS,CAAA,CACnD;CAMA,cAAc,cAAc,GAAI,SAAU;;;;;CAK1C,cAAc,iBAAiB;CAE/B,OAAO;EACN,MAAM;EACN,MAAM;EACN,MAAM;CACP;AACD"}