Skip to content

Instantly share code, notes, and snippets.

@ronssij
Created May 20, 2022 20:54
Show Gist options
  • Save ronssij/55222f8bfbf3a47a98b7553369257860 to your computer and use it in GitHub Desktop.
Save ronssij/55222f8bfbf3a47a98b7553369257860 to your computer and use it in GitHub Desktop.
Functional vue icon component
<script>
import { has, map } from 'lodash'
export default {
name: 'AftIcon',
functional: true,
props: {
tag: {
type: String,
default: () => 'span'
},
color: {
type: String,
default: () => 'default'
}
},
render (createElement, { props, data, scopedSlots }) {
const _path = () => {
if (has(scopedSlots, 'default')) {
return map(scopedSlots.default(), (slot) => {
return createElement('path', {
attrs: {
'fill-rule': 'nonzero',
d: slot.text.trim()
}
})
})
}
return createElement()
}
return createElement(props.tag, {
...data,
class: [`icon-${props.color}`]
}, [
createElement('svg', {
class: ['aft-icon__svg'],
attrs: {
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 24 24',
role: 'img',
'aria-hidden': true
}
}, _path())
])
}
}
</script>
@ronssij
Copy link
Author

ronssij commented May 20, 2022

Utlizes the tailwind colors config with custom prefix icon-
https://gist.github.com/ronssij/d31b30de50200aeddd49c82b7f474b18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment