From 2fbfaf300c45f1af9e57144975fc90a956369df5 Mon Sep 17 00:00:00 2001 From: woothu <32914662+woothu@users.noreply.github.com> Date: Tue, 11 Jun 2019 14:38:35 +0200 Subject: [PATCH] feat: add automatic size setting --- vue/CIcon.vue | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/vue/CIcon.vue b/vue/CIcon.vue index 810697208..1a8f0ab52 100644 --- a/vue/CIcon.vue +++ b/vue/CIcon.vue @@ -15,7 +15,19 @@ export default { name: String, content: String, fill: String, - background: String + background: String, + // height: String, + // width: String + }, + data () { + return { + lineHeight: null + } + }, + mounted () { + this.$nextTick(() => { + this.lineHeight = window.getComputedStyle(this.$el, null).getPropertyValue('line-height') + }) }, computed: { iconName () { @@ -24,12 +36,17 @@ export default { computedCode () { return this.content || this.$options.icons[this.iconName] }, + autoDimensions () { + const noDimensions = !this.$attrs.height && !this.$attrs.width + return noDimensions ? { height: this.lineHeight } : {} + }, style () { - return { + return Object.assign({}, this.autoDimensions, { fill: this.fill || 'currentColor', background: this.background - } - } + }) + }, + }, methods: { toCamelCase (str) {