@behavioral-agentic-design-system/core 0.26.0 → 0.28.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 +4 -4
- package/scripts/build-tokens.cjs +8 -0
- package/src/app/preview/components/page.tsx +1004 -22
- package/src/app/shell.tsx +17 -0
- package/src/components/ui/ai-badge.tsx +74 -0
- package/src/components/ui/chat-bubble.tsx +298 -0
- package/src/components/ui/clipboard.tsx +291 -0
- package/src/components/ui/copy-button.tsx +5 -1
- package/src/components/ui/data-table.tsx +388 -0
- package/src/components/ui/floating-action-button.tsx +179 -0
- package/src/components/ui/focus-trap.tsx +184 -0
- package/src/components/ui/index.ts +8 -0
- package/src/components/ui/mark.tsx +69 -0
- package/src/components/ui/meter.tsx +4 -4
- package/src/components/ui/rolling-number.tsx +200 -0
- package/src/components/ui/transfer-list.tsx +48 -13
- package/src/components/ui/typing-indicator.tsx +96 -0
- package/src/components/ui/word-rotate.tsx +87 -0
- package/src/data/docs-index.ts +1 -0
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/AiBadge.stories.tsx +67 -0
- package/src/stories/Anchor.stories.tsx +4 -4
- package/src/stories/ChatBubble.stories.tsx +222 -0
- package/src/stories/Clipboard.stories.tsx +136 -0
- package/src/stories/CopyButton.stories.tsx +2 -0
- package/src/stories/DataTable.stories.tsx +271 -0
- package/src/stories/FloatingActionButton.stories.tsx +215 -0
- package/src/stories/FocusTrap.stories.tsx +218 -0
- package/src/stories/Mark.stories.tsx +84 -0
- package/src/stories/Meter.stories.tsx +7 -0
- package/src/stories/RollingNumber.stories.tsx +226 -0
- package/src/stories/TransferList.stories.tsx +21 -0
- package/src/stories/TypingIndicator.stories.tsx +140 -0
- package/src/stories/WordRotate.stories.tsx +102 -0
- package/src/styles.css +8 -0
- package/src/tokens.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Standalone focus-containment utility. Traps Tab/Shift+Tab cycling within
|
|
9
|
+
* its children while `active` is true, and calls `onEscapeKeyDown` when
|
|
10
|
+
* Escape is pressed.
|
|
11
|
+
*
|
|
12
|
+
* Use this when a custom overlay, inline drawer, or panel needs focus
|
|
13
|
+
* containment but doesn't warrant the full Dialog or Sheet weight. All
|
|
14
|
+
* BADS Radix-based components (Dialog, Sheet) trap focus internally — this
|
|
15
|
+
* is for the cases that fall between.
|
|
16
|
+
*
|
|
17
|
+
* WCAG 2.1.2 No Keyboard Trap: trapping focus alone is compliant only when
|
|
18
|
+
* an escape mechanism exists. Wire `onEscapeKeyDown` to close the container
|
|
19
|
+
* so keyboard users can always leave.
|
|
20
|
+
*
|
|
21
|
+
* <FocusTrap active={open} onEscapeKeyDown={() => setOpen(false)}>
|
|
22
|
+
* <div role="dialog" aria-modal="true" aria-labelledby="dlg-title">
|
|
23
|
+
* <FocusTrapInitialFocus />
|
|
24
|
+
* <h2 id="dlg-title">Confirm</h2>
|
|
25
|
+
* <button>OK</button>
|
|
26
|
+
* <button onClick={() => setOpen(false)}>Cancel</button>
|
|
27
|
+
* </div>
|
|
28
|
+
* </FocusTrap>
|
|
29
|
+
*
|
|
30
|
+
* Focus cycling: on Tab from the last focusable element, cycles back to the
|
|
31
|
+
* first; on Shift+Tab from the first, cycles to the last. The cycle includes
|
|
32
|
+
* all focusable elements: <button>, <a href>, <input>, <select>, <textarea>,
|
|
33
|
+
* and any element with tabIndex >= 0.
|
|
34
|
+
*
|
|
35
|
+
* FocusTrapInitialFocus: place anywhere inside FocusTrap. When the trap
|
|
36
|
+
* activates, focus moves to the nearest [data-focus-trap-initial] element
|
|
37
|
+
* instead of the first focusable element in DOM order. Useful when the
|
|
38
|
+
* visually primary action isn't the first tabbable in the DOM.
|
|
39
|
+
*
|
|
40
|
+
* Zero dependencies. Reduced-motion safety: no animation — the focus ring
|
|
41
|
+
* uses the existing CSS base layer (SC 2.4.7 + 2.4.13 enforced).
|
|
42
|
+
* Microanimation: no interactive state changes on this wrapper; rule
|
|
43
|
+
* vacuously satisfied (same exemption as VisuallyHidden, SkipLink).
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const FOCUSABLE_SELECTORS = [
|
|
47
|
+
"button:not([disabled])",
|
|
48
|
+
"a[href]",
|
|
49
|
+
"input:not([disabled])",
|
|
50
|
+
"select:not([disabled])",
|
|
51
|
+
"textarea:not([disabled])",
|
|
52
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
53
|
+
"details > summary:not([disabled])",
|
|
54
|
+
].join(",");
|
|
55
|
+
|
|
56
|
+
export interface FocusTrapProps extends React.ComponentProps<"div"> {
|
|
57
|
+
/** Whether the trap is active. When false the component renders its
|
|
58
|
+
* children unchanged with no keyboard interception. */
|
|
59
|
+
active?: boolean;
|
|
60
|
+
/** Whether Tab cycles back to the first focusable after reaching the last
|
|
61
|
+
* (and vice versa for Shift+Tab). Default: true. */
|
|
62
|
+
loop?: boolean;
|
|
63
|
+
/** Called when Escape is pressed while the trap is active.
|
|
64
|
+
* Required for WCAG 2.1.2 compliance: always wire this to close the
|
|
65
|
+
* containing overlay so keyboard users can leave. */
|
|
66
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function FocusTrap({
|
|
70
|
+
active = true,
|
|
71
|
+
loop = true,
|
|
72
|
+
onEscapeKeyDown,
|
|
73
|
+
className,
|
|
74
|
+
children,
|
|
75
|
+
...props
|
|
76
|
+
}: FocusTrapProps) {
|
|
77
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
78
|
+
|
|
79
|
+
// On activation, move focus to the first focusable element (or the
|
|
80
|
+
// FocusTrapInitialFocus marker if one is present).
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
if (!active || !containerRef.current) return;
|
|
83
|
+
|
|
84
|
+
const container = containerRef.current;
|
|
85
|
+
|
|
86
|
+
// Prefer the explicit initial-focus marker if present.
|
|
87
|
+
const initialTarget = container.querySelector<HTMLElement>(
|
|
88
|
+
"[data-focus-trap-initial]"
|
|
89
|
+
);
|
|
90
|
+
const firstFocusable = container.querySelectorAll<HTMLElement>(
|
|
91
|
+
FOCUSABLE_SELECTORS
|
|
92
|
+
)[0];
|
|
93
|
+
|
|
94
|
+
const target = initialTarget ?? firstFocusable;
|
|
95
|
+
// Defer by one tick so the container is in the DOM before focusing.
|
|
96
|
+
const id = setTimeout(() => target?.focus(), 0);
|
|
97
|
+
return () => clearTimeout(id);
|
|
98
|
+
}, [active]);
|
|
99
|
+
|
|
100
|
+
// Handle Tab and Escape keydown events.
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (!active || !containerRef.current) return;
|
|
103
|
+
|
|
104
|
+
const container = containerRef.current;
|
|
105
|
+
|
|
106
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
107
|
+
if (event.key === "Escape") {
|
|
108
|
+
onEscapeKeyDown?.(event);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (event.key !== "Tab") return;
|
|
113
|
+
|
|
114
|
+
const focusable = Array.from(
|
|
115
|
+
container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTORS)
|
|
116
|
+
).filter((el) => !el.closest("[inert]") && !el.closest("[hidden]"));
|
|
117
|
+
|
|
118
|
+
if (focusable.length === 0) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const first = focusable[0];
|
|
124
|
+
const last = focusable[focusable.length - 1];
|
|
125
|
+
const active = document.activeElement as HTMLElement | null;
|
|
126
|
+
|
|
127
|
+
if (event.shiftKey) {
|
|
128
|
+
// Shift+Tab: if focus is on the first element, cycle to the last.
|
|
129
|
+
if (loop && active === first) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
last.focus();
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
// Tab: if focus is on the last element, cycle to the first.
|
|
135
|
+
if (loop && active === last) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
first.focus();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
container.addEventListener("keydown", handleKeyDown);
|
|
143
|
+
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
144
|
+
}, [active, loop, onEscapeKeyDown]);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
data-slot="focus-trap"
|
|
149
|
+
data-state={active ? "active" : "inactive"}
|
|
150
|
+
className={cn(className)}
|
|
151
|
+
ref={containerRef}
|
|
152
|
+
{...props}
|
|
153
|
+
>
|
|
154
|
+
{children}
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Place this element anywhere inside a FocusTrap. When the trap activates,
|
|
161
|
+
* focus moves here instead of to the first focusable in DOM order.
|
|
162
|
+
*
|
|
163
|
+
* The element itself is not focusable (tabIndex=-1, not in the Tab cycle)
|
|
164
|
+
* — it is only a focus-target marker that FocusTrap finds at activation.
|
|
165
|
+
* Its purpose is to ensure the visually primary element gets initial focus
|
|
166
|
+
* regardless of its DOM position.
|
|
167
|
+
*/
|
|
168
|
+
function FocusTrapInitialFocus({
|
|
169
|
+
className,
|
|
170
|
+
...props
|
|
171
|
+
}: React.ComponentProps<"span">) {
|
|
172
|
+
return (
|
|
173
|
+
<span
|
|
174
|
+
data-slot="focus-trap-initial-focus"
|
|
175
|
+
data-focus-trap-initial
|
|
176
|
+
tabIndex={-1}
|
|
177
|
+
className={cn("sr-only", className)}
|
|
178
|
+
aria-hidden
|
|
179
|
+
{...props}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { FocusTrap, FocusTrapInitialFocus };
|
|
@@ -114,3 +114,11 @@ export * from "./affix";
|
|
|
114
114
|
export * from "./skip-link";
|
|
115
115
|
export * from "./timer";
|
|
116
116
|
export * from "./signature-pad";
|
|
117
|
+
export * from "./floating-action-button";
|
|
118
|
+
export * from "./clipboard";
|
|
119
|
+
export * from "./chat-bubble";
|
|
120
|
+
export * from "./data-table";
|
|
121
|
+
export * from "./focus-trap";
|
|
122
|
+
export * from "./mark";
|
|
123
|
+
export * from "./rolling-number";
|
|
124
|
+
export * from "./ai-badge";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Semantic <mark> wrapper for editorial inline emphasis — the static
|
|
10
|
+
* counterpart to Highlight (which dynamically marks search-query matches).
|
|
11
|
+
*
|
|
12
|
+
* Use Mark when an author intentionally annotates a phrase as relevant:
|
|
13
|
+
*
|
|
14
|
+
* <p>
|
|
15
|
+
* The key constraint is <Mark>token discipline</Mark> — every color,
|
|
16
|
+
* spacing, and radius traces back to a single authoritative source.
|
|
17
|
+
* </p>
|
|
18
|
+
*
|
|
19
|
+
* Display-only: <mark> carries no interactive role, no focus contract, and
|
|
20
|
+
* no keyboard target. Most screen readers do not announce it as highlighted —
|
|
21
|
+
* never make the mark the sole carrier of meaning. Pair it with surrounding
|
|
22
|
+
* prose context.
|
|
23
|
+
*
|
|
24
|
+
* Microanimation: no interactive states; rule vacuously satisfied (same
|
|
25
|
+
* exemption as Blockquote, Code). No motion declarations needed.
|
|
26
|
+
*
|
|
27
|
+
* The `default` variant uses bg-warning/25 — a pale amber wash that reads
|
|
28
|
+
* as a physical highlighter across both light and dark themes. The
|
|
29
|
+
* foreground color is always `text-foreground` (the computed near-black or
|
|
30
|
+
* near-white), so WCAG contrast depends on the surrounding text, not the
|
|
31
|
+
* mark background.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const markVariants = cva(
|
|
35
|
+
"rounded-[2px] px-[0.2em] py-[0.05em]",
|
|
36
|
+
{
|
|
37
|
+
variants: {
|
|
38
|
+
variant: {
|
|
39
|
+
/** Pale amber/warning wash — the physical-highlighter register. */
|
|
40
|
+
default: "bg-warning/25 text-foreground",
|
|
41
|
+
/** Pale primary tint — use for branded or navigational emphasis. */
|
|
42
|
+
primary: "bg-primary/20 text-foreground",
|
|
43
|
+
/** Muted secondary surface — use for neutral, non-semantic callout. */
|
|
44
|
+
secondary: "bg-secondary text-secondary-foreground",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
defaultVariants: {
|
|
48
|
+
variant: "default",
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export interface MarkProps
|
|
54
|
+
extends React.ComponentProps<"mark">,
|
|
55
|
+
VariantProps<typeof markVariants> {}
|
|
56
|
+
|
|
57
|
+
function Mark({ className, variant, children, ...props }: MarkProps) {
|
|
58
|
+
return (
|
|
59
|
+
<mark
|
|
60
|
+
data-slot="mark"
|
|
61
|
+
className={cn(markVariants({ variant }), className)}
|
|
62
|
+
{...props}
|
|
63
|
+
>
|
|
64
|
+
{children}
|
|
65
|
+
</mark>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { Mark, markVariants };
|
|
@@ -118,9 +118,9 @@ function Meter({
|
|
|
118
118
|
: null)}
|
|
119
119
|
className={cn(
|
|
120
120
|
meterVariants({ variant, size }),
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
disabled &&
|
|
121
|
+
// Always dim the track when disabled — label text stays at full
|
|
122
|
+
// opacity so it meets WCAG AAA contrast regardless of state.
|
|
123
|
+
disabled && "opacity-50",
|
|
124
124
|
className
|
|
125
125
|
)}
|
|
126
126
|
{...props}
|
|
@@ -152,7 +152,7 @@ function Meter({
|
|
|
152
152
|
return (
|
|
153
153
|
<div
|
|
154
154
|
data-slot="meter-wrapper"
|
|
155
|
-
className=
|
|
155
|
+
className="flex w-full flex-col gap-2"
|
|
156
156
|
>
|
|
157
157
|
<div className="flex items-center justify-between gap-3">
|
|
158
158
|
{showLabel ? (
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* RollingNumber — animated digit counter that scrolls each digit independently
|
|
8
|
+
* (odometer / slot-machine style) when the value prop changes.
|
|
9
|
+
*
|
|
10
|
+
* Distinct from:
|
|
11
|
+
* - `FormatNumber` — static formatted display, no animation
|
|
12
|
+
* - `Stat` / `StatCard` — layout containers that hold a number; static
|
|
13
|
+
* - `Timer` — ticks on a live interval toward a deadline
|
|
14
|
+
*
|
|
15
|
+
* Use for dashboards, pricing counters, and KPI tiles where the value update
|
|
16
|
+
* itself is meaningful (revenue milestones, live seat counts, real-time stats).
|
|
17
|
+
* Don't use for values that change faster than ~1s — the animation will look
|
|
18
|
+
* like a blur rather than a meaningful transition.
|
|
19
|
+
*
|
|
20
|
+
* Motion: pattern (c) — inline style with var(--duration-base) + var(--ease-spring).
|
|
21
|
+
* Contained within each digit column; no layout shift. Base layer's
|
|
22
|
+
* prefers-reduced-motion rule silences the transition automatically.
|
|
23
|
+
*
|
|
24
|
+
* Accessibility: digits are aria-hidden; the containing span carries
|
|
25
|
+
* aria-label with the formatted value so screen readers announce the final
|
|
26
|
+
* number. aria-live="polite" is the default — value changes are typically
|
|
27
|
+
* meaningful events (a KPI crossed a milestone). Override with
|
|
28
|
+
* aria-live="off" for high-frequency updates.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// --- types ---
|
|
32
|
+
|
|
33
|
+
export interface RollingNumberProps
|
|
34
|
+
extends Omit<React.ComponentProps<"span">, "children"> {
|
|
35
|
+
/** The numeric value to display. Digit columns animate when this changes. */
|
|
36
|
+
value: number
|
|
37
|
+
/** Fixed decimal places to show. When absent, uses the value's natural precision. */
|
|
38
|
+
decimalScale?: number
|
|
39
|
+
/**
|
|
40
|
+
* Force decimalScale digits even for whole numbers (e.g. 42 → "42.00").
|
|
41
|
+
* Requires `decimalScale`. Default false.
|
|
42
|
+
*/
|
|
43
|
+
fixedDecimalScale?: boolean
|
|
44
|
+
/**
|
|
45
|
+
* Thousands separator character (e.g. "," → "1,234,567").
|
|
46
|
+
* Default "" (no separator).
|
|
47
|
+
*/
|
|
48
|
+
thousandSeparator?: string
|
|
49
|
+
/** Static prefix rendered before the number (e.g. "$"). Not animated. */
|
|
50
|
+
prefix?: string
|
|
51
|
+
/** Static suffix rendered after the number (e.g. "%", "k"). Not animated. */
|
|
52
|
+
suffix?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// --- helpers ---
|
|
56
|
+
|
|
57
|
+
type Part = { type: "digit"; value: number } | { type: "static"; char: string }
|
|
58
|
+
|
|
59
|
+
function toParts(
|
|
60
|
+
value: number,
|
|
61
|
+
thousandSeparator: string,
|
|
62
|
+
decimalScale: number | undefined,
|
|
63
|
+
fixedDecimalScale: boolean
|
|
64
|
+
): Part[] {
|
|
65
|
+
let str: string
|
|
66
|
+
if (decimalScale !== undefined) {
|
|
67
|
+
const naturalPlaces = value.toString().split(".")[1]?.length ?? 0
|
|
68
|
+
const places = fixedDecimalScale
|
|
69
|
+
? decimalScale
|
|
70
|
+
: Math.min(decimalScale, naturalPlaces)
|
|
71
|
+
str = value.toFixed(places)
|
|
72
|
+
} else {
|
|
73
|
+
str = String(value)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const [intRaw, decRaw] = str.split(".")
|
|
77
|
+
const intFormatted = thousandSeparator
|
|
78
|
+
? intRaw.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator)
|
|
79
|
+
: intRaw
|
|
80
|
+
const full = intFormatted + (decRaw !== undefined ? "." + decRaw : "")
|
|
81
|
+
|
|
82
|
+
return [...full].map((ch) =>
|
|
83
|
+
ch >= "0" && ch <= "9"
|
|
84
|
+
? { type: "digit" as const, value: Number(ch) }
|
|
85
|
+
: { type: "static" as const, char: ch }
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function formatLabel(
|
|
90
|
+
value: number,
|
|
91
|
+
prefix: string | undefined,
|
|
92
|
+
suffix: string | undefined,
|
|
93
|
+
decimalScale: number | undefined,
|
|
94
|
+
fixedDecimalScale: boolean
|
|
95
|
+
): string {
|
|
96
|
+
let str: string
|
|
97
|
+
if (decimalScale !== undefined) {
|
|
98
|
+
const naturalPlaces = value.toString().split(".")[1]?.length ?? 0
|
|
99
|
+
const places = fixedDecimalScale
|
|
100
|
+
? decimalScale
|
|
101
|
+
: Math.min(decimalScale, naturalPlaces)
|
|
102
|
+
str = value.toFixed(places)
|
|
103
|
+
} else {
|
|
104
|
+
str = String(value)
|
|
105
|
+
}
|
|
106
|
+
return (prefix ?? "") + str + (suffix ?? "")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- digit column ---
|
|
110
|
+
|
|
111
|
+
function DigitColumn({ digit }: { digit: number }) {
|
|
112
|
+
return (
|
|
113
|
+
<span
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
data-slot="rolling-number-digit"
|
|
116
|
+
className="relative inline-block overflow-hidden"
|
|
117
|
+
style={{ height: "1em", lineHeight: "1em" }}
|
|
118
|
+
>
|
|
119
|
+
{/* The inner column is 10em tall (one em per digit 0-9).
|
|
120
|
+
translateY shifts it to reveal the correct digit through the 1em window.
|
|
121
|
+
-digit * 10% of 10em = -digit * 1em — one digit height per step. */}
|
|
122
|
+
<span
|
|
123
|
+
className="flex flex-col"
|
|
124
|
+
style={{
|
|
125
|
+
transform: `translateY(${-digit * 10}%)`,
|
|
126
|
+
transitionProperty: "transform",
|
|
127
|
+
transitionDuration: "var(--duration-base)",
|
|
128
|
+
transitionTimingFunction: "var(--ease-spring)",
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((d) => (
|
|
132
|
+
<span
|
|
133
|
+
key={d}
|
|
134
|
+
style={{
|
|
135
|
+
height: "1em",
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
justifyContent: "center",
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
{d}
|
|
142
|
+
</span>
|
|
143
|
+
))}
|
|
144
|
+
</span>
|
|
145
|
+
</span>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// --- public component ---
|
|
150
|
+
|
|
151
|
+
export function RollingNumber({
|
|
152
|
+
value,
|
|
153
|
+
decimalScale,
|
|
154
|
+
fixedDecimalScale = false,
|
|
155
|
+
thousandSeparator = "",
|
|
156
|
+
prefix,
|
|
157
|
+
suffix,
|
|
158
|
+
className,
|
|
159
|
+
...props
|
|
160
|
+
}: RollingNumberProps) {
|
|
161
|
+
const parts = toParts(value, thousandSeparator, decimalScale, fixedDecimalScale)
|
|
162
|
+
const label = formatLabel(value, prefix, suffix, decimalScale, fixedDecimalScale)
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<span
|
|
166
|
+
data-slot="rolling-number"
|
|
167
|
+
aria-label={label}
|
|
168
|
+
aria-live="polite"
|
|
169
|
+
className={cn(
|
|
170
|
+
"inline-flex items-center tabular-nums",
|
|
171
|
+
className
|
|
172
|
+
)}
|
|
173
|
+
{...props}
|
|
174
|
+
>
|
|
175
|
+
{prefix && (
|
|
176
|
+
<span data-slot="rolling-number-prefix" aria-hidden="true">
|
|
177
|
+
{prefix}
|
|
178
|
+
</span>
|
|
179
|
+
)}
|
|
180
|
+
{parts.map((part, i) =>
|
|
181
|
+
part.type === "digit" ? (
|
|
182
|
+
<DigitColumn key={i} digit={part.value} />
|
|
183
|
+
) : (
|
|
184
|
+
<span
|
|
185
|
+
key={i}
|
|
186
|
+
data-slot="rolling-number-separator"
|
|
187
|
+
aria-hidden="true"
|
|
188
|
+
>
|
|
189
|
+
{part.char}
|
|
190
|
+
</span>
|
|
191
|
+
)
|
|
192
|
+
)}
|
|
193
|
+
{suffix && (
|
|
194
|
+
<span data-slot="rolling-number-suffix" aria-hidden="true">
|
|
195
|
+
{suffix}
|
|
196
|
+
</span>
|
|
197
|
+
)}
|
|
198
|
+
</span>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
@@ -50,12 +50,39 @@ interface PanelProps {
|
|
|
50
50
|
|
|
51
51
|
function Panel({ label, items, checked, onToggle, searchable }: PanelProps) {
|
|
52
52
|
const [filter, setFilter] = React.useState("")
|
|
53
|
+
const [activeIdx, setActiveIdx] = React.useState(-1)
|
|
53
54
|
const listboxId = React.useId()
|
|
54
55
|
|
|
55
56
|
const visible = filter
|
|
56
57
|
? items.filter((it) => it.toLowerCase().includes(filter.toLowerCase()))
|
|
57
58
|
: items
|
|
58
59
|
|
|
60
|
+
// Reset active index when visible list changes (filter or items update)
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setActiveIdx(-1)
|
|
63
|
+
}, [filter, items])
|
|
64
|
+
|
|
65
|
+
function handleKeyDown(e: React.KeyboardEvent<HTMLUListElement>) {
|
|
66
|
+
if (visible.length === 0) return
|
|
67
|
+
if (e.key === "ArrowDown") {
|
|
68
|
+
e.preventDefault()
|
|
69
|
+
setActiveIdx((prev) => (prev + 1) % visible.length)
|
|
70
|
+
} else if (e.key === "ArrowUp") {
|
|
71
|
+
e.preventDefault()
|
|
72
|
+
setActiveIdx((prev) => (prev <= 0 ? visible.length - 1 : prev - 1))
|
|
73
|
+
} else if (e.key === " " || e.key === "Enter") {
|
|
74
|
+
e.preventDefault()
|
|
75
|
+
if (activeIdx >= 0 && activeIdx < visible.length) {
|
|
76
|
+
onToggle(visible[activeIdx])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const activeItemId =
|
|
82
|
+
activeIdx >= 0 && activeIdx < visible.length
|
|
83
|
+
? `${listboxId}-opt-${activeIdx}`
|
|
84
|
+
: undefined
|
|
85
|
+
|
|
59
86
|
return (
|
|
60
87
|
<div className="w-56 min-h-48 max-h-72 rounded-md border border-border bg-background overflow-hidden flex flex-col">
|
|
61
88
|
{/* Panel header */}
|
|
@@ -78,41 +105,49 @@ function Panel({ label, items, checked, onToggle, searchable }: PanelProps) {
|
|
|
78
105
|
</div>
|
|
79
106
|
)}
|
|
80
107
|
|
|
81
|
-
{/* Item list
|
|
108
|
+
{/* Item list — container is the sole focusable target; items use
|
|
109
|
+
aria-activedescendant so screen readers track the active option
|
|
110
|
+
without each item needing its own tabIndex (nested-interactive). */}
|
|
82
111
|
<ul
|
|
83
112
|
id={listboxId}
|
|
84
113
|
role="listbox"
|
|
85
114
|
aria-multiselectable="true"
|
|
86
115
|
aria-label={label}
|
|
87
|
-
|
|
116
|
+
aria-activedescendant={activeItemId}
|
|
117
|
+
tabIndex={0}
|
|
118
|
+
onKeyDown={handleKeyDown}
|
|
119
|
+
className="overflow-y-auto flex-1 py-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
|
|
88
120
|
>
|
|
89
121
|
{visible.length === 0 ? (
|
|
90
|
-
<li
|
|
122
|
+
<li
|
|
123
|
+
role="option"
|
|
124
|
+
aria-disabled="true"
|
|
125
|
+
aria-selected="false"
|
|
126
|
+
className="px-3 py-2 text-sm text-muted-foreground select-none"
|
|
127
|
+
>
|
|
91
128
|
No items
|
|
92
129
|
</li>
|
|
93
130
|
) : (
|
|
94
|
-
visible.map((item) => {
|
|
131
|
+
visible.map((item, idx) => {
|
|
95
132
|
const isChecked = checked.has(item)
|
|
133
|
+
const isActive = idx === activeIdx
|
|
96
134
|
return (
|
|
97
135
|
<li
|
|
98
136
|
key={item}
|
|
137
|
+
id={`${listboxId}-opt-${idx}`}
|
|
99
138
|
role="option"
|
|
100
139
|
aria-selected={isChecked}
|
|
101
|
-
onClick={() =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
e.preventDefault()
|
|
105
|
-
onToggle(item)
|
|
106
|
-
}
|
|
140
|
+
onClick={() => {
|
|
141
|
+
setActiveIdx(idx)
|
|
142
|
+
onToggle(item)
|
|
107
143
|
}}
|
|
108
|
-
tabIndex={0}
|
|
109
144
|
className={cn(
|
|
110
145
|
"flex items-center gap-2 px-2 py-1.5 cursor-pointer select-none text-sm",
|
|
111
146
|
"transition-colors",
|
|
112
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
|
|
113
147
|
isChecked
|
|
114
148
|
? "bg-accent text-accent-foreground"
|
|
115
|
-
: "hover:bg-muted"
|
|
149
|
+
: "hover:bg-muted",
|
|
150
|
+
isActive && "ring-1 ring-ring ring-inset"
|
|
116
151
|
)}
|
|
117
152
|
style={{
|
|
118
153
|
transitionDuration: "var(--duration-fast)",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypingIndicator — three-dot animated is-typing signal for chat and AI
|
|
8
|
+
* response surfaces. Matches the pattern used by Signal, Slack, iMessage,
|
|
9
|
+
* and Ant Design X (Bubble.Typing).
|
|
10
|
+
*
|
|
11
|
+
* Motion: pattern (b) keyframe `typing-dot` defined in build-tokens.cjs,
|
|
12
|
+
* applied per-dot with a staggered `animationDelay` via inline style (pattern
|
|
13
|
+
* c). The three-dot sequence runs at 1.2 s per cycle, 200 ms apart.
|
|
14
|
+
* Reduced-motion: the base-layer `@media (prefers-reduced-motion: reduce)`
|
|
15
|
+
* forces `animation-duration: 0.01ms` — dots snap to their rest state
|
|
16
|
+
* instantly and the indicator reads as a static three-dot ellipsis.
|
|
17
|
+
*
|
|
18
|
+
* Accessibility: the outer span carries `role="status"` + `aria-label` so
|
|
19
|
+
* the typing state is announced politely to screen readers on mount. The dot
|
|
20
|
+
* spans are `aria-hidden` — the dots themselves carry no information; the
|
|
21
|
+
* label does. Pair with an aria-live region or Sonner toast for the actual
|
|
22
|
+
* response text.
|
|
23
|
+
*
|
|
24
|
+
* Ethics contract: no data collected, darkPatternRisk none. The indicator
|
|
25
|
+
* must reflect real async work — never fake a typing animation to add
|
|
26
|
+
* perceived thoughtfulness to an already-computed response (that's deceptive
|
|
27
|
+
* theater, not a loading state).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export interface TypingIndicatorProps
|
|
31
|
+
extends React.ComponentProps<"span"> {
|
|
32
|
+
/** Accessible label for screen readers. Default "Typing". */
|
|
33
|
+
label?: string
|
|
34
|
+
/** Visual size of the dot cluster. Default "default". */
|
|
35
|
+
size?: "sm" | "default" | "lg"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const DOT_SIZES: Record<NonNullable<TypingIndicatorProps["size"]>, string> = {
|
|
39
|
+
sm: "size-1",
|
|
40
|
+
default: "size-1.5",
|
|
41
|
+
lg: "size-2",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const GAP_SIZES: Record<NonNullable<TypingIndicatorProps["size"]>, string> = {
|
|
45
|
+
sm: "gap-0.5",
|
|
46
|
+
default: "gap-1",
|
|
47
|
+
lg: "gap-1.5",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const PADDING_SIZES: Record<NonNullable<TypingIndicatorProps["size"]>, string> = {
|
|
51
|
+
sm: "px-2 py-1.5",
|
|
52
|
+
default: "px-2.5 py-2",
|
|
53
|
+
lg: "px-3 py-2",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function TypingIndicator({
|
|
57
|
+
label = "Typing",
|
|
58
|
+
size = "default",
|
|
59
|
+
className,
|
|
60
|
+
...props
|
|
61
|
+
}: TypingIndicatorProps) {
|
|
62
|
+
return (
|
|
63
|
+
<span
|
|
64
|
+
role="status"
|
|
65
|
+
aria-label={label}
|
|
66
|
+
data-slot="typing-indicator"
|
|
67
|
+
data-size={size}
|
|
68
|
+
className={cn(
|
|
69
|
+
"inline-flex items-center rounded-full bg-muted",
|
|
70
|
+
PADDING_SIZES[size],
|
|
71
|
+
className
|
|
72
|
+
)}
|
|
73
|
+
{...props}
|
|
74
|
+
>
|
|
75
|
+
{/* Dot cluster — aria-hidden; the role=status label carries meaning */}
|
|
76
|
+
<span
|
|
77
|
+
aria-hidden="true"
|
|
78
|
+
className={cn("flex items-center", GAP_SIZES[size])}
|
|
79
|
+
>
|
|
80
|
+
{[0, 1, 2].map((i) => (
|
|
81
|
+
<span
|
|
82
|
+
key={i}
|
|
83
|
+
data-slot="typing-indicator-dot"
|
|
84
|
+
className={cn("rounded-full bg-muted-foreground", DOT_SIZES[size])}
|
|
85
|
+
style={{
|
|
86
|
+
animation: "typing-dot 1.2s ease-in-out infinite",
|
|
87
|
+
animationDelay: `${i * 200}ms`,
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
))}
|
|
91
|
+
</span>
|
|
92
|
+
</span>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { TypingIndicator }
|