hongluan-ui
Version:
Hongluan Component Library for Vue 3
161 lines (158 loc) • 6.97 kB
JavaScript
import { defineComponent, useSlots, reactive, computed, toRefs, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, unref, createVNode, isRef, withCtx, createTextVNode, mergeProps, createCommentVNode, withDirectives, Fragment, renderList, createBlock, vShow, renderSlot } from 'vue';
import '../../../utils/index.mjs';
import '../../../hooks/index.mjs';
import { HlCheckbox } from '../../checkbox/index.mjs';
import { HlCheckboxGroup } from '../../checkbox-group/index.mjs';
import { HlInput } from '../../input/index.mjs';
import { HlIcon } from '../../icon/index.mjs';
import '../../system-icon/index.mjs';
import { transferPanelProps, transferPanelEmits } from './transfer-panel2.mjs';
import './composables/index.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import { usePropsAlias } from './composables/use-props-alias.mjs';
import { useCheck } from './composables/use-check.mjs';
import { isEmpty } from '../../../utils/types.mjs';
import SystemSearch from '../../system-icon/src/search.mjs';
const __default__ = defineComponent({
name: "TransferPanel"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: transferPanelProps,
emits: transferPanelEmits,
setup(__props, { expose, emit }) {
const props = __props;
const slots = useSlots();
const OptionContent = ({ option }) => option;
const { t } = useLocale();
const panelState = reactive({
checked: [],
allChecked: false,
query: "",
inputHover: false,
checkChangeByUser: true
});
const propsAlias = usePropsAlias(props);
const {
filteredData,
checkedSummary,
isIndeterminate,
handleAllCheckedChange
} = useCheck(props, panelState, emit);
const hasNoMatch = computed(() => !isEmpty(panelState.query) && isEmpty(filteredData.value));
const hasFooter = computed(() => !isEmpty(slots.default()[0].children));
const showClose = computed(() => {
return panelState.query.length > 0 && panelState.inputHover ? "show-close" : "";
});
const { checked, allChecked, query, inputHover } = toRefs(panelState);
expose({
query
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass(["transfer-panel", _ctx.mark])
}, [
!_ctx.showButtons ? (openBlock(), createElementBlock("div", {
key: 0,
class: "panel-header"
}, [
createElementVNode("span", null, toDisplayString(_ctx.title), 1),
createElementVNode("span", { class: "count" }, toDisplayString(unref(checkedSummary)), 1)
])) : (openBlock(), createElementBlock("div", {
key: 1,
class: "panel-header"
}, [
createVNode(unref(HlCheckbox), {
modelValue: unref(allChecked),
"onUpdate:modelValue": ($event) => isRef(allChecked) ? allChecked.value = $event : null,
"validate-event": false,
indeterminate: unref(isIndeterminate),
onChange: unref(handleAllCheckedChange)
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(_ctx.title), 1)
]),
_: 1
}, 8, ["modelValue", "onUpdate:modelValue", "indeterminate", "onChange"]),
createElementVNode("span", { class: "count" }, toDisplayString(unref(checkedSummary)), 1)
])),
createElementVNode("div", {
class: normalizeClass(["panel-body", unref(hasFooter) ? "is-with-footer" : ""])
}, [
_ctx.filterable ? (openBlock(), createElementBlock("div", {
key: 0,
class: "panel-filter"
}, [
createVNode(unref(HlInput), mergeProps({
modelValue: unref(query),
"onUpdate:modelValue": ($event) => isRef(query) ? query.value = $event : null,
class: "no-verify",
block: "",
clearable: "",
placeholder: _ctx.placeholder,
"validate-event": false
}, _ctx.filterProps, {
onMouseenter: ($event) => inputHover.value = true,
onMouseleave: ($event) => inputHover.value = false
}), {
prefix: withCtx(() => [
createVNode(unref(HlIcon), null, {
default: withCtx(() => [
createVNode(unref(SystemSearch))
]),
_: 1
})
]),
_: 1
}, 16, ["modelValue", "onUpdate:modelValue", "placeholder", "onMouseenter", "onMouseleave"])
])) : createCommentVNode("v-if", true),
withDirectives(createVNode(unref(HlCheckboxGroup), {
modelValue: unref(checked),
"onUpdate:modelValue": ($event) => isRef(checked) ? checked.value = $event : null,
dir: "vertical",
"validate-event": false,
class: normalizeClass({ "panel-list": true, "has-filterable": _ctx.filterable }),
custom: !_ctx.showButtons
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(filteredData), (item) => {
return openBlock(), createBlock(unref(HlCheckbox), {
key: item[unref(propsAlias).key],
class: "item",
label: item[unref(propsAlias).key],
disabled: item[unref(propsAlias).disabled],
"validate-event": false
}, {
default: withCtx(() => {
var _a;
return [
createVNode(OptionContent, {
option: (_a = _ctx.optionRender) == null ? void 0 : _a.call(_ctx, item)
}, null, 8, ["option"]),
createCommentVNode(` <i v-if="mark === 'right' && !item[disabledProp]" class="system-icon error-fill"></i> `)
];
}),
_: 2
}, 1032, ["label", "disabled"]);
}), 128))
]),
_: 1
}, 8, ["modelValue", "onUpdate:modelValue", "class", "custom"]), [
[vShow, !unref(hasNoMatch) && !unref(isEmpty)(_ctx.data)]
]),
withDirectives(createElementVNode("p", { class: "panel-empty" }, toDisplayString(unref(hasNoMatch) ? unref(t)("hl.transfer.noMatch") : unref(t)("hl.transfer.noData")), 513), [
[vShow, unref(hasNoMatch) || unref(isEmpty)(_ctx.data)]
])
], 2),
unref(hasFooter) ? (openBlock(), createElementBlock("p", {
key: 2,
class: "panel-footer"
}, [
renderSlot(_ctx.$slots, "default")
])) : createCommentVNode("v-if", true)
], 2);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=transfer-panel.mjs.map