hongluan-ui
Version:
Hongluan Component Library for Vue 3
127 lines (122 loc) • 3.83 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../../hooks/index.js');
var index = require('../../icon/index.js');
require('../../system-icon/index.js');
var useOption = require('./useOption.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var checked = require('../../system-icon/src/checked.js');
var index$1 = require('../../../hooks/use-namespace/index.js');
var index$2 = require('../../../hooks/use-id/index.js');
const _sfc_main = vue.defineComponent({
name: "Option",
components: {
HlIcon: index.HlIcon,
SystemChecked: checked["default"]
},
componentName: "Option",
props: {
value: {
type: [String, Number, Boolean, Object]
},
label: [String, Number],
created: Boolean,
disabled: Boolean,
divider: Boolean
},
setup(props) {
const { namespace } = index$1.useNamespace("option");
const id = index$2.useId();
const states = vue.reactive({
index: -1,
groupDisabled: false,
visible: true,
hitState: false,
hover: false
});
const {
currentLabel,
itemSelected,
isDisabled,
select,
hoverItem
} = useOption.useOption(props, states);
const {
visible,
hover
} = vue.toRefs(states);
const vm = vue.getCurrentInstance().proxy;
select.onOptionCreate(vm);
vue.onBeforeUnmount(() => {
const key = vm.value;
const { selected } = select;
let selectedOptions = select.props.multiple ? selected : [selected];
const doesSelected = selectedOptions.some((item) => {
return item.value === vm.value;
});
vue.nextTick(() => {
if (select.cachedOptions.get(key) === vm && !doesSelected) {
select.cachedOptions.delete(key);
}
});
select.onOptionDestroy(key, vm);
});
function selectOptionClick() {
if (props.disabled !== true && states.groupDisabled !== true) {
select.handleOptionSelect(vm);
}
}
return {
id,
namespace,
currentLabel,
itemSelected,
isDisabled,
select,
hoverItem,
visible,
hover,
selectOptionClick,
states
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_system_checked = vue.resolveComponent("system-checked");
const _component_hl_icon = vue.resolveComponent("hl-icon");
return _ctx.divider ? (vue.openBlock(), vue.createElementBlock("li", {
key: 0,
class: "menu-divider"
})) : vue.withDirectives((vue.openBlock(), vue.createElementBlock("li", {
key: 1,
id: _ctx.id,
role: "option",
"aria-disabled": _ctx.isDisabled || void 0,
"aria-selected": _ctx.itemSelected,
class: vue.normalizeClass({
[_ctx.namespace]: true,
"select-dropdown-item": true,
"is-selected": _ctx.itemSelected,
"is-disabled": _ctx.isDisabled,
"hover": _ctx.hover
}),
onMouseenter: _ctx.hoverItem,
onClick: vue.withModifiers(_ctx.selectOptionClick, ["stop"])
}, [
vue.renderSlot(_ctx.$slots, "default", {}, () => [
vue.createElementVNode("div", null, vue.toDisplayString(_ctx.currentLabel), 1),
_ctx.itemSelected ? (vue.openBlock(), vue.createBlock(_component_hl_icon, { key: 0 }, {
default: vue.withCtx(() => [
vue.createVNode(_component_system_checked)
]),
_: 1
})) : vue.createCommentVNode("v-if", true)
])
], 42, ["id", "aria-disabled", "aria-selected", "onMouseenter", "onClick"])), [
[vue.vShow, _ctx.visible]
]);
}
var HlOption = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render]]);
exports["default"] = HlOption;
//# sourceMappingURL=option.js.map