create-icon.ts 821 B

123456789101112131415161718192021222324252627282930
  1. import { defineComponent, h } from 'vue';
  2. import { addIcon, Icon, type IconifyIcon } from '@iconify/vue';
  3. function createIconifyIcon(icon: string) {
  4. return defineComponent({
  5. name: `Icon-${icon}`,
  6. setup(props, { attrs }) {
  7. return () => h(Icon, { icon, ...props, ...attrs });
  8. },
  9. });
  10. }
  11. /**
  12. * 创建离线图标
  13. * @param icon 图标名称 建议与iconify的名称保持一致
  14. * @param iconComponent 从@iconify/icon-xxx/xxx导入的图标
  15. * @returns IconComponent
  16. */
  17. function createIconifyOfflineIcon(icon: string, iconComponent: IconifyIcon) {
  18. return defineComponent({
  19. name: `Icon-${icon}`,
  20. setup(props, { attrs }) {
  21. addIcon(icon, iconComponent);
  22. return () => h(Icon, { icon, ...props, ...attrs });
  23. },
  24. });
  25. }
  26. export { createIconifyIcon, createIconifyOfflineIcon };