dd142f57510631bd497ccdefcc9f53cf376739f1db1b80969cfbe08467a47ed537b6f320662fc02375f768610ef462b1c87e000e2f90dd450401cb9e6f7352 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, unref, renderSlot, createVNode, Transition, withCtx, withDirectives, createElementVNode, normalizeStyle, createTextVNode, toDisplayString, vShow } from 'vue';
  2. import { badgeProps } from './badge.mjs';
  3. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  4. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  5. import { isNumber } from '../../../utils/types.mjs';
  6. import { addUnit } from '../../../utils/dom/style.mjs';
  7. const __default__ = defineComponent({
  8. name: "ElBadge"
  9. });
  10. const _sfc_main = /* @__PURE__ */ defineComponent({
  11. ...__default__,
  12. props: badgeProps,
  13. setup(__props, { expose }) {
  14. const props = __props;
  15. const ns = useNamespace("badge");
  16. const content = computed(() => {
  17. if (props.isDot)
  18. return "";
  19. if (isNumber(props.value) && isNumber(props.max)) {
  20. return props.max < props.value ? `${props.max}+` : `${props.value}`;
  21. }
  22. return `${props.value}`;
  23. });
  24. const style = computed(() => {
  25. var _a, _b, _c, _d, _e;
  26. return [
  27. {
  28. backgroundColor: props.color,
  29. marginRight: addUnit(-((_b = (_a = props.offset) == null ? void 0 : _a[0]) != null ? _b : 0)),
  30. marginTop: addUnit((_d = (_c = props.offset) == null ? void 0 : _c[1]) != null ? _d : 0)
  31. },
  32. (_e = props.badgeStyle) != null ? _e : {}
  33. ];
  34. });
  35. expose({
  36. content
  37. });
  38. return (_ctx, _cache) => {
  39. return openBlock(), createElementBlock("div", {
  40. class: normalizeClass(unref(ns).b())
  41. }, [
  42. renderSlot(_ctx.$slots, "default"),
  43. createVNode(Transition, {
  44. name: `${unref(ns).namespace.value}-zoom-in-center`,
  45. persisted: ""
  46. }, {
  47. default: withCtx(() => [
  48. withDirectives(createElementVNode("sup", {
  49. class: normalizeClass([
  50. unref(ns).e("content"),
  51. unref(ns).em("content", _ctx.type),
  52. unref(ns).is("fixed", !!_ctx.$slots.default),
  53. unref(ns).is("dot", _ctx.isDot),
  54. unref(ns).is("hide-zero", !_ctx.showZero && props.value === 0),
  55. _ctx.badgeClass
  56. ]),
  57. style: normalizeStyle(unref(style))
  58. }, [
  59. renderSlot(_ctx.$slots, "content", { value: unref(content) }, () => [
  60. createTextVNode(toDisplayString(unref(content)), 1)
  61. ])
  62. ], 6), [
  63. [vShow, !_ctx.hidden && (unref(content) || _ctx.isDot || _ctx.$slots.content)]
  64. ])
  65. ]),
  66. _: 3
  67. }, 8, ["name"])
  68. ], 2);
  69. };
  70. }
  71. });
  72. var Badge = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "badge.vue"]]);
  73. export { Badge as default };
  74. //# sourceMappingURL=badge2.mjs.map