@etus/ui 0.4.0-beta.6 → 0.4.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2Y7PQ6ZL.js → chunk-237TQKWH.js} +4 -4
- package/dist/{chunk-2Y7PQ6ZL.js.map → chunk-237TQKWH.js.map} +1 -1
- package/dist/{chunk-KR3IVNQH.js → chunk-2FJJOHHH.js} +16 -10
- package/dist/chunk-2FJJOHHH.js.map +1 -0
- package/dist/{chunk-W4NC5CU5.js → chunk-2Q4I4VDB.js} +4 -4
- package/dist/{chunk-W4NC5CU5.js.map → chunk-2Q4I4VDB.js.map} +1 -1
- package/dist/{chunk-2HM5Z2YP.js → chunk-2YWWZEPE.js} +3 -3
- package/dist/{chunk-2HM5Z2YP.js.map → chunk-2YWWZEPE.js.map} +1 -1
- package/dist/chunk-2Z722V5K.js +231 -0
- package/dist/chunk-2Z722V5K.js.map +1 -0
- package/dist/chunk-37IIHQP4.js +233 -0
- package/dist/chunk-37IIHQP4.js.map +1 -0
- package/dist/{chunk-UFRMZ3M6.js → chunk-3JCV72FO.js} +6 -2
- package/dist/chunk-3JCV72FO.js.map +1 -0
- package/dist/{chunk-HT5XM6XK.js → chunk-43BS3PPX.js} +3 -3
- package/dist/{chunk-HT5XM6XK.js.map → chunk-43BS3PPX.js.map} +1 -1
- package/dist/{chunk-2UGDLAYC.js → chunk-45D4O7RK.js} +10 -3
- package/dist/chunk-45D4O7RK.js.map +1 -0
- package/dist/{chunk-32IJQOUV.js → chunk-4EYYCHLD.js} +4 -4
- package/dist/{chunk-32IJQOUV.js.map → chunk-4EYYCHLD.js.map} +1 -1
- package/dist/{chunk-J62TFQHR.js → chunk-5I7AXWJU.js} +13 -13
- package/dist/chunk-5I7AXWJU.js.map +1 -0
- package/dist/{chunk-65YSTUD2.js → chunk-5SUD32RK.js} +44 -14
- package/dist/chunk-5SUD32RK.js.map +1 -0
- package/dist/{chunk-23BHD62H.js → chunk-5TZDEGZN.js} +4 -4
- package/dist/chunk-5TZDEGZN.js.map +1 -0
- package/dist/{chunk-VPNFYQBL.js → chunk-6DN2UAIR.js} +3 -3
- package/dist/chunk-6DN2UAIR.js.map +1 -0
- package/dist/{chunk-EGYWK2XX.js → chunk-7CTFBOD4.js} +3 -3
- package/dist/{chunk-EGYWK2XX.js.map → chunk-7CTFBOD4.js.map} +1 -1
- package/dist/{chunk-36XTKR3B.js → chunk-BMNCNBPA.js} +3 -3
- package/dist/{chunk-36XTKR3B.js.map → chunk-BMNCNBPA.js.map} +1 -1
- package/dist/{chunk-AWYOWR5N.js → chunk-C5HSYDJC.js} +3 -3
- package/dist/{chunk-AWYOWR5N.js.map → chunk-C5HSYDJC.js.map} +1 -1
- package/dist/{chunk-VFALJSXB.js → chunk-DCUFQJYP.js} +3 -3
- package/dist/chunk-DCUFQJYP.js.map +1 -0
- package/dist/{chunk-LATTRPLQ.js → chunk-E2TI5V67.js} +3 -3
- package/dist/{chunk-LATTRPLQ.js.map → chunk-E2TI5V67.js.map} +1 -1
- package/dist/{chunk-IRKDMISK.js → chunk-G2MAGZHQ.js} +4 -3
- package/dist/chunk-G2MAGZHQ.js.map +1 -0
- package/dist/{chunk-ONQCNOLU.js → chunk-HDOR3SN3.js} +3 -3
- package/dist/{chunk-ONQCNOLU.js.map → chunk-HDOR3SN3.js.map} +1 -1
- package/dist/{chunk-PLLJNHWU.js → chunk-HI3T55XK.js} +3 -33
- package/dist/chunk-HI3T55XK.js.map +1 -0
- package/dist/chunk-HJ4E6YPW.js +236 -0
- package/dist/chunk-HJ4E6YPW.js.map +1 -0
- package/dist/{chunk-LS3WD6IZ.js → chunk-I55QJ4CU.js} +4 -4
- package/dist/{chunk-LS3WD6IZ.js.map → chunk-I55QJ4CU.js.map} +1 -1
- package/dist/{chunk-HKXQLWGR.js → chunk-IOWHM7ZY.js} +13 -11
- package/dist/chunk-IOWHM7ZY.js.map +1 -0
- package/dist/{chunk-ILAV2AZ4.js → chunk-IZC5YFGO.js} +3 -3
- package/dist/{chunk-ILAV2AZ4.js.map → chunk-IZC5YFGO.js.map} +1 -1
- package/dist/{chunk-Y7UFBSAD.js → chunk-KHOCAVQO.js} +3 -3
- package/dist/{chunk-Y7UFBSAD.js.map → chunk-KHOCAVQO.js.map} +1 -1
- package/dist/{chunk-IBVCSZCH.js → chunk-KVJOKWP4.js} +5 -4
- package/dist/chunk-KVJOKWP4.js.map +1 -0
- package/dist/{chunk-KC6CHPT3.js → chunk-KZRTQF64.js} +3 -3
- package/dist/{chunk-KC6CHPT3.js.map → chunk-KZRTQF64.js.map} +1 -1
- package/dist/{chunk-QIETN4UU.js → chunk-LEAK22ZP.js} +3 -3
- package/dist/{chunk-QIETN4UU.js.map → chunk-LEAK22ZP.js.map} +1 -1
- package/dist/{chunk-OWOVCGUZ.js → chunk-M2C7HBR5.js} +3 -3
- package/dist/{chunk-OWOVCGUZ.js.map → chunk-M2C7HBR5.js.map} +1 -1
- package/dist/{chunk-33JGPMUW.js → chunk-M7TPROVH.js} +20 -7
- package/dist/chunk-M7TPROVH.js.map +1 -0
- package/dist/{chunk-AVR3LVOQ.js → chunk-MQMRVBUL.js} +4 -4
- package/dist/{chunk-AVR3LVOQ.js.map → chunk-MQMRVBUL.js.map} +1 -1
- package/dist/{chunk-KPNNSUXM.js → chunk-O7AUE5GP.js} +5 -3
- package/dist/chunk-O7AUE5GP.js.map +1 -0
- package/dist/{chunk-6HEURMY3.js → chunk-OCXGG7UP.js} +5 -5
- package/dist/{chunk-6HEURMY3.js.map → chunk-OCXGG7UP.js.map} +1 -1
- package/dist/{chunk-V7XHE25E.js → chunk-ON7WFRYH.js} +3 -3
- package/dist/{chunk-V7XHE25E.js.map → chunk-ON7WFRYH.js.map} +1 -1
- package/dist/{chunk-FSMHI7DW.js → chunk-OXDWUKGP.js} +3 -3
- package/dist/chunk-OXDWUKGP.js.map +1 -0
- package/dist/{chunk-SJSYKUCL.js → chunk-Q335YODG.js} +3 -3
- package/dist/{chunk-SJSYKUCL.js.map → chunk-Q335YODG.js.map} +1 -1
- package/dist/{chunk-DDM2I5C6.js → chunk-R5OIL4I4.js} +3 -3
- package/dist/{chunk-DDM2I5C6.js.map → chunk-R5OIL4I4.js.map} +1 -1
- package/dist/{chunk-FYJHWYPM.js → chunk-S524YVMO.js} +3 -3
- package/dist/{chunk-FYJHWYPM.js.map → chunk-S524YVMO.js.map} +1 -1
- package/dist/{chunk-OWIFNJXZ.js → chunk-S7TVRVRU.js} +3 -3
- package/dist/chunk-S7TVRVRU.js.map +1 -0
- package/dist/{chunk-TNROOKX3.js → chunk-UDY3IDCY.js} +10 -2
- package/dist/chunk-UDY3IDCY.js.map +1 -0
- package/dist/{chunk-3WOGOTOV.js → chunk-UPYT2XM5.js} +7 -7
- package/dist/chunk-UPYT2XM5.js.map +1 -0
- package/dist/{chunk-YWA63YN3.js → chunk-VAVE4ZJF.js} +2 -2
- package/dist/chunk-VAVE4ZJF.js.map +1 -0
- package/dist/chunk-WKWLKGNI.js +643 -0
- package/dist/chunk-WKWLKGNI.js.map +1 -0
- package/dist/{chunk-Z3FL7LEK.js → chunk-X253YD45.js} +71 -6
- package/dist/chunk-X253YD45.js.map +1 -0
- package/dist/{chunk-6XY7QYVR.js → chunk-X3AXEE3S.js} +3 -3
- package/dist/{chunk-6XY7QYVR.js.map → chunk-X3AXEE3S.js.map} +1 -1
- package/dist/{chunk-R4UOT76L.js → chunk-XAIUZJOJ.js} +8 -8
- package/dist/chunk-XAIUZJOJ.js.map +1 -0
- package/dist/{chunk-ZO2EKJZM.js → chunk-XCZMJA2D.js} +7 -7
- package/dist/{chunk-ZO2EKJZM.js.map → chunk-XCZMJA2D.js.map} +1 -1
- package/dist/{chunk-XRMKL43Y.js → chunk-XOLV7G4S.js} +3 -3
- package/dist/{chunk-XRMKL43Y.js.map → chunk-XOLV7G4S.js.map} +1 -1
- package/dist/chunk-XYYOV5GW.js +186 -0
- package/dist/chunk-XYYOV5GW.js.map +1 -0
- package/dist/{chunk-4MQNDQ4O.js → chunk-YACIRNVP.js} +12 -4
- package/dist/chunk-YACIRNVP.js.map +1 -0
- package/dist/{chunk-JKYB5QAP.js → chunk-YDZBLZVZ.js} +3 -3
- package/dist/{chunk-JKYB5QAP.js.map → chunk-YDZBLZVZ.js.map} +1 -1
- package/dist/{chunk-5XQIH6WM.js → chunk-YM5YBDRM.js} +4 -4
- package/dist/{chunk-5XQIH6WM.js.map → chunk-YM5YBDRM.js.map} +1 -1
- package/dist/{chunk-AUCDXPWH.js → chunk-YQX7XZES.js} +4 -4
- package/dist/{chunk-AUCDXPWH.js.map → chunk-YQX7XZES.js.map} +1 -1
- package/dist/{chunk-CP2PEDG2.js → chunk-Z4KW5VW6.js} +3 -3
- package/dist/chunk-Z4KW5VW6.js.map +1 -0
- package/dist/{chunk-Y3BOERVB.js → chunk-ZEFK3AXP.js} +3 -3
- package/dist/{chunk-Y3BOERVB.js.map → chunk-ZEFK3AXP.js.map} +1 -1
- package/dist/{chunk-L3Z5FAJE.js → chunk-ZEYLSDSG.js} +3 -3
- package/dist/{chunk-L3Z5FAJE.js.map → chunk-ZEYLSDSG.js.map} +1 -1
- package/dist/components/advanced/Calendar/index.js +3 -3
- package/dist/components/advanced/Command/index.js +1 -1
- package/dist/components/advanced/EventCalendar/index.js +3 -3
- package/dist/components/advanced/FileDropzone/index.js +1 -1
- package/dist/components/advanced/FilterBuilder/index.js +3 -3
- package/dist/components/advanced/MarkdownEditor/index.js +2 -2
- package/dist/components/advanced/ReportBuilder/index.js +2 -2
- package/dist/components/advanced/RichTextEditor/index.js +2 -2
- package/dist/components/advanced/index.js +13 -13
- package/dist/components/data-display/AreaChart/index.js +1 -1
- package/dist/components/data-display/BarChart/index.js +1 -1
- package/dist/components/data-display/Carousel/index.js +3 -3
- package/dist/components/data-display/ChartCard/index.js +2 -2
- package/dist/components/data-display/DashboardFilterbar/index.js +5 -5
- package/dist/components/data-display/DataTable/FilterBuilder/index.js +3 -3
- package/dist/components/data-display/DataTable/index.js +6 -6
- package/dist/components/data-display/ImageGallery/index.js +6 -6
- package/dist/components/data-display/KPICard/index.js +3 -3
- package/dist/components/data-display/Lightbox/index.js +1 -1
- package/dist/components/data-display/LineChart/index.js +1 -1
- package/dist/components/data-display/List/index.js +2 -2
- package/dist/components/data-display/Table/index.js +1 -1
- package/dist/components/data-display/VirtualTable/index.js +2 -2
- package/dist/components/data-display/index.js +29 -29
- package/dist/components/feedback/Alert/index.js +1 -1
- package/dist/components/feedback/AlertDialog/index.js +3 -3
- package/dist/components/feedback/ConfirmModal/index.js +4 -4
- package/dist/components/feedback/Modal/index.js +1 -1
- package/dist/components/feedback/index.js +8 -8
- package/dist/components/forms/ColorPicker/index.js +1 -1
- package/dist/components/forms/DatePicker/index.js +4 -4
- package/dist/components/forms/DateRangePicker/index.js +4 -4
- package/dist/components/forms/IftaLabel/index.js +1 -1
- package/dist/components/forms/InputGroup/index.js +3 -3
- package/dist/components/forms/MultiSelect/index.js +2 -1
- package/dist/components/forms/RadioButton/index.js +1 -1
- package/dist/components/forms/Rating/index.js +1 -1
- package/dist/components/forms/Slider/index.js +1 -1
- package/dist/components/forms/TagsInput/index.js +2 -2
- package/dist/components/forms/ToggleGroup/index.js +1 -1
- package/dist/components/forms/index.js +19 -19
- package/dist/components/index.js +104 -104
- package/dist/components/layout/index.js +2 -2
- package/dist/components/navigation/AccountSwitch/index.js +3 -3
- package/dist/components/navigation/Drawer/index.js +1 -1
- package/dist/components/navigation/DropdownMenu/index.js +1 -1
- package/dist/components/navigation/Header/index.js +1 -1
- package/dist/components/navigation/MobileSidebar/index.js +3 -3
- package/dist/components/navigation/Pagination/index.js +3 -3
- package/dist/components/navigation/Sidebar/index.js +3 -3
- package/dist/components/navigation/UserProfileDropdown/index.js +1 -1
- package/dist/components/navigation/WorkspaceDropdown/index.js +1 -1
- package/dist/components/navigation/index.js +13 -13
- package/dist/components/primitives/AspectRatio/index.js +1 -1
- package/dist/components/primitives/Badge/index.js +1 -1
- package/dist/components/primitives/Button/index.js +2 -2
- package/dist/components/primitives/ConfirmButton/index.js +4 -4
- package/dist/components/primitives/ProgressBar/index.js +1 -1
- package/dist/components/primitives/SplitButton/index.js +2 -2
- package/dist/components/primitives/StatusIndicator/index.js +1 -1
- package/dist/components/primitives/Tag/index.js +1 -1
- package/dist/components/primitives/Toggle/index.js +1 -1
- package/dist/components/primitives/index.js +16 -16
- package/dist/components/workflow/ApprovalFlow/index.js +3 -3
- package/dist/components/workflow/CommentSystem/index.js +3 -3
- package/dist/components/workflow/Dashboard/index.js +3 -3
- package/dist/components/workflow/DashboardBuilder/index.js +3 -3
- package/dist/components/workflow/KanbanBoard/index.js +3 -3
- package/dist/components/workflow/ReportGenerator/index.js +3 -3
- package/dist/components/workflow/TaskStatus/index.js +2 -2
- package/dist/components/workflow/Wizard/index.js +3 -3
- package/dist/components/workflow/index.js +12 -12
- package/dist/index.d.ts +156 -50
- package/dist/index.js +104 -104
- package/dist/styles.css +23 -0
- package/package.json +2 -2
- package/dist/chunk-23BHD62H.js.map +0 -1
- package/dist/chunk-2UGDLAYC.js.map +0 -1
- package/dist/chunk-33JGPMUW.js.map +0 -1
- package/dist/chunk-3WOGOTOV.js.map +0 -1
- package/dist/chunk-4MQNDQ4O.js.map +0 -1
- package/dist/chunk-65YSTUD2.js.map +0 -1
- package/dist/chunk-CP2PEDG2.js.map +0 -1
- package/dist/chunk-FSMHI7DW.js.map +0 -1
- package/dist/chunk-GAP3OZR7.js +0 -223
- package/dist/chunk-GAP3OZR7.js.map +0 -1
- package/dist/chunk-HKXQLWGR.js.map +0 -1
- package/dist/chunk-IBVCSZCH.js.map +0 -1
- package/dist/chunk-ICAQYWCX.js +0 -153
- package/dist/chunk-ICAQYWCX.js.map +0 -1
- package/dist/chunk-IRKDMISK.js.map +0 -1
- package/dist/chunk-J62TFQHR.js.map +0 -1
- package/dist/chunk-KPNNSUXM.js.map +0 -1
- package/dist/chunk-KR3IVNQH.js.map +0 -1
- package/dist/chunk-OWIFNJXZ.js.map +0 -1
- package/dist/chunk-PLLJNHWU.js.map +0 -1
- package/dist/chunk-R4UOT76L.js.map +0 -1
- package/dist/chunk-SHS6EGWS.js +0 -226
- package/dist/chunk-SHS6EGWS.js.map +0 -1
- package/dist/chunk-TNROOKX3.js.map +0 -1
- package/dist/chunk-UFRMZ3M6.js.map +0 -1
- package/dist/chunk-VFALJSXB.js.map +0 -1
- package/dist/chunk-VPNFYQBL.js.map +0 -1
- package/dist/chunk-XD5LE64P.js +0 -311
- package/dist/chunk-XD5LE64P.js.map +0 -1
- package/dist/chunk-XV6NXXXP.js +0 -206
- package/dist/chunk-XV6NXXXP.js.map +0 -1
- package/dist/chunk-YWA63YN3.js.map +0 -1
- package/dist/chunk-Z3FL7LEK.js.map +0 -1
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import { Popover, PopoverTrigger, PopoverContent } from './chunk-AFCSDND5.js';
|
|
2
|
+
import { cn } from './chunk-HRNDJU7D.js';
|
|
3
|
+
import { Palette } from 'lucide-react';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var colorPickerTriggerVariants = cva(
|
|
9
|
+
// Base styles
|
|
10
|
+
[
|
|
11
|
+
"inline-flex w-full items-center justify-between gap-2 rounded-[var(--color-picker-trigger-radius)] border bg-transparent font-normal transition-[color,box-shadow] outline-none",
|
|
12
|
+
"text-left",
|
|
13
|
+
"placeholder:text-muted-foreground",
|
|
14
|
+
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
15
|
+
"focus-visible:border-[color:var(--color-picker-focus-ring-primary)] focus-visible:ring-[color:var(--color-picker-focus-ring-primary)]/50 focus-visible:ring-[length:var(--color-picker-focus-ring-width)]",
|
|
16
|
+
"aria-invalid:ring-[color:var(--color-picker-focus-ring-destructive)]/20 dark:aria-invalid:ring-[color:var(--color-picker-focus-ring-destructive)]/40 aria-invalid:border-[color:var(--color-picker-focus-ring-destructive)]"
|
|
17
|
+
],
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
size: {
|
|
21
|
+
sm: "h-9 px-2.5 py-1 text-sm",
|
|
22
|
+
md: "h-10 px-3 py-1 text-base md:text-sm",
|
|
23
|
+
lg: "h-11 px-3.5 py-1.5 text-base"
|
|
24
|
+
},
|
|
25
|
+
variant: {
|
|
26
|
+
default: "border-input shadow-xs dark:bg-input/30",
|
|
27
|
+
filled: "border-transparent bg-muted",
|
|
28
|
+
flushed: "rounded-none border-x-0 border-t-0 border-b-input px-0"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
defaultVariants: {
|
|
32
|
+
size: "md",
|
|
33
|
+
variant: "default"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
var colorPickerSwatchVariants = cva(
|
|
38
|
+
// Base styles
|
|
39
|
+
[
|
|
40
|
+
"rounded-[var(--color-picker-swatch-radius)] border border-input cursor-pointer transition-all",
|
|
41
|
+
"hover:scale-110 hover:border-ring",
|
|
42
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
43
|
+
],
|
|
44
|
+
{
|
|
45
|
+
variants: {
|
|
46
|
+
size: {
|
|
47
|
+
sm: "size-5",
|
|
48
|
+
md: "size-6",
|
|
49
|
+
lg: "size-7"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
defaultVariants: {
|
|
53
|
+
size: "md"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
var colorPickerPreviewVariants = cva(
|
|
58
|
+
// Base styles
|
|
59
|
+
[
|
|
60
|
+
"rounded-[var(--color-picker-swatch-radius)] border border-input shrink-0"
|
|
61
|
+
],
|
|
62
|
+
{
|
|
63
|
+
variants: {
|
|
64
|
+
size: {
|
|
65
|
+
sm: "size-4",
|
|
66
|
+
md: "size-5",
|
|
67
|
+
lg: "size-6"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
defaultVariants: {
|
|
71
|
+
size: "md"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// src/components/forms/ColorPicker/colorMath.ts
|
|
77
|
+
var clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
78
|
+
function hexToRgba(hex) {
|
|
79
|
+
const match = /^#?([0-9a-f]{3,8})$/i.exec(hex.trim());
|
|
80
|
+
if (!match?.[1]) return null;
|
|
81
|
+
let h = match[1];
|
|
82
|
+
if (h.length === 3 || h.length === 4) {
|
|
83
|
+
h = h.replaceAll(/./g, (c) => c + c);
|
|
84
|
+
}
|
|
85
|
+
if (h.length !== 6 && h.length !== 8) return null;
|
|
86
|
+
return {
|
|
87
|
+
r: Number.parseInt(h.slice(0, 2), 16),
|
|
88
|
+
g: Number.parseInt(h.slice(2, 4), 16),
|
|
89
|
+
b: Number.parseInt(h.slice(4, 6), 16),
|
|
90
|
+
a: h.length === 8 ? Number.parseInt(h.slice(6, 8), 16) / 255 : 1
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var toHex2 = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0");
|
|
94
|
+
function rgbaToHex({ r, g, b, a }) {
|
|
95
|
+
const base = `#${toHex2(r)}${toHex2(g)}${toHex2(b)}`;
|
|
96
|
+
return a >= 1 ? base : base + toHex2(clamp(a, 0, 1) * 255);
|
|
97
|
+
}
|
|
98
|
+
function chromaToRgb(h, c, x, m) {
|
|
99
|
+
const [rp, gp, bp] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
|
|
100
|
+
return {
|
|
101
|
+
r: Math.round((rp + m) * 255),
|
|
102
|
+
g: Math.round((gp + m) * 255),
|
|
103
|
+
b: Math.round((bp + m) * 255),
|
|
104
|
+
a: 1
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function rgbToHsv(r, g, b) {
|
|
108
|
+
const rn = r / 255;
|
|
109
|
+
const gn = g / 255;
|
|
110
|
+
const bn = b / 255;
|
|
111
|
+
const max = Math.max(rn, gn, bn);
|
|
112
|
+
const min = Math.min(rn, gn, bn);
|
|
113
|
+
const d = max - min;
|
|
114
|
+
let h = 0;
|
|
115
|
+
if (d !== 0) {
|
|
116
|
+
if (max === rn) h = (gn - bn) / d % 6;
|
|
117
|
+
else if (max === gn) h = (bn - rn) / d + 2;
|
|
118
|
+
else h = (rn - gn) / d + 4;
|
|
119
|
+
h *= 60;
|
|
120
|
+
if (h < 0) h += 360;
|
|
121
|
+
}
|
|
122
|
+
return { h, s: (max === 0 ? 0 : d / max) * 100, v: max * 100 };
|
|
123
|
+
}
|
|
124
|
+
function hsvToRgb(h, s, v) {
|
|
125
|
+
const sn = s / 100;
|
|
126
|
+
const vn = v / 100;
|
|
127
|
+
const c = vn * sn;
|
|
128
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
129
|
+
return chromaToRgb(h, c, x, vn - c);
|
|
130
|
+
}
|
|
131
|
+
function rgbToHsl(r, g, b) {
|
|
132
|
+
const rn = r / 255;
|
|
133
|
+
const gn = g / 255;
|
|
134
|
+
const bn = b / 255;
|
|
135
|
+
const max = Math.max(rn, gn, bn);
|
|
136
|
+
const min = Math.min(rn, gn, bn);
|
|
137
|
+
const d = max - min;
|
|
138
|
+
const l = (max + min) / 2;
|
|
139
|
+
let h = 0;
|
|
140
|
+
let s = 0;
|
|
141
|
+
if (d !== 0) {
|
|
142
|
+
s = d / (1 - Math.abs(2 * l - 1));
|
|
143
|
+
if (max === rn) h = (gn - bn) / d % 6;
|
|
144
|
+
else if (max === gn) h = (bn - rn) / d + 2;
|
|
145
|
+
else h = (rn - gn) / d + 4;
|
|
146
|
+
h *= 60;
|
|
147
|
+
if (h < 0) h += 360;
|
|
148
|
+
}
|
|
149
|
+
return { h, s: s * 100, l: l * 100 };
|
|
150
|
+
}
|
|
151
|
+
function hslToRgb(h, s, l) {
|
|
152
|
+
const sn = s / 100;
|
|
153
|
+
const ln = l / 100;
|
|
154
|
+
const c = (1 - Math.abs(2 * ln - 1)) * sn;
|
|
155
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
156
|
+
return chromaToRgb(h, c, x, ln - c / 2);
|
|
157
|
+
}
|
|
158
|
+
function formatColor(rgba, format) {
|
|
159
|
+
const { r, g, b, a } = rgba;
|
|
160
|
+
if (format === "hex") return rgbaToHex(rgba).toUpperCase();
|
|
161
|
+
if (format === "rgb") {
|
|
162
|
+
const rgb = `${String(Math.round(r))}, ${String(Math.round(g))}, ${String(Math.round(b))}`;
|
|
163
|
+
return a >= 1 ? `rgb(${rgb})` : `rgba(${rgb}, ${String(Number(a.toFixed(2)))})`;
|
|
164
|
+
}
|
|
165
|
+
const { h, s, l } = rgbToHsl(r, g, b);
|
|
166
|
+
const hsl = `${String(Math.round(h))}, ${String(Math.round(s))}%, ${String(Math.round(l))}%`;
|
|
167
|
+
return a >= 1 ? `hsl(${hsl})` : `hsla(${hsl}, ${String(Number(a.toFixed(2)))})`;
|
|
168
|
+
}
|
|
169
|
+
function parseColor(input, format) {
|
|
170
|
+
const str = input.trim();
|
|
171
|
+
if (format === "hex") return hexToRgba(str);
|
|
172
|
+
if (format === "rgb") {
|
|
173
|
+
const m2 = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(
|
|
174
|
+
str
|
|
175
|
+
);
|
|
176
|
+
if (!m2) return null;
|
|
177
|
+
return {
|
|
178
|
+
r: clamp(Math.round(Number(m2[1])), 0, 255),
|
|
179
|
+
g: clamp(Math.round(Number(m2[2])), 0, 255),
|
|
180
|
+
b: clamp(Math.round(Number(m2[3])), 0, 255),
|
|
181
|
+
a: m2[4] === void 0 ? 1 : clamp(Number(m2[4]), 0, 1)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const m = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%?\s*,\s*([\d.]+)%?\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(
|
|
185
|
+
str
|
|
186
|
+
);
|
|
187
|
+
if (!m) return null;
|
|
188
|
+
const rgb = hslToRgb(
|
|
189
|
+
Number(m[1]),
|
|
190
|
+
clamp(Number(m[2]), 0, 100),
|
|
191
|
+
clamp(Number(m[3]), 0, 100)
|
|
192
|
+
);
|
|
193
|
+
return { ...rgb, a: m[4] === void 0 ? 1 : clamp(Number(m[4]), 0, 1) };
|
|
194
|
+
}
|
|
195
|
+
var FORMATS = ["hex", "rgb", "hsl"];
|
|
196
|
+
var clampPct = (n) => Math.min(100, Math.max(0, n));
|
|
197
|
+
var HUE_TRACK = "linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)";
|
|
198
|
+
var CHECKERBOARD = "repeating-conic-gradient(#bbb 0% 25%, #fff 0% 50%) 50% / 12px 12px";
|
|
199
|
+
var SATURATION_WHITE = "linear-gradient(to right, #fff, rgba(255,255,255,0))";
|
|
200
|
+
var SATURATION_BLACK = "linear-gradient(to top, #000, rgba(0,0,0,0))";
|
|
201
|
+
var thumbClass = "pointer-events-none absolute -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white ring-1 ring-black/30";
|
|
202
|
+
function SaturationArea({ hue, s, v, onChange }) {
|
|
203
|
+
const ref = React.useRef(null);
|
|
204
|
+
const setFromPoint = (clientX, clientY) => {
|
|
205
|
+
const el = ref.current;
|
|
206
|
+
if (!el) return;
|
|
207
|
+
const rect = el.getBoundingClientRect();
|
|
208
|
+
onChange(
|
|
209
|
+
clampPct((clientX - rect.left) / rect.width * 100),
|
|
210
|
+
clampPct((1 - (clientY - rect.top) / rect.height) * 100)
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
const handlePointerDown = (e) => {
|
|
214
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
215
|
+
setFromPoint(e.clientX, e.clientY);
|
|
216
|
+
};
|
|
217
|
+
const handlePointerMove = (e) => {
|
|
218
|
+
if (e.buttons !== 1) return;
|
|
219
|
+
setFromPoint(e.clientX, e.clientY);
|
|
220
|
+
};
|
|
221
|
+
const handleKeyDown = (e) => {
|
|
222
|
+
const step = e.shiftKey ? 10 : 1;
|
|
223
|
+
let ns = s;
|
|
224
|
+
let nv = v;
|
|
225
|
+
let handled = true;
|
|
226
|
+
if (e.key === "ArrowRight") ns = clampPct(s + step);
|
|
227
|
+
else if (e.key === "ArrowLeft") ns = clampPct(s - step);
|
|
228
|
+
else if (e.key === "ArrowUp") nv = clampPct(v + step);
|
|
229
|
+
else if (e.key === "ArrowDown") nv = clampPct(v - step);
|
|
230
|
+
else handled = false;
|
|
231
|
+
if (handled) {
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
onChange(ns, nv);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return /* @__PURE__ */ jsxs(
|
|
237
|
+
"div",
|
|
238
|
+
{
|
|
239
|
+
ref,
|
|
240
|
+
"aria-label": "Saturation and brightness",
|
|
241
|
+
"aria-valuetext": `Saturation ${String(Math.round(s))}%, brightness ${String(Math.round(v))}%`,
|
|
242
|
+
className: "relative h-40 w-full touch-none cursor-crosshair overflow-hidden rounded-md outline-none focus-visible:ring-[length:var(--color-picker-focus-ring-width)] focus-visible:ring-[color:var(--color-picker-focus-ring-primary)]/50",
|
|
243
|
+
"data-slot": "color-picker-area",
|
|
244
|
+
role: "slider",
|
|
245
|
+
style: { backgroundColor: `hsl(${String(hue)}, 100%, 50%)` },
|
|
246
|
+
tabIndex: 0,
|
|
247
|
+
onKeyDown: handleKeyDown,
|
|
248
|
+
onPointerDown: handlePointerDown,
|
|
249
|
+
onPointerMove: handlePointerMove,
|
|
250
|
+
children: [
|
|
251
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-0", style: { background: SATURATION_WHITE } }),
|
|
252
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-0", style: { background: SATURATION_BLACK } }),
|
|
253
|
+
/* @__PURE__ */ jsx(
|
|
254
|
+
"span",
|
|
255
|
+
{
|
|
256
|
+
style: {
|
|
257
|
+
left: `${String(s)}%`,
|
|
258
|
+
top: `${String(100 - v)}%`,
|
|
259
|
+
backgroundColor: rgbaToHex(hsvToRgb(hue, s, v))
|
|
260
|
+
},
|
|
261
|
+
className: cn(thumbClass, "size-3.5"),
|
|
262
|
+
"data-slot": "color-picker-area-thumb"
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function ColorSlider({
|
|
270
|
+
ariaLabel,
|
|
271
|
+
max,
|
|
272
|
+
thumbColor,
|
|
273
|
+
trackStyle,
|
|
274
|
+
value,
|
|
275
|
+
onChange
|
|
276
|
+
}) {
|
|
277
|
+
const ref = React.useRef(null);
|
|
278
|
+
const setFromPoint = (clientX) => {
|
|
279
|
+
const el = ref.current;
|
|
280
|
+
if (!el) return;
|
|
281
|
+
const rect = el.getBoundingClientRect();
|
|
282
|
+
const next = (clientX - rect.left) / rect.width * max;
|
|
283
|
+
onChange(Math.min(max, Math.max(0, next)));
|
|
284
|
+
};
|
|
285
|
+
const handlePointerDown = (e) => {
|
|
286
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
287
|
+
setFromPoint(e.clientX);
|
|
288
|
+
};
|
|
289
|
+
const handlePointerMove = (e) => {
|
|
290
|
+
if (e.buttons !== 1) return;
|
|
291
|
+
setFromPoint(e.clientX);
|
|
292
|
+
};
|
|
293
|
+
const handleKeyDown = (e) => {
|
|
294
|
+
const step = (e.shiftKey ? 10 : 1) * (max / 100);
|
|
295
|
+
let next = value;
|
|
296
|
+
let handled = true;
|
|
297
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") next = Math.min(max, value + step);
|
|
298
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") next = Math.max(0, value - step);
|
|
299
|
+
else if (e.key === "Home") next = 0;
|
|
300
|
+
else if (e.key === "End") next = max;
|
|
301
|
+
else handled = false;
|
|
302
|
+
if (handled) {
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
onChange(next);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
return /* @__PURE__ */ jsx(
|
|
308
|
+
"div",
|
|
309
|
+
{
|
|
310
|
+
ref,
|
|
311
|
+
"aria-label": ariaLabel,
|
|
312
|
+
"aria-valuemax": max,
|
|
313
|
+
"aria-valuemin": 0,
|
|
314
|
+
"aria-valuenow": Math.round(value),
|
|
315
|
+
className: "relative h-3 w-full touch-none cursor-pointer rounded-full outline-none focus-visible:ring-[length:var(--color-picker-focus-ring-width)] focus-visible:ring-[color:var(--color-picker-focus-ring-primary)]/50",
|
|
316
|
+
role: "slider",
|
|
317
|
+
style: trackStyle,
|
|
318
|
+
tabIndex: 0,
|
|
319
|
+
onKeyDown: handleKeyDown,
|
|
320
|
+
onPointerDown: handlePointerDown,
|
|
321
|
+
onPointerMove: handlePointerMove,
|
|
322
|
+
children: /* @__PURE__ */ jsx(
|
|
323
|
+
"span",
|
|
324
|
+
{
|
|
325
|
+
className: cn(thumbClass, "top-1/2 size-4"),
|
|
326
|
+
style: { left: `${String(value / max * 100)}%`, backgroundColor: thumbColor }
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
function ColorPickerPanel({
|
|
333
|
+
showAlpha,
|
|
334
|
+
showInput,
|
|
335
|
+
value,
|
|
336
|
+
onChange
|
|
337
|
+
}) {
|
|
338
|
+
const initial = hexToRgba(value) ?? { r: 0, g: 0, b: 0, a: 1 };
|
|
339
|
+
const [hsv, setHsv] = React.useState(() => rgbToHsv(initial.r, initial.g, initial.b));
|
|
340
|
+
const [alpha, setAlpha] = React.useState(initial.a);
|
|
341
|
+
const [format, setFormat] = React.useState("hex");
|
|
342
|
+
const [draft, setDraft] = React.useState("");
|
|
343
|
+
const lastEmittedRef = React.useRef(value);
|
|
344
|
+
const rgba = { ...hsvToRgb(hsv.h, hsv.s, hsv.v), a: alpha };
|
|
345
|
+
const formatted = formatColor(rgba, format);
|
|
346
|
+
React.useEffect(() => {
|
|
347
|
+
if (value === lastEmittedRef.current) return;
|
|
348
|
+
const next = hexToRgba(value);
|
|
349
|
+
if (!next) return;
|
|
350
|
+
setHsv(rgbToHsv(next.r, next.g, next.b));
|
|
351
|
+
setAlpha(next.a);
|
|
352
|
+
}, [value]);
|
|
353
|
+
React.useEffect(() => {
|
|
354
|
+
setDraft(formatted);
|
|
355
|
+
}, [formatted]);
|
|
356
|
+
const emit = (nextHsv, nextAlpha) => {
|
|
357
|
+
setHsv(nextHsv);
|
|
358
|
+
setAlpha(nextAlpha);
|
|
359
|
+
const hex = rgbaToHex({ ...hsvToRgb(nextHsv.h, nextHsv.s, nextHsv.v), a: nextAlpha });
|
|
360
|
+
lastEmittedRef.current = hex;
|
|
361
|
+
onChange(hex);
|
|
362
|
+
};
|
|
363
|
+
const handleInputChange = (e) => {
|
|
364
|
+
const raw = e.target.value;
|
|
365
|
+
setDraft(raw);
|
|
366
|
+
if (format === "hex" && !/^#?[0-9a-f]{6}(?:[0-9a-f]{2})?$/i.test(raw.trim())) return;
|
|
367
|
+
const parsed = parseColor(raw, format);
|
|
368
|
+
if (parsed) emit(rgbToHsv(parsed.r, parsed.g, parsed.b), parsed.a);
|
|
369
|
+
};
|
|
370
|
+
const handleInputBlur = () => {
|
|
371
|
+
const parsed = parseColor(draft, format);
|
|
372
|
+
if (parsed) emit(rgbToHsv(parsed.r, parsed.g, parsed.b), parsed.a);
|
|
373
|
+
else setDraft(formatted);
|
|
374
|
+
};
|
|
375
|
+
const solidHex = rgbaToHex(hsvToRgb(hsv.h, hsv.s, hsv.v));
|
|
376
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3", "data-slot": "color-picker-panel", children: [
|
|
377
|
+
/* @__PURE__ */ jsx(
|
|
378
|
+
SaturationArea,
|
|
379
|
+
{
|
|
380
|
+
hue: hsv.h,
|
|
381
|
+
s: hsv.s,
|
|
382
|
+
v: hsv.v,
|
|
383
|
+
onChange: (s, v) => {
|
|
384
|
+
emit({ h: hsv.h, s, v }, alpha);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
),
|
|
388
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
389
|
+
/* @__PURE__ */ jsx(
|
|
390
|
+
"span",
|
|
391
|
+
{
|
|
392
|
+
style: {
|
|
393
|
+
background: `linear-gradient(${rgbaToHex(rgba)}, ${rgbaToHex(rgba)}), ${CHECKERBOARD}`
|
|
394
|
+
},
|
|
395
|
+
"aria-hidden": "true",
|
|
396
|
+
className: "size-9 shrink-0 rounded-full border border-[color:var(--color-picker-trigger-border)]",
|
|
397
|
+
"data-slot": "color-picker-panel-preview"
|
|
398
|
+
}
|
|
399
|
+
),
|
|
400
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-2", children: [
|
|
401
|
+
/* @__PURE__ */ jsx(
|
|
402
|
+
ColorSlider,
|
|
403
|
+
{
|
|
404
|
+
ariaLabel: "Hue",
|
|
405
|
+
max: 360,
|
|
406
|
+
thumbColor: `hsl(${String(hsv.h)}, 100%, 50%)`,
|
|
407
|
+
trackStyle: { background: HUE_TRACK },
|
|
408
|
+
value: hsv.h,
|
|
409
|
+
onChange: (h) => {
|
|
410
|
+
emit({ h, s: hsv.s, v: hsv.v }, alpha);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
),
|
|
414
|
+
showAlpha && /* @__PURE__ */ jsx("div", { className: "relative rounded-full", style: { background: CHECKERBOARD }, children: /* @__PURE__ */ jsx(
|
|
415
|
+
ColorSlider,
|
|
416
|
+
{
|
|
417
|
+
trackStyle: {
|
|
418
|
+
background: `linear-gradient(to right, rgba(0,0,0,0), ${solidHex})`
|
|
419
|
+
},
|
|
420
|
+
ariaLabel: "Alpha",
|
|
421
|
+
max: 1,
|
|
422
|
+
thumbColor: solidHex,
|
|
423
|
+
value: alpha,
|
|
424
|
+
onChange: (a) => {
|
|
425
|
+
emit(hsv, a);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
) })
|
|
429
|
+
] })
|
|
430
|
+
] }),
|
|
431
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
432
|
+
/* @__PURE__ */ jsx("div", { "aria-label": "Color format", className: "flex gap-1", role: "group", children: FORMATS.map((f) => /* @__PURE__ */ jsx(
|
|
433
|
+
"button",
|
|
434
|
+
{
|
|
435
|
+
className: cn(
|
|
436
|
+
"rounded-md px-2 py-1 text-xs font-medium uppercase transition-colors",
|
|
437
|
+
format === f ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-accent/50"
|
|
438
|
+
),
|
|
439
|
+
"aria-pressed": format === f,
|
|
440
|
+
type: "button",
|
|
441
|
+
onClick: () => {
|
|
442
|
+
setFormat(f);
|
|
443
|
+
},
|
|
444
|
+
children: f
|
|
445
|
+
},
|
|
446
|
+
f
|
|
447
|
+
)) }),
|
|
448
|
+
showInput && /* @__PURE__ */ jsx(
|
|
449
|
+
"input",
|
|
450
|
+
{
|
|
451
|
+
"aria-label": `Color value (${format})`,
|
|
452
|
+
className: "flex h-9 w-full min-w-0 flex-1 rounded-md border border-input bg-transparent px-3 py-1 font-mono text-sm uppercase shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[color:var(--color-picker-focus-ring-primary)]/50 focus-visible:ring-[length:var(--color-picker-focus-ring-width)]",
|
|
453
|
+
"data-slot": "color-picker-input",
|
|
454
|
+
spellCheck: false,
|
|
455
|
+
value: draft,
|
|
456
|
+
onBlur: handleInputBlur,
|
|
457
|
+
onChange: handleInputChange
|
|
458
|
+
}
|
|
459
|
+
)
|
|
460
|
+
] })
|
|
461
|
+
] });
|
|
462
|
+
}
|
|
463
|
+
function normalizeHexColor(color) {
|
|
464
|
+
let normalized = color;
|
|
465
|
+
if (!normalized.startsWith("#")) {
|
|
466
|
+
normalized = `#${normalized}`;
|
|
467
|
+
}
|
|
468
|
+
if (normalized.length === 4) {
|
|
469
|
+
const r = normalized[1] ?? "";
|
|
470
|
+
const g = normalized[2] ?? "";
|
|
471
|
+
const b = normalized[3] ?? "";
|
|
472
|
+
return `#${r}${r}${g}${g}${b}${b}`.toLowerCase();
|
|
473
|
+
}
|
|
474
|
+
return normalized.toLowerCase();
|
|
475
|
+
}
|
|
476
|
+
var DEFAULT_SWATCHES = [
|
|
477
|
+
"#ef4444",
|
|
478
|
+
// red
|
|
479
|
+
"#f97316",
|
|
480
|
+
// orange
|
|
481
|
+
"#eab308",
|
|
482
|
+
// yellow
|
|
483
|
+
"#22c55e",
|
|
484
|
+
// green
|
|
485
|
+
"#14b8a6",
|
|
486
|
+
// teal
|
|
487
|
+
"#3b82f6",
|
|
488
|
+
// blue
|
|
489
|
+
"#8b5cf6",
|
|
490
|
+
// violet
|
|
491
|
+
"#ec4899",
|
|
492
|
+
// pink
|
|
493
|
+
"#000000",
|
|
494
|
+
// black
|
|
495
|
+
"#ffffff"
|
|
496
|
+
// white
|
|
497
|
+
];
|
|
498
|
+
function ColorPicker({
|
|
499
|
+
className,
|
|
500
|
+
value,
|
|
501
|
+
defaultValue,
|
|
502
|
+
placeholder = "Select color",
|
|
503
|
+
disabled = false,
|
|
504
|
+
swatches = DEFAULT_SWATCHES,
|
|
505
|
+
showInput = true,
|
|
506
|
+
showAlpha = true,
|
|
507
|
+
showPreview = true,
|
|
508
|
+
onChange,
|
|
509
|
+
onOpenChange,
|
|
510
|
+
size = "md",
|
|
511
|
+
variant = "default",
|
|
512
|
+
required = false,
|
|
513
|
+
invalid = false,
|
|
514
|
+
id,
|
|
515
|
+
name,
|
|
516
|
+
"aria-label": ariaLabel,
|
|
517
|
+
"aria-labelledby": ariaLabelledby,
|
|
518
|
+
...props
|
|
519
|
+
}) {
|
|
520
|
+
const [open, setOpen] = React.useState(false);
|
|
521
|
+
const [internalColor, setInternalColor] = React.useState(defaultValue);
|
|
522
|
+
const selectedColor = value ?? internalColor;
|
|
523
|
+
const handleColorChange = (color) => {
|
|
524
|
+
const normalizedColor = normalizeHexColor(color);
|
|
525
|
+
if (value === void 0) {
|
|
526
|
+
setInternalColor(normalizedColor);
|
|
527
|
+
}
|
|
528
|
+
onChange?.(normalizedColor);
|
|
529
|
+
};
|
|
530
|
+
const handleSwatchClick = (color) => {
|
|
531
|
+
handleColorChange(color);
|
|
532
|
+
};
|
|
533
|
+
const handleOpenChange = (isOpen) => {
|
|
534
|
+
setOpen(isOpen);
|
|
535
|
+
onOpenChange?.(isOpen);
|
|
536
|
+
};
|
|
537
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative", className), "data-slot": "color-picker", ...props, children: [
|
|
538
|
+
/* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
|
|
539
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
540
|
+
"button",
|
|
541
|
+
{
|
|
542
|
+
className: cn(
|
|
543
|
+
colorPickerTriggerVariants({ size, variant }),
|
|
544
|
+
!selectedColor && "text-muted-foreground"
|
|
545
|
+
),
|
|
546
|
+
"aria-expanded": open,
|
|
547
|
+
"aria-haspopup": "dialog",
|
|
548
|
+
"aria-invalid": invalid,
|
|
549
|
+
"aria-label": ariaLabel,
|
|
550
|
+
"aria-labelledby": ariaLabelledby,
|
|
551
|
+
"aria-required": required,
|
|
552
|
+
"data-has-value": !!selectedColor,
|
|
553
|
+
"data-size": size,
|
|
554
|
+
"data-slot": "color-picker-trigger",
|
|
555
|
+
"data-state": open ? "open" : "closed",
|
|
556
|
+
"data-variant": variant,
|
|
557
|
+
disabled,
|
|
558
|
+
id,
|
|
559
|
+
role: "combobox",
|
|
560
|
+
type: "button",
|
|
561
|
+
children: [
|
|
562
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 flex-1 truncate", children: [
|
|
563
|
+
showPreview && selectedColor && /* @__PURE__ */ jsx(
|
|
564
|
+
"span",
|
|
565
|
+
{
|
|
566
|
+
"aria-hidden": "true",
|
|
567
|
+
className: cn(colorPickerPreviewVariants({ size })),
|
|
568
|
+
"data-slot": "color-picker-preview",
|
|
569
|
+
style: { backgroundColor: selectedColor }
|
|
570
|
+
}
|
|
571
|
+
),
|
|
572
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: selectedColor ?? placeholder })
|
|
573
|
+
] }),
|
|
574
|
+
/* @__PURE__ */ jsx(Palette, { "aria-hidden": "true", className: "size-4 shrink-0 opacity-50" })
|
|
575
|
+
]
|
|
576
|
+
}
|
|
577
|
+
) }),
|
|
578
|
+
/* @__PURE__ */ jsx(
|
|
579
|
+
PopoverContent,
|
|
580
|
+
{
|
|
581
|
+
align: "start",
|
|
582
|
+
className: "w-[var(--color-picker-content-width)] p-[var(--color-picker-content-padding)]",
|
|
583
|
+
"data-slot": "color-picker-content",
|
|
584
|
+
children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
585
|
+
/* @__PURE__ */ jsx(
|
|
586
|
+
ColorPickerPanel,
|
|
587
|
+
{
|
|
588
|
+
showAlpha,
|
|
589
|
+
showInput,
|
|
590
|
+
value: selectedColor ?? "#000000",
|
|
591
|
+
onChange: handleColorChange
|
|
592
|
+
}
|
|
593
|
+
),
|
|
594
|
+
swatches.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
595
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground font-medium", children: "Preset colors" }),
|
|
596
|
+
/* @__PURE__ */ jsx(
|
|
597
|
+
"div",
|
|
598
|
+
{
|
|
599
|
+
"aria-label": "Color swatches",
|
|
600
|
+
className: "grid grid-cols-5 gap-2",
|
|
601
|
+
"data-slot": "color-picker-swatches",
|
|
602
|
+
role: "group",
|
|
603
|
+
children: swatches.map((color, index) => /* @__PURE__ */ jsx(
|
|
604
|
+
"button",
|
|
605
|
+
{
|
|
606
|
+
className: cn(
|
|
607
|
+
colorPickerSwatchVariants({ size }),
|
|
608
|
+
selectedColor === color && "ring-2 ring-ring ring-offset-2"
|
|
609
|
+
),
|
|
610
|
+
"aria-label": `Select color ${color}`,
|
|
611
|
+
"aria-pressed": selectedColor === color,
|
|
612
|
+
"data-color": color,
|
|
613
|
+
"data-selected": selectedColor === color,
|
|
614
|
+
"data-slot": "color-picker-swatch",
|
|
615
|
+
style: { backgroundColor: color },
|
|
616
|
+
type: "button",
|
|
617
|
+
onClick: () => {
|
|
618
|
+
handleSwatchClick(color);
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
`${color}-${String(index)}`
|
|
622
|
+
))
|
|
623
|
+
}
|
|
624
|
+
)
|
|
625
|
+
] }) : null
|
|
626
|
+
] })
|
|
627
|
+
}
|
|
628
|
+
)
|
|
629
|
+
] }),
|
|
630
|
+
name && /* @__PURE__ */ jsx(
|
|
631
|
+
"input",
|
|
632
|
+
{
|
|
633
|
+
name,
|
|
634
|
+
type: "hidden",
|
|
635
|
+
value: selectedColor ?? ""
|
|
636
|
+
}
|
|
637
|
+
)
|
|
638
|
+
] });
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export { ColorPicker, colorPickerPreviewVariants, colorPickerSwatchVariants, colorPickerTriggerVariants };
|
|
642
|
+
//# sourceMappingURL=chunk-WKWLKGNI.js.map
|
|
643
|
+
//# sourceMappingURL=chunk-WKWLKGNI.js.map
|