@behavioral-agentic-design-system/core 0.18.0 → 0.21.0
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/package.json +1 -1
- package/src/app/preview/components/page.tsx +247 -234
- package/src/app/shell.tsx +57 -4
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/ui/color-picker.tsx +454 -74
- package/src/stories/Accordion.stories.tsx +12 -9
- package/src/stories/ButtonGroup.stories.tsx +16 -16
- package/src/stories/ColorPicker.stories.tsx +53 -1
- package/src/stories/DatePicker.stories.tsx +2 -2
- package/src/stories/EmptyState.stories.tsx +21 -21
- package/src/stories/List.stories.tsx +28 -28
- package/src/stories/RatingGroup.stories.tsx +2 -2
- package/src/stories/SegmentedControl.stories.tsx +3 -3
- package/src/stories/TagsInput.stories.tsx +21 -21
- package/src/stories/Timeline.stories.tsx +50 -50
|
@@ -1,34 +1,303 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { Plus } from "lucide-react";
|
|
5
5
|
import { cn } from "../../lib/utils";
|
|
6
|
+
import { Popover, PopoverTrigger, PopoverContent } from "./popover";
|
|
7
|
+
import { Button } from "./button";
|
|
6
8
|
|
|
7
9
|
/* -------------------------------------------------------------------------- */
|
|
8
10
|
/* Helpers */
|
|
9
11
|
/* -------------------------------------------------------------------------- */
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
|
|
19
|
-
});
|
|
20
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
13
|
+
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
|
|
14
|
+
|
|
15
|
+
function hexToRgb(hex: string): [number, number, number] | null {
|
|
16
|
+
if (!isValidHex(hex)) return null;
|
|
17
|
+
let h = hex.replace("#", "");
|
|
18
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
19
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
return
|
|
22
|
+
function rgbToHex(r: number, g: number, b: number): string {
|
|
23
|
+
const to = (v: number) => Math.round(clamp(v, 0, 255)).toString(16).padStart(2, "0");
|
|
24
|
+
return `#${to(r)}${to(g)}${to(b)}`;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
function isValidHex(v: string): boolean {
|
|
29
28
|
return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(v);
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
/** hex -> {h: 0-360, s: 0-100, v: 0-100} */
|
|
32
|
+
function hexToHsv(hex: string): { h: number; s: number; v: number } {
|
|
33
|
+
const rgb = hexToRgb(hex);
|
|
34
|
+
if (!rgb) return { h: 0, s: 0, v: 100 };
|
|
35
|
+
const [r, g, b] = rgb.map((v) => v / 255);
|
|
36
|
+
const max = Math.max(r, g, b);
|
|
37
|
+
const min = Math.min(r, g, b);
|
|
38
|
+
const d = max - min;
|
|
39
|
+
let h = 0;
|
|
40
|
+
if (d !== 0) {
|
|
41
|
+
if (max === r) h = ((g - b) / d) % 6;
|
|
42
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
43
|
+
else h = (r - g) / d + 4;
|
|
44
|
+
h *= 60;
|
|
45
|
+
if (h < 0) h += 360;
|
|
46
|
+
}
|
|
47
|
+
const s = max === 0 ? 0 : d / max;
|
|
48
|
+
return { h, s: s * 100, v: max * 100 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** {h: 0-360, s: 0-100, v: 0-100} -> hex */
|
|
52
|
+
function hsvToHex(h: number, s: number, v: number): string {
|
|
53
|
+
const sn = s / 100;
|
|
54
|
+
const vn = v / 100;
|
|
55
|
+
const c = vn * sn;
|
|
56
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
57
|
+
const m = vn - c;
|
|
58
|
+
let r = 0, g = 0, b = 0;
|
|
59
|
+
if (h < 60) [r, g, b] = [c, x, 0];
|
|
60
|
+
else if (h < 120) [r, g, b] = [x, c, 0];
|
|
61
|
+
else if (h < 180) [r, g, b] = [0, c, x];
|
|
62
|
+
else if (h < 240) [r, g, b] = [0, x, c];
|
|
63
|
+
else if (h < 300) [r, g, b] = [x, 0, c];
|
|
64
|
+
else [r, g, b] = [c, 0, x];
|
|
65
|
+
return rgbToHex((r + m) * 255, (g + m) * 255, (b + m) * 255);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* -------------------------------------------------------------------------- */
|
|
69
|
+
/* Color wheel (hue ring + saturation/brightness square) */
|
|
70
|
+
/* -------------------------------------------------------------------------- */
|
|
71
|
+
|
|
72
|
+
const WHEEL_SIZE = 208;
|
|
73
|
+
const RING_THICKNESS = 22;
|
|
74
|
+
const HOLE = WHEEL_SIZE - RING_THICKNESS * 2;
|
|
75
|
+
const SQUARE = Math.round(HOLE / Math.SQRT2);
|
|
76
|
+
const CENTER = WHEEL_SIZE / 2;
|
|
77
|
+
const RING_RADIUS = CENTER - RING_THICKNESS / 2;
|
|
78
|
+
|
|
79
|
+
const HUE_CONIC =
|
|
80
|
+
"conic-gradient(from 0deg, hsl(0 100% 50%), hsl(60 100% 50%), hsl(120 100% 50%), hsl(180 100% 50%), hsl(240 100% 50%), hsl(300 100% 50%), hsl(360 100% 50%))";
|
|
81
|
+
|
|
82
|
+
function ColorWheel({
|
|
83
|
+
value,
|
|
84
|
+
onChange,
|
|
85
|
+
disabled,
|
|
86
|
+
}: {
|
|
87
|
+
value: string;
|
|
88
|
+
onChange: (hex: string) => void;
|
|
89
|
+
disabled?: boolean;
|
|
90
|
+
}) {
|
|
91
|
+
const ringRef = React.useRef<HTMLDivElement>(null);
|
|
92
|
+
const squareRef = React.useRef<HTMLDivElement>(null);
|
|
93
|
+
|
|
94
|
+
const { h, s, v } = isValidHex(value) ? hexToHsv(value) : { h: 0, s: 0, v: 100 };
|
|
95
|
+
|
|
96
|
+
const commitHsv = React.useCallback(
|
|
97
|
+
(nh: number, ns: number, nv: number) => {
|
|
98
|
+
if (disabled) return;
|
|
99
|
+
onChange(hsvToHex(((nh % 360) + 360) % 360, clamp(ns, 0, 100), clamp(nv, 0, 100)));
|
|
100
|
+
},
|
|
101
|
+
[disabled, onChange]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const pointerFromRing = (clientX: number, clientY: number) => {
|
|
105
|
+
const el = ringRef.current;
|
|
106
|
+
if (!el) return;
|
|
107
|
+
const r = el.getBoundingClientRect();
|
|
108
|
+
const dx = clientX - (r.left + r.width / 2);
|
|
109
|
+
const dy = clientY - (r.top + r.height / 2);
|
|
110
|
+
let ang = (Math.atan2(dx, -dy) * 180) / Math.PI; // 0 = top, clockwise
|
|
111
|
+
if (ang < 0) ang += 360;
|
|
112
|
+
commitHsv(ang, s, v);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const pointerFromSquare = (clientX: number, clientY: number) => {
|
|
116
|
+
const el = squareRef.current;
|
|
117
|
+
if (!el) return;
|
|
118
|
+
const r = el.getBoundingClientRect();
|
|
119
|
+
const ns = clamp((clientX - r.left) / r.width, 0, 1) * 100;
|
|
120
|
+
const nv = (1 - clamp((clientY - r.top) / r.height, 0, 1)) * 100;
|
|
121
|
+
commitHsv(h, ns, nv);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const dragRing = (e: React.PointerEvent) => {
|
|
125
|
+
if (disabled) return;
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
128
|
+
pointerFromRing(e.clientX, e.clientY);
|
|
129
|
+
};
|
|
130
|
+
const moveRing = (e: React.PointerEvent) => {
|
|
131
|
+
if (disabled || !(e.currentTarget as HTMLElement).hasPointerCapture(e.pointerId)) return;
|
|
132
|
+
pointerFromRing(e.clientX, e.clientY);
|
|
133
|
+
};
|
|
134
|
+
const dragSquare = (e: React.PointerEvent) => {
|
|
135
|
+
if (disabled) return;
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
138
|
+
pointerFromSquare(e.clientX, e.clientY);
|
|
139
|
+
};
|
|
140
|
+
const moveSquare = (e: React.PointerEvent) => {
|
|
141
|
+
if (disabled || !(e.currentTarget as HTMLElement).hasPointerCapture(e.pointerId)) return;
|
|
142
|
+
pointerFromSquare(e.clientX, e.clientY);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const ringKey = (e: React.KeyboardEvent) => {
|
|
146
|
+
if (disabled) return;
|
|
147
|
+
const big = e.key === "PageUp" || e.key === "PageDown";
|
|
148
|
+
const step = big ? 10 : 1;
|
|
149
|
+
let nh = h;
|
|
150
|
+
switch (e.key) {
|
|
151
|
+
case "ArrowRight":
|
|
152
|
+
case "ArrowUp":
|
|
153
|
+
case "PageUp":
|
|
154
|
+
nh = h + step;
|
|
155
|
+
break;
|
|
156
|
+
case "ArrowLeft":
|
|
157
|
+
case "ArrowDown":
|
|
158
|
+
case "PageDown":
|
|
159
|
+
nh = h - step;
|
|
160
|
+
break;
|
|
161
|
+
case "Home":
|
|
162
|
+
nh = 0;
|
|
163
|
+
break;
|
|
164
|
+
case "End":
|
|
165
|
+
nh = 359;
|
|
166
|
+
break;
|
|
167
|
+
default:
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
commitHsv(nh, s, v);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const squareKey = (e: React.KeyboardEvent) => {
|
|
175
|
+
if (disabled) return;
|
|
176
|
+
let ns = s;
|
|
177
|
+
let nv = v;
|
|
178
|
+
switch (e.key) {
|
|
179
|
+
case "ArrowRight":
|
|
180
|
+
ns = s + 2;
|
|
181
|
+
break;
|
|
182
|
+
case "ArrowLeft":
|
|
183
|
+
ns = s - 2;
|
|
184
|
+
break;
|
|
185
|
+
case "ArrowUp":
|
|
186
|
+
nv = v + 2;
|
|
187
|
+
break;
|
|
188
|
+
case "ArrowDown":
|
|
189
|
+
nv = v - 2;
|
|
190
|
+
break;
|
|
191
|
+
case "Home":
|
|
192
|
+
ns = 0;
|
|
193
|
+
break;
|
|
194
|
+
case "End":
|
|
195
|
+
ns = 100;
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
commitHsv(h, ns, nv);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const rad = (h * Math.PI) / 180;
|
|
205
|
+
const hueX = CENTER + RING_RADIUS * Math.sin(rad);
|
|
206
|
+
const hueY = CENTER - RING_RADIUS * Math.cos(rad);
|
|
207
|
+
const svX = (s / 100) * SQUARE;
|
|
208
|
+
const svY = (1 - v / 100) * SQUARE;
|
|
209
|
+
|
|
210
|
+
const thumb =
|
|
211
|
+
"absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white pointer-events-none shadow-[0_0_0_1px_rgba(0,0,0,0.45)]";
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div
|
|
215
|
+
className={cn("relative select-none touch-none", disabled && "opacity-50")}
|
|
216
|
+
style={{ width: WHEEL_SIZE, height: WHEEL_SIZE }}
|
|
217
|
+
>
|
|
218
|
+
<div
|
|
219
|
+
ref={ringRef}
|
|
220
|
+
role="slider"
|
|
221
|
+
aria-label="Hue"
|
|
222
|
+
aria-valuemin={0}
|
|
223
|
+
aria-valuemax={360}
|
|
224
|
+
aria-valuenow={Math.round(h)}
|
|
225
|
+
aria-valuetext={`${Math.round(h)} degrees`}
|
|
226
|
+
aria-disabled={disabled || undefined}
|
|
227
|
+
tabIndex={disabled ? -1 : 0}
|
|
228
|
+
onPointerDown={dragRing}
|
|
229
|
+
onPointerMove={moveRing}
|
|
230
|
+
onKeyDown={ringKey}
|
|
231
|
+
className={cn(
|
|
232
|
+
"absolute inset-0 rounded-full",
|
|
233
|
+
!disabled && "cursor-pointer",
|
|
234
|
+
"outline-none focus-visible:ring-[3px] focus-visible:ring-ring/70 focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
235
|
+
)}
|
|
236
|
+
style={{ background: HUE_CONIC }}
|
|
237
|
+
/>
|
|
238
|
+
|
|
239
|
+
<div
|
|
240
|
+
aria-hidden
|
|
241
|
+
className="absolute rounded-full bg-background pointer-events-none"
|
|
242
|
+
style={{ width: HOLE, height: HOLE, left: RING_THICKNESS, top: RING_THICKNESS }}
|
|
243
|
+
/>
|
|
244
|
+
|
|
245
|
+
<div
|
|
246
|
+
ref={squareRef}
|
|
247
|
+
role="slider"
|
|
248
|
+
aria-label="Saturation and brightness"
|
|
249
|
+
aria-valuemin={0}
|
|
250
|
+
aria-valuemax={100}
|
|
251
|
+
aria-valuenow={Math.round(s)}
|
|
252
|
+
aria-valuetext={`Saturation ${Math.round(s)} percent, brightness ${Math.round(v)} percent`}
|
|
253
|
+
aria-disabled={disabled || undefined}
|
|
254
|
+
tabIndex={disabled ? -1 : 0}
|
|
255
|
+
onPointerDown={dragSquare}
|
|
256
|
+
onPointerMove={moveSquare}
|
|
257
|
+
onKeyDown={squareKey}
|
|
258
|
+
className={cn(
|
|
259
|
+
"absolute rounded-md",
|
|
260
|
+
!disabled && "cursor-crosshair",
|
|
261
|
+
"outline-none focus-visible:ring-[3px] focus-visible:ring-ring/70 focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
262
|
+
)}
|
|
263
|
+
style={{
|
|
264
|
+
width: SQUARE,
|
|
265
|
+
height: SQUARE,
|
|
266
|
+
left: CENTER - SQUARE / 2,
|
|
267
|
+
top: CENTER - SQUARE / 2,
|
|
268
|
+
background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${Math.round(h)} 100% 50%))`,
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
<span
|
|
272
|
+
aria-hidden
|
|
273
|
+
className={thumb}
|
|
274
|
+
style={{
|
|
275
|
+
left: svX,
|
|
276
|
+
top: svY,
|
|
277
|
+
backgroundColor: isValidHex(value) ? value : "#ffffff",
|
|
278
|
+
transitionProperty: "box-shadow",
|
|
279
|
+
transitionDuration: "var(--duration-fast)",
|
|
280
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
281
|
+
}}
|
|
282
|
+
/>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
<span
|
|
286
|
+
aria-hidden
|
|
287
|
+
className={thumb}
|
|
288
|
+
style={{
|
|
289
|
+
left: hueX,
|
|
290
|
+
top: hueY,
|
|
291
|
+
backgroundColor: `hsl(${Math.round(h)} 100% 50%)`,
|
|
292
|
+
transitionProperty: "box-shadow",
|
|
293
|
+
transitionDuration: "var(--duration-fast)",
|
|
294
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
</div>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
32
301
|
/* -------------------------------------------------------------------------- */
|
|
33
302
|
/* ColorPicker */
|
|
34
303
|
/* -------------------------------------------------------------------------- */
|
|
@@ -41,8 +310,17 @@ export interface ColorPickerProps {
|
|
|
41
310
|
onValueChange?: (value: string) => void;
|
|
42
311
|
/** Preset swatch colors (hex strings) */
|
|
43
312
|
swatches?: string[];
|
|
44
|
-
/** Show a hex text input for custom colors */
|
|
313
|
+
/** Show a standalone hex text input for custom colors */
|
|
45
314
|
allowCustom?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Add an "add a custom color" tile (+) after the swatches. Clicking it opens
|
|
317
|
+
* a popover with a hue-ring + saturation/brightness color wheel (and a hex
|
|
318
|
+
* field); confirming appends the picked color to the swatches and selects it.
|
|
319
|
+
* The wheel only appears on demand — the swatch grid stays the default view.
|
|
320
|
+
*/
|
|
321
|
+
wheel?: boolean;
|
|
322
|
+
/** Fired when a color is added to the swatches via the wheel. */
|
|
323
|
+
onAddSwatch?: (hex: string) => void;
|
|
46
324
|
disabled?: boolean;
|
|
47
325
|
/** Accessible label for the radiogroup */
|
|
48
326
|
"aria-label"?: string;
|
|
@@ -55,6 +333,8 @@ export function ColorPicker({
|
|
|
55
333
|
onValueChange,
|
|
56
334
|
swatches = [],
|
|
57
335
|
allowCustom = false,
|
|
336
|
+
wheel = false,
|
|
337
|
+
onAddSwatch,
|
|
58
338
|
disabled = false,
|
|
59
339
|
"aria-label": ariaLabel = "Color picker",
|
|
60
340
|
className,
|
|
@@ -67,6 +347,18 @@ export function ColorPicker({
|
|
|
67
347
|
value && !swatches.includes(value) ? value : ""
|
|
68
348
|
);
|
|
69
349
|
|
|
350
|
+
// Colors the user has added through the wheel, appended after the presets.
|
|
351
|
+
const [addedSwatches, setAddedSwatches] = React.useState<string[]>([]);
|
|
352
|
+
const allSwatches = React.useMemo(
|
|
353
|
+
() => [...swatches, ...addedSwatches.filter((c) => !swatches.includes(c))],
|
|
354
|
+
[swatches, addedSwatches]
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
// Wheel popover state + its in-progress draft color.
|
|
358
|
+
const [wheelOpen, setWheelOpen] = React.useState(false);
|
|
359
|
+
const [draft, setDraft] = React.useState("#3b82f6");
|
|
360
|
+
const [draftInput, setDraftInput] = React.useState("#3b82f6");
|
|
361
|
+
|
|
70
362
|
const swatchRefs = React.useRef<(HTMLButtonElement | null)[]>([]);
|
|
71
363
|
|
|
72
364
|
const commit = React.useCallback(
|
|
@@ -115,64 +407,155 @@ export function ColorPicker({
|
|
|
115
407
|
if (isValidHex(v)) commit(v);
|
|
116
408
|
};
|
|
117
409
|
|
|
118
|
-
const
|
|
410
|
+
const openWheel = (open: boolean) => {
|
|
411
|
+
if (open) {
|
|
412
|
+
const seed = isValidHex(value) ? value : "#3b82f6";
|
|
413
|
+
setDraft(seed);
|
|
414
|
+
setDraftInput(seed);
|
|
415
|
+
}
|
|
416
|
+
setWheelOpen(open);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const setDraftColor = (hex: string) => {
|
|
420
|
+
setDraft(hex);
|
|
421
|
+
setDraftInput(hex);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const handleDraftInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
425
|
+
const v = e.target.value;
|
|
426
|
+
setDraftInput(v);
|
|
427
|
+
if (isValidHex(v)) setDraft(v);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const addColor = () => {
|
|
431
|
+
if (disabled || !isValidHex(draft)) return;
|
|
432
|
+
if (!allSwatches.includes(draft)) setAddedSwatches((prev) => [...prev, draft]);
|
|
433
|
+
commit(draft);
|
|
434
|
+
if (!swatches.includes(draft)) setCustomInput("");
|
|
435
|
+
onAddSwatch?.(draft);
|
|
436
|
+
setWheelOpen(false);
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const selectedSwatchIdx = allSwatches.indexOf(value);
|
|
119
440
|
|
|
120
441
|
return (
|
|
121
|
-
<div className={cn("space-y-
|
|
122
|
-
{
|
|
123
|
-
<div
|
|
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
|
-
|
|
442
|
+
<div className={cn("space-y-3", className)}>
|
|
443
|
+
{(allSwatches.length > 0 || wheel) && (
|
|
444
|
+
<div className="flex flex-wrap items-center gap-1.5">
|
|
445
|
+
{allSwatches.length > 0 && (
|
|
446
|
+
<div
|
|
447
|
+
role="radiogroup"
|
|
448
|
+
aria-label={ariaLabel}
|
|
449
|
+
aria-disabled={disabled || undefined}
|
|
450
|
+
className="flex flex-wrap gap-1.5"
|
|
451
|
+
>
|
|
452
|
+
{allSwatches.map((swatch, i) => {
|
|
453
|
+
const isSelected = value === swatch;
|
|
454
|
+
const isRovingFocus = selectedSwatchIdx >= 0 ? isSelected : i === 0;
|
|
455
|
+
return (
|
|
456
|
+
<button
|
|
457
|
+
key={swatch}
|
|
458
|
+
ref={(el) => {
|
|
459
|
+
swatchRefs.current[i] = el;
|
|
460
|
+
}}
|
|
461
|
+
type="button"
|
|
462
|
+
role="radio"
|
|
463
|
+
aria-checked={isSelected}
|
|
464
|
+
aria-label={swatch}
|
|
465
|
+
tabIndex={isRovingFocus ? 0 : -1}
|
|
466
|
+
disabled={disabled}
|
|
467
|
+
onClick={() => {
|
|
468
|
+
commit(swatch);
|
|
469
|
+
setCustomInput("");
|
|
470
|
+
}}
|
|
471
|
+
onKeyDown={(e) => handleKeyDown(e, i)}
|
|
472
|
+
className={cn(
|
|
473
|
+
"size-7 shrink-0 rounded-md outline-none transition-[box-shadow]",
|
|
474
|
+
"focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
475
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
476
|
+
// Selected: an offset ring (radio-style), NOT a border on the color, so it
|
|
477
|
+
// reads as "selected" on any swatch instead of a harsh frame. Box-shadow
|
|
478
|
+
// rings are dropped in Windows High Contrast, so a forced-colors outline
|
|
479
|
+
// carries the selected state there (maps to a system color).
|
|
480
|
+
isSelected
|
|
481
|
+
? "ring-2 ring-offset-2 ring-offset-background ring-foreground forced-colors:outline forced-colors:outline-2 forced-colors:outline-offset-2"
|
|
482
|
+
: "hover:ring-2 hover:ring-offset-2 hover:ring-offset-background hover:ring-foreground/25"
|
|
483
|
+
)}
|
|
484
|
+
style={{
|
|
485
|
+
backgroundColor: swatch,
|
|
486
|
+
transitionDuration: "var(--duration-fast)",
|
|
487
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
488
|
+
}}
|
|
489
|
+
/>
|
|
490
|
+
);
|
|
491
|
+
})}
|
|
492
|
+
</div>
|
|
493
|
+
)}
|
|
494
|
+
|
|
495
|
+
{wheel && (
|
|
496
|
+
<Popover open={wheelOpen} onOpenChange={openWheel}>
|
|
497
|
+
<PopoverTrigger asChild>
|
|
498
|
+
<button
|
|
499
|
+
type="button"
|
|
500
|
+
aria-label="Add a custom color"
|
|
501
|
+
disabled={disabled}
|
|
502
|
+
className={cn(
|
|
503
|
+
"flex size-7 shrink-0 items-center justify-center rounded-md",
|
|
504
|
+
"border-2 border-dashed border-input text-muted-foreground",
|
|
505
|
+
"hover:border-foreground/40 hover:text-foreground",
|
|
506
|
+
"focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-offset-1",
|
|
507
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
508
|
+
"transition-[border-color,color]"
|
|
509
|
+
)}
|
|
510
|
+
style={{
|
|
511
|
+
transitionDuration: "var(--duration-fast)",
|
|
512
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
513
|
+
}}
|
|
514
|
+
>
|
|
515
|
+
<Plus className="size-4" strokeWidth={1.5} aria-hidden />
|
|
516
|
+
</button>
|
|
517
|
+
</PopoverTrigger>
|
|
518
|
+
<PopoverContent align="start" className="w-auto space-y-3">
|
|
519
|
+
<ColorWheel value={draft} onChange={setDraftColor} disabled={disabled} />
|
|
520
|
+
<div className="flex items-center gap-2">
|
|
521
|
+
<div
|
|
522
|
+
role="presentation"
|
|
523
|
+
className="size-8 shrink-0 rounded-md border border-input"
|
|
524
|
+
style={{ backgroundColor: isValidHex(draft) ? draft : "transparent" }}
|
|
171
525
|
/>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
526
|
+
<input
|
|
527
|
+
type="text"
|
|
528
|
+
value={draftInput}
|
|
529
|
+
onChange={handleDraftInput}
|
|
530
|
+
disabled={disabled}
|
|
531
|
+
placeholder="#000000"
|
|
532
|
+
aria-label="Hex color"
|
|
533
|
+
spellCheck={false}
|
|
534
|
+
maxLength={7}
|
|
535
|
+
className={cn(
|
|
536
|
+
"h-9 w-full rounded-md border border-input bg-background px-2 py-1",
|
|
537
|
+
"font-mono text-sm text-foreground placeholder:text-muted-foreground",
|
|
538
|
+
"focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
539
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
540
|
+
"transition-[border-color,box-shadow]"
|
|
541
|
+
)}
|
|
542
|
+
style={{
|
|
543
|
+
transitionDuration: "var(--duration-fast)",
|
|
544
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
545
|
+
}}
|
|
546
|
+
/>
|
|
547
|
+
</div>
|
|
548
|
+
<Button
|
|
549
|
+
type="button"
|
|
550
|
+
onClick={addColor}
|
|
551
|
+
disabled={disabled || !isValidHex(draft)}
|
|
552
|
+
className="w-full"
|
|
553
|
+
>
|
|
554
|
+
Add color
|
|
555
|
+
</Button>
|
|
556
|
+
</PopoverContent>
|
|
557
|
+
</Popover>
|
|
558
|
+
)}
|
|
176
559
|
</div>
|
|
177
560
|
)}
|
|
178
561
|
|
|
@@ -180,10 +563,7 @@ export function ColorPicker({
|
|
|
180
563
|
<div className="flex items-center gap-2">
|
|
181
564
|
<div
|
|
182
565
|
role="presentation"
|
|
183
|
-
className={cn(
|
|
184
|
-
"size-7 shrink-0 rounded-md border border-input",
|
|
185
|
-
"transition-colors"
|
|
186
|
-
)}
|
|
566
|
+
className={cn("size-7 shrink-0 rounded-md border border-input", "transition-colors")}
|
|
187
567
|
style={{
|
|
188
568
|
backgroundColor: value || "transparent",
|
|
189
569
|
transitionDuration: "var(--duration-fast)",
|
|
@@ -58,24 +58,27 @@ export const Variant_Multiple: Story = {
|
|
|
58
58
|
render: () => (
|
|
59
59
|
<Accordion type="multiple" className="w-[400px]">
|
|
60
60
|
<AccordionItem value="item-1">
|
|
61
|
-
<AccordionTrigger>
|
|
61
|
+
<AccordionTrigger>Token sync</AccordionTrigger>
|
|
62
62
|
<AccordionContent>
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
Tokens live in one source of truth and publish as CSS variables. When
|
|
64
|
+
the values change, every component that references them updates on the
|
|
65
|
+
next build.
|
|
65
66
|
</AccordionContent>
|
|
66
67
|
</AccordionItem>
|
|
67
68
|
<AccordionItem value="item-2">
|
|
68
|
-
<AccordionTrigger>
|
|
69
|
+
<AccordionTrigger>Component adoption</AccordionTrigger>
|
|
69
70
|
<AccordionContent>
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
Install the package, import the primitive you need, and drop it into a
|
|
72
|
+
route. Each component ships with an accessibility contract and a set
|
|
73
|
+
of documented variants.
|
|
72
74
|
</AccordionContent>
|
|
73
75
|
</AccordionItem>
|
|
74
76
|
<AccordionItem value="item-3">
|
|
75
|
-
<AccordionTrigger>
|
|
77
|
+
<AccordionTrigger>Versioning and releases</AccordionTrigger>
|
|
76
78
|
<AccordionContent>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
Releases follow semantic versioning. Breaking changes land in major
|
|
80
|
+
bumps with a migration note, and the changelog records every shipped
|
|
81
|
+
fix and feature.
|
|
79
82
|
</AccordionContent>
|
|
80
83
|
</AccordionItem>
|
|
81
84
|
</Accordion>
|