All files / src/components/profiles ColorPalette.vue

0% Statements 0/75
0% Branches 0/1
0% Functions 0/1
0% Lines 0/75

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182                                                                                                                                                                                                                                                                                                                                                                           
<template>
  <div class="color-palette">
    <label v-if="label" class="palette-label">{{ label }}</label>
    <div class="color-grid">
      <button
        v-for="color in colors"
        :key="color"
        type="button"
        class="color-swatch"
        :class="{ selected: modelValue === color }"
        :style="{ backgroundColor: color }"
        :title="color"
        @click="selectColor(color)"
      >
        <span v-if="modelValue === color" class="check-mark">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            viewBox="0 0 20 20"
            fill="currentColor"
          >
            <path
              fill-rule="evenodd"
              d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
              clip-rule="evenodd"
            />
          </svg>
        </span>
      </button>
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'ColorPalette',
  props: {
    modelValue: {
      type: String,
      default: '#3B82F6',
    },
    label: {
      type: String,
      default: '',
    },
  },
  emits: ['update:modelValue'],
  setup(props, { emit }) {
    // 16 preset colors organized by hue
    const colors = [
      // Blues
      '#3B82F6', // Blue 500
      '#1D4ED8', // Blue 700
      '#0EA5E9', // Sky 500
      '#06B6D4', // Cyan 500
      // Greens
      '#22C55E', // Green 500
      '#10B981', // Emerald 500
      '#14B8A6', // Teal 500
      // Warm colors
      '#EF4444', // Red 500
      '#DC2626', // Red 600
      '#F97316', // Orange 500
      '#F59E0B', // Amber 500
      // Purples
      '#8B5CF6', // Violet 500
      '#A855F7', // Purple 500
      '#EC4899', // Pink 500
      // Neutrals
      '#FFFFFF', // White
      '#000000', // Black
    ];
 
    const selectColor = color => {
      emit('update:modelValue', color);
    };
 
    return {
      colors,
      selectColor,
    };
  },
};
</script>
 
<style scoped>
.color-palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
 
.palette-label {
  font-weight: 600;
  color: #374151;
  font-size: 14px;
}
 
.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
 
@media (max-width: 480px) {
  .color-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
 
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
 
.color-swatch:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
 
.color-swatch.selected {
  border-color: #1f2937;
  box-shadow:
    0 0 0 2px white,
    0 0 0 4px #1f2937;
}
 
/* White swatch needs a visible border */
.color-swatch[style*='#FFFFFF'],
.color-swatch[style*='white'] {
  border-color: #e5e7eb;
}
 
.color-swatch.selected[style*='#FFFFFF'],
.color-swatch.selected[style*='white'] {
  border-color: #1f2937;
}
 
.check-mark {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.check-mark svg {
  width: 14px;
  height: 14px;
}
 
/* Dark colors get white checkmark */
.color-swatch[style*='#1D4ED8'] .check-mark,
.color-swatch[style*='#DC2626'] .check-mark,
.color-swatch[style*='#000000'] .check-mark,
.color-swatch[style*='#8B5CF6'] .check-mark,
.color-swatch[style*='#A855F7'] .check-mark {
  color: white;
}
 
/* Light colors get dark checkmark */
.color-swatch[style*='#FFFFFF'] .check-mark,
.color-swatch[style*='#F59E0B'] .check-mark,
.color-swatch[style*='#22C55E'] .check-mark,
.color-swatch[style*='#0EA5E9'] .check-mark {
  color: #1f2937;
}
 
/* Default checkmark color based on luminance */
.check-mark {
  color: white;
}
</style>