UNPKG

hongluan-ui

Version:
1 lines 2.91 kB
{"version":3,"file":"option-group.mjs","sources":["../../../../../../packages/components/select/src/option-group.vue"],"sourcesContent":["<template>\n <li v-show=\"visible\" :class=\"namespace\">\n <strong class=\"select-group-title\">{{ label }}</strong>\n <ul>\n <slot></slot>\n </ul>\n </li>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, provide, inject, ref, reactive, toRefs, getCurrentInstance, onMounted, toRaw, watch } from 'vue'\nimport { useNamespace } from '@hongluan-ui/hooks'\nimport { selectGroupKey, selectKey } from './token'\n\nexport default defineComponent({\n name: 'OptionGroup',\n componentName: 'OptionGroup',\n\n props: {\n /**\n * @description name of the group\n */\n label: String,\n /**\n * @description whether to disable all options in this group\n */\n disabled: Boolean,\n },\n\n setup(props) {\n const { namespace } = useNamespace('option-group')\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 === 'Option' &&\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(\n groupQueryChange,\n () => {\n visible.value = children.value.some(option => option.visible === true)\n },\n { flush: 'post' },\n )\n\n return {\n namespace,\n visible,\n }\n },\n})\n</script>\n"],"names":["_createElementVNode"],"mappings":";;;;;;AAcA,MAAK,YAAa,gBAAa;AAAA,EAC7B,MAAM;AAAA,EACN,eAAe;AAAA,EAEf,OAAO;AAAA,IAIL,OAAO;AAAA,IAIP,UAAU;AAAA;AACZ,EAEA,MAAM,OAAO;AACX,UAAM,EAAE,cAAc,aAAa,cAAc;AACjD,UAAM,UAAU,IAAI,IAAI;AACxB,UAAM,WAAW;AACjB,UAAM,WAAW,IAAI,EAAE;AAEvB,YACE,gBACA,SAAS;AAAA,SACJ,OAAO,KAAK;AAAA,KAChB,CACH;AAEA,UAAM,SAAS,OAAO,SAAS;AAE/B,cAAU,MAAM;AACd,eAAS,QAAQ,gBAAgB,SAAS,OAAO;AAAA,KAClD;AAGD,UAAM,kBAAkB,UAAQ;AAC9B,YAAM,YAAW;AACjB,UAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAChC,aAAK,SAAS,QAAQ,WAAS;AAC7B,cACE;AAKA,iCAAoB,UAAU,KAAK;AAAA,qBAC1B,MAAM;AACf,sBAAS,KAAK,mBAAmB;AAAM;AACzC;AACD;AAEH;AAAO;AAGT;AACA,UACE,kBACA;AACE;AAAqE;AAKzE;AAAO;AACL,MACA;AAAA;AACF;AAEJ;;;AA5EO;AALiC;;AACO,IAC3CA,mBAEK;AAAA;AADU;;;AAHE;;;;;;;"}