@@ -43,14 +43,20 @@ const values = computed<string[]>({
43
43
return currentValues .slice ();
44
44
}
45
45
46
- return props . question . currentState . valueOptions . map (( option ) => option . value );
46
+ return getRankItems ( );
47
47
},
48
48
set : (orderedValues ) => {
49
49
touched .value = true ;
50
50
props .question .setValues (orderedValues );
51
51
},
52
52
});
53
53
54
+ const getRankItems = () => props .question .currentState .valueOptions .map ((option ) => option .value );
55
+
56
+ const selectDefaultOrder = () => {
57
+ values .value = getRankItems ();
58
+ };
59
+
54
60
const setHighlight = (index : number | null ) => {
55
61
highlight .index .value = index ;
56
62
@@ -101,58 +107,70 @@ const swapItems = (index: number, newPosition: number) => {
101
107
<template >
102
108
<ControlText :question =" question" />
103
109
104
- <VueDraggable
105
- :id =" question.nodeId"
106
- v-model =" values"
107
- :delay =" HOLD_DELAY"
108
- :delay-on-touch-only =" true"
109
- :disabled =" disabled"
110
- ghost-class =" fade-moving"
111
- class =" rank-control"
112
- :class =" { 'disabled': disabled }"
113
- >
114
- <div
115
- v-for =" (value, index) in values"
116
- :id =" value"
117
- :key =" value"
118
- class =" rank-option"
119
- :class =" { 'moving': highlight.index.value === index }"
120
- tabindex =" 0"
121
- @keydown.up.prevent =" moveUp(index)"
122
- @keydown.down.prevent =" moveDown(index)"
123
- >
124
- <div class =" rank-label" >
125
- <svg xmlns =" http://www.w3.org/2000/svg" width =" 25" height =" 25" viewBox =" 0 0 768 768" >
126
- <path d =" M480 511.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM480 319.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM480 256.5q-25.5 0-45-19.5t-19.5-45 19.5-45 45-19.5 45 19.5 19.5 45-19.5 45-45 19.5zM288 127.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM288 319.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM352.5 576q0 25.5-19.5 45t-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5 45 19.5 19.5 45z" />
110
+ <div class =" range-control-container" >
111
+ <div v-if =" !touched" class =" rank-overlay" >
112
+ <button :disabled =" disabled" @click =" selectDefaultOrder" >
113
+ <svg xmlns =" http://www.w3.org/2000/svg" width =" 8" height =" 15" viewBox =" 0 0 8 15" fill =" none" >
114
+ <path d =" M3.91263 2.57495L5.96263 4.52245C6.28763 4.8312 6.81263 4.8312 7.13763 4.52245C7.46263 4.2137 7.46263 3.71495 7.13763 3.4062L4.49596 0.888697C4.17096 0.579948 3.64596 0.579948 3.32096 0.888697L0.679297 3.4062C0.354297 3.71495 0.354297 4.2137 0.679297 4.52245C1.0043 4.8312 1.5293 4.8312 1.8543 4.52245L3.91263 2.57495ZM3.91263 12.3441L1.86263 10.3966C1.53763 10.0879 1.01263 10.0879 0.68763 10.3966C0.36263 10.7054 0.36263 11.2041 0.68763 11.5129L3.3293 14.0304C3.6543 14.3391 4.1793 14.3391 4.5043 14.0304L7.14596 11.5208C7.47096 11.212 7.47096 10.7133 7.14596 10.4045C6.82096 10.0958 6.29596 10.0958 5.97096 10.4045L3.91263 12.3441Z" fill =" #323232" />
127
115
</svg >
128
- <span >{{ props.question.getValueLabel(value)?.asString }}</span >
129
- </div >
116
+ <!-- TODO: translations -->
117
+ <span >Rank items</span >
118
+ </button >
119
+ </div >
130
120
131
- <div class =" rank-buttons" >
132
- <button
133
- v-if =" values.length > 1"
134
- :disabled =" disabled || (index === 0)"
135
- @click =" moveUp(index)"
136
- @mousedown =" setHighlight(index)"
137
- >
138
- <svg xmlns =" http://www.w3.org/2000/svg" width =" 15" height =" 15" viewBox =" 0 0 768 768" >
139
- <path d =" M384 256.5l192 192-45 45-147-147-147 147-45-45z" />
140
- </svg >
141
- </button >
142
-
143
- <button
144
- v-if =" values.length > 1"
145
- :disabled =" disabled || (index === values.length - 1)"
146
- @click =" moveDown(index)"
147
- @mousedown =" setHighlight(index)"
148
- >
149
- <svg xmlns =" http://www.w3.org/2000/svg" width =" 15" height =" 15" viewBox =" 0 0 768 768" >
150
- <path d =" M531 274.5l45 45-192 192-192-192 45-45 147 147z" />
121
+ <VueDraggable
122
+ :id =" question.nodeId"
123
+ v-model =" values"
124
+ :delay =" HOLD_DELAY"
125
+ :delay-on-touch-only =" true"
126
+ :disabled =" disabled"
127
+ ghost-class =" fade-moving"
128
+ class =" rank-control"
129
+ :class =" { disabled: disabled }"
130
+ >
131
+ <div
132
+ v-for =" (value, index) in values"
133
+ :id =" value"
134
+ :key =" value"
135
+ class =" rank-option"
136
+ :class =" { moving: highlight.index.value === index }"
137
+ tabindex =" 0"
138
+ @keydown.up.prevent =" moveUp(index)"
139
+ @keydown.down.prevent =" moveDown(index)"
140
+ >
141
+ <div class =" rank-label" >
142
+ <svg xmlns =" http://www.w3.org/2000/svg" width =" 25" height =" 25" viewBox =" 0 0 768 768" >
143
+ <path d =" M480 511.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM480 319.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM480 256.5q-25.5 0-45-19.5t-19.5-45 19.5-45 45-19.5 45 19.5 19.5 45-19.5 45-45 19.5zM288 127.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM288 319.5q25.5 0 45 19.5t19.5 45-19.5 45-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5zM352.5 576q0 25.5-19.5 45t-45 19.5-45-19.5-19.5-45 19.5-45 45-19.5 45 19.5 19.5 45z" />
151
144
</svg >
152
- </button >
145
+ <span >{{ props.question.getValueLabel(value)?.asString }}</span >
146
+ </div >
147
+
148
+ <div class =" rank-buttons" >
149
+ <button
150
+ v-if =" values.length > 1"
151
+ :disabled =" disabled || index === 0"
152
+ @click =" moveUp(index)"
153
+ @mousedown =" setHighlight(index)"
154
+ >
155
+ <svg xmlns =" http://www.w3.org/2000/svg" width =" 15" height =" 15" viewBox =" 0 0 768 768" >
156
+ <path d =" M384 256.5l192 192-45 45-147-147-147 147-45-45z" />
157
+ </svg >
158
+ </button >
159
+
160
+ <button
161
+ v-if =" values.length > 1"
162
+ :disabled =" disabled || index === values.length - 1"
163
+ @click =" moveDown(index)"
164
+ @mousedown =" setHighlight(index)"
165
+ >
166
+ <svg xmlns =" http://www.w3.org/2000/svg" width =" 15" height =" 15" viewBox =" 0 0 768 768" >
167
+ <path d =" M531 274.5l45 45-192 192-192-192 45-45 147 147z" />
168
+ </svg >
169
+ </button >
170
+ </div >
153
171
</div >
154
- </div >
155
- </VueDraggable >
172
+ </VueDraggable >
173
+ </div >
156
174
157
175
<ValidationMessage
158
176
:message =" question.validationState.violation?.message.asString"
@@ -164,18 +182,25 @@ const swapItems = (index: number, newPosition: number) => {
164
182
@import ' primeflex/core/_variables.scss' ;
165
183
166
184
// Variable definition to root element
167
- .rank -control {
185
+ .range -control-container {
168
186
--rankSpacing : 7px ;
169
187
--rankBorder : 1px solid var (--surface-300 );
170
188
--rankBorderRadius : 10px ;
171
189
--rankHighlightBackground : var (--primary-50 );
172
190
--rankHighlightBorder : var (--primary-500 );
191
+ --rankBaseBackground : var (--surface-0 );
192
+ --rankDisabledBackground : var (--surface-300 );
193
+ --rankDisabledText : var (--surface-500 );
173
194
}
174
195
175
196
// Overriding VueDraggable's sortable-chosen class
176
197
.sortable-chosen {
177
198
opacity : 0.9 ;
178
- background-color : var (--surface-0 );
199
+ background-color : var (--rankBaseBackground );
200
+ }
201
+
202
+ .range-control-container {
203
+ position : relative ;
179
204
}
180
205
181
206
.rank-control {
@@ -193,6 +218,7 @@ const swapItems = (index: number, newPosition: number) => {
193
218
justify-content : space-between ;
194
219
width : 100% ;
195
220
padding : 8px ;
221
+ background : var (--rankBaseBackground );
196
222
border : var (--rankBorder );
197
223
border-radius : var (--rankBorderRadius );
198
224
font-size : 1rem ;
@@ -205,6 +231,10 @@ const swapItems = (index: number, newPosition: number) => {
205
231
align-items : center ;
206
232
gap : var (--rankSpacing );
207
233
}
234
+
235
+ .rank-label svg {
236
+ flex-shrink : 0 ;
237
+ }
208
238
}
209
239
210
240
.moving ,
@@ -217,28 +247,29 @@ const swapItems = (index: number, newPosition: number) => {
217
247
opacity : 0.5 ;
218
248
}
219
249
220
- .rank-buttons {
250
+ .rank-overlay button ,
251
+ .rank-buttons button {
221
252
display : flex ;
253
+ align-items : center ;
222
254
gap : var (--rankSpacing );
255
+ border : var (--rankBorder );
256
+ border-radius : var (--rankBorderRadius );
257
+ background : var (--rankBaseBackground );
258
+ padding : var (--rankSpacing );
259
+ line-height : 0 ;
223
260
224
- button {
225
- border : var (--rankBorder );
226
- border-radius : var (--rankBorderRadius );
227
- background : var (--surface-0 );
228
- padding : var (--rankSpacing );
229
- line-height : 0 ;
230
- }
231
-
232
- button :hover:not (:disabled ) {
261
+ & :hover:not (:disabled ) {
233
262
background : var (--rankHighlightBackground );
234
263
border : 1px solid var (--rankHighlightBorder );
235
264
}
236
265
237
- button :disabled {
238
- background : var (--surface-100 );
266
+ & :disabled {
267
+ background : var (--rankDisabledBackground );
268
+ color : var (--rankDisabledText );
239
269
border : none ;
270
+
240
271
svg path {
241
- fill : var (--surface-300 );
272
+ fill : var (--rankDisabledText );
242
273
}
243
274
}
244
275
}
@@ -248,6 +279,30 @@ const swapItems = (index: number, newPosition: number) => {
248
279
cursor : not-allowed ;
249
280
}
250
281
282
+ .rank-buttons {
283
+ display : flex ;
284
+ gap : var (--rankSpacing );
285
+ }
286
+
287
+ .rank-overlay {
288
+ position : absolute ;
289
+ width : 100% ;
290
+ height : 100% ;
291
+ display : flex ;
292
+ justify-content : center ;
293
+ align-items : center ;
294
+ background-color : rgba (244 , 243 , 242 , 0.9 );
295
+ border-radius : var (--rankBorderRadius );
296
+
297
+ button {
298
+ padding : var (--rankSpacing ) 20px ;
299
+ }
300
+ }
301
+
302
+ .highlight .rank-overlay {
303
+ background-color : rgba (157 , 157 , 157 , 0.9 );
304
+ }
305
+
251
306
@media screen and (max-width : #{$sm } ) {
252
307
.rank-buttons {
253
308
display : none ;
0 commit comments