@underpin/ui 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +45 -2
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/button-group.d.ts +17 -0
- package/components/button-group.js +27 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +128 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +15 -0
- package/components/pagination.js +63 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/tabs.d.ts +18 -0
- package/components/tabs.js +65 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +23 -0
- package/lib/icons.js +28 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +116 -4
- package/styles.css +619 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatIdList } from "../lib/aria.js";
|
|
3
|
+
import { descriptionClasses } from "../lib/classes.js";
|
|
4
|
+
import { cn } from "../lib/variants.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { Callout, CalloutText } from "./callout.js";
|
|
7
|
+
import { Checkbox } from "./checkbox.js";
|
|
8
|
+
import { DatePickerTrigger } from "./date-picker-trigger.js";
|
|
9
|
+
import { DetailRow } from "./detail-row.js";
|
|
10
|
+
import { DisabledReason } from "./disabled-reason.js";
|
|
11
|
+
import { Input } from "./input.js";
|
|
12
|
+
import { Label } from "./label.js";
|
|
13
|
+
import { NumberInput } from "./number-input.js";
|
|
14
|
+
import { RadioCard, RadioGroup } from "./radio-group.js";
|
|
15
|
+
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "./select.js";
|
|
16
|
+
import { Switch } from "./switch.js";
|
|
17
|
+
import { Textarea } from "./textarea.js";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
import { Suspense, cloneElement, lazy, useId } from "react";
|
|
20
|
+
import { mergeProps } from "@base-ui/react/merge-props";
|
|
21
|
+
import { createFormHookContexts } from "@tanstack/react-form";
|
|
22
|
+
// src/components/form.tsx
|
|
23
|
+
/**
|
|
24
|
+
* Form primitives over TanStack Form. An app wires them up once with `createFormHook`:
|
|
25
|
+
*
|
|
26
|
+
* const { useAppForm } = createFormHook({ fieldContext, formContext, fieldComponents, formComponents })
|
|
27
|
+
*
|
|
28
|
+
* and then writes `<form.AppField name="email">{field => <field.TextField label="Email" />}</form.AppField>`
|
|
29
|
+
* inside a `<Form form={form}>`. The field components read the field they belong to from context,
|
|
30
|
+
* so a call site names the field once, on `AppField`.
|
|
31
|
+
*/
|
|
32
|
+
const { fieldContext, formContext, useFieldContext, useFormContext } = createFormHookContexts();
|
|
33
|
+
/** A validator's error as text. Standard Schema issues are objects; a plain validator returns a string. */
|
|
34
|
+
function errorMessage(error) {
|
|
35
|
+
if (typeof error === "string") return error;
|
|
36
|
+
if (error && typeof error === "object" && "message" in error) return String(error.message);
|
|
37
|
+
}
|
|
38
|
+
/** The error a touched field shows, for a field that renders its own control and message. */
|
|
39
|
+
function fieldError(meta) {
|
|
40
|
+
if (!meta.isTouched) return;
|
|
41
|
+
return meta.errors.map(errorMessage).find(Boolean);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A field's validation error, under its control. Not a live region: the message is in the
|
|
45
|
+
* control's `aria-describedby`, so it is read when the submit moves focus there, and a live role
|
|
46
|
+
* would fire one alert per invalid field.
|
|
47
|
+
*/
|
|
48
|
+
function FieldMessage({ id, message, className }) {
|
|
49
|
+
if (!message) return null;
|
|
50
|
+
return /* @__PURE__ */ jsx("p", {
|
|
51
|
+
id,
|
|
52
|
+
className: cn(descriptionClasses, "text-danger-ink", className),
|
|
53
|
+
children: message
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One labelled field in whichever frame the form asked for: label, control, description, and
|
|
58
|
+
* the first validation error, with the label's `htmlFor` and the control's `aria-describedby`
|
|
59
|
+
* and `aria-invalid` wired the same way in both layouts. In `stack` the error takes the
|
|
60
|
+
* description's place, worded as the fix, so the line under the control never doubles up.
|
|
61
|
+
*/
|
|
62
|
+
function Field({ label, description, isRequired, layout = "stack", className, labelClassName, valueClassName, trailing, disabledReason, children }) {
|
|
63
|
+
const field = useFieldContext();
|
|
64
|
+
const id = useId();
|
|
65
|
+
const descriptionId = `${id}-description`;
|
|
66
|
+
const messageId = `${id}-message`;
|
|
67
|
+
const message = fieldError(field.state.meta);
|
|
68
|
+
const showsDescription = !!description && (layout === "rows" || !message);
|
|
69
|
+
const controlProps = {
|
|
70
|
+
id,
|
|
71
|
+
name: field.name,
|
|
72
|
+
"aria-describedby": formatIdList(showsDescription && descriptionId, message && messageId),
|
|
73
|
+
"aria-invalid": message ? true : void 0,
|
|
74
|
+
"aria-required": isRequired ? true : void 0,
|
|
75
|
+
onBlur: field.handleBlur
|
|
76
|
+
};
|
|
77
|
+
const control = typeof children === "function" ? children(controlProps) : /* @__PURE__ */ jsx(DisabledReason, {
|
|
78
|
+
reason: disabledReason,
|
|
79
|
+
children: cloneElement(children, mergeProps(controlProps, children.props))
|
|
80
|
+
});
|
|
81
|
+
let labelNode = /* @__PURE__ */ jsx(Label, {
|
|
82
|
+
htmlFor: id,
|
|
83
|
+
isRequired,
|
|
84
|
+
className: labelClassName,
|
|
85
|
+
children: label
|
|
86
|
+
});
|
|
87
|
+
if (trailing) labelNode = /* @__PURE__ */ jsxs("div", {
|
|
88
|
+
className: "flex items-center justify-between gap-2",
|
|
89
|
+
children: [labelNode, /* @__PURE__ */ jsx("div", {
|
|
90
|
+
className: "flex shrink-0 items-center text-control",
|
|
91
|
+
children: trailing
|
|
92
|
+
})]
|
|
93
|
+
});
|
|
94
|
+
const messageNode = /* @__PURE__ */ jsx(FieldMessage, {
|
|
95
|
+
id: messageId,
|
|
96
|
+
message
|
|
97
|
+
});
|
|
98
|
+
if (layout === "rows") return /* @__PURE__ */ jsxs(DetailRow, {
|
|
99
|
+
density: "form",
|
|
100
|
+
label: labelNode,
|
|
101
|
+
description: description && /* @__PURE__ */ jsx("p", {
|
|
102
|
+
id: descriptionId,
|
|
103
|
+
children: description
|
|
104
|
+
}),
|
|
105
|
+
className,
|
|
106
|
+
valueClassName,
|
|
107
|
+
children: [control, messageNode]
|
|
108
|
+
});
|
|
109
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
110
|
+
className: cn("flex flex-col gap-1.5 has-disabled:[&_label]:cursor-default has-aria-disabled:[&_label]:cursor-default", className),
|
|
111
|
+
children: [
|
|
112
|
+
labelNode,
|
|
113
|
+
control,
|
|
114
|
+
showsDescription && /* @__PURE__ */ jsx("p", {
|
|
115
|
+
id: descriptionId,
|
|
116
|
+
className: "max-w-prose text-copy text-ink-muted",
|
|
117
|
+
children: description
|
|
118
|
+
}),
|
|
119
|
+
messageNode
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Splits a field component's props into the `Field` frame's and the control's. */
|
|
124
|
+
function splitFrame({ label, description, isRequired, layout, className, labelClassName, valueClassName, trailing, disabledReason, ...control }) {
|
|
125
|
+
return [{
|
|
126
|
+
label,
|
|
127
|
+
description,
|
|
128
|
+
isRequired,
|
|
129
|
+
layout,
|
|
130
|
+
className,
|
|
131
|
+
labelClassName,
|
|
132
|
+
valueClassName,
|
|
133
|
+
trailing,
|
|
134
|
+
disabledReason
|
|
135
|
+
}, control];
|
|
136
|
+
}
|
|
137
|
+
/** A `Field` around an `Input` bound to a string field. */
|
|
138
|
+
function TextField(props) {
|
|
139
|
+
const [frame, control] = splitFrame(props);
|
|
140
|
+
const field = useFieldContext();
|
|
141
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
142
|
+
...frame,
|
|
143
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
144
|
+
...control,
|
|
145
|
+
value: field.state.value,
|
|
146
|
+
readOnly: control.readOnly === true || !!frame.disabledReason,
|
|
147
|
+
onChange: (event) => field.handleChange(event.target.value)
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** A `Field` around a `Textarea` bound to a string field. */
|
|
152
|
+
function TextareaField(props) {
|
|
153
|
+
const [frame, control] = splitFrame(props);
|
|
154
|
+
const field = useFieldContext();
|
|
155
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
156
|
+
...frame,
|
|
157
|
+
children: /* @__PURE__ */ jsx(Textarea, {
|
|
158
|
+
...control,
|
|
159
|
+
value: field.state.value,
|
|
160
|
+
readOnly: control.readOnly === true || !!frame.disabledReason,
|
|
161
|
+
onChange: (event) => field.handleChange(event.target.value)
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/** A `Field` around a `NumberInput` bound to a number field; `nullable` for one that may be null. */
|
|
166
|
+
function NumberField(props) {
|
|
167
|
+
const [frame, control] = splitFrame(props);
|
|
168
|
+
const field = useFieldContext();
|
|
169
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
170
|
+
...frame,
|
|
171
|
+
children: /* @__PURE__ */ jsx(NumberInput, {
|
|
172
|
+
...control,
|
|
173
|
+
value: field.state.value,
|
|
174
|
+
readOnly: control.readOnly === true || !!frame.disabledReason,
|
|
175
|
+
onValueChange: (value) => field.handleChange(value)
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A `Field` around a `Select` bound to a string field, one item per entry of `items`, or per
|
|
181
|
+
* entry of each of the `groups`.
|
|
182
|
+
*/
|
|
183
|
+
function SelectField({ items, groups, reasons, prefix, placeholder, ...frame }) {
|
|
184
|
+
const field = useFieldContext();
|
|
185
|
+
const sections = groups ?? [{ items: items ?? {} }];
|
|
186
|
+
const labels = Object.assign({}, ...sections.map((section) => section.items));
|
|
187
|
+
function item(value, label) {
|
|
188
|
+
return /* @__PURE__ */ jsx(SelectItem, {
|
|
189
|
+
value,
|
|
190
|
+
label,
|
|
191
|
+
prefix: prefix?.(value),
|
|
192
|
+
disabledReason: reasons?.[value],
|
|
193
|
+
children: label
|
|
194
|
+
}, value);
|
|
195
|
+
}
|
|
196
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
197
|
+
...frame,
|
|
198
|
+
children: ({ onBlur, ...control }) => /* @__PURE__ */ jsxs(Select, {
|
|
199
|
+
items: labels,
|
|
200
|
+
value: field.state.value,
|
|
201
|
+
readOnly: !!frame.disabledReason,
|
|
202
|
+
onValueChange: (value) => value !== null && field.handleChange(value),
|
|
203
|
+
onOpenChange: (open) => !open && onBlur(),
|
|
204
|
+
children: [/* @__PURE__ */ jsx(DisabledReason, {
|
|
205
|
+
reason: frame.disabledReason,
|
|
206
|
+
children: /* @__PURE__ */ jsx(SelectTrigger, {
|
|
207
|
+
...control,
|
|
208
|
+
children: /* @__PURE__ */ jsx(SelectValue, { placeholder })
|
|
209
|
+
})
|
|
210
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: sections.map((section, index) => /* @__PURE__ */ jsxs(SelectGroup, { children: [
|
|
211
|
+
index > 0 && /* @__PURE__ */ jsx(SelectSeparator, {}),
|
|
212
|
+
section.label && /* @__PURE__ */ jsx(SelectLabel, { children: section.label }),
|
|
213
|
+
Object.entries(section.items).map(([value, label]) => item(value, label))
|
|
214
|
+
] }, index)) })]
|
|
215
|
+
})
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const DatePicker = lazy(() => import("./date-picker.js").then((module) => ({ default: module.DatePicker })));
|
|
219
|
+
/** A `Field` around a `DatePicker` bound to a "YYYY-MM-DD" string field. */
|
|
220
|
+
function DateField({ min, max, placeholder, formatDay, disabled = false, clearable, ...frame }) {
|
|
221
|
+
const field = useFieldContext();
|
|
222
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
223
|
+
...frame,
|
|
224
|
+
children: ({ name: _name, ...control }) => /* @__PURE__ */ jsx(Suspense, {
|
|
225
|
+
fallback: /* @__PURE__ */ jsx(DatePickerTrigger, {
|
|
226
|
+
value: field.state.value,
|
|
227
|
+
"aria-hidden": true,
|
|
228
|
+
placeholder,
|
|
229
|
+
formatDay,
|
|
230
|
+
disabled,
|
|
231
|
+
inert: true
|
|
232
|
+
}),
|
|
233
|
+
children: /* @__PURE__ */ jsx(DatePicker, {
|
|
234
|
+
...control,
|
|
235
|
+
value: field.state.value,
|
|
236
|
+
min,
|
|
237
|
+
max,
|
|
238
|
+
placeholder,
|
|
239
|
+
formatDay,
|
|
240
|
+
clearable,
|
|
241
|
+
disabled,
|
|
242
|
+
disabledReason: frame.disabledReason,
|
|
243
|
+
onChange: (value) => field.handleChange(value)
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A switch with its label and one line of consequence beside it, bound to a boolean field.
|
|
250
|
+
* Its own frame rather than `Field`: a switch sits at the end of its label's line in every
|
|
251
|
+
* layout, and Base UI renders it as a `<span role="switch">`, which `<label for>` cannot address.
|
|
252
|
+
*/
|
|
253
|
+
function SwitchField({ label, description, className, children }) {
|
|
254
|
+
const field = useFieldContext();
|
|
255
|
+
const id = useId();
|
|
256
|
+
const descriptionId = `${id}-description`;
|
|
257
|
+
const messageId = `${id}-message`;
|
|
258
|
+
const message = fieldError(field.state.meta);
|
|
259
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
260
|
+
className: cn("flex flex-col gap-3", className),
|
|
261
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
262
|
+
className: "flex items-start justify-between gap-4",
|
|
263
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
264
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
265
|
+
children: [
|
|
266
|
+
/* @__PURE__ */ jsx("span", {
|
|
267
|
+
id,
|
|
268
|
+
className: "font-medium text-sm",
|
|
269
|
+
children: label
|
|
270
|
+
}),
|
|
271
|
+
description && /* @__PURE__ */ jsx("span", {
|
|
272
|
+
id: descriptionId,
|
|
273
|
+
className: "max-w-prose text-copy text-ink-muted",
|
|
274
|
+
children: description
|
|
275
|
+
}),
|
|
276
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
277
|
+
id: messageId,
|
|
278
|
+
message
|
|
279
|
+
})
|
|
280
|
+
]
|
|
281
|
+
}), /* @__PURE__ */ jsx(Switch, {
|
|
282
|
+
checked: field.state.value,
|
|
283
|
+
"aria-labelledby": id,
|
|
284
|
+
"aria-describedby": formatIdList(!!description && descriptionId, message && messageId),
|
|
285
|
+
"aria-invalid": message ? true : void 0,
|
|
286
|
+
className: "mt-0.5 shrink-0",
|
|
287
|
+
onCheckedChange: (checked) => field.handleChange(checked),
|
|
288
|
+
onBlur: field.handleBlur
|
|
289
|
+
})]
|
|
290
|
+
}), field.state.value && children]
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* A checkbox before its label, bound to a boolean field. The row is a `<label>`, so a click on
|
|
295
|
+
* the text toggles the box; the description and the error sit under the label text, not under
|
|
296
|
+
* the box. Use it for an option of a one-off action; a setting that stays on is a `SwitchField`.
|
|
297
|
+
*/
|
|
298
|
+
function CheckboxField({ label, description, className }) {
|
|
299
|
+
const field = useFieldContext();
|
|
300
|
+
const id = useId();
|
|
301
|
+
const descriptionId = `${id}-description`;
|
|
302
|
+
const messageId = `${id}-message`;
|
|
303
|
+
const message = fieldError(field.state.meta);
|
|
304
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
305
|
+
className: cn("flex flex-col gap-0.5 self-start", className),
|
|
306
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
307
|
+
className: "flex cursor-pointer items-start gap-2",
|
|
308
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
309
|
+
checked: field.state.value,
|
|
310
|
+
"aria-labelledby": id,
|
|
311
|
+
"aria-describedby": formatIdList(!!description && descriptionId, message && messageId),
|
|
312
|
+
"aria-invalid": message ? true : void 0,
|
|
313
|
+
className: "mt-0.5",
|
|
314
|
+
onCheckedChange: (checked) => field.handleChange(checked),
|
|
315
|
+
onBlur: field.handleBlur
|
|
316
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
317
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
318
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
319
|
+
id,
|
|
320
|
+
className: "text-sm",
|
|
321
|
+
children: label
|
|
322
|
+
}), description && /* @__PURE__ */ jsx("span", {
|
|
323
|
+
id: descriptionId,
|
|
324
|
+
className: "max-w-prose text-copy text-ink-muted",
|
|
325
|
+
children: description
|
|
326
|
+
})]
|
|
327
|
+
})]
|
|
328
|
+
}), /* @__PURE__ */ jsx(FieldMessage, {
|
|
329
|
+
id: messageId,
|
|
330
|
+
message,
|
|
331
|
+
className: "pl-6"
|
|
332
|
+
})]
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* A choice out of a few cards, bound to a string field, for choices that each need a sentence
|
|
337
|
+
* to tell apart. Two plain states are a `SwitchField`, a long list a `SelectField`.
|
|
338
|
+
*/
|
|
339
|
+
function RadioCardField({ label, description, options, className, disabledReason, children }) {
|
|
340
|
+
const field = useFieldContext();
|
|
341
|
+
const id = useId();
|
|
342
|
+
const descriptionId = `${id}-description`;
|
|
343
|
+
const messageId = `${id}-message`;
|
|
344
|
+
const message = fieldError(field.state.meta);
|
|
345
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
346
|
+
className: cn("flex flex-col gap-3", className),
|
|
347
|
+
children: [
|
|
348
|
+
/* @__PURE__ */ jsxs("div", {
|
|
349
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
350
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
351
|
+
id,
|
|
352
|
+
className: "font-medium text-sm",
|
|
353
|
+
children: label
|
|
354
|
+
}), description && /* @__PURE__ */ jsx("span", {
|
|
355
|
+
id: descriptionId,
|
|
356
|
+
className: "max-w-prose text-copy text-ink-muted",
|
|
357
|
+
children: description
|
|
358
|
+
})]
|
|
359
|
+
}),
|
|
360
|
+
/* @__PURE__ */ jsx(RadioGroup, {
|
|
361
|
+
value: field.state.value,
|
|
362
|
+
readOnly: !!disabledReason,
|
|
363
|
+
"aria-labelledby": id,
|
|
364
|
+
"aria-describedby": formatIdList(!!description && descriptionId, message && messageId),
|
|
365
|
+
"aria-invalid": message ? true : void 0,
|
|
366
|
+
onValueChange: (value) => field.handleChange(value),
|
|
367
|
+
children: options.map(({ value, disabledReason: optionReason, ...option }) => /* @__PURE__ */ jsx(RadioCard, {
|
|
368
|
+
value,
|
|
369
|
+
disabledReason: disabledReason ?? optionReason,
|
|
370
|
+
onBlur: field.handleBlur,
|
|
371
|
+
...option
|
|
372
|
+
}, value))
|
|
373
|
+
}),
|
|
374
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
375
|
+
id: messageId,
|
|
376
|
+
message
|
|
377
|
+
}),
|
|
378
|
+
children
|
|
379
|
+
]
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The control to focus for the first invalid field: the marked element itself, or for a group
|
|
384
|
+
* that cannot take focus (a radio group), the control inside it the Tab key would reach.
|
|
385
|
+
*/
|
|
386
|
+
function findInvalidControl(form) {
|
|
387
|
+
const invalid = form.querySelector("[aria-invalid=\"true\"]");
|
|
388
|
+
if (!invalid) return;
|
|
389
|
+
if (invalid.tabIndex >= 0) return invalid;
|
|
390
|
+
return invalid.querySelector("[tabindex=\"0\"]") ?? void 0;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* The `<form>` element of a TanStack form: provides the form to the components inside it,
|
|
394
|
+
* validates the whole form and hands submit to `handleSubmit`, then moves focus to the first
|
|
395
|
+
* invalid control. Browser validation is off, since the form's own validators own the messages.
|
|
396
|
+
*
|
|
397
|
+
* The explicit `validate` matters: `handleSubmit` runs the form-level validators (where a
|
|
398
|
+
* schema lives) only once every field is valid, so while one error stands a field revealed
|
|
399
|
+
* since the last submit would never get its own.
|
|
400
|
+
*/
|
|
401
|
+
function Form({ form: { AppForm, validate, handleSubmit }, ...props }) {
|
|
402
|
+
return /* @__PURE__ */ jsx(AppForm, { children: /* @__PURE__ */ jsx("form", {
|
|
403
|
+
noValidate: true,
|
|
404
|
+
...props,
|
|
405
|
+
onSubmit: (event) => {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
event.stopPropagation();
|
|
408
|
+
const element = event.currentTarget;
|
|
409
|
+
Promise.resolve(validate("submit")).then(() => handleSubmit()).then(() => findInvalidControl(element)?.focus());
|
|
410
|
+
}
|
|
411
|
+
}) });
|
|
412
|
+
}
|
|
413
|
+
/** A submit button that shows the form's pending state. */
|
|
414
|
+
function SubmitButton({ isPending = false, ...props }) {
|
|
415
|
+
const form = useFormContext();
|
|
416
|
+
return /* @__PURE__ */ jsx(form.Subscribe, {
|
|
417
|
+
selector: (state) => state.isSubmitting,
|
|
418
|
+
children: (isSubmitting) => /* @__PURE__ */ jsx(Button, {
|
|
419
|
+
type: "submit",
|
|
420
|
+
isPending: isPending || isSubmitting,
|
|
421
|
+
...props
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/** The error the last submit left on the form as a whole, if any. Field errors show on their fields. */
|
|
426
|
+
function FormError({ className }) {
|
|
427
|
+
const form = useFormContext();
|
|
428
|
+
return /* @__PURE__ */ jsx(form.Subscribe, {
|
|
429
|
+
selector: (state) => errorMessage(state.errorMap.onSubmit),
|
|
430
|
+
children: (message) => message ? /* @__PURE__ */ jsx(Callout, {
|
|
431
|
+
tone: "danger",
|
|
432
|
+
live: "assertive",
|
|
433
|
+
className,
|
|
434
|
+
children: /* @__PURE__ */ jsx(CalloutText, { children: message })
|
|
435
|
+
}) : null
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
/** The sets `createFormHook` takes, so an app registers every primitive in one line. */
|
|
439
|
+
const fieldComponents = {
|
|
440
|
+
Field,
|
|
441
|
+
TextField,
|
|
442
|
+
TextareaField,
|
|
443
|
+
NumberField,
|
|
444
|
+
SelectField,
|
|
445
|
+
DateField,
|
|
446
|
+
SwitchField,
|
|
447
|
+
CheckboxField,
|
|
448
|
+
RadioCardField
|
|
449
|
+
};
|
|
450
|
+
const formComponents = {
|
|
451
|
+
SubmitButton,
|
|
452
|
+
FormError
|
|
453
|
+
};
|
|
454
|
+
export { CheckboxField, DateField, Field, Form, FormError, NumberField, RadioCardField, SelectField, SubmitButton, SwitchField, TextField, TextareaField, fieldComponents, fieldContext, fieldError, formComponents, formContext, useFieldContext, useFormContext };
|
|
455
|
+
|
|
456
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","names":[],"sources":["../../src/components/form.tsx"],"sourcesContent":["\"use client\"\n\nimport { mergeProps } from \"@base-ui/react/merge-props\"\nimport { createFormHookContexts } from \"@tanstack/react-form\"\nimport {\n cloneElement,\n type ComponentProps,\n type ComponentType,\n lazy,\n type ReactElement,\n type ReactNode,\n Suspense,\n useId,\n} from \"react\"\nimport { formatIdList } from \"../lib/aria\"\nimport { descriptionClasses } from \"../lib/classes\"\nimport { cn } from \"../lib/variants\"\nimport { Button } from \"./button\"\nimport { Callout, CalloutText } from \"./callout\"\nimport { Checkbox } from \"./checkbox\"\nimport type { DatePickerProps } from \"./date-picker\"\nimport { DatePickerTrigger } from \"./date-picker-trigger\"\nimport { DetailRow } from \"./detail-row\"\nimport { DisabledReason } from \"./disabled-reason\"\nimport { Input } from \"./input\"\nimport { Label } from \"./label\"\nimport { NumberInput } from \"./number-input\"\nimport { RadioCard, RadioGroup } from \"./radio-group\"\nimport {\n Select,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectSeparator,\n SelectTrigger,\n SelectValue,\n} from \"./select\"\nimport { Switch } from \"./switch\"\nimport { Textarea } from \"./textarea\"\n\n/**\n * Form primitives over TanStack Form. An app wires them up once with `createFormHook`:\n *\n * const { useAppForm } = createFormHook({ fieldContext, formContext, fieldComponents, formComponents })\n *\n * and then writes `<form.AppField name=\"email\">{field => <field.TextField label=\"Email\" />}</form.AppField>`\n * inside a `<Form form={form}>`. The field components read the field they belong to from context,\n * so a call site names the field once, on `AppField`.\n */\n\nexport const { fieldContext, formContext, useFieldContext, useFormContext } =\n createFormHookContexts()\n\n/**\n * `stack` puts the label above a full-width control, for dialogs and single-column pages;\n * `rows` puts the label and its description beside the control, for a `divide-y` settings body.\n */\nexport type FieldLayout = \"stack\" | \"rows\"\n\n/** What a control needs to be the field's: its id, the aria links to the copy under it, and blur. */\nexport interface FieldControlProps {\n id: string\n name: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: true\n \"aria-required\"?: true\n onBlur: () => void\n}\n\n/** A validator's error as text. Standard Schema issues are objects; a plain validator returns a string. */\nfunction errorMessage(error: unknown) {\n if (typeof error === \"string\") return error\n if (error && typeof error === \"object\" && \"message\" in error) return String(error.message)\n return\n}\n\n/** The error a touched field shows, for a field that renders its own control and message. */\nexport function fieldError(meta: { isTouched: boolean; errors: unknown[] }) {\n if (!meta.isTouched) return\n return meta.errors.map(errorMessage).find(Boolean)\n}\n\ninterface FieldMessageProps {\n id: string\n message: string | undefined\n className?: string\n}\n\n/**\n * A field's validation error, under its control. Not a live region: the message is in the\n * control's `aria-describedby`, so it is read when the submit moves focus there, and a live role\n * would fire one alert per invalid field.\n */\nfunction FieldMessage({ id, message, className }: FieldMessageProps) {\n if (!message) return null\n\n return (\n <p id={id} className={cn(descriptionClasses, \"text-danger-ink\", className)}>\n {message}\n </p>\n )\n}\n\nexport interface FieldProps {\n label: ReactNode\n description?: ReactNode\n isRequired?: boolean\n layout?: FieldLayout\n /** Classes for the whole field; a width set here constrains the control, which fills it. */\n className?: string\n /** Extra classes for the label, e.g. `sr-only` where the row around the control already names it. */\n labelClassName?: string\n /** An item at the end of the label's line: an `InlineAction`, a badge. */\n trailing?: ReactNode\n /** Extra classes for the value column in `rows` layout, e.g. `sm:items-end`. */\n valueClassName?: string\n /**\n * Why the control cannot be used: read with it, and shown above it on hover and focus. A\n * control handed over as an element gets it through `DisabledReason`; a text field also needs\n * `readOnly`, which the typed fields set. A function child wraps its own control.\n */\n disabledReason?: string\n /**\n * The control: an element the field's id and aria attributes are merged onto, or a function\n * handed them to put on the element that should carry them.\n */\n children: ReactElement<FieldControlProps> | ((control: FieldControlProps) => ReactNode)\n}\n\n/**\n * One labelled field in whichever frame the form asked for: label, control, description, and\n * the first validation error, with the label's `htmlFor` and the control's `aria-describedby`\n * and `aria-invalid` wired the same way in both layouts. In `stack` the error takes the\n * description's place, worded as the fix, so the line under the control never doubles up.\n */\nexport function Field({\n label,\n description,\n isRequired,\n layout = \"stack\",\n className,\n labelClassName,\n valueClassName,\n trailing,\n disabledReason,\n children,\n}: FieldProps) {\n const field = useFieldContext()\n const id = useId()\n const descriptionId = `${id}-description`\n const messageId = `${id}-message`\n // Only a touched field shows its error, so one a switch has just revealed starts clean; a\n // submit touches every field, which is when the whole form's errors appear.\n const message = fieldError(field.state.meta)\n // In `rows` the description sits beside the label, so an error never replaces it.\n const showsDescription = !!description && (layout === \"rows\" || !message)\n\n const controlProps: FieldControlProps = {\n id,\n name: field.name,\n \"aria-describedby\": formatIdList(showsDescription && descriptionId, message && messageId),\n \"aria-invalid\": message ? true : undefined,\n \"aria-required\": isRequired ? true : undefined,\n onBlur: field.handleBlur,\n }\n\n const control =\n typeof children === \"function\" ? (\n children(controlProps)\n ) : (\n <DisabledReason reason={disabledReason}>\n {cloneElement(children, mergeProps(controlProps, children.props))}\n </DisabledReason>\n )\n\n let labelNode = (\n <Label htmlFor={id} isRequired={isRequired} className={labelClassName}>\n {label}\n </Label>\n )\n if (trailing) {\n labelNode = (\n <div className=\"flex items-center justify-between gap-2\">\n {labelNode}\n <div className=\"flex shrink-0 items-center text-control\">{trailing}</div>\n </div>\n )\n }\n const messageNode = <FieldMessage id={messageId} message={message} />\n\n if (layout === \"rows\") {\n return (\n <DetailRow\n density=\"form\"\n label={labelNode}\n description={description && <p id={descriptionId}>{description}</p>}\n className={className}\n valueClassName={valueClassName}\n >\n {control}\n {messageNode}\n </DetailRow>\n )\n }\n\n return (\n <div\n className={cn(\n \"flex flex-col gap-1.5 has-disabled:[&_label]:cursor-default has-aria-disabled:[&_label]:cursor-default\",\n className,\n )}\n >\n {labelNode}\n {control}\n {showsDescription && (\n <p id={descriptionId} className={descriptionClasses}>\n {description}\n </p>\n )}\n {messageNode}\n </div>\n )\n}\n\ntype FrameProps = Omit<FieldProps, \"children\">\n\n/** Splits a field component's props into the `Field` frame's and the control's. */\nfunction splitFrame<T extends FrameProps>({\n label,\n description,\n isRequired,\n layout,\n className,\n labelClassName,\n valueClassName,\n trailing,\n disabledReason,\n ...control\n}: T) {\n const frame = {\n label,\n description,\n isRequired,\n layout,\n className,\n labelClassName,\n valueClassName,\n trailing,\n disabledReason,\n }\n return [frame, control] as const\n}\n\ntype TextFieldProps = FrameProps &\n Omit<ComponentProps<typeof Input>, \"value\" | \"onChange\" | \"id\" | \"name\" | \"className\">\n\n/** A `Field` around an `Input` bound to a string field. */\nexport function TextField(props: TextFieldProps) {\n const [frame, control] = splitFrame(props)\n const field = useFieldContext<string>()\n\n return (\n <Field {...frame}>\n <Input\n {...control}\n value={field.state.value}\n readOnly={control.readOnly === true || !!frame.disabledReason}\n onChange={event => field.handleChange(event.target.value)}\n />\n </Field>\n )\n}\n\ntype TextareaFieldProps = FrameProps &\n Omit<ComponentProps<typeof Textarea>, \"value\" | \"onChange\" | \"id\" | \"name\" | \"className\">\n\n/** A `Field` around a `Textarea` bound to a string field. */\nexport function TextareaField(props: TextareaFieldProps) {\n const [frame, control] = splitFrame(props)\n const field = useFieldContext<string>()\n\n return (\n <Field {...frame}>\n <Textarea\n {...control}\n value={field.state.value}\n readOnly={control.readOnly === true || !!frame.disabledReason}\n onChange={event => field.handleChange(event.target.value)}\n />\n </Field>\n )\n}\n\ntype NumberFieldProps = FrameProps &\n Omit<ComponentProps<typeof NumberInput>, \"value\" | \"onValueChange\" | \"id\" | \"name\" | \"className\">\n\n/** A `Field` around a `NumberInput` bound to a number field; `nullable` for one that may be null. */\nexport function NumberField(props: NumberFieldProps) {\n const [frame, control] = splitFrame(props)\n const field = useFieldContext<number | null | undefined>()\n\n return (\n <Field {...frame}>\n <NumberInput\n {...control}\n value={field.state.value}\n readOnly={control.readOnly === true || !!frame.disabledReason}\n onValueChange={value => field.handleChange(value)}\n />\n </Field>\n )\n}\n\n/** A run of items under one optional heading, drawn apart from the next by a separator. */\nexport interface SelectFieldGroup {\n label?: string\n /** Value to label. */\n items: Record<string, string>\n}\n\ninterface SelectFieldProps extends FrameProps {\n /**\n * Value to label, one flat list. The trigger shows the label of the selected value. Pass\n * `groups` instead to draw the list in sections.\n */\n items?: Record<string, string>\n groups?: SelectFieldGroup[]\n /** Why an item cannot be chosen, by value: it stays in the list, disabled, with the reason. */\n reasons?: Record<string, string>\n /** Something to draw before an item's label, like a glyph for the value. */\n prefix?: (value: string) => ReactNode\n placeholder?: string\n}\n\n/**\n * A `Field` around a `Select` bound to a string field, one item per entry of `items`, or per\n * entry of each of the `groups`.\n */\nexport function SelectField({\n items,\n groups,\n reasons,\n prefix,\n placeholder,\n ...frame\n}: SelectFieldProps) {\n const field = useFieldContext<string>()\n const sections = groups ?? [{ items: items ?? {} }]\n // Every value to its label, whichever section it sits in: the trigger reads it from here.\n const labels = Object.assign({}, ...sections.map(section => section.items))\n\n function item(value: string, label: string) {\n return (\n <SelectItem\n key={value}\n value={value}\n label={label}\n prefix={prefix?.(value)}\n disabledReason={reasons?.[value]}\n >\n {label}\n </SelectItem>\n )\n }\n\n return (\n <Field {...frame}>\n {({ onBlur, ...control }) => (\n <Select\n items={labels}\n value={field.state.value}\n readOnly={!!frame.disabledReason}\n // Base UI reports a cleared selection as null; a select with no empty item never clears.\n onValueChange={value => value !== null && field.handleChange(value)}\n onOpenChange={open => !open && onBlur()}\n >\n <DisabledReason reason={frame.disabledReason}>\n <SelectTrigger {...control}>\n <SelectValue placeholder={placeholder} />\n </SelectTrigger>\n </DisabledReason>\n <SelectContent>\n {sections.map((section, index) => (\n <SelectGroup key={index}>\n {index > 0 && <SelectSeparator />}\n {section.label && <SelectLabel>{section.label}</SelectLabel>}\n {Object.entries(section.items).map(([value, label]) => item(value, label))}\n </SelectGroup>\n ))}\n </SelectContent>\n </Select>\n )}\n </Field>\n )\n}\n\ntype DateFieldProps = FrameProps &\n Pick<DatePickerProps, \"min\" | \"max\" | \"placeholder\" | \"formatDay\" | \"disabled\" | \"clearable\">\n\n// Every form hook registers `DateField`, so a direct import would put the calendar and its\n// popover on every page with a form, sign-in included. It loads when a date field first renders.\nconst DatePicker = lazy(() =>\n import(\"./date-picker\").then(module => ({ default: module.DatePicker })),\n)\n\n/** A `Field` around a `DatePicker` bound to a \"YYYY-MM-DD\" string field. */\nexport function DateField({\n min,\n max,\n placeholder,\n formatDay,\n disabled = false,\n clearable,\n ...frame\n}: DateFieldProps) {\n const field = useFieldContext<string>()\n\n return (\n <Field {...frame}>\n {({ name: _name, ...control }) => (\n // The fallback is the picker's own trigger, so nothing moves when the calendar arrives.\n // `inert` rather than `disabled`, which would dim it for that moment.\n <Suspense\n fallback={\n <DatePickerTrigger\n value={field.state.value}\n aria-hidden\n placeholder={placeholder}\n formatDay={formatDay}\n disabled={disabled}\n inert\n />\n }\n >\n <DatePicker\n {...control}\n value={field.state.value}\n min={min}\n max={max}\n placeholder={placeholder}\n formatDay={formatDay}\n clearable={clearable}\n disabled={disabled}\n disabledReason={frame.disabledReason}\n onChange={value => field.handleChange(value)}\n />\n </Suspense>\n )}\n </Field>\n )\n}\n\ninterface SwitchFieldProps {\n label: ReactNode\n description?: ReactNode\n className?: string\n /** What the switch turns on, e.g. the password field itself. Rendered only while it is on. */\n children?: ReactNode\n}\n\n/**\n * A switch with its label and one line of consequence beside it, bound to a boolean field.\n * Its own frame rather than `Field`: a switch sits at the end of its label's line in every\n * layout, and Base UI renders it as a `<span role=\"switch\">`, which `<label for>` cannot address.\n */\nexport function SwitchField({ label, description, className, children }: SwitchFieldProps) {\n const field = useFieldContext<boolean>()\n const id = useId()\n const descriptionId = `${id}-description`\n const messageId = `${id}-message`\n const message = fieldError(field.state.meta)\n\n return (\n <div className={cn(\"flex flex-col gap-3\", className)}>\n <div className=\"flex items-start justify-between gap-4\">\n <div className=\"flex min-w-0 flex-col gap-0.5\">\n <span id={id} className=\"font-medium text-sm\">\n {label}\n </span>\n {description && (\n <span id={descriptionId} className={descriptionClasses}>\n {description}\n </span>\n )}\n <FieldMessage id={messageId} message={message} />\n </div>\n\n <Switch\n checked={field.state.value}\n aria-labelledby={id}\n aria-describedby={formatIdList(!!description && descriptionId, message && messageId)}\n aria-invalid={message ? true : undefined}\n className=\"mt-0.5 shrink-0\"\n onCheckedChange={checked => field.handleChange(checked)}\n onBlur={field.handleBlur}\n />\n </div>\n\n {field.state.value && children}\n </div>\n )\n}\n\ninterface CheckboxFieldProps {\n label: ReactNode\n description?: ReactNode\n className?: string\n}\n\n/**\n * A checkbox before its label, bound to a boolean field. The row is a `<label>`, so a click on\n * the text toggles the box; the description and the error sit under the label text, not under\n * the box. Use it for an option of a one-off action; a setting that stays on is a `SwitchField`.\n */\nexport function CheckboxField({ label, description, className }: CheckboxFieldProps) {\n const field = useFieldContext<boolean>()\n const id = useId()\n const descriptionId = `${id}-description`\n const messageId = `${id}-message`\n const message = fieldError(field.state.meta)\n\n return (\n <div className={cn(\"flex flex-col gap-0.5 self-start\", className)}>\n <label className=\"flex cursor-pointer items-start gap-2\">\n <Checkbox\n checked={field.state.value}\n aria-labelledby={id}\n aria-describedby={formatIdList(!!description && descriptionId, message && messageId)}\n aria-invalid={message ? true : undefined}\n className=\"mt-0.5\"\n onCheckedChange={checked => field.handleChange(checked)}\n onBlur={field.handleBlur}\n />\n\n <span className=\"flex min-w-0 flex-col gap-0.5\">\n <span id={id} className=\"text-sm\">\n {label}\n </span>\n {description && (\n <span id={descriptionId} className={descriptionClasses}>\n {description}\n </span>\n )}\n </span>\n </label>\n\n {/* Indented by the box and its gap, so it lines up with the label text. */}\n <FieldMessage id={messageId} message={message} className=\"pl-6\" />\n </div>\n )\n}\n\nexport interface RadioCardOption {\n value: string\n label: ReactNode\n description?: ReactNode\n badge?: ReactNode\n /** Why this card alone cannot be chosen, as `disabledReason` says it for all of them. */\n disabledReason?: string\n}\n\ninterface RadioCardFieldProps {\n label: ReactNode\n description?: ReactNode\n options: RadioCardOption[]\n className?: string\n /**\n * Why the cards cannot be chosen: they stay reachable and cannot be picked, and each one reads\n * the reason and shows it above itself on hover and focus.\n */\n disabledReason?: string\n /** Under the cards, e.g. a note that holds for every choice. */\n children?: ReactNode\n}\n\n/**\n * A choice out of a few cards, bound to a string field, for choices that each need a sentence\n * to tell apart. Two plain states are a `SwitchField`, a long list a `SelectField`.\n */\nexport function RadioCardField({\n label,\n description,\n options,\n className,\n disabledReason,\n children,\n}: RadioCardFieldProps) {\n const field = useFieldContext<string>()\n const id = useId()\n const descriptionId = `${id}-description`\n const messageId = `${id}-message`\n const message = fieldError(field.state.meta)\n\n return (\n <div className={cn(\"flex flex-col gap-3\", className)}>\n <div className=\"flex min-w-0 flex-col gap-0.5\">\n <span id={id} className=\"font-medium text-sm\">\n {label}\n </span>\n {description && (\n <span id={descriptionId} className={descriptionClasses}>\n {description}\n </span>\n )}\n </div>\n\n <RadioGroup\n value={field.state.value}\n readOnly={!!disabledReason}\n aria-labelledby={id}\n aria-describedby={formatIdList(!!description && descriptionId, message && messageId)}\n aria-invalid={message ? true : undefined}\n onValueChange={value => field.handleChange(value)}\n >\n {options.map(({ value, disabledReason: optionReason, ...option }) => (\n <RadioCard\n key={value}\n value={value}\n disabledReason={disabledReason ?? optionReason}\n onBlur={field.handleBlur}\n {...option}\n />\n ))}\n </RadioGroup>\n\n <FieldMessage id={messageId} message={message} />\n\n {children}\n </div>\n )\n}\n\n/** The part of a `useAppForm` result the `Form` element needs: the provider and the submit. */\nexport interface SubmittableForm {\n AppForm: ComponentType<{ children?: ReactNode }>\n validate: (cause: \"submit\") => unknown\n handleSubmit: () => Promise<void>\n}\n\ninterface FormProps extends Omit<ComponentProps<\"form\">, \"onSubmit\"> {\n form: SubmittableForm\n}\n\n/**\n * The control to focus for the first invalid field: the marked element itself, or for a group\n * that cannot take focus (a radio group), the control inside it the Tab key would reach.\n */\nfunction findInvalidControl(form: HTMLFormElement) {\n const invalid = form.querySelector<HTMLElement>('[aria-invalid=\"true\"]')\n if (!invalid) return\n if (invalid.tabIndex >= 0) return invalid\n return invalid.querySelector<HTMLElement>('[tabindex=\"0\"]') ?? undefined\n}\n\n/**\n * The `<form>` element of a TanStack form: provides the form to the components inside it,\n * validates the whole form and hands submit to `handleSubmit`, then moves focus to the first\n * invalid control. Browser validation is off, since the form's own validators own the messages.\n *\n * The explicit `validate` matters: `handleSubmit` runs the form-level validators (where a\n * schema lives) only once every field is valid, so while one error stands a field revealed\n * since the last submit would never get its own.\n */\nexport function Form({ form: { AppForm, validate, handleSubmit }, ...props }: FormProps) {\n return (\n <AppForm>\n <form\n noValidate\n {...props}\n onSubmit={event => {\n event.preventDefault()\n event.stopPropagation()\n const element = event.currentTarget\n void Promise.resolve(validate(\"submit\"))\n .then(() => handleSubmit())\n .then(() => findInvalidControl(element)?.focus())\n }}\n />\n </AppForm>\n )\n}\n\n/** A submit button that shows the form's pending state. */\nexport function SubmitButton({ isPending = false, ...props }: ComponentProps<typeof Button>) {\n const form = useFormContext()\n\n return (\n <form.Subscribe selector={state => state.isSubmitting}>\n {isSubmitting => <Button type=\"submit\" isPending={isPending || isSubmitting} {...props} />}\n </form.Subscribe>\n )\n}\n\ninterface FormErrorProps {\n className?: string\n}\n\n/** The error the last submit left on the form as a whole, if any. Field errors show on their fields. */\nexport function FormError({ className }: FormErrorProps) {\n const form = useFormContext()\n\n return (\n <form.Subscribe selector={state => errorMessage(state.errorMap.onSubmit)}>\n {message =>\n message ? (\n <Callout tone=\"danger\" live=\"assertive\" className={className}>\n <CalloutText>{message}</CalloutText>\n </Callout>\n ) : null\n }\n </form.Subscribe>\n )\n}\n\n/** The sets `createFormHook` takes, so an app registers every primitive in one line. */\nexport const fieldComponents = {\n Field,\n TextField,\n TextareaField,\n NumberField,\n SelectField,\n DateField,\n SwitchField,\n CheckboxField,\n RadioCardField,\n}\nexport const formComponents = { SubmitButton, FormError }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,EAAE,cAAc,aAAa,iBAAiB,mBACzD,uBAAuB;;AAmBzB,SAAS,aAAa,OAAgB;CACpC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,SAAS,OAAO,UAAU,YAAY,aAAa,OAAO,OAAO,OAAO,MAAM,OAAO;AAE3F;;AAGA,SAAgB,WAAW,MAAiD;CAC1E,IAAI,CAAC,KAAK,WAAW;CACrB,OAAO,KAAK,OAAO,IAAI,YAAY,CAAC,CAAC,KAAK,OAAO;AACnD;;;;;;AAaA,SAAS,aAAa,EAAE,IAAI,SAAS,aAAgC;CACnE,IAAI,CAAC,SAAS,OAAO;CAErB,OACE,oBAAC,KAAD;EAAO;EAAI,WAAW,GAAG,oBAAoB,mBAAmB,SAAS;EACtE,UAAA;CACA,CAAA;AAEP;;;;;;;AAkCA,SAAgB,MAAM,EACpB,OACA,aACA,YACA,SAAS,SACT,WACA,gBACA,gBACA,UACA,gBACA,YACa;CACb,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,KAAK,MAAM;CACjB,MAAM,gBAAgB,GAAG,GAAG;CAC5B,M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AAC,KAAK,WAAN;EAAgB,WAAU,UAAS,aAAa,MAAM,SAAS,QAAQ;EACpE,WAAA,YACC,UACE,oBAAC,SAAD;GAAS,MAAK;GAAS,MAAK;GAAuB;GACjD,UAAA,oBAAC,aAAD,EAAA,UAAc,QAAqB,CAAA;EAC5B,CAAA,IACP;CAEQ,CAAA;AAEpB;;AAGA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAa,iBAAiB;CAAE;CAAc;AAAU"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a number into the text a reader sees. The app supplies it, so every figure on a page
|
|
3
|
+
* follows the app's own locale and rules: the library builds no number formatter of its own.
|
|
4
|
+
*/
|
|
5
|
+
export type NumberFormat = (value: number) => string;
|
|
6
|
+
interface FormattedNumberProps {
|
|
7
|
+
/**
|
|
8
|
+
* Strings (empty-value dashes like "—") render as-is.
|
|
9
|
+
*/
|
|
10
|
+
value: number | string;
|
|
11
|
+
/** Without one, the number renders as its plain digits. */
|
|
12
|
+
format?: NumberFormat;
|
|
13
|
+
prefix?: string;
|
|
14
|
+
suffix?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A formatted number, rendered as plain text. Memoised: a board renders hundreds of these, and
|
|
18
|
+
* most keep their value from one render to the next.
|
|
19
|
+
*/
|
|
20
|
+
export declare const FormattedNumber: import("react").MemoExoticComponent<({ value, format, prefix, suffix }: FormattedNumberProps) => string>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { memo } from "react";
|
|
2
|
+
// src/components/formatted-number.tsx
|
|
3
|
+
/**
|
|
4
|
+
* A formatted number, rendered as plain text. Memoised: a board renders hundreds of these, and
|
|
5
|
+
* most keep their value from one render to the next.
|
|
6
|
+
*/
|
|
7
|
+
const FormattedNumber = memo(function FormattedNumber({ value, format, prefix = "", suffix = "" }) {
|
|
8
|
+
if (typeof value === "string") return value;
|
|
9
|
+
return `${prefix}${format ? format(value) : String(value)}${suffix}`;
|
|
10
|
+
});
|
|
11
|
+
export { FormattedNumber };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=formatted-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatted-number.js","names":[],"sources":["../../src/components/formatted-number.tsx"],"sourcesContent":["import { memo } from \"react\"\n\n/**\n * Turns a number into the text a reader sees. The app supplies it, so every figure on a page\n * follows the app's own locale and rules: the library builds no number formatter of its own.\n */\nexport type NumberFormat = (value: number) => string\n\ninterface FormattedNumberProps {\n /**\n * Strings (empty-value dashes like \"—\") render as-is.\n */\n value: number | string\n /** Without one, the number renders as its plain digits. */\n format?: NumberFormat\n prefix?: string\n suffix?: string\n}\n\n/**\n * A formatted number, rendered as plain text. Memoised: a board renders hundreds of these, and\n * most keep their value from one render to the next.\n */\nexport const FormattedNumber = memo(function FormattedNumber({\n value,\n format,\n prefix = \"\",\n suffix = \"\",\n}: FormattedNumberProps) {\n if (typeof value === \"string\") return value\n return `${prefix}${format ? format(value) : String(value)}${suffix}`\n})\n"],"mappings":";;;;;;AAuBA,MAAa,kBAAkB,KAAK,SAAS,gBAAgB,EAC3D,OACA,QACA,SAAS,IACT,SAAS,MACc;CACvB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,GAAG,SAAS,SAAS,OAAO,KAAK,IAAI,OAAO,KAAK,IAAI;AAC9D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
import { ElementType, JSX } from "react";
|
|
4
|
+
declare const headingVariants: import("tailwind-variants").TVReturnType<{
|
|
5
|
+
size: {
|
|
6
|
+
h1: string;
|
|
7
|
+
h2: string;
|
|
8
|
+
h3: string;
|
|
9
|
+
h4: string;
|
|
10
|
+
h5: string;
|
|
11
|
+
h6: string;
|
|
12
|
+
};
|
|
13
|
+
}, undefined, "font-display font-medium", undefined, undefined, undefined>;
|
|
14
|
+
export type HeadingProps = Omit<useRender.ComponentProps<"h2">, "size"> & VariantProps<typeof headingVariants> & {
|
|
15
|
+
/**
|
|
16
|
+
* Render as a different element type (h1–h6, span, ...).
|
|
17
|
+
*/
|
|
18
|
+
as?: ElementType;
|
|
19
|
+
};
|
|
20
|
+
declare function Heading({ className, as, render, size, ...props }: HeadingProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
|
+
declare function H5(props: HeadingProps): JSX.Element;
|
|
22
|
+
declare function H6(props: HeadingProps): JSX.Element;
|
|
23
|
+
export { H5, H6, Heading };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { variants } from "../lib/variants.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
4
|
+
// src/components/heading.tsx
|
|
5
|
+
const headingVariants = variants({
|
|
6
|
+
base: "font-display font-medium",
|
|
7
|
+
variants: { size: {
|
|
8
|
+
h1: "text-3xl text-balance font-semibold md:text-4xl",
|
|
9
|
+
h2: "text-2xl text-balance font-semibold md:text-3xl",
|
|
10
|
+
h3: "text-2xl text-balance",
|
|
11
|
+
h4: "text-xl text-balance",
|
|
12
|
+
h5: "text-base font-medium tracking-micro",
|
|
13
|
+
h6: "text-sm font-medium"
|
|
14
|
+
} },
|
|
15
|
+
defaultVariants: { size: "h3" }
|
|
16
|
+
});
|
|
17
|
+
function Heading({ className, as, render, size, ...props }) {
|
|
18
|
+
return useRender({
|
|
19
|
+
render,
|
|
20
|
+
defaultTagName: as ?? size ?? "h2",
|
|
21
|
+
props: {
|
|
22
|
+
className: headingVariants({
|
|
23
|
+
size,
|
|
24
|
+
className
|
|
25
|
+
}),
|
|
26
|
+
...props
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function H5(props) {
|
|
31
|
+
return /* @__PURE__ */ jsx(Heading, {
|
|
32
|
+
size: "h5",
|
|
33
|
+
...props
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function H6(props) {
|
|
37
|
+
return /* @__PURE__ */ jsx(Heading, {
|
|
38
|
+
size: "h6",
|
|
39
|
+
...props
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { H5, H6, Heading };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=heading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading.js","names":[],"sources":["../../src/components/heading.tsx"],"sourcesContent":["import { useRender } from \"@base-ui/react/use-render\"\nimport type { ElementType, JSX } from \"react\"\nimport { variants, type VariantProps } from \"../lib/variants\"\n\nconst headingVariants = variants({\n base: \"font-display font-medium\",\n\n variants: {\n size: {\n // Balanced: an even last line beats a ragged edge. `h5`/`h6` are label-sized and fit\n // one line, so they skip the cost.\n h1: \"text-3xl text-balance font-semibold md:text-4xl\",\n h2: \"text-2xl text-balance font-semibold md:text-3xl\",\n h3: \"text-2xl text-balance\",\n h4: \"text-xl text-balance\",\n h5: \"text-base font-medium tracking-micro\",\n h6: \"text-sm font-medium\",\n },\n },\n\n defaultVariants: {\n size: \"h3\",\n },\n})\n\nexport type HeadingProps = Omit<useRender.ComponentProps<\"h2\">, \"size\"> &\n VariantProps<typeof headingVariants> & {\n /**\n * Render as a different element type (h1–h6, span, ...).\n */\n as?: ElementType\n }\n\nfunction Heading({ className, as, render, size, ...props }: HeadingProps) {\n return useRender({\n render,\n defaultTagName: (as ?? size ?? \"h2\") as keyof JSX.IntrinsicElements,\n props: { className: headingVariants({ size, className }), ...props },\n })\n}\n\nfunction H5(props: HeadingProps) {\n return <Heading size=\"h5\" {...props} />\n}\n\nfunction H6(props: HeadingProps) {\n return <Heading size=\"h6\" {...props} />\n}\n\nexport { H5, H6, Heading }\n"],"mappings":";;;;AAIA,MAAM,kBAAkB,SAAS;CAC/B,MAAM;CAEN,UAAU,EACR,MAAM;EAGJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CAEA,iBAAiB,EACf,MAAM,KACR;AACF,CAAC;AAUD,SAAS,QAAQ,EAAE,WAAW,IAAI,QAAQ,MAAM,GAAG,SAAuB;CACxE,OAAO,UAAU;EACf;EACA,gBAAiB,MAAM,QAAQ;EAC/B,OAAO;GAAE,WAAW,gBAAgB;IAAE;IAAM;GAAU,CAAC;GAAG,GAAG;EAAM;CACrE,CAAC;AACH;AAEA,SAAS,GAAG,OAAqB;CAC/B,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAK,GAAI;CAAQ,CAAA;AACxC;AAEA,SAAS,GAAG,OAAqB;CAC/B,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAK,GAAI;CAAQ,CAAA;AACxC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
interface IconSwapProps<T extends string> {
|
|
3
|
+
/** The key of the mark on show. */
|
|
4
|
+
value: T;
|
|
5
|
+
marks: Record<T, ReactNode>;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Marks that share one spot and cross-fade with a state, all mounted so leaving a state animates
|
|
10
|
+
* as well as entering it. `value` names the mark on show, and the spot is as large as the
|
|
11
|
+
* largest mark. Reduced motion drops the travel and keeps the crossfade: the mark still changes,
|
|
12
|
+
* it just no longer grows into place.
|
|
13
|
+
*/
|
|
14
|
+
export declare function IconSwap<T extends string>({ value, marks, className }: IconSwapProps<T>): import("react").JSX.Element;
|
|
15
|
+
export {};
|