Skip to content

Commit d50bc39

Browse files
docs: explain better icon examples of custom aliases on icon fonts (#21955)
Co-authored-by: Andrew Henry <[email protected]> Resolves #21784
1 parent b531dbf commit d50bc39

File tree

2 files changed

+56
-30
lines changed

2 files changed

+56
-30
lines changed

packages/docs/src/examples/v-btn/prop-icon.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</v-col>
77

88
<v-col cols="auto">
9-
<v-btn density="comfortable" icon="$vuetify"></v-btn>
9+
<v-btn density="comfortable" icon="mdi-cow"></v-btn>
1010
</v-col>
1111

1212
<v-col cols="auto">
@@ -24,7 +24,7 @@
2424
</v-col>
2525

2626
<v-col cols="auto">
27-
<v-btn icon="$vuetify"></v-btn>
27+
<v-btn icon="mdi-cow"></v-btn>
2828
</v-col>
2929

3030
<v-col cols="auto">

packages/docs/src/pages/en/features/icon-fonts.md

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,64 @@ app.mount('#app')
439439
</template>
440440
```
441441

442-
## Built-in aliases
442+
## Icon aliases
443443

444-
The following icons are available as aliases for use in Vuetify components:
444+
Icon aliases allow you to define short, reusable names for icons that can map to different sources — such as icon names from a set, local Vue components, or raw SVG paths. Aliases are referenced with an initial `$` followed by the name of the alias, e.g. `$product`. The following icons are available as aliases for use in Vuetify components:
445445

446446
<DocIconTable />
447447

448+
### Custom aliases
449+
450+
If you are developing custom Vuetify components, you can extend the `aliases` object to utilize the same functionality that internal Vuetify components use. This makes it easier to manage icons consistently throughout your project.
451+
452+
Here’s an example:
453+
454+
```js { resource="src/plugins/vuetify.js" }
455+
import { createVuetify } from 'vuetify'
456+
import AccountIcon from './account-icon.vue'
457+
import ClosetIcon from './closet-icon.vue'
458+
459+
export const customIcons = {
460+
mdiCustomAlias: 'mdi-cow',
461+
account: AccountIcon,
462+
annotation: [
463+
'M14 9.45h-1v-1a1 1 0 0 0-2 0v1h-1a1 1 0 0 0 0 2h1v1a1 1 0 0 0 2 0v-1h1a1 1 0 0 0 0-2Zm6.46.18A8.5 8.5 0 1 0 6 16.46l5.3 5.31a1 1 0 0 0 1.42 0L18 16.46a8.46 8.46 0 0 0 2.46-6.83Zm-3.86 5.42l-4.6 4.6l-4.6-4.6a6.49 6.49 0 0 1-1.87-5.22A6.57 6.57 0 0 1 8.42 5a6.47 6.47 0 0 1 7.16 0a6.57 6.57 0 0 1 2.89 4.81a6.49 6.49 0 0 1-1.87 5.24Z',
464+
],
465+
closet: ClosetIcon,
466+
}
467+
468+
export const vuetify = createVuetify({
469+
theme: {
470+
defaultTheme: 'light',
471+
//
472+
},
473+
icons: {
474+
defaultSet: 'mdi',
475+
aliases: {
476+
...customIcons,
477+
},
478+
},
479+
})
480+
```
481+
482+
```html
483+
<template>
484+
<v-btn prepend-icon="$account">Custom Icon 1</v-btn>
485+
<v-btn prepend-icon="$mdiCustomAlias">Custom Icon 2</v-btn>
486+
<v-btn prepend-icon="$closet">Custom Icon 3</v-btn>
487+
<v-btn prepend-icon="$annotation">Custom Icon 4</v-btn>
488+
<v-btn prepend-icon="mdi-close">Default MDI Icon</v-btn>
489+
</template>
490+
```
491+
492+
In this setup:
493+
494+
* $account and $closet render your own Vue component SVG icons.
495+
* $mdiCustomAlias references an alias for the mdi-cow icon.
496+
* $annotation references inline SVG path data.
497+
498+
This approach gives you flexibility: you can mix external libraries with your own icons seamlessly, while keeping your templates cleaner and easier to maintain.
499+
448500
## Multiple icon sets
449501

450502
Out of the box, Vuetify supports the use of multiple *different* icon sets at the same time. The following example demonstrates how to change the default icon font to Font Awesome (`fa`) while still maintaining access to the original Material Design Icons (`mdi`) through the use of a prefix:
@@ -550,29 +602,3 @@ export default createVuetify({
550602
},
551603
})
552604
```
553-
554-
## Extending available aliases
555-
556-
If you are developing custom Vuetify components, you can extend the `aliases` object to utilize the same functionality that internal Vuetify components use. Icon aliases are referenced with an initial `$` followed by the name of the alias, e.g. `$product`.
557-
558-
```js { resource="src/plugins/vuetify.js" }
559-
import { createVuetify } from 'vuetify'
560-
import { aliases, mdi } from 'vuetify/iconsets/mdi'
561-
562-
export default createVuetify({
563-
icons: {
564-
aliases: {
565-
...aliases,
566-
product: 'mdi-dropbox',
567-
support: 'mdi-lifebuoy',
568-
},
569-
},
570-
})
571-
```
572-
573-
```html
574-
<template>
575-
<v-icon icon="$product" />
576-
<v-icon icon="$support" />
577-
</template>
578-
```

0 commit comments

Comments
 (0)