UNPKG

@oruga-ui/oruga-next

Version:

UI components for Vue.js and CSS framework agnostic

1 lines 2.51 kB
{"version":3,"file":"SlotComponent-BMmH3QFp.cjs","sources":["../../src/components/utils/SlotComponent.ts"],"sourcesContent":["import {\n createVNode,\n defineComponent,\n type DefineComponent,\n type VNode,\n type VNodeChild,\n type VNodeTypes,\n} from \"vue\";\nimport type { ComponentProps } from \"vue-component-type-helpers\";\nimport type { DynamicComponent } from \"@/types\";\n\ntype SlotComponentProps<C extends VNodeTypes> = {\n /** Component to be get the slot from */\n component: C;\n /** Props to be binded to the injected component. */\n props?: ComponentProps<C>;\n /**\n * Slot name\n * @default \"default\"\n */\n name?: string;\n /**\n * Tag name of the slot wrapper element\n * @default \"div\"\n */\n tag?: DynamicComponent;\n};\n\n/** This components renders a specific slot and only the slot of another component */\nexport default defineComponent<SlotComponentProps<any>>(\n <C extends DefineComponent>(props: SlotComponentProps<C>, { slots }) => {\n const _props = { tag: \"div\", name: \"default\", ...props };\n\n return (): VNode => {\n let slot: VNodeChild | (() => VNodeChild) = (): VNodeChild =>\n props.component.$slots[_props.name]\n ? props.component.$slots[_props.name](props.props)\n : slots.default\n ? slots.default()\n : undefined;\n if (typeof _props.tag === \"string\") {\n // Vue prefers components' children to be passed as functions,\n // but native elements' children can't be passed that way.\n slot = slot();\n }\n\n return createVNode(_props.tag as VNode, {}, slot);\n };\n },\n {\n name: \"OSlotComponent\",\n // manual runtime props declaration is currently still needed.\n props: [\"component\", \"props\", \"name\", \"tag\"],\n },\n);\n"],"names":["defineComponent","createVNode"],"mappings":";;;AA6BA,MAAA,iBAAeA,IAAA;AAAA,EACX,CAA4B,OAA8B,EAAE,YAAY;AACpE,UAAM,SAAS,EAAE,KAAK,OAAO,MAAM,WAAW,GAAG,MAAM;AAEvD,WAAO,MAAa;AACZ,UAAA,OAAwC,MACxC,MAAM,UAAU,OAAO,OAAO,IAAI,IAC5B,MAAM,UAAU,OAAO,OAAO,IAAI,EAAE,MAAM,KAAK,IAC/C,MAAM,UACJ,MAAM,QAAA,IACN;AACR,UAAA,OAAO,OAAO,QAAQ,UAAU;AAGhC,eAAO,KAAK;AAAA,MAAA;AAGhB,aAAOC,IAAY,YAAA,OAAO,KAAc,CAAA,GAAI,IAAI;AAAA,IACpD;AAAA,EACJ;AAAA,EACA;AAAA,IACI,MAAM;AAAA;AAAA,IAEN,OAAO,CAAC,aAAa,SAAS,QAAQ,KAAK;AAAA,EAAA;AAEnD;;"}