Skip to content

Commit d3ad304

Browse files
committed
refactor score label
1 parent ccd050b commit d3ad304

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

front/src/components/map/ScoreLabel.vue

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<script setup lang="ts">
22
import { computed } from "vue"
3+
import type { ScoreLabelSize } from "@/utils/enum"
34
4-
const props = defineProps({
5-
score: {
6-
required: true,
7-
type: Number
8-
},
9-
label: {
10-
required: true,
11-
type: String
12-
},
13-
size: {
14-
required: true,
15-
type: String
16-
}
17-
})
18-
19-
const scoreBg: Record<number, string> = {
5+
interface ScoreLabelProps {
6+
score: number
7+
label: string
8+
size: ScoreLabelSize
9+
}
10+
const SCORE_BG_CLASSES: Record<number, string> = {
2011
0: "bg-scale-0 border-scale-0",
2112
1: "bg-scale-1 border-scale-1",
2213
2: "bg-scale-2 border-scale-2",
@@ -30,29 +21,32 @@ const scoreBg: Record<number, string> = {
3021
10: "bg-scale-10 border-scale-10 text-white"
3122
}
3223
33-
const backgroundClass = computed(() => scoreBg[props.score])
24+
const props = defineProps<ScoreLabelProps>()
25+
26+
const backgroundClass = computed(() => SCORE_BG_CLASSES[props.score] || SCORE_BG_CLASSES[0])
3427
const sizeClass = computed(() => props.size)
3528
</script>
3629

3730
<template>
38-
<div class="hexagon relative m-[5px] block text-center" :class="[backgroundClass, sizeClass]">
31+
<div
32+
class="hexagon relative m-[5px] block text-center flex justify-center items-center"
33+
:class="[backgroundClass, sizeClass]"
34+
>
3935
<span>{{ label }}</span>
4036
</div>
4137
</template>
4238

4339
<style scoped>
4440
.hexagon {
45-
position: relative;
46-
display: flex;
47-
justify-content: center;
48-
align-items: center;
4941
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
5042
}
43+
5144
.hexagon.small {
5245
height: 2em;
5346
width: 2em;
5447
font-size: 1.5em;
5548
}
49+
5650
.hexagon.huge {
5751
height: 4em;
5852
width: 4em;

front/src/components/map/legend/PlantabilityLegend.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import ScoreLabel from "../ScoreLabel.vue"
3+
import { ScoreLabelSize } from "@/utils/enum"
34
</script>
45

56
<template>
@@ -15,7 +16,7 @@ import ScoreLabel from "../ScoreLabel.vue"
1516
class="flex items-center justify-center"
1617
:score="index"
1718
:label="`${index}`"
18-
size="small"
19+
:size="ScoreLabelSize.SMALL"
1920
/>
2021
</div>
2122
<span class="text-[0.9rem] leading-3">Plantable</span>

front/src/components/map/popup/MapScorePopup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useMapStore } from "@/stores/map"
55
import { DataType } from "@/utils/enum"
66
77
const mapStore = useMapStore()
8-
const props = defineProps({
8+
defineProps({
99
index: {
1010
required: true,
1111
type: String

front/src/components/map/popup/PlantabilityScorePopupContent.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import ScoreLabel from "@/components/map/ScoreLabel.vue"
33
import { computed } from "vue"
4+
import { ScoreLabelSize } from "@/utils/enum"
45
56
const props = defineProps({
67
index: {
@@ -20,7 +21,7 @@ const label = computed(() => {
2021
<template>
2122
<div data-cy="plantability-score-popup" class="p-2.5 max-w-xs">
2223
<div class="flex-grow mr-1.25">
23-
<score-label :score="score" :label="`${score}/10`" size="huge" />
24+
<score-label :score="score" :label="`${score}/10`" :size="ScoreLabelSize.HUGE" />
2425
</div>
2526
<div class="flex-grow ml-1.25">
2627
<h3 class="font-mono text-lg">{{ label }}</h3>

front/src/utils/enum.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export enum DataType {
88
LOCAL_CLIMATE_ZONES = "lcz"
99
}
1010

11+
export enum ScoreLabelSize {
12+
SMALL = "small",
13+
HUGE = "huge"
14+
}
1115
export const DataTypeToLabel: Record<DataType, string> = {
1216
[DataType.PLANTABILITY]: "Plantabilité",
1317
[DataType.LOCAL_CLIMATE_ZONES]: "Zones climatiques locales"

0 commit comments

Comments
 (0)