Skip to content

Commit f211656

Browse files
authored
Merge pull request doccano#291 from CatalystCode/enhancement/color-palette
Added color dropdown to help choose contrasting colors for the labels.
2 parents 2b4c54a + 48c7ec5 commit f211656

File tree

3 files changed

+1698
-1661
lines changed

3 files changed

+1698
-1661
lines changed

app/server/static/components/label.vue

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,22 @@
5252
label.label Color
5353
div.field.has-addons
5454
div.control
55-
a.button(
56-
v-bind:style="{ \
57-
color: newLabel.text_color, \
58-
backgroundColor: newLabel.background_color \
59-
}"
55+
div.form__field
56+
div.form__input
57+
swatches(
58+
v-model="newLabel.background_color"
59+
colors="basic"
60+
show-fallback=true
61+
popover-to=""
62+
v-bind:trigger-style="{ width: '36px', height: '36px' }"
63+
)
64+
div.control
65+
a.button.random-color-button(
6066
v-on:click="setColor(newLabel)"
6167
)
6268
span.icon.is-small
6369
i.fas.fa-sync-alt
6470

65-
div.control.is-expanded
66-
input.input(
67-
type="text"
68-
placeholder="Text input"
69-
v-model="newLabel.background_color"
70-
)
71-
7271
div.column
7372
div.field
7473
label.label  
@@ -151,20 +150,22 @@
151150
label.label Color
152151
div.field.has-addons
153152
div.control
154-
a.button.has-text-white(
155-
v-bind:style="{ backgroundColor: label.background_color }"
156-
v-on:click="setColor(label)"
153+
div.form__field
154+
div.form__input
155+
swatches(
156+
v-model="label.background_color"
157+
colors="basic"
158+
show-fallback=true
159+
popover-to=""
160+
v-bind:trigger-style="{ width: '36px', height: '36px' }"
161+
)
162+
div.control
163+
a.button.random-color-button(
164+
v-on:click="setEditColor"
157165
)
158166
span.icon.is-small
159167
i.fas.fa-sync-alt
160168

161-
div.control.is-expanded
162-
input.input(
163-
type="text"
164-
placeholder="Text input"
165-
v-model="label.background_color"
166-
)
167-
168169
div.column
169170
div.field
170171
label.label  
@@ -176,13 +177,25 @@
176177
a.button.is-primary(v-on:click="doneEdit(label)") Save changes
177178
</template>
178179

180+
<style scoped>
181+
.random-color-button {
182+
height: 36px;
183+
width: 36px;
184+
background-color: transparent;
185+
color: #404040;
186+
border: none;
187+
}
188+
</style>
189+
179190
<script>
191+
import Swatches from 'vue-swatches';
192+
import 'vue-swatches/dist/vue-swatches.min.css';
180193
import HTTP from './http';
181194
import Messages from './messages.vue';
182195
import { simpleShortcut } from './filter';
183196
184197
export default {
185-
components: { Messages },
198+
components: { Messages, Swatches },
186199
187200
filters: { simpleShortcut },
188201
@@ -203,8 +216,8 @@ export default {
203216
204217
methods: {
205218
generateColor() {
206-
const color = Math.floor(Math.random() * 0xFFFFFF).toString(16);
207-
const randomColor = '#' + ('000000' + color).slice(-6);
219+
const gencolor = Math.floor(Math.random() * 0xFFFFFF).toString(16);
220+
const randomColor = '#' + ('000000' + gencolor).slice(-6);
208221
return randomColor;
209222
},
210223
@@ -222,6 +235,10 @@ export default {
222235
label.text_color = textColor;
223236
},
224237
238+
setEditColor() {
239+
this.setColor(this.editedLabel);
240+
},
241+
225242
shortcutKey(label) {
226243
let shortcut = label.suffix_key;
227244
if (label.prefix_key) {
@@ -264,6 +281,7 @@ export default {
264281
background_color: '#209cee',
265282
text_color: '#ffffff',
266283
};
284+
this.setColor(this.newLabel);
267285
},
268286
269287
cancelCreate() {

0 commit comments

Comments
 (0)