@behavioral-agentic-design-system/core 0.22.0 → 0.23.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 +3 -2
- 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 +124 -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/editable.tsx +56 -27
- package/src/components/ui/fieldset.tsx +238 -0
- package/src/components/ui/index.ts +2 -0
- package/src/components/ui/input-group.tsx +194 -0
- package/src/data/docs-index.ts +13 -0
- package/src/stories/Accordion.stories.tsx +21 -0
- package/src/stories/Button.stories.tsx +15 -0
- package/src/stories/CopyButton.stories.tsx +2 -2
- 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 +249 -0
- package/src/stories/InputGroup.stories.tsx +229 -0
- package/src/stories/Label.stories.tsx +2 -2
- 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.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
|
|
5
5
|
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Button } from "./button"
|
|
6
7
|
|
|
7
8
|
type SubmitMode = "blur" | "enter" | "both"
|
|
8
9
|
|
|
@@ -10,6 +11,7 @@ interface EditableContextValue {
|
|
|
10
11
|
editing: boolean
|
|
11
12
|
value: string
|
|
12
13
|
inputRef: React.RefObject<HTMLInputElement | null>
|
|
14
|
+
previewRef: React.RefObject<HTMLDivElement | null>
|
|
13
15
|
startEditing: () => void
|
|
14
16
|
cancelEditing: () => void
|
|
15
17
|
submitEditing: () => void
|
|
@@ -35,6 +37,12 @@ interface EditableProps {
|
|
|
35
37
|
disabled?: boolean
|
|
36
38
|
placeholder?: string
|
|
37
39
|
submitMode?: SubmitMode
|
|
40
|
+
/**
|
|
41
|
+
* Accessible name for the edit-mode input (e.g. "Project name"). Falls back
|
|
42
|
+
* to `placeholder` — pass a real label whenever the placeholder is the
|
|
43
|
+
* generic "Click to edit", or screen readers announce a nameless textbox.
|
|
44
|
+
*/
|
|
45
|
+
label?: string
|
|
38
46
|
children: React.ReactNode
|
|
39
47
|
className?: string
|
|
40
48
|
}
|
|
@@ -48,6 +56,7 @@ function Editable({
|
|
|
48
56
|
disabled = false,
|
|
49
57
|
placeholder = "Click to edit",
|
|
50
58
|
submitMode = "blur",
|
|
59
|
+
label,
|
|
51
60
|
children,
|
|
52
61
|
className,
|
|
53
62
|
}: EditableProps) {
|
|
@@ -55,6 +64,8 @@ function Editable({
|
|
|
55
64
|
const [editing, setEditing] = React.useState(false)
|
|
56
65
|
const [draft, setDraft] = React.useState(defaultValue)
|
|
57
66
|
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
67
|
+
const previewRef = React.useRef<HTMLDivElement>(null)
|
|
68
|
+
const rootRef = React.useRef<HTMLDivElement>(null)
|
|
58
69
|
|
|
59
70
|
const isControlled = valueProp !== undefined
|
|
60
71
|
const value = isControlled ? valueProp : internalValue
|
|
@@ -68,6 +79,17 @@ function Editable({
|
|
|
68
79
|
queueMicrotask(() => inputRef.current?.focus())
|
|
69
80
|
}, [disabled, value, onEditStart])
|
|
70
81
|
|
|
82
|
+
// When edit mode ends, DOM focus may still sit on the now aria-hidden,
|
|
83
|
+
// opacity-0 input (Escape/Enter don't blur) or on a Save/Cancel button that
|
|
84
|
+
// is about to unmount — both strand keyboard focus on nothing. Return focus
|
|
85
|
+
// to the preview, but ONLY if focus is still inside this Editable: a
|
|
86
|
+
// blur-submit triggered by clicking elsewhere must not steal focus back.
|
|
87
|
+
const restoreFocusToPreview = React.useCallback(() => {
|
|
88
|
+
const hadFocusInside = rootRef.current?.contains(document.activeElement)
|
|
89
|
+
if (!hadFocusInside) return
|
|
90
|
+
queueMicrotask(() => previewRef.current?.focus())
|
|
91
|
+
}, [])
|
|
92
|
+
|
|
71
93
|
const submitEditing = React.useCallback(() => {
|
|
72
94
|
if (!editing) return
|
|
73
95
|
const trimmed = draft.trim()
|
|
@@ -75,13 +97,15 @@ function Editable({
|
|
|
75
97
|
if (!isControlled) setInternalValue(committed)
|
|
76
98
|
onValueChange?.(committed)
|
|
77
99
|
onEditEnd?.(committed)
|
|
100
|
+
restoreFocusToPreview()
|
|
78
101
|
setEditing(false)
|
|
79
|
-
}, [editing, draft, value, isControlled, onValueChange, onEditEnd])
|
|
102
|
+
}, [editing, draft, value, isControlled, onValueChange, onEditEnd, restoreFocusToPreview])
|
|
80
103
|
|
|
81
104
|
const cancelEditing = React.useCallback(() => {
|
|
82
105
|
setDraft(value)
|
|
106
|
+
restoreFocusToPreview()
|
|
83
107
|
setEditing(false)
|
|
84
|
-
}, [value])
|
|
108
|
+
}, [value, restoreFocusToPreview])
|
|
85
109
|
|
|
86
110
|
return (
|
|
87
111
|
<EditableContext.Provider
|
|
@@ -89,6 +113,7 @@ function Editable({
|
|
|
89
113
|
editing,
|
|
90
114
|
value,
|
|
91
115
|
inputRef,
|
|
116
|
+
previewRef,
|
|
92
117
|
startEditing,
|
|
93
118
|
cancelEditing,
|
|
94
119
|
submitEditing,
|
|
@@ -98,6 +123,7 @@ function Editable({
|
|
|
98
123
|
}}
|
|
99
124
|
>
|
|
100
125
|
<div
|
|
126
|
+
ref={rootRef}
|
|
101
127
|
data-slot="editable"
|
|
102
128
|
data-editing={editing || undefined}
|
|
103
129
|
data-disabled={disabled || undefined}
|
|
@@ -108,6 +134,7 @@ function Editable({
|
|
|
108
134
|
<input
|
|
109
135
|
ref={inputRef}
|
|
110
136
|
type="text"
|
|
137
|
+
aria-label={label ?? placeholder}
|
|
111
138
|
aria-hidden={!editing}
|
|
112
139
|
tabIndex={editing ? 0 : -1}
|
|
113
140
|
value={draft}
|
|
@@ -131,9 +158,18 @@ function Editable({
|
|
|
131
158
|
}
|
|
132
159
|
}}
|
|
133
160
|
className={cn(
|
|
134
|
-
|
|
161
|
+
// Overlay ONLY the preview area (top of the root), not inset-0 — the root
|
|
162
|
+
// also holds EditableControl (Save/Cancel), and inset-0 stretched the input
|
|
163
|
+
// over those controls, hiding them and ballooning the box. min-h-11 + py-2
|
|
164
|
+
// matches the preview's box so the text doesn't jump on the edit crossfade.
|
|
165
|
+
"absolute inset-x-0 top-0 min-h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground outline-none",
|
|
135
166
|
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
136
|
-
|
|
167
|
+
// The overlay input is only ever visible while editing. A disabled
|
|
168
|
+
// Editable can never enter edit mode, so it must NOT get disabled:opacity-50
|
|
169
|
+
// here — that variant beat the opacity-0 below and un-hid the input at
|
|
170
|
+
// 50%, ghosting it over the (also-50%) preview. Dimming when disabled is
|
|
171
|
+
// the preview's job.
|
|
172
|
+
"disabled:cursor-not-allowed",
|
|
137
173
|
!editing && "pointer-events-none opacity-0"
|
|
138
174
|
)}
|
|
139
175
|
style={{
|
|
@@ -153,15 +189,20 @@ interface EditablePreviewProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
153
189
|
}
|
|
154
190
|
|
|
155
191
|
function EditablePreview({ className, ...props }: EditablePreviewProps) {
|
|
156
|
-
const { editing, value, placeholder, startEditing, disabled } =
|
|
192
|
+
const { editing, value, placeholder, startEditing, disabled, previewRef } =
|
|
157
193
|
useEditableContext()
|
|
158
194
|
|
|
159
195
|
return (
|
|
160
196
|
<div
|
|
197
|
+
ref={previewRef}
|
|
161
198
|
data-slot="editable-preview"
|
|
162
199
|
role="button"
|
|
163
200
|
tabIndex={disabled ? -1 : 0}
|
|
164
201
|
aria-label={`Edit: ${value || placeholder}`}
|
|
202
|
+
// Marks the control disabled for assistive tech AND tells axe to exempt the
|
|
203
|
+
// dimmed (opacity-50) label from the contrast check — disabled controls are
|
|
204
|
+
// WCAG-exempt, but without aria-disabled axe can't know this div is one.
|
|
205
|
+
aria-disabled={disabled || undefined}
|
|
165
206
|
onClick={() => !disabled && startEditing()}
|
|
166
207
|
onKeyDown={(e) => {
|
|
167
208
|
if ((e.key === "Enter" || e.key === " ") && !disabled) {
|
|
@@ -219,7 +260,7 @@ function EditableControl({ className, ...props }: EditableControlProps) {
|
|
|
219
260
|
return (
|
|
220
261
|
<div
|
|
221
262
|
data-slot="editable-control"
|
|
222
|
-
className={cn("flex items-center gap-
|
|
263
|
+
className={cn("flex items-center gap-2 pt-2.5", className)}
|
|
223
264
|
{...props}
|
|
224
265
|
/>
|
|
225
266
|
)
|
|
@@ -233,20 +274,16 @@ interface EditableSubmitProps
|
|
|
233
274
|
function EditableSubmit({ className, children, ...props }: EditableSubmitProps) {
|
|
234
275
|
const { submitEditing } = useEditableContext()
|
|
235
276
|
return (
|
|
236
|
-
|
|
237
|
-
<button
|
|
277
|
+
<Button
|
|
238
278
|
type="button"
|
|
239
279
|
data-slot="editable-submit"
|
|
280
|
+
size="default"
|
|
240
281
|
onClick={submitEditing}
|
|
241
|
-
className={
|
|
242
|
-
"inline-flex min-h-7 items-center rounded-md bg-primary px-2 text-sm font-medium text-primary-foreground",
|
|
243
|
-
"hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
244
|
-
className
|
|
245
|
-
)}
|
|
282
|
+
className={className}
|
|
246
283
|
{...props}
|
|
247
284
|
>
|
|
248
285
|
{children ?? "Save"}
|
|
249
|
-
</
|
|
286
|
+
</Button>
|
|
250
287
|
)
|
|
251
288
|
}
|
|
252
289
|
|
|
@@ -262,25 +299,17 @@ function EditableCancel({
|
|
|
262
299
|
}: EditableCancelProps) {
|
|
263
300
|
const { cancelEditing } = useEditableContext()
|
|
264
301
|
return (
|
|
265
|
-
|
|
266
|
-
<button
|
|
302
|
+
<Button
|
|
267
303
|
type="button"
|
|
268
304
|
data-slot="editable-cancel"
|
|
305
|
+
variant="ghost"
|
|
306
|
+
size="default"
|
|
269
307
|
onClick={cancelEditing}
|
|
270
|
-
className={
|
|
271
|
-
"inline-flex min-h-7 items-center rounded-md px-2 text-sm font-medium text-muted-foreground",
|
|
272
|
-
"hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
273
|
-
className
|
|
274
|
-
)}
|
|
275
|
-
style={{
|
|
276
|
-
transitionProperty: "background-color, color",
|
|
277
|
-
transitionDuration: "var(--duration-fast)",
|
|
278
|
-
transitionTimingFunction: "var(--ease-out)",
|
|
279
|
-
}}
|
|
308
|
+
className={className}
|
|
280
309
|
{...props}
|
|
281
310
|
>
|
|
282
311
|
{children ?? "Cancel"}
|
|
283
|
-
</
|
|
312
|
+
</Button>
|
|
284
313
|
)
|
|
285
314
|
}
|
|
286
315
|
|