1c5fcf00d487efe22b4decb77306cbeaf9dc72bda9dd2f54c7848dd14d5e7331fb73b0a010680c47e944f4984977c79847314ea899fc65b9b3ccd294d3b90c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createBlock, withCtx, resolveDynamicComponent, renderSlot } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { avatarProps, avatarEmits } from './avatar.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. import { isString } from '@vue/shared';
  7. import { isNumber } from '../../../utils/types.mjs';
  8. import { addUnit } from '../../../utils/dom/style.mjs';
  9. const __default__ = defineComponent({
  10. name: "ElAvatar"
  11. });
  12. const _sfc_main = /* @__PURE__ */ defineComponent({
  13. ...__default__,
  14. props: avatarProps,
  15. emits: avatarEmits,
  16. setup(__props, { emit }) {
  17. const props = __props;
  18. const ns = useNamespace("avatar");
  19. const hasLoadError = ref(false);
  20. const avatarClass = computed(() => {
  21. const { size, icon, shape } = props;
  22. const classList = [ns.b()];
  23. if (isString(size))
  24. classList.push(ns.m(size));
  25. if (icon)
  26. classList.push(ns.m("icon"));
  27. if (shape)
  28. classList.push(ns.m(shape));
  29. return classList;
  30. });
  31. const sizeStyle = computed(() => {
  32. const { size } = props;
  33. return isNumber(size) ? ns.cssVarBlock({
  34. size: addUnit(size) || ""
  35. }) : void 0;
  36. });
  37. const fitStyle = computed(() => ({
  38. objectFit: props.fit
  39. }));
  40. watch(() => props.src, () => hasLoadError.value = false);
  41. function handleError(e) {
  42. hasLoadError.value = true;
  43. emit("error", e);
  44. }
  45. return (_ctx, _cache) => {
  46. return openBlock(), createElementBlock("span", {
  47. class: normalizeClass(unref(avatarClass)),
  48. style: normalizeStyle(unref(sizeStyle))
  49. }, [
  50. (_ctx.src || _ctx.srcSet) && !hasLoadError.value ? (openBlock(), createElementBlock("img", {
  51. key: 0,
  52. src: _ctx.src,
  53. alt: _ctx.alt,
  54. srcset: _ctx.srcSet,
  55. style: normalizeStyle(unref(fitStyle)),
  56. onError: handleError
  57. }, null, 44, ["src", "alt", "srcset"])) : _ctx.icon ? (openBlock(), createBlock(unref(ElIcon), { key: 1 }, {
  58. default: withCtx(() => [
  59. (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon)))
  60. ]),
  61. _: 1
  62. })) : renderSlot(_ctx.$slots, "default", { key: 2 })
  63. ], 6);
  64. };
  65. }
  66. });
  67. var Avatar = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "avatar.vue"]]);
  68. export { Avatar as default };
  69. //# sourceMappingURL=avatar2.mjs.map