1
1
<template >
2
2
<div >
3
3
<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 >
27
33
</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" >
29
36
<div
30
37
v-for =" (value, prop) in selectedColorItems"
31
38
:key =" prop"
49
56
/>
50
57
</div >
51
58
</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
+
52
86
</div >
53
87
</template >
54
88
@@ -75,7 +109,8 @@ export default {
75
109
76
110
data () {
77
111
return {
78
- selectedProp: ' backgroundColor'
112
+ selectedProp: ' backgroundColor' ,
113
+ groupColors: false
79
114
}
80
115
},
81
116
@@ -84,6 +119,10 @@ export default {
84
119
return this .data [this .selectedProp ]
85
120
},
86
121
122
+ groupedColorItems () {
123
+ return this .groupColors ? this .groupColorByName (this .selectedColorItems ) : this .selectedColorItems
124
+ },
125
+
87
126
selectedPropClassPrefix () {
88
127
const map = {
89
128
backgroundColor: ' bg' ,
@@ -108,7 +147,34 @@ export default {
108
147
border: ` 2px solid ${ value} `
109
148
}
110
149
}
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
111
163
}
112
164
}
113
165
}
114
166
</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