UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 2.83 kB
{"version":3,"file":"option-group.mjs","sources":["../../../../../../packages/components/select/src/option-group.vue"],"sourcesContent":["<template>\n <ul v-show=\"visible\" :class=\"ns.be('group', 'wrap')\">\n <li :class=\"ns.be('group', 'title')\">{{ label }}</li>\n <li>\n <ul :class=\"ns.b('group')\">\n <slot></slot>\n </ul>\n </li>\n </ul>\n</template>\n\n<script lang=\"ts\">\nimport {\n defineComponent,\n provide,\n inject,\n ref,\n reactive,\n toRefs,\n getCurrentInstance,\n onMounted,\n watch,\n toRaw,\n} from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { selectGroupKey, selectKey } from './token'\n\nexport default defineComponent({\n name: 'ElOptionGroup',\n componentName: 'ElOptionGroup',\n\n props: {\n label: String,\n disabled: {\n type: Boolean,\n default: false,\n },\n },\n setup(props) {\n const ns = useNamespace('select')\n const visible = ref(true)\n const instance = getCurrentInstance()\n const children = ref([])\n\n provide(\n selectGroupKey,\n reactive({\n ...toRefs(props),\n })\n )\n\n const select = inject(selectKey)\n\n onMounted(() => {\n children.value = flattedChildren(instance.subTree)\n })\n\n // get all instances of options\n const flattedChildren = (node) => {\n const children = []\n if (Array.isArray(node.children)) {\n node.children.forEach((child) => {\n if (\n child.type &&\n child.type.name === 'ElOption' &&\n child.component &&\n child.component.proxy\n ) {\n children.push(child.component.proxy)\n } else if (child.children?.length) {\n children.push(...flattedChildren(child))\n }\n })\n }\n return children\n }\n\n const { groupQueryChange } = toRaw(select)\n watch(groupQueryChange, () => {\n visible.value = children.value.some((option) => option.visible === true)\n })\n\n return {\n visible,\n ns,\n }\n },\n})\n</script>\n"],"names":[],"mappings":";;;;;;AA2BA,MAAK,YAAa,gBAAa;AAAA,EAC7B,MAAM;AAAA,EACN,eAAe;AAAA,EAEf,OAAO;AAAA,IACL,OAAO;AAAA,IACP,UAAU;AAAA,MACR,MAAM;AAAA,MACN,SAAS;AAAA;AAAA;AAAA,EAGb,MAAM,OAAO;AACX,UAAM,KAAK,aAAa;AACxB,UAAM,UAAU,IAAI;AACpB,UAAM,WAAW;AACjB,UAAM,WAAW,IAAI;AAErB,YACE,gBACA,SAAS;AAAA,SACJ,OAAO;AAAA;AAId,UAAM,SAAS,OAAO;AAEtB,cAAU,MAAM;AACd,eAAS,QAAQ,gBAAgB,SAAS;AAAA;AAI5C,UAAM,kBAAkB,CAAC,SAAS;AAChC,YAAM,YAAW;AACjB,UAAI,MAAM,QAAQ,KAAK,WAAW;AAChC,aAAK,SAAS,QAAQ,CAAC,UAAU;AAC/B,cACE;AAKA,iCAAoB,UAAU;AAAA,qBACrB,MAAM;AACf,sBAAS,KAAK,mBAAmB;AAAA;AAAA;AAAA;AAIvC;AAAO;AAGT;AACA,UAAM,kBAAkB;AACtB;AAAmE;AAGrE;AAAO;AACL,MACA;AAAA;AAAA;AAAA;;SAnFuB;AAAO;;AAChC;AAAY;AAAiC;AAKxC,uBAHH;AAEK;AAFO;;AACV;;;;AAJM;;;;;;;;"}