hongluan-ui
Version:
Hongluan Component Library for Vue 3
164 lines (161 loc) • 7.19 kB
JavaScript
import { defineComponent, ref, openBlock, createBlock, TransitionGroup, normalizeClass, unref, withCtx, createElementBlock, Fragment, renderList, withKeys, renderSlot, createCommentVNode, createVNode, createElementVNode, toDisplayString, withModifiers } from 'vue';
import { HlProgress } from '../../progress/index.mjs';
import { HlIcon } from '../../icon/index.mjs';
import '../../system-icon/index.mjs';
import '../../../hooks/index.mjs';
import { uploadListProps, uploadListEmits } from './upload-list2.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import { useConsistentProp } from '../../../hooks/use-consistent-prop/index.mjs';
import SystemFile from '../../system-icon/src/file.mjs';
import SystemChecked from '../../system-icon/src/checked.mjs';
import SystemClose from '../../system-icon/src/close.mjs';
import SystemZoomIn from '../../system-icon/src/zoom-in.mjs';
const __default__ = defineComponent({
name: "UploadList"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: uploadListProps,
emits: uploadListEmits,
setup(__props, { emit }) {
const { t } = useLocale();
const { disabled } = useConsistentProp();
const focusing = ref(false);
const handleRemove = (file) => {
emit("remove", file);
};
return (_ctx, _cache) => {
return openBlock(), createBlock(TransitionGroup, {
tag: "ul",
class: normalizeClass([
"upload-list",
"list-" + _ctx.listType,
{ "is-disabled": unref(disabled) }
]),
name: "list"
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.files, (file, index) => {
return openBlock(), createElementBlock("li", {
key: file.uid || file.name,
class: normalizeClass([
"item",
"is-" + file.status,
{ focusing: focusing.value }
]),
tabindex: "0",
onKeydown: withKeys(($event) => !unref(disabled) && handleRemove(file), ["delete"]),
onFocus: ($event) => focusing.value = true,
onBlur: ($event) => focusing.value = false,
onClick: ($event) => focusing.value = false
}, [
renderSlot(_ctx.$slots, "default", {
file,
index
}, () => [
renderSlot(_ctx.$slots, "file-preview", {
file,
index
}, () => [
file.status !== "uploading" && ["card", "picture"].includes(_ctx.listType) ? (openBlock(), createElementBlock("img", {
key: 0,
class: "item-thumb",
src: file.url,
crossorigin: _ctx.crossorigin,
alt: ""
}, null, 8, ["src", "crossorigin"])) : createCommentVNode("v-if", true)
]),
renderSlot(_ctx.$slots, "file-icon", {
file,
index
}, () => [
createVNode(unref(HlIcon), {
type: file.status,
class: "file-icon"
}, {
default: withCtx(() => [
createVNode(unref(SystemFile))
]),
_: 2
}, 1032, ["type"])
]),
createElementVNode("div", { class: "item-content" }, [
createElementVNode("a", {
class: "item-name",
title: file.name,
onClick: ($event) => _ctx.handlePreview(file)
}, toDisplayString(file.name), 9, ["title", "onClick"]),
file.status === "uploading" ? (openBlock(), createBlock(unref(HlProgress), {
key: 0,
"show-as": _ctx.listType === "card" ? "circle" : "line",
percentage: Number(file.percentage)
}, null, 8, ["show-as", "percentage"])) : createCommentVNode("v-if", true)
]),
createElementVNode("div", { class: "item-status" }, [
createVNode(unref(HlIcon), {
class: normalizeClass({
"icon-status": true,
"success": _ctx.listType === "text",
"icon-check": ["card", "picture"].includes(_ctx.listType)
})
}, {
default: withCtx(() => [
createVNode(unref(SystemChecked))
]),
_: 1
}, 8, ["class"]),
!unref(disabled) ? (openBlock(), createBlock(unref(HlIcon), {
key: 0,
class: "icon-close",
title: unref(t)("hl.upload.deleteTip"),
onClick: ($event) => handleRemove(file)
}, {
default: withCtx(() => [
createVNode(unref(SystemClose))
]),
_: 2
}, 1032, ["title", "onClick"])) : createCommentVNode("v-if", true),
createCommentVNode(" Due to close btn only appears when li gets focused disappears after li gets blurred, thus keyboard navigation can never reach close btn"),
createCommentVNode(" This is a bug which needs to be fixed "),
createCommentVNode(" TODO: Fix the incorrect navigation interaction ")
]),
_ctx.listType === "card" ? (openBlock(), createElementBlock("span", {
key: 0,
class: "item-actions"
}, [
createElementVNode("span", {
class: "item-preview",
onClick: withModifiers(($event) => _ctx.handlePreview(file), ["prevent"])
}, [
createVNode(unref(HlIcon), { name: "ZoomIn" }, {
default: withCtx(() => [
createVNode(unref(SystemZoomIn))
]),
_: 1
})
], 8, ["onClick"]),
!unref(disabled) ? (openBlock(), createElementBlock("span", {
key: 0,
class: "item-delete",
onClick: ($event) => handleRemove(file)
}, [
createVNode(unref(HlIcon), null, {
default: withCtx(() => [
createVNode(unref(SystemClose))
]),
_: 1
})
], 8, ["onClick"])) : createCommentVNode("v-if", true)
])) : createCommentVNode("v-if", true)
])
], 42, ["onKeydown", "onFocus", "onBlur", "onClick"]);
}), 128)),
renderSlot(_ctx.$slots, "append")
]),
_: 3
}, 8, ["class"]);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=upload-list.mjs.map