Refactored EntityIcon component

This commit is contained in:
Fabio Manganiello 2023-01-15 20:02:50 +01:00
parent 9a5e2899e8
commit 22b8b03cb2
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
11 changed files with 35 additions and 16 deletions

View file

@ -3,6 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:entity="value"
:icon="icon" :icon="icon"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />

View file

@ -3,7 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -3,7 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -3,7 +3,7 @@
<div class="head" :class="{collapsed: collapsed}"> <div class="head" :class="{collapsed: collapsed}">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="this.value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -4,7 +4,7 @@
:style="colorFillStyle"> :style="colorFillStyle">
<img src="@/assets/img/spinner.gif" class="loading" v-if="loading"> <img src="@/assets/img/spinner.gif" class="loading" v-if="loading">
<i class="fas fa-circle-exclamation error" v-else-if="error" /> <i class="fas fa-circle-exclamation error" v-else-if="error" />
<Icon v-bind="computedIcon" v-else /> <Icon v-bind="computedIconNormalized" v-else />
</div> </div>
</template> </template>
@ -25,11 +25,16 @@ export default {
default: false, default: false,
}, },
icon: { entity: {
type: Object, type: Object,
required: true, required: true,
}, },
icon: {
type: Object,
default: () => {},
},
hasColorFill: { hasColorFill: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -44,16 +49,23 @@ export default {
}, },
computed: { computed: {
computedIcon() {
let icon = {...(this.entity?.meta?.icon || {})}
if (Object.keys(this.icon || {}).length)
icon = this.icon
return {...icon}
},
colorFill() { colorFill() {
return (this.hasColorFill && this.icon.color) ? this.icon.color : null return this.hasColorFill && this.computedIcon.color
}, },
colorFillStyle() { colorFillStyle() {
return this.colorFill && !this.error ? {'background': this.colorFill} : {} return this.colorFill && !this.error ? {'background': this.colorFill} : {}
}, },
computedIcon() { computedIconNormalized() {
const icon = {...this.icon} const icon = {...this.computedIcon}
if (this.colorFill) if (this.colorFill)
delete icon.color delete icon.color
return icon return icon

View file

@ -3,7 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -3,7 +3,7 @@
<div class="head" :class="{collapsed: collapsed}"> <div class="head" :class="{collapsed: collapsed}">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="this.value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -2,8 +2,12 @@
<div class="entity light-container"> <div class="entity light-container">
<div class="head" :class="{collapsed: collapsed}"> <div class="head" :class="{collapsed: collapsed}">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon :icon="icon" :hasColorFill="true" <EntityIcon
:loading="loading" :error="error" /> :entity="value"
:icon="icon"
:hasColorFill="true"
:loading="loading"
:error="error" />
</div> </div>
<div class="col-s-8 col-m-9 label"> <div class="col-s-8 col-m-9 label">

View file

@ -3,7 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -3,7 +3,7 @@
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon <EntityIcon
:icon="value.meta?.icon || {}" :entity="value"
:loading="loading" :loading="loading"
:error="error" /> :error="error" />
</div> </div>

View file

@ -2,8 +2,10 @@
<div class="entity switch-container"> <div class="entity switch-container">
<div class="head"> <div class="head">
<div class="col-1 icon"> <div class="col-1 icon">
<EntityIcon :icon="value.meta?.icon || {}" <EntityIcon
:loading="loading" :error="error" /> :entity="value"
:loading="loading"
:error="error" />
</div> </div>
<div class="col-9 label"> <div class="col-9 label">