@behavioral-agentic-design-system/core 0.47.0 → 0.48.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behavioral-agentic-design-system/core",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
5
5
  "license": "MIT",
6
6
  "author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
@@ -124,6 +124,7 @@ import { FloatingPanel } from "@behavioral-agentic-design-system/core/components
124
124
  import { NumberInput } from "@behavioral-agentic-design-system/core/components/ui/number-input";
125
125
  import { InlineEdit } from "@behavioral-agentic-design-system/core/components/ui/inline-edit";
126
126
  import { OTPInput } from "@behavioral-agentic-design-system/core/components/ui/otp-input";
127
+ import { NumberField } from "@behavioral-agentic-design-system/core/components/ui/number-field";
127
128
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@behavioral-agentic-design-system/core/components/ui/collapsible";
128
129
  import { ChevronDownIcon } from "lucide-react";
129
130
  import { FileUpload } from "@behavioral-agentic-design-system/core/components/ui/file-upload";
@@ -6451,6 +6452,9 @@ export default function ComponentsPreview() {
6451
6452
  <Section title="Collapsible">
6452
6453
  <CollapsibleShowcase />
6453
6454
  </Section>
6455
+ <Section title="NumberField">
6456
+ <NumberFieldShowcase />
6457
+ </Section>
6454
6458
  </div>
6455
6459
  </div>
6456
6460
  );
@@ -15371,3 +15375,88 @@ function CollapsibleShowcase() {
15371
15375
  </div>
15372
15376
  )
15373
15377
  }
