Skip to content

Instantly share code, notes, and snippets.

@jakedohm
Created July 19, 2021 03:10
Show Gist options
  • Save jakedohm/188e491d1181d8b68956ef427ee6d98c to your computer and use it in GitHub Desktop.
Save jakedohm/188e491d1181d8b68956ef427ee6d98c to your computer and use it in GitHub Desktop.
Craft CMS + Vue Icons
<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>
plugins:
- removeViewBox: false
- removeDimensions: true
- convertColors:
currentColor: true
- addAttributesToSVGElement:
attribute: 'id="icon-definition"'
<!-- 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