Created
May 20, 2022 20:54
-
-
Save ronssij/55222f8bfbf3a47a98b7553369257860 to your computer and use it in GitHub Desktop.
Functional vue icon component
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Utlizes the tailwind colors config with custom prefix
icon-
https://gist.github.com/ronssij/d31b30de50200aeddd49c82b7f474b18