15378
+
15379
+ function NumberFieldShowcase() {
15380
+ const [quantity, setQuantity] = React.useState(2);
15381
+ const [price, setPrice] = React.useState(49.0);
15382
+ const [discount, setDiscount] = React.useState(25);
15383
+ const total = quantity * price * (1 - discount / 100);
15384
+
15385
+ return (
15386
+ <div className="space-y-8">
15387
+ <div className="flex flex-wrap gap-6 items-start">
15388
+ <div className="w-56">
15389
+ <NumberField label="Quantity" defaultValue={1} min={1} max={99} size="sm" />
15390
+ </div>
15391
+ <div className="w-56">
15392
+ <NumberField label="Quantity" defaultValue={1} min={1} max={99} />
15393
+ </div>
15394
+ <div className="w-56">
15395
+ <NumberField label="Quantity" defaultValue={1} min={1} max={99} size="lg" />
15396
+ </div>
15397
+ </div>
15398
+ <div className="flex flex-wrap gap-6 items-start">
15399
+ <div className="w-64">
15400
+ <NumberField
15401
+ label="Price"
15402
+ defaultValue={29.99}
15403
+ step={0.01}
15404
+ min={0}
15405
+ formatOptions={{ style: "currency", currency: "USD" }}
15406
+ helperText="Enter price before tax"
15407
+ />
15408
+ </div>
15409
+ <div className="w-64">
15410
+ <NumberField
15411
+ label="Discount"
15412
+ defaultValue={0}
15413
+ min={0}
15414
+ max={100}
15415
+ step={5}
15416
+ formatOptions={{ style: "percent", maximumFractionDigits: 0 }}
15417
+ errorMessage="Value must be between 0 and 100"
15418
+ />
15419
+ </div>
15420
+ <div className="w-64">
15421
+ <NumberField label="Seat count" defaultValue={5} disabled helperText="Set during checkout" />
15422
+ </div>
15423
+ </div>
15424
+ <div className="w-80 flex flex-col gap-5 rounded-lg border p-5">
15425
+ <p className="text-sm font-medium text-foreground">Order summary</p>
15426
+ <NumberField
15427
+ label="Quantity"
15428
+ value={quantity}
15429
+ onChange={setQuantity}
15430
+ min={1}
15431
+ max={99}
15432
+ required
15433
+ helperText="Maximum 99 per order"
15434
+ />
15435
+ <NumberField
15436
+ label="Unit price"
15437
+ value={price}
15438
+ onChange={setPrice}
15439
+ step={0.01}
15440
+ min={0}
15441
+ formatOptions={{ style: "currency", currency: "USD" }}
15442
+ />
15443
+ <NumberField
15444
+ label="Discount"
15445
+ value={discount}
15446
+ onChange={setDiscount}
15447
+ min={0}
15448
+ max={100}
15449
+ step={5}
15450
+ formatOptions={{ style: "percent", maximumFractionDigits: 0 }}
15451
+ helperText="Applied at checkout"
15452
+ />
15453
+ <div className="flex justify-between text-sm pt-2 border-t border-border">
15454
+ <span className="text-muted-foreground">Total</span>
15455
+ <span className="font-medium tabular-nums">
15456
+ {new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(total)}
15457
+ </span>
15458
+ </div>
15459
+ </div>
15460
+ </div>
15461
+ )
15462
+ }
@@ -0,0 +1,390 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { Minus, Plus } from "lucide-react";
6
+
7
+ import { cn } from "../../lib/utils";
8
+ import { clamp } from "../../lib/clamp";
9
+ import { Label } from "./label";
10
+
11
+ // ─── Variants ─────────────────────────────────────────────────────────────────
12
+
13
+ const numberFieldControlVariants = cva(
14
+ [
15
+ "flex items-stretch overflow-hidden",
16
+ "rounded-md border border-input bg-transparent shadow-xs",
17
+ "transition-[color,box-shadow]",
18
+ // raw-value-ok: ring-[3px] matches the system-wide BADS focus-ring convention (3px not in Tailwind's default ring-width scale)
19
+ "focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
20
+ "data-[invalid=true]:border-destructive data-[invalid=true]:focus-within:ring-destructive/50",
21
+ ],
22
+ {
23
+ variants: {
24
+ size: {
25
+ sm: "h-9 text-sm",
26
+ default: "h-11 text-base",
27
+ lg: "h-14 text-xl",
28
+ },
29
+ },
30
+ defaultVariants: { size: "default" },
31
+ }
32
+ );
33
+
34
+ // ─── Types ────────────────────────────────────────────────────────────────────
35
+
36
+ export interface NumberFieldProps
37
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> {
38
+ /** Visible form label (required for accessibility) */
39
+ label: string;
40
+ /** Controlled value */
41
+ value?: number;
42
+ /** Uncontrolled default */
43
+ defaultValue?: number;
44
+ /** Fires with the new number after each committed change */
45
+ onChange?: (value: number) => void;
46
+ min?: number;
47
+ max?: number;
48
+ /** Amount to increment/decrement per step (default 1) */
49
+ step?: number;
50
+ /** Size variant */
51
+ size?: VariantProps<typeof numberFieldControlVariants>["size"];
52
+ /** Locale for Intl.NumberFormat display (e.g. "en-US", "de-DE"). Defaults to the browser locale. */
53
+ locale?: string;
54
+ /** Options passed to Intl.NumberFormat for display (currency, percent, notation, etc.) */
55
+ formatOptions?: Intl.NumberFormatOptions;
56
+ /** Helper text shown below the field */
57
+ helperText?: React.ReactNode;
58
+ /** Error message. When provided, the field renders as invalid. */
59
+ errorMessage?: React.ReactNode;
60
+ /** Mark the field as required */
61
+ required?: boolean;
62
+ /** Disable the field */
63
+ disabled?: boolean;
64
+ /** Override auto-generated id */
65
+ id?: string;
66
+ /** HTML name for form serialization */
67
+ name?: string;
68
+ }
69
+
70
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
71
+
72
+ function decimalsOf(n: number): number {
73
+ if (!Number.isFinite(n)) return 0;
74
+ const [, frac = ""] = String(n).split(".");
75
+ return frac.length;
76
+ }
77
+
78
+ function roundTo(n: number, decimals: number): number {
79
+ return Number(n.toFixed(Math.min(decimals, 12)));
80
+ }
81
+
82
+ // ─── NumberField ──────────────────────────────────────────────────────────────
83
+
84
+ /**
85
+ * A self-contained number form field: visible label, stepper spinbutton,
86
+ * optional helper text, optional error message, and optional Intl.NumberFormat
87
+ * display (currency, percentage, notation, etc.).
88
+ *
89
+ * Unlike NumberInput (stepper-only), NumberField owns its accessible label and
90
+ * description infrastructure. Use it wherever the spinbutton appears inside a
91
+ * form layout; use NumberInput directly only inside a custom Field composition.
92
+ *
93
+ * @example
94
+ * // Plain quantity field
95
+ * <NumberField label="Quantity" min={1} max={99} />
96
+ *
97
+ * @example
98
+ * // Currency display
99
+ * <NumberField
100
+ * label="Price"
101
+ * defaultValue={29.99}
102
+ * step={0.01}
103
+ * formatOptions={{ style: "currency", currency: "USD" }}
104
+ * helperText="Displayed price before tax"
105
+ * />
106
+ *
107
+ * @example
108
+ * // Percentage display
109
+ * <NumberField
110
+ * label="Discount"
111
+ * defaultValue={25}
112
+ * min={0}
113
+ * max={100}
114
+ * formatOptions={{ style: "percent", maximumFractionDigits: 0 }}
115
+ * locale="en-US"
116
+ * />
117
+ */
118
+ function NumberField({
119
+ label,
120
+ value: valueProp,
121
+ defaultValue = 0,
122
+ onChange,
123
+ min = -Infinity,
124
+ max = Infinity,
125
+ step = 1,
126
+ size,
127
+ locale,
128
+ formatOptions,
129
+ helperText,
130
+ errorMessage,
131
+ required = false,
132
+ disabled = false,
133
+ id: idProp,
134
+ name,
135
+ className,
136
+ ...rest
137
+ }: NumberFieldProps) {
138
+ const reactId = React.useId();
139
+ const id = idProp ?? reactId;
140
+ const helperId = `${id}-helper`;
141
+ const errorId = `${id}-error`;
142
+ const isInvalid = !!errorMessage;
143
+
144
+ // ── controlled / uncontrolled numeric value ────────────────────────────────
145
+
146
+ const isControlled = valueProp !== undefined;
147
+ const [localValue, setLocalValue] = React.useState<number>(
148
+ isControlled ? (valueProp ?? 0) : defaultValue
149
+ );
150
+ const value = isControlled ? (valueProp ?? 0) : localValue;
151
+
152
+ // ── display string (raw during typing, formatted when blurred) ─────────────
153
+
154
+ const [isFocused, setIsFocused] = React.useState(false);
155
+
156
+ const formatValue = React.useCallback(
157
+ (n: number): string => {
158
+ if (!formatOptions) return String(n);
159
+ try {
160
+ // For percent style, Intl expects 0–1 range internally but callers pass 0–100.
161
+ // Normalise: if style="percent" and value >= 1, divide by 100.
162
+ const normalized =
163
+ formatOptions.style === "percent" && n >= 1 ? n / 100 : n;
164
+ return new Intl.NumberFormat(locale, formatOptions).format(normalized);
165
+ } catch {
166
+ return String(n);
167
+ }
168
+ },
169
+ [locale, formatOptions]
170
+ );
171
+
172
+ const [inputStr, setInputStr] = React.useState(
173
+ formatOptions ? formatValue(value) : String(value)
174
+ );
175
+ const lastCommittedRef = React.useRef(value);
176
+
177
+ React.useEffect(() => {
178
+ if (isControlled && valueProp !== lastCommittedRef.current) {
179
+ lastCommittedRef.current = valueProp ?? 0;
180
+ setInputStr(
181
+ isFocused ? String(valueProp ?? 0) : formatValue(valueProp ?? 0)
182
+ );
183
+ }
184
+ }, [isControlled, valueProp, isFocused, formatValue]);
185
+
186
+ // ── commit ─────────────────────────────────────────────────────────────────
187
+
188
+ const commit = React.useCallback(
189
+ (next: number) => {
190
+ const clamped = clamp(next, min, max);
191
+ lastCommittedRef.current = clamped;
192
+ setInputStr(formatOptions ? formatValue(clamped) : String(clamped));
193
+ if (!isControlled) setLocalValue(clamped);
194
+ onChange?.(clamped);
195
+ },
196
+ [min, max, isControlled, onChange, formatOptions, formatValue]
197
+ );
198
+
199
+ const stepBy = (delta: number) => {
200
+ const typed = parseFloat(inputStr.replace(/[^0-9.\-]/g, ""));
201
+ const base = Number.isFinite(typed) ? typed : value;
202
+ commit(roundTo(base + delta, Math.max(decimalsOf(step), decimalsOf(base))));
203
+ };
204
+ const increment = () => stepBy(step);
205
+ const decrement = () => stepBy(-step);
206
+
207
+ // ── keyboard ───────────────────────────────────────────────────────────────
208
+
209
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
210
+ if (e.key === "ArrowUp") {
211
+ e.preventDefault();
212
+ increment();
213
+ } else if (e.key === "ArrowDown") {
214
+ e.preventDefault();
215
+ decrement();
216
+ } else if (e.key === "PageUp") {
217
+ e.preventDefault();
218
+ stepBy(step * 10);
219
+ } else if (e.key === "PageDown") {
220
+ e.preventDefault();
221
+ stepBy(-step * 10);
222
+ } else if (e.key === "Home" && Number.isFinite(min)) {
223
+ e.preventDefault();
224
+ commit(min);
225
+ } else if (e.key === "End" && Number.isFinite(max)) {
226
+ e.preventDefault();
227
+ commit(max);
228
+ }
229
+ };
230
+
231
+ // ── focus / blur ───────────────────────────────────────────────────────────
232
+
233
+ const handleFocus = () => {
234
+ setIsFocused(true);
235
+ // Switch to raw numeric string for editing
236
+ setInputStr(String(value));
237
+ };
238
+
239
+ const handleBlur = () => {
240
+ setIsFocused(false);
241
+ const parsed = parseFloat(inputStr.replace(/[^0-9.\-]/g, ""));
242
+ if (Number.isFinite(parsed)) {
243
+ commit(parsed);
244
+ } else {
245
+ setInputStr(formatOptions ? formatValue(value) : String(value));
246
+ }
247
+ };
248
+
249
+ // ── step button disabled states ────────────────────────────────────────────
250
+
251
+ const atMin = Number.isFinite(min) && value <= min;
252
+ const atMax = Number.isFinite(max) && value >= max;
253
+
254
+ // ── describedby ids ────────────────────────────────────────────────────────
255
+
256
+ const describedBy =
257
+ [isInvalid ? errorId : null, !isInvalid && helperText ? helperId : null]
258
+ .filter(Boolean)
259
+ .join(" ") || undefined;
260
+
261
+ const stepButtonClass = cn(
262
+ "flex shrink-0 items-center justify-center px-2.5",
263
+ "text-muted-foreground outline-none",
264
+ "hover:bg-accent hover:text-accent-foreground",
265
+ "focus-visible:bg-accent focus-visible:text-accent-foreground",
266
+ "disabled:pointer-events-none disabled:opacity-40",
267
+ "transition-colors"
268
+ );
269
+
270
+ return (
271
+ <div
272
+ data-slot="number-field"
273
+ data-invalid={isInvalid || undefined}
274
+ data-disabled={disabled || undefined}
275
+ className={cn("flex flex-col gap-2 group", className)}
276
+ {...rest}
277
+ >
278
+ {/* Label */}
279
+ <Label
280
+ htmlFor={id}
281
+ data-slot="number-field-label"
282
+ className={cn(
283
+ "group-data-[disabled]:pointer-events-none group-data-[disabled]:opacity-50"
284
+ )}
285
+ >
286
+ {label}
287
+ {required && (
288
+ <span aria-hidden="true" className="text-destructive font-normal ml-0.5">
289
+ *
290
+ </span>
291
+ )}
292
+ </Label>
293
+
294
+ {/* Stepper control */}
295
+ <div
296
+ data-slot="number-field-control"
297
+ data-invalid={isInvalid || undefined}
298
+ className={cn(numberFieldControlVariants({ size }))}
299
+ style={{
300
+ transitionDuration: "var(--duration-fast)",
301
+ transitionTimingFunction: "var(--ease-out)",
302
+ }}
303
+ >
304
+ <button
305
+ type="button"
306
+ data-slot="number-field-decrement"
307
+ aria-label="Decrement"
308
+ disabled={disabled || atMin}
309
+ onClick={decrement}
310
+ tabIndex={-1}
311
+ className={cn(stepButtonClass, "border-r border-input")}
312
+ style={{
313
+ transitionDuration: "var(--duration-fast)",
314
+ transitionTimingFunction: "var(--ease-out)",
315
+ }}
316
+ >
317
+ <Minus strokeWidth={1.5} className="size-4" />
318
+ </button>
319
+
320
+ <input
321
+ data-slot="number-field-input"
322
+ role="spinbutton"
323
+ type="text"
324
+ inputMode="decimal"
325
+ id={id}
326
+ name={name}
327
+ aria-valuenow={Number.isFinite(value) ? value : undefined}
328
+ aria-valuemin={Number.isFinite(min) ? min : undefined}
329
+ aria-valuemax={Number.isFinite(max) ? max : undefined}
330
+ aria-required={required || undefined}
331
+ aria-invalid={isInvalid || undefined}
332
+ aria-describedby={describedBy}
333
+ disabled={disabled}
334
+ required={required}
335
+ value={inputStr}
336
+ onChange={(e) => setInputStr(e.target.value)}
337
+ onFocus={handleFocus}
338
+ onBlur={handleBlur}
339
+ onKeyDown={handleKeyDown}
340
+ className={cn(
341
+ "min-w-0 flex-1 bg-transparent text-center font-sans tabular-nums text-foreground",
342
+ "outline-none placeholder:text-muted-foreground",
343
+ "disabled:pointer-events-none disabled:opacity-50"
344
+ )}
345
+ />
346
+
347
+ <button
348
+ type="button"
349
+ data-slot="number-field-increment"
350
+ aria-label="Increment"
351
+ disabled={disabled || atMax}
352
+ onClick={increment}
353
+ tabIndex={-1}
354
+ className={cn(stepButtonClass, "border-l border-input")}
355
+ style={{
356
+ transitionDuration: "var(--duration-fast)",
357
+ transitionTimingFunction: "var(--ease-out)",
358
+ }}
359
+ >
360
+ <Plus strokeWidth={1.5} className="size-4" />
361
+ </button>
362
+ </div>
363
+
364
+ {/* Helper text */}
365
+ {!isInvalid && helperText && (
366
+ <p
367
+ data-slot="number-field-helper"
368
+ id={helperId}
369
+ className="text-sm text-muted-foreground"
370
+ >
371
+ {helperText}
372
+ </p>
373
+ )}
374
+
375
+ {/* Error message */}
376
+ {isInvalid && errorMessage && (
377
+ <p
378
+ data-slot="number-field-error"
379
+ id={errorId}
380
+ role="alert"
381
+ className="text-sm font-medium text-destructive"
382
+ >
383
+ {errorMessage}
384
+ </p>
385
+ )}
386
+ </div>
387
+ );
388
+ }
389
+
390
+ export { NumberField, numberFieldControlVariants };
@@ -955,6 +955,10 @@
955
955
  "date": "2026-10-19",
