vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

fix(VIcon): add mdi set only if defaultSet is mdi

Open dnldsht opened this issue 2 years ago • 4 comments

Description

Avoid adding the mdi set if defaultSet is not 'mdi'.

If you configure vuetify as follows

vuetify config

const nuxtIcon: IconSet = {
  component: (props: IconProps) => {
    return h(Icon, { name: props.icon })
  },
}

createVuetify({
  icons: {
    defaultSet: 'nuxtIcon',
    sets: {
      nuxtIcon,
    },
  },
})

the name of icon will change if it starts with mdi even if you are using the default mdi iconset provided by vuetify

packages/vuetify/src/composables/icons.tsx

export const useIcon = (props: Ref<IconValue | undefined>) => {
 // omitted code
 // eg: icon = 'mdi:pencil'
  const iconSetName = Object.keys(icons.sets).find(setName => typeof icon === 'string' && icon.startsWith(`${setName}:`));
  // this will remove mdi: (icon = 'pencil')
  const iconName = iconSetName ? icon.slice(iconSetName.length + 1) : icon;
  const iconSet = icons.sets[iconSetName ?? icons.defaultSet];

  return {
        component: iconSet.component,
        icon: iconName
  };
}

dnldsht avatar Dec 14 '23 16:12 dnldsht

I'm not understanding the use-case. I need a better reproduction example.

johnleider avatar Dec 18 '23 22:12 johnleider

@johnleider here is a small reproduction https://stackblitz.com/edit/github-ph4pzm?file=app.vue

dnldsht avatar Dec 19 '23 08:12 dnldsht

I made a few tweaks. You can test this in the Vuetify playground with the following:

// vuetify/dev/icons.js

import { aliases, mdi as mdiSvg } from 'vuetify/src/iconsets/mdi-svg'
import { mdi } from 'vuetify/src/iconsets/mdi'
import { fa } from 'vuetify/src/iconsets/fa-svg'

export default {
  defaultSet: 'mdiSvg',
  aliases,
  sets: {
    mdi,
    mdiSvg,
    fa,
  },
}

and

<template>
  <v-app>
    <div class="ma-4 pa-4">
      <v-icon icon="mdi:pencil" />
      <br>
      <v-icon icon="fa:pencil" />
      <br>
      <v-icon icon="$success" />
    </div>
  </v-app>
</template>

<script setup>
  import { ref } from 'vue'
</script>

johnleider avatar Dec 19 '23 16:12 johnleider

@johnleider looks good to me

dnldsht avatar Dec 19 '23 16:12 dnldsht