@behavioral-agentic-design-system/core 0.22.0 → 0.24.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 +6 -4
- package/scripts/size-audit.cjs +147 -0
- package/src/api/layers/file.ts +0 -1
- package/src/app/layout.tsx +29 -4
- package/src/app/opengraph-image.tsx +103 -0
- package/src/app/preview/components/page.tsx +405 -5
- package/src/app/shell.tsx +31 -7
- package/src/components/customize-tab.tsx +111 -139
- package/src/components/home-tab.tsx +7 -14
- package/src/components/layers-tab.tsx +5 -0
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/ui/copy-button.tsx +2 -2
- package/src/components/ui/data-list.tsx +169 -0
- package/src/components/ui/editable.tsx +56 -27
- package/src/components/ui/fieldset.tsx +244 -0
- package/src/components/ui/index.ts +4 -0
- package/src/components/ui/input-group.tsx +204 -0
- package/src/components/ui/qr-code.tsx +107 -0
- package/src/data/docs-index.ts +14 -0
- package/src/stories/Accordion.stories.tsx +21 -0
- package/src/stories/Button.stories.tsx +15 -0
- package/src/stories/CopyButton.stories.tsx +3 -3
- package/src/stories/DataList.stories.tsx +160 -0
- package/src/stories/Dialog.stories.tsx +33 -0
- package/src/stories/Editable.stories.tsx +34 -7
- package/src/stories/Field.stories.tsx +1 -1
- package/src/stories/Fieldset.stories.tsx +253 -0
- package/src/stories/InputGroup.stories.tsx +227 -0
- package/src/stories/Label.stories.tsx +2 -2
- package/src/stories/QrCode.stories.tsx +146 -0
- package/src/stories/Tabs.stories.tsx +24 -0
- package/src/styles.css +0 -12
- package/src/tokens.json +45 -49
|
@@ -84,41 +84,50 @@ function ColorSwatch({
|
|
|
84
84
|
const currentHex = overrides[variable]?.toUpperCase();
|
|
85
85
|
const entries = Object.entries(options);
|
|
86
86
|
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
// wheelHex drives the HexColorPicker (always a valid 6-char hex).
|
|
88
|
+
// inputValue leads the hex input and may be incomplete while the user types.
|
|
89
|
+
const [wheelHex, setWheelHex] = useState(currentHex ?? "#808080");
|
|
90
|
+
const [inputValue, setInputValue] = useState(currentHex ?? "");
|
|
91
|
+
|
|
92
|
+
// True when the current wheelHex already exists in the brand palette.
|
|
93
|
+
const inPalette = useMemo(
|
|
94
|
+
() =>
|
|
95
|
+
entries.some(([, opt]) => {
|
|
96
|
+
const swatch = (opt.swatch ?? opt.primary ?? "").toUpperCase();
|
|
97
|
+
return swatch !== "" && swatch === wheelHex;
|
|
98
|
+
}),
|
|
99
|
+
[entries, wheelHex],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Apply a validated hex to the token and sync both local states.
|
|
103
|
+
const applyHex = (hex: string) => {
|
|
104
|
+
const upper = hex.toUpperCase();
|
|
105
|
+
setWheelHex(upper);
|
|
106
|
+
setInputValue(upper);
|
|
107
|
+
setToken(variable, upper);
|
|
103
108
|
};
|
|
104
109
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!id) {
|
|
113
|
-
setAddError("Could not add color");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
setToken(variable, value.toUpperCase());
|
|
117
|
-
resetAddState();
|
|
110
|
+
const handleReset = () => {
|
|
111
|
+
resetToken(variable);
|
|
112
|
+
// Chart vars are written inline by use-global-primary-color; clearing the
|
|
113
|
+
// override here won't restore the brand-derived ramp without this call.
|
|
114
|
+
if (variable.startsWith("--chart-")) reapplyChartRamp();
|
|
115
|
+
setWheelHex("#808080");
|
|
116
|
+
setInputValue("");
|
|
118
117
|
};
|
|
119
118
|
|
|
120
119
|
return (
|
|
121
|
-
<Popover
|
|
120
|
+
<Popover
|
|
121
|
+
onOpenChange={(open) => {
|
|
122
|
+
if (open) {
|
|
123
|
+
// Sync to the current override each time the popover opens so the
|
|
124
|
+
// wheel reflects the live token value rather than stale local state.
|
|
125
|
+
const cur = overrides[variable]?.toUpperCase();
|
|
126
|
+
setWheelHex(cur ?? "#808080");
|
|
127
|
+
setInputValue(cur ?? "");
|
|
128
|
+
}
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
122
131
|
<PopoverTrigger asChild>
|
|
123
132
|
<button
|
|
124
133
|
type="button"
|
|
@@ -138,129 +147,91 @@ function ColorSwatch({
|
|
|
138
147
|
<PopoverContent align="start" className="w-72 p-3">
|
|
139
148
|
<div className="flex items-center justify-between gap-2 mb-3">
|
|
140
149
|
<p className="text-xs font-mono text-muted-foreground truncate">{variable}</p>
|
|
141
|
-
{
|
|
150
|
+
{isOverridden && (
|
|
142
151
|
<button
|
|
143
152
|
type="button"
|
|
144
|
-
onClick={
|
|
145
|
-
resetToken(variable);
|
|
146
|
-
// Chart vars are written inline by use-global-primary-color
|
|
147
|
-
// so clearing the override here doesn't put the live --chart-N
|
|
148
|
-
// back into a brand-derived state — call back into the hook
|
|
149
|
-
// to re-evaluate the ramp against the current --primary.
|
|
150
|
-
if (variable.startsWith("--chart-")) {
|
|
151
|
-
reapplyChartRamp();
|
|
152
|
-
}
|
|
153
|
-
}}
|
|
153
|
+
onClick={handleReset}
|
|
154
154
|
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
155
155
|
>
|
|
156
156
|
<RotateCcw className="h-3 w-3" strokeWidth={1.5} />
|
|
157
157
|
Reset
|
|
158
158
|
</button>
|
|
159
159
|
)}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
{/* Color wheel — always visible; no sub-flow required */}
|
|
163
|
+
<HexColorPicker
|
|
164
|
+
style={{ width: "100%", height: "180px" }}
|
|
165
|
+
color={isValidHex(wheelHex) ? wheelHex : "#808080"}
|
|
166
|
+
onChange={(c) => applyHex(c)}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
{/* Hex input synced with the wheel + save-to-palette when not already there */}
|
|
170
|
+
<div className="flex items-center gap-2 mt-2">
|
|
171
|
+
<Input
|
|
172
|
+
value={inputValue}
|
|
173
|
+
onChange={(e) => {
|
|
174
|
+
setInputValue(e.target.value);
|
|
175
|
+
if (isValidHex(e.target.value.trim())) {
|
|
176
|
+
applyHex(e.target.value.trim());
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
placeholder="#1F1F1F"
|
|
180
|
+
className="h-9 flex-1 min-w-0 font-mono text-sm"
|
|
181
|
+
/>
|
|
182
|
+
{!inPalette && isValidHex(wheelHex) && (
|
|
183
|
+
<Button
|
|
165
184
|
type="button"
|
|
166
|
-
|
|
167
|
-
|
|
185
|
+
size="icon"
|
|
186
|
+
variant="outline"
|
|
187
|
+
className="h-9 w-9 shrink-0"
|
|
188
|
+
onClick={() => addCustomSilent(wheelHex)}
|
|
189
|
+
title="Save to brand palette"
|
|
168
190
|
>
|
|
169
|
-
|
|
170
|
-
</
|
|
191
|
+
<Plus className="h-4 w-4" strokeWidth={1.5} />
|
|
192
|
+
</Button>
|
|
171
193
|
)}
|
|
172
194
|
</div>
|
|
173
195
|
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}}
|
|
197
|
-
onKeyDown={(e) => {
|
|
198
|
-
if (e.key === "Enter") handleAddAndApply();
|
|
199
|
-
}}
|
|
200
|
-
placeholder="#1F1F1F"
|
|
201
|
-
className="h-9 flex-1 min-w-0 font-mono text-sm"
|
|
202
|
-
/>
|
|
203
|
-
<Button size="sm" onClick={handleAddAndApply}>
|
|
204
|
-
Add
|
|
205
|
-
</Button>
|
|
206
|
-
</div>
|
|
207
|
-
{addError && <span className="text-xs text-destructive">{addError}</span>}
|
|
208
|
-
<p className="text-xs text-muted-foreground">
|
|
209
|
-
Saved to your brand colors and applied here.
|
|
210
|
-
</p>
|
|
211
|
-
</div>
|
|
212
|
-
) : (
|
|
213
|
-
<div className="grid grid-cols-4 gap-2">
|
|
214
|
-
{entries.map(([key, opt]) => {
|
|
215
|
-
const swatch = opt.swatch ?? opt.primary;
|
|
216
|
-
const isActive =
|
|
217
|
-
currentHex !== undefined &&
|
|
218
|
-
currentHex === (swatch ?? "").toUpperCase();
|
|
219
|
-
return (
|
|
220
|
-
<button
|
|
221
|
-
key={key}
|
|
222
|
-
type="button"
|
|
223
|
-
onClick={() => setToken(variable, swatch)}
|
|
224
|
-
title={`${opt.label} · ${swatch}`}
|
|
225
|
-
className={`group/sw flex flex-col items-center gap-1.5 rounded-md border p-2 transition-all ${
|
|
226
|
-
isActive
|
|
227
|
-
? "border-primary ring-2 ring-primary/30"
|
|
228
|
-
: "border-border hover:border-primary/40"
|
|
229
|
-
}`}
|
|
196
|
+
{/* Brand color presets — clicking applies the color and syncs the wheel */}
|
|
197
|
+
<div className="grid grid-cols-4 gap-2 mt-3">
|
|
198
|
+
{entries.map(([key, opt]) => {
|
|
199
|
+
const swatch = opt.swatch ?? opt.primary;
|
|
200
|
+
const isActive =
|
|
201
|
+
swatch != null && swatch.toUpperCase() === wheelHex;
|
|
202
|
+
return (
|
|
203
|
+
<button
|
|
204
|
+
key={key}
|
|
205
|
+
type="button"
|
|
206
|
+
onClick={() => { if (swatch) applyHex(swatch); }}
|
|
207
|
+
aria-label={`${opt.label} — ${swatch}${isActive ? ", selected" : ""}`}
|
|
208
|
+
aria-pressed={isActive}
|
|
209
|
+
className={`group/sw flex flex-col items-center gap-1.5 rounded-md border p-2 transition-all ${
|
|
210
|
+
isActive
|
|
211
|
+
? "border-primary ring-2 ring-primary/30"
|
|
212
|
+
: "border-border hover:border-primary/40"
|
|
213
|
+
}`}
|
|
214
|
+
>
|
|
215
|
+
<div
|
|
216
|
+
className="relative h-7 w-7 rounded-full border border-border/50"
|
|
217
|
+
style={{ backgroundColor: swatch }}
|
|
230
218
|
>
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
);
|
|
248
|
-
})}
|
|
249
|
-
<button
|
|
250
|
-
type="button"
|
|
251
|
-
onClick={() => setShowAdd(true)}
|
|
252
|
-
title="Add a new brand color and apply it here"
|
|
253
|
-
className="group/sw flex flex-col items-center gap-1.5 rounded-md border border-dashed border-border p-2 transition-all hover:border-primary/40"
|
|
254
|
-
>
|
|
255
|
-
<div className="flex h-7 w-7 items-center justify-center rounded-full border border-dashed border-border/60 text-muted-foreground group-hover/sw:text-foreground">
|
|
256
|
-
<Plus className="h-3.5 w-3.5" strokeWidth={1.5} />
|
|
257
|
-
</div>
|
|
258
|
-
<span className="text-xs leading-tight text-muted-foreground group-hover/sw:text-foreground truncate w-full text-center">
|
|
259
|
-
Add
|
|
260
|
-
</span>
|
|
261
|
-
</button>
|
|
262
|
-
</div>
|
|
263
|
-
)}
|
|
219
|
+
{isActive && (
|
|
220
|
+
<Check
|
|
221
|
+
aria-hidden="true"
|
|
222
|
+
className="absolute inset-0 m-auto h-3.5 w-3.5"
|
|
223
|
+
style={{ color: opt.swatchForeground ?? opt.primaryForeground }}
|
|
224
|
+
strokeWidth={1.5}
|
|
225
|
+
/>
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
<span className="text-xs leading-tight truncate w-full text-center">
|
|
229
|
+
{opt.label}
|
|
230
|
+
</span>
|
|
231
|
+
</button>
|
|
232
|
+
);
|
|
233
|
+
})}
|
|
234
|
+
</div>
|
|
264
235
|
</PopoverContent>
|
|
265
236
|
</Popover>
|
|
266
237
|
);
|
|
@@ -518,6 +489,7 @@ function BrandColorCard({
|
|
|
518
489
|
>
|
|
519
490
|
{isActive && (
|
|
520
491
|
<Check
|
|
492
|
+
aria-hidden="true"
|
|
521
493
|
className="absolute inset-0 m-auto h-5 w-5"
|
|
522
494
|
style={{ color: swatchFg }}
|
|
523
495
|
strokeWidth={1.5}
|
|
@@ -250,7 +250,7 @@ function MetricPill({
|
|
|
250
250
|
<span className="font-mono text-2xl font-semibold tracking-tight tabular-nums">
|
|
251
251
|
{value}
|
|
252
252
|
</span>
|
|
253
|
-
<span className="text-xs uppercase tracking-wide text-
|
|
253
|
+
<span className="text-xs uppercase tracking-wide text-foreground">
|
|
254
254
|
{label}
|
|
255
255
|
</span>
|
|
256
256
|
</div>
|
|
@@ -315,7 +315,7 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
|
|
|
315
315
|
<Separator />
|
|
316
316
|
|
|
317
317
|
<section className="flex flex-col gap-4">
|
|
318
|
-
<h2 className="text-sm font-semibold uppercase tracking-wide text-
|
|
318
|
+
<h2 className="text-sm font-semibold uppercase tracking-wide text-foreground">
|
|
319
319
|
What ships today
|
|
320
320
|
</h2>
|
|
321
321
|
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
|
@@ -341,18 +341,11 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
|
|
|
341
341
|
{STARTER_CARDS.map((card) => {
|
|
342
342
|
const Icon = card.icon;
|
|
343
343
|
return (
|
|
344
|
-
<
|
|
344
|
+
<button
|
|
345
345
|
key={card.id}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
onKeyDown={(e) => {
|
|
350
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
351
|
-
e.preventDefault();
|
|
352
|
-
openDocAt(card.path);
|
|
353
|
-
}
|
|
354
|
-
}}
|
|
355
|
-
className="group cursor-pointer transition-colors hover:border-primary/40 hover:bg-accent/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
346
|
+
type="button"
|
|
347
|
+
onClick={() => openDocAt(card.path)} // lint-disable: card-bypass — whole card is a click target, so it must be a <button> for keyboard activation, not a <Card> div
|
|
348
|
+
className="flex flex-col gap-4 rounded-lg border bg-card text-card-foreground shadow-sm group cursor-pointer text-left w-full transition-colors hover:border-primary/40 hover:bg-accent/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
356
349
|
style={{
|
|
357
350
|
transitionDuration: "var(--duration-fast)",
|
|
358
351
|
transitionTimingFunction: "var(--ease-out)",
|
|
@@ -383,7 +376,7 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
|
|
|
383
376
|
/>
|
|
384
377
|
</div>
|
|
385
378
|
</CardContent>
|
|
386
|
-
</
|
|
379
|
+
</button>
|
|
387
380
|
);
|
|
388
381
|
})}
|
|
389
382
|
</div>
|
|
@@ -163,6 +163,11 @@ export function LayersTab() {
|
|
|
163
163
|
setStatus("idle");
|
|
164
164
|
setStatusMessage("");
|
|
165
165
|
|
|
166
|
+
// Markdown files default to the rendered preview so they're never blank.
|
|
167
|
+
if (isMarkdown(activePath)) {
|
|
168
|
+
setViewMode("preview");
|
|
169
|
+
}
|
|
170
|
+
|
|
166
171
|
// Synthetic semantic-tokens view: read tokens.json (the only non-layer
|
|
167
172
|
// path the file route allows) and pull the theme.light / theme.dark
|
|
168
173
|
// maps into a name → {light, dark} table. Always read-only.
|
|
@@ -75,7 +75,7 @@ function CopyButton({
|
|
|
75
75
|
{/* In labeled mode this span provides the button's accessible name — not aria-hidden */}
|
|
76
76
|
<span
|
|
77
77
|
className={cn(
|
|
78
|
-
"inline-flex items-center gap-
|
|
78
|
+
"inline-flex items-center gap-1.5 transition-all",
|
|
79
79
|
copied ? "opacity-0 scale-75" : "opacity-100 scale-100"
|
|
80
80
|
)}
|
|
81
81
|
style={{
|
|
@@ -90,7 +90,7 @@ function CopyButton({
|
|
|
90
90
|
{/* Always hidden — state announced by the aria-live region */}
|
|
91
91
|
<span
|
|
92
92
|
className={cn(
|
|
93
|
-
"absolute inset-0 inline-flex items-center justify-center gap-
|
|
93
|
+
"absolute inset-0 inline-flex items-center justify-center gap-1.5 text-[var(--success)] transition-all",
|
|
94
94
|
copied ? "opacity-100 scale-100" : "opacity-0 scale-75"
|
|
95
95
|
)}
|
|
96
96
|
style={{
|
|
@@ -0,0 +1,169 @@
|
|
|
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 key–value list primitive. Renders a native <dl> with <dt>/<dd>
|
|
10
|
+
* pairs, so screen readers announce a description list and associate each
|
|
11
|
+
* term with its description — semantics a div grid or the <ul>-based List
|
|
12
|
+
* primitive cannot produce.
|
|
13
|
+
*
|
|
14
|
+
* Use DataList for read-only detail surfaces: profile panels, invoice and
|
|
15
|
+
* order summaries, settings recaps, metadata blocks, confirmation review
|
|
16
|
+
* steps. It is display-only — no interaction, no focus, no motion. For
|
|
17
|
+
* editable values compose Editable or CopyButton inside DataListValue; for
|
|
18
|
+
* tabular column data use Table.
|
|
19
|
+
*
|
|
20
|
+
* <DataList orientation="horizontal">
|
|
21
|
+
* <DataListItem>
|
|
22
|
+
* <DataListLabel>Billing email</DataListLabel>
|
|
23
|
+
* <DataListValue>jordan@reeves.design</DataListValue>
|
|
24
|
+
* </DataListItem>
|
|
25
|
+
* </DataList>
|
|
26
|
+
*
|
|
27
|
+
* Orientation "vertical" (default) stacks label over value; "horizontal"
|
|
28
|
+
* lays each pair on a grid row with the label column aligned across ALL
|
|
29
|
+
* rows via CSS subgrid (root owns the two-column track, each item spans it
|
|
30
|
+
* with grid-cols-subgrid). Browsers without subgrid degrade to a stacked
|
|
31
|
+
* row — readable, non-breaking.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
type DataListContextValue = {
|
|
35
|
+
orientation: "vertical" | "horizontal";
|
|
36
|
+
size: "sm" | "default" | "lg";
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const DataListContext = React.createContext<DataListContextValue>({
|
|
40
|
+
orientation: "vertical",
|
|
41
|
+
size: "default",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function useDataListContext() {
|
|
45
|
+
return React.useContext(DataListContext);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const dataListVariants = cva("min-w-0", {
|
|
49
|
+
variants: {
|
|
50
|
+
orientation: {
|
|
51
|
+
// Stacked pairs; the root is a simple column.
|
|
52
|
+
vertical: "flex flex-col",
|
|
53
|
+
// Root owns the two-column track (label auto-sized, value fills);
|
|
54
|
+
// items span it with subgrid so the label column aligns across rows.
|
|
55
|
+
horizontal: "grid grid-cols-[auto_1fr] gap-x-6",
|
|
56
|
+
},
|
|
57
|
+
size: {
|
|
58
|
+
sm: "",
|
|
59
|
+
default: "",
|
|
60
|
+
lg: "",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
compoundVariants: [
|
|
64
|
+
{ orientation: "vertical", size: "sm", className: "gap-3" },
|
|
65
|
+
{ orientation: "vertical", size: "default", className: "gap-4" },
|
|
66
|
+
{ orientation: "vertical", size: "lg", className: "gap-5" },
|
|
67
|
+
{ orientation: "horizontal", size: "sm", className: "gap-y-2" },
|
|
68
|
+
{ orientation: "horizontal", size: "default", className: "gap-y-3" },
|
|
69
|
+
{ orientation: "horizontal", size: "lg", className: "gap-y-4" },
|
|
70
|
+
],
|
|
71
|
+
defaultVariants: { orientation: "vertical", size: "default" },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export interface DataListProps
|
|
75
|
+
extends React.ComponentProps<"dl">,
|
|
76
|
+
VariantProps<typeof dataListVariants> {}
|
|
77
|
+
|
|
78
|
+
function DataList({
|
|
79
|
+
className,
|
|
80
|
+
orientation = "vertical",
|
|
81
|
+
size = "default",
|
|
82
|
+
...props
|
|
83
|
+
}: DataListProps) {
|
|
84
|
+
const ctx = React.useMemo<DataListContextValue>(
|
|
85
|
+
() => ({ orientation: orientation ?? "vertical", size: size ?? "default" }),
|
|
86
|
+
[orientation, size],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<DataListContext.Provider value={ctx}>
|
|
91
|
+
<dl
|
|
92
|
+
data-slot="data-list"
|
|
93
|
+
data-orientation={ctx.orientation}
|
|
94
|
+
className={cn(dataListVariants({ orientation, size }), className)}
|
|
95
|
+
{...props}
|
|
96
|
+
/>
|
|
97
|
+
</DataListContext.Provider>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* One term–description pair. A <div> is spec-valid inside <dl> for grouping
|
|
103
|
+
* a <dt> with its <dd>, and is transparent to the accessibility tree.
|
|
104
|
+
*/
|
|
105
|
+
function DataListItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
106
|
+
const { orientation } = useDataListContext();
|
|
107
|
+
return (
|
|
108
|
+
<div
|
|
109
|
+
data-slot="data-list-item"
|
|
110
|
+
className={cn(
|
|
111
|
+
"min-w-0",
|
|
112
|
+
orientation === "horizontal"
|
|
113
|
+
? // Span the root's two-column track; subgrid keeps every row's
|
|
114
|
+
// label column aligned. No-subgrid browsers fall back to a
|
|
115
|
+
// stacked block row.
|
|
116
|
+
"col-span-2 grid grid-cols-subgrid items-baseline"
|
|
117
|
+
: "flex flex-col gap-1",
|
|
118
|
+
className,
|
|
119
|
+
)}
|
|
120
|
+
{...props}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The term (<dt>) — muted, medium weight. */
|
|
126
|
+
function DataListLabel({ className, ...props }: React.ComponentProps<"dt">) {
|
|
127
|
+
const { size } = useDataListContext();
|
|
128
|
+
return (
|
|
129
|
+
<dt
|
|
130
|
+
data-slot="data-list-label"
|
|
131
|
+
className={cn(
|
|
132
|
+
"font-medium text-muted-foreground",
|
|
133
|
+
// BADS scale: text-xs = 14px (AAA floor), text-sm = 16px.
|
|
134
|
+
size === "lg" ? "text-sm" : "text-xs",
|
|
135
|
+
className,
|
|
136
|
+
)}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The description (<dd>). Values are arbitrary runtime strings (emails,
|
|
144
|
+
* URLs, IDs), so the long-label overflow contract applies: min-w-0 +
|
|
145
|
+
* overflow-wrap anywhere. m-0 defensively clears the UA stylesheet's
|
|
146
|
+
* <dd> start margin outside preflight contexts.
|
|
147
|
+
*/
|
|
148
|
+
function DataListValue({ className, ...props }: React.ComponentProps<"dd">) {
|
|
149
|
+
const { size } = useDataListContext();
|
|
150
|
+
return (
|
|
151
|
+
<dd
|
|
152
|
+
data-slot="data-list-value"
|
|
153
|
+
className={cn(
|
|
154
|
+
"m-0 min-w-0 text-foreground [overflow-wrap:anywhere]",
|
|
155
|
+
size === "lg" ? "text-base" : "text-sm",
|
|
156
|
+
className,
|
|
157
|
+
)}
|
|
158
|
+
{...props}
|
|
159
|
+
/>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export {
|
|
164
|
+
DataList,
|
|
165
|
+
DataListItem,
|
|
166
|
+
DataListLabel,
|
|
167
|
+
DataListValue,
|
|
168
|
+
dataListVariants,
|
|
169
|
+
};
|