Refactored EntityIcon component

This commit is contained in:
Fabio Manganiello 2023-01-15 20:02:50 +01:00
parent 9a5e2899e8
commit 22b8b03cb2
Signed by: 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="col-1 icon">
<EntityIcon
:entity="value"
:icon="icon"
:loading="loading"
:error="error" />

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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