This project is a palette creator tool that allows users to generate and customize color palettes for their design projects.
1// This component is the variations slots panel that displays color variations
2based on the main color. Users can click on any variation to copy it, and then
3paste it into one of the color slots in the palette panel. The panel can be
4collapsed or expanded.
5
6<template>
7 <!-- wrapper -->
8 <section class="mini-slots-pane" data-testid="expanded-panel">
9 <!-- all the slots -->
10 <div class="mini-slots" role="listbox" aria-label="Color variations">
11 <!-- one slot -->
12 <div
13 v-for="(entry, i) in colors"
14 :class="[
15 'mini-slot',
16 {
17 'mini-slot-copied':
18 colorCopied && colorCopiedIndex === i,
19 },
20 ]"
21 :data-testid="`mini-slot-${i}`"
22 :key="i"
23 :style="{ backgroundColor: entry.hsl }"
24 :data-tooltip="
25 colorCopied && colorCopiedIndex === i
26 ? 'click to deselect'
27 : 'select · then click a slot to paste'
28 "
29 @click="copyColor(entry.hsl, Number(i))"
30 role="option"
31 :aria-selected="colorCopied && colorCopiedIndex === i"
32 :aria-label="`Color variation ${Number(i) + 1}: ${entry.hsl}. Click to copy.`"
33 ></div>
34 </div>
35 </section>
36</template>
37
38<script setup>
39 import { computed } from 'vue';
40 import { useStore } from 'vuex';
41
42 const store = useStore();
43
44 const colorCopied = computed(() => store.state.copiedColor);
45 const colorCopiedIndex = computed(() => store.state.copiedColorIndex);
46 const colors = computed(() => store.getters.uniqueColors);
47
48 /**
49 * Puts the clicked on variation in memory for pasting, or clears it if already selected.
50 * @param {string} color - The color to copy.
51 * @param {number} index - The index of the color in the list.
52 */
53 const copyColor = (color, index) => {
54 if (colorCopied.value === color && colorCopiedIndex.value === index) {
55 store.dispatch('CLEAR_COPIED_COLOR');
56 } else {
57 store.dispatch('COPY_COLOR', { color, index });
58 }
59 };
60</script>