UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

56 lines (55 loc) 1.46 kB
"use strict"; const vue = require("vue"); const type = require("./type.js"); const _sfc_main = vue.defineComponent({ name: "Option", props: { /** 选项的值 */ value: { type: [String, Number], default: "" }, /** 选项文本内容 */ label: { type: String, default: "" }, /** 是否禁用 Disabled or not */ disabled: { type: Boolean, default: false } }, setup(props) { const name = "bp-option"; const ctx = vue.ref(); const slot = vue.useSlots(); const option = vue.reactive(new type.SelectOption()); const init = () => { var _a; ctx.value = vue.inject(type.selectInjectionKey, null); option.label = props.label || ((_a = slot.default) == null ? void 0 : _a.call(slot)[0].children); option.value = props.value; }; const clsName = vue.computed(() => { let cls = [`${name}-item`]; if (ctx.value.currentSelect.value === props.value) cls.push(`${name}-active`); if (props.disabled) cls.push(`${name}-disabled`); return cls; }); const handleClick = () => { var _a; if (props.disabled) return; (_a = ctx.value) == null ? void 0 : _a.onSelect(option.value, { ...option }); }; vue.watch( () => props, () => { init(); }, { immediate: true } ); return { name, clsName, handleClick }; } }); module.exports = _sfc_main;