"use client"; import { cn } from "@suphark/ui/lib/utils"; import { Check } from "lucide-react"; import { type ComponentProps, type CSSProperties, type KeyboardEvent, useRef, useState, } from "react"; export interface ColorPickerItem { value: T; label: string; /** class สีพื้น เช่น `bg-amber-500` (แอปเป็นคนเลือก palette — แพ็กเกจไม่ bundle) */ swatchClassName?: string; /** สี CSS ตรง ๆ (hex/oklch) เมื่อไม่ใช้ class เช่นสีที่ผู้ใช้กำหนดเอง */ swatch?: string; } export interface ColorPickerText { /** ป้ายกลุ่ม (aria-label ของกริด) */ label: string; /** ต่อท้าย aria-label ของช่องที่เลือกอยู่ */ selected: string; ariaLabel: (label: string) => string; } const TEXT: Record<"th" | "en", ColorPickerText> = { th: { label: "เลือกสี", selected: "เลือกอยู่", ariaLabel: (l) => `สี ${l}` }, en: { label: "Choose color", selected: "selected", ariaLabel: (l) => `${l} color` }, }; export interface ColorPickerProps { value: T | null | undefined; onChange: (value: T) => void; colors: ReadonlyArray>; /** คอลัมน์ของกริด (ค่าเริ่มต้น grid-cols-5) */ columnsClassName?: string; /** sm = ช่อง size-7, md = size-8 (ค่าเริ่มต้น) */ size?: "sm" | "md"; language?: "th" | "en"; text?: Partial; className?: string; } function swatchStyle(item: { swatch?: string }): CSSProperties | undefined { return item.swatch ? { backgroundColor: item.swatch } : undefined; } /** * จุดสีเล็กสำหรับ trigger/badge/รายการ — ใช้ `color` (CSS) หรือ class สี (`className="bg-amber-500"`) * · */ export function ColorSwatch({ color, className, style, ...props }: ComponentProps<"span"> & { color?: string }) { return (