import React from "react"; import { CHIP_COLORS, cls } from "../util"; import { ChipColorKey, ChipColorScheme } from "./Chip"; import type { ChipTone } from "../util/chip_colors"; import { CheckIcon } from "lucide-react"; import { Tooltip } from "./Tooltip"; export interface ColorPickerProps { /** * Currently selected color key */ value?: ChipColorKey; /** * Callback when color selection changes. Passes undefined when "Auto" is selected. */ onChange: (colorKey: ChipColorKey | undefined) => void; /** * Size of the color swatches */ size?: "small" | "medium"; /** * Whether to show the "Auto" option that clears the selection */ allowClear?: boolean; /** * Whether the picker is disabled */ disabled?: boolean; } // Hues across, tones down — the arrangement the palette is built in. const BASE_COLORS = ["blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose", "red", "orange", "yellow", "green", "emerald", "teal", "cyan", "gray"] as const; // Lightest first, matching how the bare hue name reads. const TONES: ChipTone[] = ["Lighter", "Light", "Dark", "Darker"]; // Helper to get readable name from color key function getColorDisplayName(hue: string, tone: ChipTone): string { const hueName = `${hue.charAt(0).toUpperCase()}${hue.slice(1)}`; return tone === "Lighter" ? hueName : `${hueName} ${tone.toLowerCase()}`; } /** * A color picker component that displays a grid of predefined CHIP_COLORS. * Used for selecting colors for enum values, tags, and other chip-based UI elements. * * @group Form components */ export function ColorPicker({ value, onChange, size = "medium", allowClear = true, disabled = false }: ColorPickerProps) { const swatchSize = size === "small" ? "w-5 h-5" : "w-6 h-6"; const checkSize = size === "small" ? 12 : 14; return (