Skip to content

Commit 476a383

Browse files
committed
Use icon sprite for icons in place of vue components
1 parent 71f464b commit 476a383

13 files changed

Lines changed: 102 additions & 193 deletions

File tree

packages/modules/web_themes/koala/source/src/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<template>
2+
<IconSprite />
23
<router-view />
34
</template>
45

56
<script setup lang="ts">
7+
import IconSprite from 'src/components/svgIcons/IconSprite.vue';
8+
69
defineOptions({
710
name: 'OpenwbKoalaWebTheme',
811
});

packages/modules/web_themes/koala/source/src/components/charts/dailyTotals/DailyTotalsRow.vue

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,6 @@ const arrowDirection = (id: string) => {
167167
height: 1.75rem;
168168
color: var(--q-diagram-icon);
169169
}
170-
171-
:deep(.base-icon svg) {
172-
width: 100%;
173-
height: 100%;
174-
fill: currentColor;
175-
vertical-align: middle;
176-
overflow: hidden;
177-
}
178170
.col-title {
179171
flex: 0 0 5.5rem;
180172
}

packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/EnergyFlowChart.vue

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import { useMqttStore } from 'src/stores/mqtt-store';
33
import { ref, computed, watch } from 'vue';
44
import type { SvgSize, FlowComponent } from './energy-flow-chart-models';
55
import type { ValueObject } from 'src/stores/mqtt-store-model';
6-
//SVG Icons
7-
import GridIcon from 'src/components/svgIcons/GridIcon.vue';
8-
import HouseIcon from 'src/components/svgIcons/HouseIcon.vue';
9-
import PvIcon from 'src/components/svgIcons/PvIcon.vue';
10-
import BatteryIcon from 'src/components/svgIcons/BatteryIcon.vue';
11-
import ChargePointIcon from 'src/components/svgIcons/ChargePointIcon.vue';
12-
import VehicleIcon from 'src/components/svgIcons/VehicleIcon.vue';
136
147
const mqttStore = useMqttStore();
158
@@ -341,7 +334,7 @@ const svgComponents = computed((): FlowComponent[] => {
341334
position: { row: 0, column: 0 },
342335
label: ['EVU', absoluteValueObject(gridPower.value).textValue],
343336
powerValue: Number(gridPower.value.value),
344-
iconComponent: GridIcon,
337+
iconName: 'grid',
345338
iconColor:
346339
mqttStore.getGridComponentColor(gridID.value) ||
347340
'var(--q-diagram-icon)',
@@ -360,7 +353,7 @@ const svgComponents = computed((): FlowComponent[] => {
360353
position: { row: 0, column: 2 },
361354
label: ['Haus', absoluteValueObject(homePower.value).textValue],
362355
powerValue: Number(homePower.value.value),
363-
iconComponent: HouseIcon,
356+
iconName: 'house',
364357
iconColor: 'var(--q-diagram-icon)',
365358
});
366359
}
@@ -377,7 +370,7 @@ const svgComponents = computed((): FlowComponent[] => {
377370
position: { row: 1, column: 0 },
378371
label: ['PV', absoluteValueObject(pvPower.value).textValue],
379372
powerValue: Number(pvPower.value.value),
380-
iconComponent: PvIcon,
373+
iconName: 'pv',
381374
iconColor:
382375
mqttStore.getPvComponentColor(pvId.value) || 'var(--q-diagram-icon)',
383376
});
@@ -396,7 +389,7 @@ const svgComponents = computed((): FlowComponent[] => {
396389
label: ['Speicher', absoluteValueObject(batteryPower.value).textValue],
397390
powerValue: Number(batteryPower.value.value),
398391
soc: batterySoc.value,
399-
iconComponent: BatteryIcon,
392+
iconName: 'battery',
400393
iconColor: 'var(--q-diagram-icon)',
401394
});
402395
}
@@ -422,7 +415,7 @@ const svgComponents = computed((): FlowComponent[] => {
422415
absoluteValueObject(chargePoint1Power.value).textValue,
423416
],
424417
powerValue: Number(chargePoint1Power.value.value),
425-
iconComponent: ChargePointIcon,
418+
iconName: 'chargepoint',
426419
iconColor:
427420
mqttStore.chargePointUserDefinedColor(
428421
connectedChargePoints.value[0],
@@ -450,7 +443,7 @@ const svgComponents = computed((): FlowComponent[] => {
450443
chargePoint1ConnectedVehicleChargeMode.value.label || '---',
451444
],
452445
soc: (chargePoint1ConnectedVehicleSoc.value.value?.soc || 0) / 100,
453-
iconComponent: VehicleIcon,
446+
iconName: 'vehicle',
454447
iconColor:
455448
mqttStore.vehicleUserDefinedColor(
456449
chargePoint1ConnectedVehicle.value?.id,
@@ -479,7 +472,7 @@ const svgComponents = computed((): FlowComponent[] => {
479472
absoluteValueObject(chargePoint2Power.value).textValue,
480473
],
481474
powerValue: Number(chargePoint2Power.value.value),
482-
iconComponent: ChargePointIcon,
475+
iconName: 'chargepoint',
483476
iconColor:
484477
mqttStore.chargePointUserDefinedColor(
485478
connectedChargePoints.value[1],
@@ -508,7 +501,7 @@ const svgComponents = computed((): FlowComponent[] => {
508501
chargePoint2ConnectedVehicleChargeMode.value.label || '---',
509502
],
510503
soc: (chargePoint2ConnectedVehicleSoc.value.value?.soc || 0) / 100,
511-
iconComponent: VehicleIcon,
504+
iconName: 'vehicle',
512505
iconColor:
513506
mqttStore.vehicleUserDefinedColor(
514507
chargePoint2ConnectedVehicle.value?.id,
@@ -534,7 +527,7 @@ const svgComponents = computed((): FlowComponent[] => {
534527
absoluteValueObject(chargePoint3Power.value).textValue,
535528
],
536529
powerValue: Number(chargePoint3Power.value.value),
537-
iconComponent: ChargePointIcon,
530+
iconName: 'chargepoint',
538531
iconColor:
539532
mqttStore.chargePointUserDefinedColor(
540533
connectedChargePoints.value[2],
@@ -563,7 +556,7 @@ const svgComponents = computed((): FlowComponent[] => {
563556
chargePoint3ConnectedVehicleChargeMode.value.label || '---',
564557
],
565558
soc: (chargePoint3ConnectedVehicleSoc.value.value?.soc || 0) / 100,
566-
iconComponent: VehicleIcon,
559+
iconName: 'vehicle',
567560
iconColor:
568561
mqttStore.vehicleUserDefinedColor(
569562
chargePoint3ConnectedVehicle.value?.id,
@@ -588,7 +581,7 @@ const svgComponents = computed((): FlowComponent[] => {
588581
absoluteValueObject(chargePointSumPower.value).textValue,
589582
],
590583
powerValue: Number(chargePointSumPower.value.value),
591-
iconComponent: ChargePointIcon,
584+
iconName: 'chargepoint',
592585
iconColor: 'var(--q-diagram-icon)',
593586
});
594587
}
@@ -819,19 +812,15 @@ const svgRectWidth = computed(
819812
:clip-path="`url(#clip-soc-${component.id})`"
820813
/>
821814

822-
<foreignObject
815+
<use
816+
v-if="component.iconName"
817+
:href="`#icon-${component.iconName}`"
823818
:x="-svgIconWidth / 2"
824819
:y="-svgIconHeight / 2"
825820
:width="svgIconWidth"
826821
:height="svgIconHeight"
827-
>
828-
<div class="icon-wrapper" :style="{ color: component.iconColor }">
829-
<component
830-
:is="component.iconComponent"
831-
style="width: 100%; height: 100%"
832-
/>
833-
</div>
834-
</foreignObject>
822+
:style="{ color: component.iconColor }"
823+
/>
835824
</g>
836825
</g>
837826
</g>
@@ -987,18 +976,6 @@ rect {
987976
fill: var(--q-secondary);
988977
}
989978
990-
:root {
991-
image {
992-
filter: brightness(0.4); /* Creates a dark grey icons in light theme */
993-
}
994-
}
995-
996-
.body--dark {
997-
image {
998-
filter: brightness(1); /* white icons in dark theme */
999-
}
1000-
}
1001-
1002979
text {
1003980
font-size: v-bind(svgFontSize);
1004981
line-height: 1.25;
@@ -1108,11 +1085,8 @@ text .fill-dark {
11081085
.vehicle circle:not(.soc) {
11091086
fill: color-mix(in srgb, var(--q-accent) 50%, transparent);
11101087
}
1111-
.icon-wrapper {
1112-
width: 100%;
1113-
height: 100%;
1114-
display: flex;
1115-
align-items: center;
1116-
justify-content: center;
1088+
1089+
use {
1090+
fill: currentColor;
11171091
}
11181092
</style>

packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/energy-flow-chart-models.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Component } from 'vue';
2-
31
export interface SvgSize {
42
xMin: number;
53
xMax: number;
@@ -33,6 +31,6 @@ export interface FlowComponent {
3331
label: string[];
3432
powerValue?: number;
3533
soc?: number;
36-
iconComponent?: Component;
34+
iconName?: string;
3735
iconColor?: string | null;
3836
}
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
11
<template>
2-
<div :style="color ? { color } : undefined">
3-
<component :is="iconComponent" v-if="iconComponent" />
4-
</div>
2+
<svg
3+
class="base-icon"
4+
:style="color ? { color } : undefined"
5+
aria-hidden="true"
6+
>
7+
<use :href="`#icon-${iconName}`" />
8+
</svg>
59
</template>
610

711
<script setup lang="ts">
8-
import { computed } from 'vue';
9-
10-
import GridIcon from 'src/components/svgIcons/GridIcon.vue';
11-
import CounterIcon from 'src/components/svgIcons/CounterIcon.vue';
12-
import BatteryIcon from 'src/components/svgIcons/BatteryIcon.vue';
13-
import ChargePointIcon from 'src/components/svgIcons/ChargePointIcon.vue';
14-
import VehicleIcon from 'src/components/svgIcons/VehicleIcon.vue';
15-
import PvIcon from 'src/components/svgIcons/PvIcon.vue';
16-
import HouseIcon from 'src/components/svgIcons/HouseIcon.vue';
17-
18-
const props = defineProps<{
12+
defineProps<{
1913
iconName: string;
2014
color?: string | null;
2115
}>();
22-
23-
const iconMap = {
24-
grid: GridIcon,
25-
counter: CounterIcon,
26-
battery: BatteryIcon,
27-
chargepoint: ChargePointIcon,
28-
pv: PvIcon,
29-
house: HouseIcon,
30-
vehicle: VehicleIcon,
31-
};
32-
33-
const iconComponent = computed(() => {
34-
return iconMap[props.iconName] || null;
35-
});
3616
</script>
17+
18+
<style scoped>
19+
.base-icon {
20+
width: 100%;
21+
height: 100%;
22+
fill: currentColor;
23+
vertical-align: middle;
24+
overflow: hidden;
25+
}
26+
</style>

packages/modules/web_themes/koala/source/src/components/svgIcons/BatteryIcon.vue

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/modules/web_themes/koala/source/src/components/svgIcons/ChargePointIcon.vue

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/modules/web_themes/koala/source/src/components/svgIcons/CounterIcon.vue

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/modules/web_themes/koala/source/src/components/svgIcons/GridIcon.vue

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/modules/web_themes/koala/source/src/components/svgIcons/HouseIcon.vue

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)