Skip to content

Commit 278cc42

Browse files
committed
feat: Group color tiles by name
1 parent 56d6d2e commit 278cc42

File tree

1 file changed

+91
-25
lines changed

1 file changed

+91
-25
lines changed

src/components/Canvas/Sections/Colors.vue

+91-25
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
<template>
22
<div>
33
<StickySectionHeader id="section-colors">
4-
<ButtonGroup>
5-
<Button
6-
class="w-full sm:w-32"
7-
:selected="selectedProp === 'backgroundColor'"
8-
@click="selectedProp = 'backgroundColor'"
9-
>
10-
Background
11-
</Button>
12-
<Button
13-
class="w-full sm:w-32"
14-
:selected="selectedProp === 'textColor'"
15-
@click="selectedProp = 'textColor'"
16-
>
17-
Text
18-
</Button>
19-
<Button
20-
class="w-full sm:w-32"
21-
:selected="selectedProp === 'borderColor'"
22-
@click="selectedProp = 'borderColor'"
23-
>
24-
Border
25-
</Button>
26-
</ButtonGroup>
4+
<div class="flex">
5+
<ButtonGroup>
6+
<Button
7+
class="w-full sm:w-32"
8+
:selected="selectedProp === 'backgroundColor'"
9+
@click="selectedProp = 'backgroundColor'"
10+
>
11+
Background
12+
</Button>
13+
<Button
14+
class="w-full sm:w-32"
15+
:selected="selectedProp === 'textColor'"
16+
@click="selectedProp = 'textColor'"
17+
>
18+
Text
19+
</Button>
20+
<Button
21+
class="w-full sm:w-32"
22+
:selected="selectedProp === 'borderColor'"
23+
@click="selectedProp = 'borderColor'"
24+
>
25+
Border
26+
</Button>
27+
</ButtonGroup>
28+
<span class="flex items-center mx-4 dark:text-white">
29+
<input type="checkbox" id="groupColors" v-model="groupColors" class="mr-2">
30+
<label class="cursor-pointer" for="groupColors">Group colors</label>
31+
</span>
32+
</div>
2733
</StickySectionHeader>
28-
<div class="flex flex-wrap -mb-4 mt-6">
34+
35+
<div v-if="!groupColors" class="flex flex-wrap -mb-4 mt-6">
2936
<div
3037
v-for="(value, prop) in selectedColorItems"
3138
:key="prop"
@@ -49,6 +56,33 @@
4956
/>
5057
</div>
5158
</div>
59+
60+
<template v-else>
61+
<div v-for="(items, groupName) in groupedColorItems" :key="groupName">
62+
<h3 class="text-xl mt-6 mb-2 font-semibold capitalize dark:text-white">{{ groupName }}</h3>
63+
<ul class="flex-container">
64+
<li v-for="item in items" :key="item.id" class="flex-item">
65+
<div
66+
class="mb-2 flex-none w-full md:w-36 h-16 md:h-36 flex items-center justify-center"
67+
:class="{'border border-gray-300': selectedProp === 'textColor'}"
68+
:style="tileStyle(item.value)"
69+
>
70+
<span
71+
class="text-3xl"
72+
:style="{
73+
color: item.value
74+
}"
75+
v-if="selectedProp === 'textColor'">Aa</span>
76+
</div>
77+
<CanvasBlockLabel
78+
:label="`${selectedPropClassPrefix}-${item.key}`"
79+
:value="item.value"
80+
/>
81+
</li>
82+
</ul>
83+
</div>
84+
</template>
85+
5286
</div>
5387
</template>
5488

@@ -75,7 +109,8 @@ export default {
75109
76110
data () {
77111
return {
78-
selectedProp: 'backgroundColor'
112+
selectedProp: 'backgroundColor',
113+
groupColors: false
79114
}
80115
},
81116
@@ -84,6 +119,10 @@ export default {
84119
return this.data[this.selectedProp]
85120
},
86121
122+
groupedColorItems () {
123+
return this.groupColors ? this.groupColorByName(this.selectedColorItems) : this.selectedColorItems
124+
},
125+
87126
selectedPropClassPrefix () {
88127
const map = {
89128
backgroundColor: 'bg',
@@ -108,7 +147,34 @@ export default {
108147
border: `2px solid ${value}`
109148
}
110149
}
150+
},
151+
groupColorByName (items) {
152+
const groups = {}
153+
for (const key in items) {
154+
if (items.hasOwnProperty(key)) {
155+
const group = key.substring(0, key.lastIndexOf('-'))
156+
if (!groups[group]) {
157+
groups[group] = []
158+
}
159+
groups[group].push({ key, value: items[key] })
160+
}
161+
}
162+
return groups
111163
}
112164
}
113165
}
114166
</script>
167+
168+
<style>
169+
.flex-container {
170+
display: flex;
171+
flex-wrap: wrap;
172+
gap: 16px;
173+
justify-content: flex-start;
174+
align-items: flex-start;
175+
}
176+
177+
.flex-item {
178+
flex-basis: 5%;
179+
}
180+
</style>

0 commit comments

Comments
 (0)