@opensig/opendesign
Version:
101 lines (100 loc) • 3.51 kB
JavaScript
import { defineComponent, ref, createElementBlock, createCommentVNode, openBlock, normalizeClass, createVNode, TransitionGroup, withCtx, Fragment, renderList, createBlock, unref, createTextVNode, toDisplayString, resolveDynamicComponent } from "vue";
import _sfc_main$1 from "./OToast.vue.mjs";
import { isString, isFunction } from "../_utils/is.mjs";
import { useGetUniqueId } from "../_utils/unique-id.mjs";
import { toastListProps } from "./types.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "OToastList",
props: toastListProps,
setup(__props, { expose: __expose }) {
const props = __props;
const getUniqueId = useGetUniqueId();
const optionList = ref([]);
const add = (params) => {
const option = {
id: getUniqueId(),
...params
};
optionList.value.push(option);
return option.id;
};
const remove = (idx) => {
optionList.value.splice(idx, 1);
};
const removeAll = () => {
optionList.value = [];
isFunction(props.onDestroy) && props.onDestroy();
};
const close = (id) => {
const idx = optionList.value.findIndex((option) => option.id === id);
remove(idx);
};
const handleDurationEnd = (item) => {
const { id, onDurationEnd } = item;
onDurationEnd == null ? void 0 : onDurationEnd();
close(id);
};
const handleClose = (item, ev) => {
const { id, onClose } = item;
onClose == null ? void 0 : onClose(ev);
close(id);
};
__expose({ add, close, remove, removeAll });
return (_ctx, _cache) => {
return optionList.value.length ? (openBlock(), createElementBlock(
"div",
{
key: 0,
class: normalizeClass(["o-toast-list", [`o-toast-list-${props.position}`]])
},
[
createVNode(TransitionGroup, { name: "o-toast-fade" }, {
default: withCtx(() => [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(optionList.value, (item) => {
return openBlock(), createBlock(_sfc_main$1, {
key: item.id,
duration: item.duration,
onDurationEnd: ($event) => handleDurationEnd(item),
onClose: (ev) => {
handleClose(item, ev);
}
}, {
default: withCtx(() => [
unref(isString)(item.content) ? (openBlock(), createElementBlock(
Fragment,
{ key: 0 },
[
createTextVNode(
toDisplayString(item.content),
1
/* TEXT */
)
],
64
/* STABLE_FRAGMENT */
)) : (openBlock(), createBlock(resolveDynamicComponent(item.content), { key: 1 }))
]),
_: 2
/* DYNAMIC */
}, 1032, ["duration", "onDurationEnd", "onClose"]);
}),
128
/* KEYED_FRAGMENT */
))
]),
_: 1
/* STABLE */
})
],
2
/* CLASS */
)) : createCommentVNode("v-if", true);
};
}
});
export {
_sfc_main as default
};