Created
July 19, 2021 03:10
-
-
Save jakedohm/188e491d1181d8b68956ef427ee6d98c to your computer and use it in GitHub Desktop.
Craft CMS + Vue Icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<svg> | |
<use :xlink:href="path"></use> | |
</svg> | |
</template> | |
<script> | |
export default { | |
props: { | |
name: String, | |
}, | |
computed: { | |
path() { | |
// approx result "/assets/icons/facebook.svg#icon-definition" | |
const path = `/assets/icons/${this.name}.svg#icon-definition` | |
const url = encodeURI(path) | |
return url | |
} | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins: | |
- removeViewBox: false | |
- removeDimensions: true | |
- convertColors: | |
currentColor: true | |
- addAttributesToSVGElement: | |
attribute: 'id="icon-definition"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Basic Usage --> | |
<icon name="facebook"></icon> | |
<!-- Result --> | |
<svg> | |
<use xlink:href="/assets/icons/facebook.svg#icon-definition"></use> | |
</svg> | |
<!-- Usage + styling (classes pass through automatically) --> | |
<icon name="facebook" class="text-red w-[16px]"></icon> | |
<!-- Result --> | |
<svg class="text-red w-[16px]"> | |
<use xlink:href="/assets/icons/facebook.svg#icon-definition"></use> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment