1
0
mirror of https://github.com/coreui/coreui-icons.git synced 2025-08-12 11:44:02 +02:00

feat: change CIcon component mechanism

This commit is contained in:
woothu
2019-06-14 10:51:08 +02:00
parent ad30e7ae7d
commit 71b9cad7ee
2 changed files with 26 additions and 15 deletions

View File

@@ -1,8 +1,9 @@
<template> <template>
<svg <svg
viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"
:viewBox="viewBox"
:style="style" :style="style"
v-html="computedCode" v-html="icon.svgContent"
></svg> ></svg>
</template> </template>
@@ -13,11 +14,9 @@ export default {
icons: {}, icons: {},
props: { props: {
name: String, name: String,
content: String, content: [String, Array],
fill: String, fill: String,
background: String, background: String
// height: String,
// width: String
}, },
data () { data () {
return { return {
@@ -26,16 +25,31 @@ export default {
}, },
mounted () { mounted () {
this.$nextTick(() => { this.$nextTick(() => {
this.lineHeight = window.getComputedStyle(this.$el, null).getPropertyValue('line-height') if (this.$el && this.code) {
const computedStyle = window.getComputedStyle(this.$el, null)
this.lineHeight = computedStyle.getPropertyValue('line-height')
}
}) })
}, },
computed: { computed: {
iconName () { iconName () {
return this.name.includes('-') ? this.toCamelCase(this.name) : this.name const iconNameIsKebabCase = this.name && this.name.includes('-')
return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name
}, },
computedCode () { code () {
return this.content || this.$options.icons[this.iconName] return this.content || this.$options.icons[this.iconName]
}, },
icon () {
if (Array.isArray(this.code)) {
const coordinates = this.code.length > 1 ? this.code[0] : '64 64'
const svgContent = this.code.length > 1 ? this.code[1] : this.code[0]
return { coordinates, svgContent }
}
return { coordinates: '64 64', svgContent: this.code }
},
viewBox () {
return this.$attrs.viewBox || `0 0 ${ this.icon.coordinates }`
},
autoDimensions () { autoDimensions () {
const noDimensions = !this.$attrs.height && !this.$attrs.width const noDimensions = !this.$attrs.height && !this.$attrs.width
return noDimensions ? { height: this.lineHeight } : {} return noDimensions ? { height: this.lineHeight } : {}
@@ -45,8 +59,7 @@ export default {
fill: this.fill || 'currentColor', fill: this.fill || 'currentColor',
background: this.background background: this.background
}) })
}, }
}, },
methods: { methods: {
toCamelCase (str) { toCamelCase (str) {

View File

@@ -1,11 +1,9 @@
import Icons from '../js'
import CIcon from './CIcon' import CIcon from './CIcon'
export { CIcon } export { CIcon }
const CIconPlugin = { const CIconPlugin = {
install (Vue) { install (Vue, customIconSet) {
CIcon.icons = Icons CIcon.icons = customIconSet
Vue.component('CIcon', CIcon) Vue.component('CIcon', CIcon)
} }
} }