Icon.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
  2. import { inject, computed, defineComponent } from "vue";
  3. import { addUnit, numericProp, makeStringProp, createNamespace } from "../utils/index.mjs";
  4. import { Badge } from "../badge/index.mjs";
  5. import { CONFIG_PROVIDER_KEY } from "../config-provider/ConfigProvider.mjs";
  6. const [name, bem] = createNamespace("icon");
  7. const isImage = (name2) => name2 == null ? void 0 : name2.includes("/");
  8. const iconProps = {
  9. dot: Boolean,
  10. tag: makeStringProp("i"),
  11. name: String,
  12. size: numericProp,
  13. badge: numericProp,
  14. color: String,
  15. badgeProps: Object,
  16. classPrefix: String
  17. };
  18. var stdin_default = defineComponent({
  19. name,
  20. props: iconProps,
  21. setup(props, {
  22. slots
  23. }) {
  24. const config = inject(CONFIG_PROVIDER_KEY, null);
  25. const classPrefix = computed(() => props.classPrefix || (config == null ? void 0 : config.iconPrefix) || bem());
  26. return () => {
  27. const {
  28. tag,
  29. dot,
  30. name: name2,
  31. size,
  32. badge,
  33. color
  34. } = props;
  35. const isImageIcon = isImage(name2);
  36. return _createVNode(Badge, _mergeProps({
  37. "dot": dot,
  38. "tag": tag,
  39. "class": [classPrefix.value, isImageIcon ? "" : `${classPrefix.value}-${name2}`],
  40. "style": {
  41. color,
  42. fontSize: addUnit(size)
  43. },
  44. "content": badge
  45. }, props.badgeProps), {
  46. default: () => {
  47. var _a;
  48. return [(_a = slots.default) == null ? void 0 : _a.call(slots), isImageIcon && _createVNode("img", {
  49. "class": bem("image"),
  50. "src": name2
  51. }, null)];
  52. }
  53. });
  54. };
  55. }
  56. });
  57. export {
  58. stdin_default as default
  59. };