@behavioral-agentic-design-system/core 0.47.0 → 0.49.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.
Files changed (214) hide show
  1. package/package.json +1 -1
  2. package/scripts/build-tokens.cjs +24 -3
  3. package/scripts/ux-smoke.mjs +5 -1
  4. package/src/api/save-tokens.ts +170 -24
  5. package/src/app/layout.tsx +12 -1
  6. package/src/app/preview/components/page.tsx +114 -18
  7. package/src/app/preview/global-font-client.tsx +2 -0
  8. package/src/app/providers.tsx +2 -0
  9. package/src/app/shell.tsx +50 -156
  10. package/src/components/customize/brand-mark-section.tsx +65 -95
  11. package/src/components/customize/font-pickers.tsx +25 -2
  12. package/src/components/customize/save-bar.tsx +120 -7
  13. package/src/components/customize/theme-io.tsx +62 -21
  14. package/src/components/customize-tab.tsx +3 -1
  15. package/src/components/home-recent.tsx +58 -25
  16. package/src/components/motion/reveal.tsx +168 -12
  17. package/src/components/studio/control-panel.tsx +98 -19
  18. package/src/components/studio/import-theme-dialog.tsx +167 -0
  19. package/src/components/studio/tokens-panel.tsx +215 -0
  20. package/src/components/studio/types.ts +5 -2
  21. package/src/components/studio/use-studio-tweaks.ts +36 -4
  22. package/src/components/studio/use-token-edits.ts +160 -0
  23. package/src/components/ui/number-field.tsx +390 -0
  24. package/src/components/ui/toggle-tip.tsx +38 -29
  25. package/src/data/component-added.json +4 -0
  26. package/src/data/component-stories.json +1214 -0
  27. package/src/data/docs-index.ts +7 -2
  28. package/src/data/hidden-views.ts +22 -0
  29. package/src/data/history.json +51 -51
  30. package/src/data/sticker-sheet.json +1918 -1808
  31. package/src/fonts/Figtree-OFL.txt +93 -0
  32. package/src/fonts/figtree-latin-ext-wght-normal.woff2 +0 -0
  33. package/src/fonts/figtree-latin-wght-italic.woff2 +0 -0
  34. package/src/fonts/figtree-latin-wght-normal.woff2 +0 -0
  35. package/src/fonts-cdn.css +3 -1
  36. package/src/fonts.css +44 -0
  37. package/src/hooks/use-global-heading-font.ts +104 -0
  38. package/src/hooks/use-global-sans-font.ts +8 -3
  39. package/src/hooks/use-global-theme.ts +2 -2
  40. package/src/hooks/use-token-overrides.ts +62 -14
  41. package/src/lib/css-color.ts +42 -0
  42. package/src/lib/storybook-url.ts +28 -0
  43. package/src/lib/theme-editor.ts +7 -1
  44. package/src/lib/theme-import.ts +99 -0
  45. package/src/lib/theme-transition.ts +93 -0
  46. package/src/lib/token-list.ts +133 -0
  47. package/src/lib/token-value.ts +31 -0
  48. package/src/stories/Accordion.stories.tsx +1 -1
  49. package/src/stories/Affix.stories.tsx +1 -1
  50. package/src/stories/AiBadge.stories.tsx +1 -1
  51. package/src/stories/Alert.stories.tsx +1 -1
  52. package/src/stories/AlertDialog.stories.tsx +1 -1
  53. package/src/stories/AngleSlider.stories.tsx +1 -1
  54. package/src/stories/AnnouncementBar.stories.tsx +2 -2
  55. package/src/stories/AspectRatio.stories.tsx +1 -1
  56. package/src/stories/Attachment.stories.tsx +1 -1
  57. package/src/stories/Autocomplete.stories.tsx +1 -1
  58. package/src/stories/Avatar.stories.tsx +1 -1
  59. package/src/stories/Badge.stories.tsx +1 -1
  60. package/src/stories/Blockquote.stories.tsx +1 -1
  61. package/src/stories/Burger.stories.tsx +1 -1
  62. package/src/stories/Button.stories.tsx +1 -1
  63. package/src/stories/ButtonGroup.stories.tsx +1 -1
  64. package/src/stories/Calendar.stories.tsx +1 -1
  65. package/src/stories/Callout.stories.tsx +1 -1
  66. package/src/stories/Canvas.stories.tsx +1 -1
  67. package/src/stories/Card.stories.tsx +1 -1
  68. package/src/stories/Carousel.stories.tsx +1 -1
  69. package/src/stories/Cascader.stories.tsx +1 -1
  70. package/src/stories/Chart.stories.tsx +1 -1
  71. package/src/stories/ChatBubble.stories.tsx +1 -1
  72. package/src/stories/ChatMarker.stories.tsx +1 -1
  73. package/src/stories/Checkbox.stories.tsx +1 -1
  74. package/src/stories/CheckboxCard.stories.tsx +1 -1
  75. package/src/stories/CheckboxGroup.stories.tsx +2 -1
  76. package/src/stories/Chip.stories.tsx +1 -1
  77. package/src/stories/CircularProgress.stories.tsx +1 -1
  78. package/src/stories/Clipboard.stories.tsx +1 -1
  79. package/src/stories/CloseButton.stories.tsx +1 -1
  80. package/src/stories/Code.stories.tsx +1 -1
  81. package/src/stories/Collapsible.stories.tsx +1 -1
  82. package/src/stories/ColorPicker.stories.tsx +1 -1
  83. package/src/stories/ColorSwatch.stories.tsx +1 -1
  84. package/src/stories/Combobox.stories.tsx +1 -1
  85. package/src/stories/Container.stories.tsx +1 -1
  86. package/src/stories/ContextMenu.stories.tsx +1 -1
  87. package/src/stories/CopyButton.stories.tsx +1 -1
  88. package/src/stories/DataList.stories.tsx +1 -1
  89. package/src/stories/DataTable.stories.tsx +1 -1
  90. package/src/stories/DateField.stories.tsx +1 -1
  91. package/src/stories/DatePicker.stories.tsx +1 -1
  92. package/src/stories/DateRangePicker.stories.tsx +1 -1
  93. package/src/stories/Dialog.stories.tsx +1 -1
  94. package/src/stories/Drawer.stories.tsx +1 -1
  95. package/src/stories/DropdownMenu.stories.tsx +1 -1
  96. package/src/stories/Editable.stories.tsx +1 -1
  97. package/src/stories/EmptyState.stories.tsx +1 -1
  98. package/src/stories/FacetedFilter.stories.tsx +1 -1
  99. package/src/stories/Field.stories.tsx +1 -1
  100. package/src/stories/Fieldset.stories.tsx +1 -1
  101. package/src/stories/FileButton.stories.tsx +1 -1
  102. package/src/stories/FileUpload.stories.tsx +1 -1
  103. package/src/stories/FloatLabel.stories.tsx +1 -1
  104. package/src/stories/FloatingActionButton.stories.tsx +1 -1
  105. package/src/stories/FloatingIndicator.stories.tsx +1 -1
  106. package/src/stories/FloatingPanel.stories.tsx +1 -1
  107. package/src/stories/FocusTrap.stories.tsx +1 -1
  108. package/src/stories/FormatByte.stories.tsx +1 -1
  109. package/src/stories/FormatDate.stories.tsx +1 -1
  110. package/src/stories/FormatNumber.stories.tsx +1 -1
  111. package/src/stories/FormatRelativeTime.stories.tsx +1 -1
  112. package/src/stories/GaugeChart.stories.tsx +1 -1
  113. package/src/stories/Grid.stories.tsx +1 -1
  114. package/src/stories/Heatmap.stories.tsx +1 -1
  115. package/src/stories/Highlight.stories.tsx +1 -1
  116. package/src/stories/HoverCard.stories.tsx +1 -1
  117. package/src/stories/Icon.stories.tsx +1 -1
  118. package/src/stories/Image.stories.tsx +1 -1
  119. package/src/stories/Indicator.stories.tsx +1 -1
  120. package/src/stories/InfiniteScroll.stories.tsx +1 -1
  121. package/src/stories/InlineEdit.stories.tsx +1 -1
  122. package/src/stories/Input.stories.tsx +1 -1
  123. package/src/stories/InputClearButton.stories.tsx +1 -1
  124. package/src/stories/InputGroup.stories.tsx +1 -1
  125. package/src/stories/JsonInput.stories.tsx +1 -1
  126. package/src/stories/Kbd.stories.tsx +1 -1
  127. package/src/stories/KeyboardShortcut.stories.tsx +1 -1
  128. package/src/stories/Label.stories.tsx +1 -1
  129. package/src/stories/List.stories.tsx +1 -1
  130. package/src/stories/Listbox.stories.tsx +1 -1
  131. package/src/stories/LoadingDots.stories.tsx +1 -1
  132. package/src/stories/LoadingOverlay.stories.tsx +1 -1
  133. package/src/stories/Mark.stories.tsx +1 -1
  134. package/src/stories/MarkdownPreview.stories.tsx +1 -1
  135. package/src/stories/Marquee.stories.tsx +1 -1
  136. package/src/stories/Masonry.stories.tsx +1 -1
  137. package/src/stories/Meter.stories.tsx +1 -1
  138. package/src/stories/MonthPicker.stories.tsx +1 -1
  139. package/src/stories/MotionToggle.stories.tsx +1 -1
  140. package/src/stories/MultiSelect.stories.tsx +1 -1
  141. package/src/stories/NativeSelect.stories.tsx +1 -1
  142. package/src/stories/NavigationProgress.stories.tsx +1 -1
  143. package/src/stories/Notification.stories.tsx +1 -1
  144. package/src/stories/NumberField.stories.tsx +214 -0
  145. package/src/stories/NumberInput.stories.tsx +1 -1
  146. package/src/stories/OtpInput.stories.tsx +1 -1
  147. package/src/stories/Overlay.stories.tsx +1 -1
  148. package/src/stories/PageHeader.stories.tsx +1 -1
  149. package/src/stories/PasswordInput.stories.tsx +1 -1
  150. package/src/stories/PasswordStrengthInput.stories.tsx +1 -1
  151. package/src/stories/PhoneInput.stories.tsx +1 -1
  152. package/src/stories/Pill.stories.tsx +1 -1
  153. package/src/stories/PinInput.stories.tsx +1 -1
  154. package/src/stories/Popover.stories.tsx +1 -1
  155. package/src/stories/Portal.stories.tsx +1 -1
  156. package/src/stories/Presence.stories.tsx +1 -1
  157. package/src/stories/Progress.stories.tsx +1 -1
  158. package/src/stories/ProgressStack.stories.tsx +1 -1
  159. package/src/stories/Prose.stories.tsx +1 -1
  160. package/src/stories/QrCode.stories.tsx +1 -1
  161. package/src/stories/Questionnaire.stories.tsx +1 -1
  162. package/src/stories/RadioGroup.stories.tsx +1 -1
  163. package/src/stories/RatingGroup.stories.tsx +1 -1
  164. package/src/stories/Resizable.stories.tsx +1 -1
  165. package/src/stories/Result.stories.tsx +1 -1
  166. package/src/stories/Reveal.stories.tsx +1 -1
  167. package/src/stories/RollingNumber.stories.tsx +1 -1
  168. package/src/stories/ScrollArea.stories.tsx +1 -1
  169. package/src/stories/ScrollProgress.stories.tsx +1 -1
  170. package/src/stories/SearchInput.stories.tsx +1 -1
  171. package/src/stories/SegmentedControl.stories.tsx +1 -1
  172. package/src/stories/Select.stories.tsx +1 -1
  173. package/src/stories/Separator.stories.tsx +1 -1
  174. package/src/stories/Sheet.stories.tsx +1 -1
  175. package/src/stories/SignaturePad.stories.tsx +1 -1
  176. package/src/stories/SimpleGrid.stories.tsx +1 -1
  177. package/src/stories/Skeleton.stories.tsx +1 -1
  178. package/src/stories/SkeletonTable.stories.tsx +1 -1
  179. package/src/stories/Slider.stories.tsx +1 -1
  180. package/src/stories/Snackbar.stories.tsx +1 -1
  181. package/src/stories/Sonner.stories.tsx +1 -1
  182. package/src/stories/SortableList.stories.tsx +1 -1
  183. package/src/stories/Sparkline.stories.tsx +1 -1
  184. package/src/stories/Spinner.stories.tsx +1 -1
  185. package/src/stories/Spoiler.stories.tsx +1 -1
  186. package/src/stories/Squircle.stories.tsx +1 -1
  187. package/src/stories/Stack.stories.tsx +1 -1
  188. package/src/stories/StatusBadge.stories.tsx +1 -1
  189. package/src/stories/Switch.stories.tsx +1 -1
  190. package/src/stories/Table.stories.tsx +1 -1
  191. package/src/stories/Tag.stories.tsx +1 -1
  192. package/src/stories/TagsInput.stories.tsx +1 -1
  193. package/src/stories/Text.stories.tsx +1 -1
  194. package/src/stories/Textarea.stories.tsx +1 -1
  195. package/src/stories/ThemeIcon.stories.tsx +1 -1
  196. package/src/stories/TimePicker.stories.tsx +1 -1
  197. package/src/stories/Timeline.stories.tsx +1 -1
  198. package/src/stories/Timer.stories.tsx +1 -1
  199. package/src/stories/Toggle.stories.tsx +1 -1
  200. package/src/stories/ToggleGroup.stories.tsx +1 -1
  201. package/src/stories/ToggleTip.stories.tsx +106 -1
  202. package/src/stories/Tooltip.stories.tsx +56 -1
  203. package/src/stories/TransferList.stories.tsx +1 -1
  204. package/src/stories/TreeSelect.stories.tsx +1 -1
  205. package/src/stories/TypingIndicator.stories.tsx +1 -1
  206. package/src/stories/VisuallyHidden.stories.tsx +1 -1
  207. package/src/stories/Watermark.stories.tsx +1 -1
  208. package/src/stories/WeekPicker.stories.tsx +1 -1
  209. package/src/stories/WordRotate.stories.tsx +1 -1
  210. package/src/stories/YearPicker.stories.tsx +1 -1
  211. package/src/stories/story-groups.json +216 -223
  212. package/src/styles.css +20 -3
  213. package/src/tokens.default.json +6 -1
  214. package/src/tokens.json +7 -2
