Icon.mjs 1.7 KB

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