956
956
  "kind": "primitive"
957
957
  },
958
+ "NumberField": {
959
+ "date": "2026-10-29",
960
+ "kind": "primitive"
961
+ },
958
962
  "ChangePasswordCard": {
959
963
  "date": "2026-09-19",
960
964
  "kind": "composition"
@@ -4,11 +4,11 @@
4
4
  "stats": [
5
5
  {
6
6
  "label": "commits",
7
- "value": 1757
7
+ "value": 1766
8
8
  },
9
9
  {
10
10
  "label": "components",
11
- "value": 241
11
+ "value": 242
12
12
  },
13
13
  {
14
14
  "label": "semantic tokens",
@@ -25,6 +25,24 @@
25
25
  "subject": "Initial commit: BADS template v0.1.0"
26
26
  },
27
27
  "milestones": [
28
+ {
29
+ "sha": "09122e27",
30
+ "date": "2026-11-11",
31
+ "scope": "components",
32
+ "title": "add NumberField primitive (#721)"
33
+ },
34
+ {
35
+ "sha": "9227690f",
36
+ "date": "2026-11-11",
37
+ "scope": "comments",
38
+ "title": "sticky notes, kept and shared by the comments server (#793)"
39
+ },
40
+ {
41
+ "sha": "97b65b22",
42
+ "date": "2026-11-11",
43
+ "scope": "comments",
44
+ "title": "a host can put its own tabs at the top of the sidebar (#791)"
45
+ },
28
46
  {
29
47
  "sha": "546d8f41",
30
48
  "date": "2026-11-10",
@@ -246,24 +264,6 @@
246
264
  "date": "2026-10-18",
247
265
  "scope": "composition",
248
266
  "title": "add MembersTable — night shift 2026-10-18"
249
- },
250
- {
251
- "sha": "beb0746c",
252
- "date": "2026-10-18",
253
- "scope": "compositions",
254
- "title": "add PlanCard pricing tier composition"
255
- },
256
- {
257
- "sha": "8f5b8cda",
258
- "date": "2026-10-17",
259
- "scope": "components",
260
- "title": "OAuthButtons, DescriptionList, StatGroup — Night Shift 2026-10-17 (#669)"
261
- },
262
- {
263
- "sha": "783a21c0",
264
- "date": "2026-10-17",
265
- "scope": "[Night Shift]",
266
- "title": "feat([Night Shift]) Add BillingHistoryCard composition (#666)"
267
267
  }
268
268
  ]
269
269
  }
@@ -4043,6 +4043,59 @@
4043
4043
  }
