|
| 1 | +<script setup lang="ts"> |
| 2 | +const props = defineProps({ |
| 3 | + label: { |
| 4 | + type: String, |
| 5 | + default: 'Color', |
| 6 | + }, |
| 7 | + default: { |
| 8 | + type: String, |
| 9 | + default: '#030712', |
| 10 | + }, |
| 11 | + icon: { |
| 12 | + type: String, |
| 13 | + default: 'i-ph-pencil', |
| 14 | + }, |
| 15 | +}) |
| 16 | +const emit = defineEmits(['color']) |
| 17 | +
|
| 18 | +// Tailwind CSS 500 colors hexadecimal values |
| 19 | +const colors = ['#f87171', '#fb923c', '#fbbf24', '#facc15', '#a3e635', '#4ade80', '#34d399', '#2dd4bf', '#22d3ee', '#38bdf8', '#60a5fa', '#818cf8', '#a78bfa', '#c084fc', '#e879f9', '#f472b6', '#fb7185'] |
| 20 | +const grayColors = ['#030712', '#1f2937', '#4b5563', '#9ca3af', '#e5e7eb', '#f9fafb'] |
| 21 | +const current = ref(props.default) |
| 22 | +function setColor(hex: string) { |
| 23 | + current.value = hex |
| 24 | + emit('color', hex) |
| 25 | +} |
| 26 | +</script> |
| 27 | + |
| 28 | +<template> |
| 29 | + <UPopover |
| 30 | + mode="hover" |
| 31 | + :ui="{ width: 'w-[156px]' }" |
| 32 | + > |
| 33 | + <template #default="{ open }"> |
| 34 | + <UButton |
| 35 | + color="gray" |
| 36 | + variant="ghost" |
| 37 | + square |
| 38 | + :class="[open && 'bg-gray-50 dark:bg-gray-800']" |
| 39 | + aria-label="Color picker" |
| 40 | + :icon="icon" |
| 41 | + > |
| 42 | + <div |
| 43 | + class="w-5 h-5 rounded-full" |
| 44 | + :style="{ backgroundColor: current }" |
| 45 | + /> |
| 46 | + </UButton> |
| 47 | + </template> |
| 48 | + |
| 49 | + <template #panel> |
| 50 | + <div class="p-2"> |
| 51 | + <div class="grid grid-cols-6 gap-px"> |
| 52 | + <div |
| 53 | + v-for="color in colors" |
| 54 | + :key="color" |
| 55 | + class="w-5 h-5 rounded-full border-2 hover:border-gray-200 cursor-pointer" |
| 56 | + :class="color === current ? 'border-gray-200' : 'border-white'" |
| 57 | + :style="{ backgroundColor: color }" |
| 58 | + @click="setColor(color)" |
| 59 | + /> |
| 60 | + </div> |
| 61 | + |
| 62 | + <hr class="border-gray-200 dark:border-gray-800 my-2"> |
| 63 | + |
| 64 | + <div class="grid grid-cols-6 gap-px"> |
| 65 | + <div |
| 66 | + v-for="color in grayColors" |
| 67 | + :key="color" |
| 68 | + class="w-5 h-5 rounded-full border-2 hover:border-gray-200 cursor-pointer" |
| 69 | + :class="color === current ? 'border-gray-200' : 'border-white'" |
| 70 | + :style="{ backgroundColor: color }" |
| 71 | + @click="setColor(color)" |
| 72 | + /> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </template> |
| 76 | + </UPopover> |
| 77 | +</template> |
0 commit comments