@@ -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 };
@@ -6,6 +6,10 @@ import * as PopoverPrimitive from "@radix-ui/react-popover"
6
6
  import { cn } from "../../lib/utils"
7
7
  import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
8
8
 
9
+ /** Arrow size in px. Radix adds the height to sideOffset, so the gap to the trigger is sideOffset + this. */
10
+ const ARROW_WIDTH = 14
11
+ const ARROW_HEIGHT = 7
12
+
9
13
  interface ToggleTipProps {
10
14
  /** The tip body. Informational, non-interactive by default. */
11
15
  content: React.ReactNode
@@ -82,38 +86,43 @@ function ToggleTip({
82
86
  }}
83
87
  >
84
88
  {content}
85
- {/* The arrow is a rotated square, not Radix's filled polygon — the
86
- * shadcn Tooltip pattern. Tooltip can leave it borderless because
87
- * its surface is a solid inverted fill with no border; ToggleTip
88
- * rides the bordered, shadowed popover surface, so an unbordered
89
- * arrow reads as a detached white triangle hanging off the panel.
90
- *
91
- * A 45°-rotated square points at a corner, and only the TWO edges
92
- * meeting at that corner are outside the panel — the other two are
93
- * tucked under it, where a border would draw a line across the
94
- * panel's own edge. So the borders are applied per side, keyed off
95
- * the data-side Radix sets on the content (hence `group` above):
89
+ {/* The arrow is Radix's own svg slot, drawn as a bordered triangle.
96
90
  *
97
- * side=top arrow points down → bottom + right edges
98
- * side=bottom arrow points up → top + left edges
99
- * side=left arrow points right → top + right edges
100
- * side=right arrow points left → bottom + left edges
91
+ * History: this used to be a CSS square rotated 45 degrees inside
92
+ * `<Arrow asChild>`. Radix Popper wraps the arrow in a span it positions
93
+ * and rotates for the placed side, with transforms worked out for a
94
+ * `width` by `height` shape (10 by 5). A 10 by 10 square rotated by
95
+ * Tailwind's separate `rotate` property broke that math: it landed
96
+ * 5 to 12px off the panel edge on bottom, left and right, floating
97
+ * detached and below the trigger's centre line. Only top looked right.
101
98
  *
102
- * shadow-md matches the panel so the elevation continues around the
103
- * arrow instead of stopping at the panel edge. -translate 2px past
104
- * half keeps the panel's own border from cutting across the base.
99
+ * Now the child is an svg of the declared size, so every side, and the
100
+ * arrowX / arrowY offsets Radix applies when a collision shifts the
101
+ * panel, work the way Radix designed them. The triangle is filled with
102
+ * the popover surface and stroked only along its two outer edges, so no
103
+ * line crosses the panel's own edge. drop-shadow carries the elevation
104
+ * around the arrow, and clip-path stops it at the base so no shadow is
105
+ * cast back over the panel. The svg sits 1px into the panel (-translate-y-px,
106
+ * which is in Radix's rotated frame, so it is "toward the panel" on every
107
+ * side) so its fill covers the panel's own 1px border where the arrow
108
+ * joins it; without that a border line ran across the arrow base.
109
+ * Guarded by the AllSides story.
105
110
  */}
106
- <PopoverPrimitive.Arrow asChild>
107
- <div
108
- data-slot="toggle-tip-arrow"
109
- className={cn(
110
- "z-50 size-2.5 rotate-45 rounded-[2px] border border-border bg-popover shadow-md",
111
- "group-data-[side=top]:translate-y-[calc(-50%_-_2px)] group-data-[side=top]:border-t-0 group-data-[side=top]:border-l-0",
112
- "group-data-[side=bottom]:translate-y-[calc(50%_+_2px)] group-data-[side=bottom]:border-b-0 group-data-[side=bottom]:border-r-0",
113
- "group-data-[side=left]:translate-x-[calc(-50%_-_2px)] group-data-[side=left]:border-b-0 group-data-[side=left]:border-l-0",
114
- "group-data-[side=right]:translate-x-[calc(50%_+_2px)] group-data-[side=right]:border-t-0 group-data-[side=right]:border-r-0"
115
- )}
116
- />
111
+ <PopoverPrimitive.Arrow asChild width={ARROW_WIDTH} height={ARROW_HEIGHT}>
112
+ <svg
113
+ data-slot="toggle-tip-arrow"
114
+ aria-hidden="true"
115
+ viewBox={`0 0 ${ARROW_WIDTH} ${ARROW_HEIGHT}`}
116
+ className="block -translate-y-px overflow-visible fill-popover stroke-border drop-shadow-sm [clip-path:inset(0_-12px_-12px_-12px)]"
117
+ >
118
+ <path d={`M0 0 L${ARROW_WIDTH / 2} ${ARROW_HEIGHT} L${ARROW_WIDTH} 0 Z`} stroke="none" />
119
+ <path
120
+ d={`M0 0 L${ARROW_WIDTH / 2} ${ARROW_HEIGHT} L${ARROW_WIDTH} 0`}
121
+ fill="none"
122
+ strokeWidth={1}
123
+ strokeLinejoin="round"
124
+ />
125
+ </svg>
117
126
  </PopoverPrimitive.Arrow>
118
127
  </PopoverPrimitive.Content>
119
128
  </PopoverPrimitive.Portal>
@@ -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"