4044
4044
  ]
4045
4045
  },
4046
+ "NumberField": {
4047
+ "title": "Components/Forms/NumberField",
4048
+ "entries": [
4049
+ {
4050
+ "id": "components-forms-numberfield--default",
4051
+ "name": "Default"
4052
+ },
4053
+ {
4054
+ "id": "components-forms-numberfield--required",
4055
+ "name": "Required"
4056
+ },
4057
+ {
4058
+ "id": "components-forms-numberfield--with-helper-text",
4059
+ "name": "With Helper Text"
4060
+ },
4061
+ {
4062
+ "id": "components-forms-numberfield--invalid",
4063
+ "name": "Invalid"
4064
+ },
4065
+ {
4066
+ "id": "components-forms-numberfield--disabled",
4067
+ "name": "Disabled"
4068
+ },
4069
+ {
4070
+ "id": "components-forms-numberfield--size-sm",
4071
+ "name": "Size Sm"
4072
+ },
4073
+ {
4074
+ "id": "components-forms-numberfield--size-default",
4075
+ "name": "Size Default"
4076
+ },
4077
+ {
4078
+ "id": "components-forms-numberfield--size-lg",
4079
+ "name": "Size Lg"
4080
+ },
4081
+ {
4082
+ "id": "components-forms-numberfield--variant-currency",
4083
+ "name": "Variant Currency"
4084
+ },
4085
+ {
4086
+ "id": "components-forms-numberfield--variant-percentage",
4087
+ "name": "Variant Percentage"
4088
+ },
4089
+ {
4090
+ "id": "components-forms-numberfield--variant-euro-currency",
4091
+ "name": "Variant Euro Currency"
4092
+ },
4093
+ {
4094
+ "id": "components-forms-numberfield--realistic-use",
4095
+ "name": "Realistic Use"
4096
+ }
4097
+ ]
4098
+ },
4046
4099
  "NumberInput": {
4047
4100
  "title": "Components/Forms/NumberInput",
4048
4101
  "entries": [
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
2
  import * as React from "react";
3
+ import { Checkbox } from "@behavioral-agentic-design-system/core/components/ui/checkbox";
3
4
  import {
4
5
  CheckboxGroup,
5
6
  CheckboxGroupItem,
@@ -0,0 +1,214 @@
1
+ // ring-[3px] advisory marker added to number-field.tsx (2026-11-11); story coverage unchanged.
2
+ import type { Meta, StoryObj } from "@storybook/react";
3
+ import * as React from "react";
4
+ import { NumberField } from "@behavioral-agentic-design-system/core/components/ui/number-field";
5
+
6
+ const meta: Meta<typeof NumberField> = {
7
+ title: "Components/Forms/NumberField",
8
+ component: NumberField,
9
+ parameters: { layout: "centered" },
10
+ tags: ["autodocs"],
11
+ };
12
+ export default meta;
13
+ type Story = StoryObj<typeof NumberField>;
14
+
15
+ // ─── Controlled wrapper ────────────────────────────────────────────────────────
16
+ function Controlled(props: Omit<React.ComponentProps<typeof NumberField>, "value" | "onChange">) {
17
+ const [value, setValue] = React.useState(props.defaultValue ?? 0);
18
+ return <NumberField {...props} value={value} onChange={setValue} />;
19
+ }
20
+
21
+ // ─── Default ──────────────────────────────────────────────────────────────────
22
+ export const Default: Story = {
23
+ parameters: { controls: { disable: true } },
24
+ render: () => (
25
+ <div className="w-64">
26
+ <Controlled label="Quantity" defaultValue={1} min={1} />
27
+ </div>
28
+ ),
29
+ };
30
+
31
+ // ─── Required ─────────────────────────────────────────────────────────────────
32
+ export const Required: Story = {
33
+ parameters: { controls: { disable: true } },
34
+ render: () => (
35
+ <div className="w-64">
36
+ <Controlled
37
+ label="Seat count"
38
+ required
39
+ defaultValue={1}
40
+ min={1}
41
+ max={50}
42
+ helperText="Maximum 50 seats per booking"
43
+ />
44
+ </div>
45
+ ),
46
+ };
47
+
48
+ // ─── With helper text ─────────────────────────────────────────────────────────
49
+ export const WithHelperText: Story = {
50
+ parameters: { controls: { disable: true } },
51
+ render: () => (
52
+ <div className="w-64">
53
+ <Controlled
54
+ label="Line spacing"
55
+ defaultValue={1.5}
56
+ step={0.1}
57
+ min={1}
58
+ max={3}
59
+ helperText="Recommended: 1.4–1.8 for body text"
60
+ />
61
+ </div>
62
+ ),
63
+ };
64
+
65
+ // ─── Error / invalid state ─────────────────────────────────────────────────────
66
+ export const Invalid: Story = {
67
+ parameters: { controls: { disable: true } },
68
+ render: () => (
69
+ <div className="w-64">
70
+ <Controlled
71
+ label="Stock quantity"
72
+ defaultValue={-1}
73
+ min={0}
74
+ errorMessage="Quantity cannot be negative"
75
+ />
76
+ </div>
77
+ ),
78
+ };
79
+
80
+ // ─── Disabled ─────────────────────────────────────────────────────────────────
81
+ export const Disabled: Story = {
82
+ parameters: { controls: { disable: true } },
83
+ render: () => (
84
+ <div className="w-64">
85
+ <Controlled label="Seat count" defaultValue={5} disabled />
86
+ </div>
87
+ ),
88
+ };
89
+
90
+ // ─── Size_Sm ──────────────────────────────────────────────────────────────────
91
+ export const Size_Sm: Story = {
92
+ parameters: { controls: { disable: true } },
93
+ render: () => (
94
+ <div className="w-64">
95
+ <Controlled label="Quantity" size="sm" defaultValue={1} min={1} />
96
+ </div>
97
+ ),
98
+ };
99
+
100
+ // ─── Size_Default ─────────────────────────────────────────────────────────────
101
+ export const Size_Default: Story = {
102
+ parameters: { controls: { disable: true } },
103
+ render: () => (
104
+ <div className="w-64">
105
+ <Controlled label="Quantity" size="default" defaultValue={1} min={1} />
106
+ </div>
107
+ ),
108
+ };
109
+
110
+ // ─── Size_Lg ──────────────────────────────────────────────────────────────────
111
+ export const Size_Lg: Story = {
112
+ parameters: { controls: { disable: true } },
113
+ render: () => (
114
+ <div className="w-64">
115
+ <Controlled label="Quantity" size="lg" defaultValue={1} min={1} />
116
+ </div>
117
+ ),
118
+ };
119
+
120
+ // ─── Currency format ──────────────────────────────────────────────────────────
121
+ export const Variant_Currency: Story = {
122
+ parameters: { controls: { disable: true } },
123
+ render: () => (
124
+ <div className="w-64">
125
+ <Controlled
126
+ label="Price"
127
+ defaultValue={29.99}
128
+ step={0.01}
129
+ min={0}
130
+ formatOptions={{ style: "currency", currency: "USD" }}
131
+ helperText="Enter price before tax"
132
+ />
133
+ </div>
134
+ ),
135
+ name: "Variant: Currency (USD)",
136
+ };
137
+
138
+ // ─── Percentage format ────────────────────────────────────────────────────────
139
+ export const Variant_Percentage: Story = {
140
+ parameters: { controls: { disable: true } },
141
+ render: () => (
142
+ <div className="w-64">
143
+ <Controlled
144
+ label="Discount"
145
+ defaultValue={25}
146
+ min={0}
147
+ max={100}
148
+ step={5}
149
+ formatOptions={{ style: "percent", maximumFractionDigits: 0 }}
150
+ helperText="Applied at checkout"
151
+ />
152
+ </div>
153
+ ),
154
+ name: "Variant: Percentage",
155
+ };
156
+
157
+ // ─── Locale format ────────────────────────────────────────────────────────────
158
+ export const Variant_EuroCurrency: Story = {
159
+ parameters: { controls: { disable: true } },
160
+ render: () => (
161
+ <div className="w-64">
162
+ <Controlled
163
+ label="Preis"
164
+ defaultValue={1234.5}
165
+ step={0.01}
166
+ min={0}
167
+ locale="de-DE"
168
+ formatOptions={{ style: "currency", currency: "EUR" }}
169
+ />
170
+ </div>
171
+ ),
172
+ name: "Variant: Euro (de-DE locale)",
173
+ };
174
+
175
+ // ─── Realistic use ────────────────────────────────────────────────────────────
176
+ export const RealisticUse: Story = {
177
+ parameters: { controls: { disable: true } },
178
+ render: () => {
179
+ const [quantity, setQuantity] = React.useState(2);
180
+ const [price, setPrice] = React.useState(49.0);
181
+ const total = quantity * price;
182
+ return (
183
+ <div className="w-80 flex flex-col gap-5">
184
+ <NumberField
185
+ label="Quantity"
186
+ value={quantity}
187
+ onChange={setQuantity}
188
+ min={1}
189
+ max={99}
190
+ required
191
+ helperText="Maximum 99 per order"
192
+ />
193
+ <NumberField
194
+ label="Unit price"
195
+ value={price}
196
+ onChange={setPrice}
197
+ step={0.01}
198
+ min={0}
199
+ formatOptions={{ style: "currency", currency: "USD" }}
200
+ helperText="Price before quantity discount"
201
+ />
202
+ <div className="flex justify-between text-sm pt-1 border-t border-border">
203
+ <span className="text-muted-foreground">Total</span>
204
+ <span className="font-medium tabular-nums">
205
+ {new Intl.NumberFormat("en-US", {
206
+ style: "currency",
207
+ currency: "USD",
208
+ }).format(total)}
209
+ </span>
210
+ </div>
211
+ </div>
212
+ );
213
+ },
214
+ };
@@ -15,7 +15,7 @@
15
15
  "story files.",
16
16
  "",
17
17
  "GROUP NAMES ARE FOR PEOPLE SCANNING A SIDEBAR. They are not an architectural",
18
- "statement and they are not the layer model — they answer 'where would someone",
18
+ "statement and they are not the layer model \u2014 they answer 'where would someone",
19
19
  "look for this', which is why Accordion sits under Layout rather than Actions",
20
20
  "and Carousel sits under Layout rather than Content.",
21
21
  "",
@@ -48,6 +48,7 @@
48
48
  "JsonInput",
49
49
  "Label",
50
50
  "NumberInput",
51
+ "NumberField",
51
52
  "OTPInput",
52
53
  "PasswordInput",
53
54
  "PasswordStrengthInput",