@brdgapp/ui 1.12.0 → 1.13.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/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
4
4
 
5
+ ## 1.13.0
6
+
7
+ 2026-11-25. Form basics on Select, Switch, TagInput and DatePicker; a banner slot and a fill-the-screen
8
+ option on AppShell; FilterChipGroup; decimals in number fields. Nothing changes for screens that pass `value` and `onChange`.
9
+
10
+ - New: AppShell's `banner`, one PageBanner under the top bar, pinned while the page scrolls. Only a banner:
11
+ tabs and the page's own controls stay in the page.
12
+ - New: Drawer's `cancelLabel={null}` leaves Cancel out, as in Dialog; `footer` replaces the standard buttons
13
+ for what they can't express (Back and Next in a step-by-step import).
14
+ - Changed: Drawer sits under AppShell's top bar only when the page has one; on a page without it (an embed,
15
+ a public page) it starts at the top of the screen. It used to leave a 56px gap there.
16
+ - New: AppShell's `fillScreen`. The page area exactly fills the screen under the top bar (and above the
17
+ phone's bottom bar), and the window doesn't scroll, for a tool whose panes scroll on their own. It replaces
18
+ `h-screen` and `h-[calc(100vh-56px)]` layouts.
19
+
20
+ - New: Select, Switch, TagInput and DatePicker take `name`, `required`, `id`, `onBlur` and `ref`, and keep
21
+ their own value when you don't pass one (`defaultValue`; `defaultChecked` on Switch). A plain `<form>` or a
22
+ form library can read them: Select sends its value under `name`, Switch sends "on", TagInput sends each
23
+ tag, DatePicker sends "YYYY-MM-DD". `required` stops the form until it's filled.
24
+ - Changed: TagInput's `id` and `onBlur` go on its text box (they went on the box around the chips).
25
+ - New: FilterChipGroup, the row of FilterChips, named for screen readers with `label`. Up to seven chips; on
26
+ a phone it stays one line that swipes sideways, and from 768px it wraps.
27
+ - New: Input `format="number"` takes `decimals` (1 for 2.5, 2 for cents, up to 6). Whole numbers stay the
28
+ default.
29
+
5
30
  ## 1.12.0
6
31
 
7
32
  2026-11-24. PageHeader, and a table toolbar that sits on the page. Nothing changes for apps already on 1.11.
@@ -42,11 +42,22 @@ type AppShellProps = {
42
42
  account?: React.ReactNode;
43
43
  /** Side menu only: a link at the bottom, such as "Back to Bridge OS" in an admin area. */
44
44
  sideFooter?: React.ReactNode;
45
+ /**
46
+ * A PageBanner that stays in view under the top bar, above the page: "You're viewing your own directory".
47
+ * Only a banner: tabs, filters and other navigation belong in the page.
48
+ */
49
+ banner?: React.ReactNode;
50
+ /**
51
+ * The page area exactly fills the screen under the top bar (and above the phone's bottom bar), and the
52
+ * window doesn't scroll. For a tool whose panes scroll on their own: an inbox, a chat. The page's root
53
+ * takes the full height (`h-full`), and each pane scrolls with `overflow-y-auto`.
54
+ */
55
+ fillScreen?: boolean;
45
56
  /** Draws each link with your router's: `(p) => <Link {...p} />` (Next), `({ href, ...p }) => <Link to={href} {...p} />` (React Router). Default a plain <a>. */
46
57
  renderLink?: (props: AppShellLinkProps) => React.ReactElement;
47
58
  /** The page. */
48
59
  children: React.ReactNode;
49
60
  };
50
- declare function AppShell({ logo, logoMark, homeHref, items, nav, breadcrumbs, search, actions, account, sideFooter, renderLink, children, }: AppShellProps): React.JSX.Element;
61
+ declare function AppShell({ logo, logoMark, homeHref, items, nav, breadcrumbs, search, actions, account, sideFooter, renderLink, banner, fillScreen, children, }: AppShellProps): React.JSX.Element;
51
62
  export { AppShell };
52
63
  export type { AppShellItem, AppShellLinkProps, AppShellProps };
@@ -122,7 +122,7 @@ function BarLogo({ logo, mark, link, className }) {
122
122
  return (_jsxs("span", { ref: box, className: cn("relative flex min-w-0 items-center overflow-hidden", useMark && "[&_img]:h-4 [&_img]:w-auto [&_svg]:h-4 [&_svg]:w-auto", className), children: [link(useMark ? mark : logo), mark ? (_jsx("span", { ref: full, "aria-hidden": "true", inert: true, className: "pointer-events-none invisible absolute top-0 left-0 flex whitespace-nowrap", children: logo })) : null] }));
123
123
  }
124
124
  // ── The shell ──────────────────────────────────────────────────────────────────────────────────
125
- function AppShell({ logo, logoMark, homeHref = "/", items, nav = "top", breadcrumbs, search, actions, account, sideFooter, renderLink, children, }) {
125
+ function AppShell({ logo, logoMark, homeHref = "/", items, nav = "top", breadcrumbs, search, actions, account, sideFooter, renderLink, banner, fillScreen = false, children, }) {
126
126
  const link = renderLink ?? plainLink;
127
127
  const side = nav === "side";
128
128
  const collapsed = useCollapsed();
@@ -159,6 +159,6 @@ function AppShell({ logo, logoMark, homeHref = "/", items, nav = "top", breadcru
159
159
  // keeps its own width, so it never runs over the logo; the logo gives way instead (BarLogo).
160
160
  const right = (_jsxs("div", { className: "ml-auto flex min-w-0 flex-1 items-center justify-end gap-3 pl-4 @max-[639px]/bar:flex-none md:gap-4 md:pl-8", children: [search ? _jsx("div", { className: "@container/search flex min-w-9 flex-1 items-center justify-end", children: searchSized }) : null, actions ? _jsx("div", { className: "flex shrink-0 items-center gap-2 md:gap-4", children: actions }) : null, account ? (_jsxs(_Fragment, { children: [actions || search ? _jsx("span", { "aria-hidden": "true", className: "h-6 w-px shrink-0 bg-[var(--border-default)]" }) : null, _jsx("div", { className: "flex shrink-0 items-center", children: account })] })) : null] }));
161
161
  const topBar = (_jsx("header", { "data-slot": "app-shell-top-bar", className: "glass-chrome @container/bar sticky top-0 z-50 h-14 shrink-0 border-b border-[var(--glass-border)] bg-[var(--glass-bg)] backdrop-blur-2xl backdrop-saturate-150", children: _jsxs("nav", { "aria-label": "Top bar", className: "flex h-full items-center gap-3 px-4 sm:px-6 md:gap-5 lg:px-8", children: [side ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "-ml-1.5 md:hidden", children: _jsx(IconButton, { size: "sm", "aria-label": "Open menu", "aria-expanded": menuOpen, onClick: () => setMenuOpen(true), children: _jsx(Menu, {}) }) }), _jsx(BarLogo, { logo: logo, mark: logoMark, link: (c) => logoLink(c), className: "flex-1 md:hidden" }), breadcrumbs ? _jsx("div", { className: "hidden min-w-0 shrink md:flex", children: breadcrumbs }) : null] })) : (_jsxs(_Fragment, { children: [_jsx(BarLogo, { logo: logo, mark: logoMark, link: (c) => logoLink(c), className: "shrink-0 max-md:flex-1" }), items.length ? (_jsxs(_Fragment, { children: [divider, _jsx(TopTabs, { items: items, link: link })] })) : null] })), right] }) }));
162
- return (_jsxs("div", { "data-slot": "app-shell", "data-nav": nav, className: cn("flex min-h-dvh", side ? "flex-row" : "flex-col"), children: [_jsx(SkipLink, {}), side ? (_jsxs("nav", { "aria-label": "Main", "data-slot": "app-shell-side-menu", "data-collapsed": collapsed || undefined, className: cn("sticky top-0 hidden h-dvh shrink-0 flex-col border-r border-[var(--border-divider)] bg-[var(--surface-primary)] transition-[width] duration-200 ease-out motion-reduce:transition-none md:flex", collapsed ? "w-14" : "w-56"), children: [collapsed ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex h-14 shrink-0 items-center justify-center border-b border-[var(--glass-border)] [&_img]:h-4 [&_img]:w-auto [&_svg]:h-4 [&_svg]:w-auto", children: logoMark ? logoLink(logoMark) : null }), _jsx("div", { className: "flex shrink-0 justify-center pt-3", children: toggle })] })) : (_jsxs("div", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-[var(--glass-border)] pr-3 pl-4", children: [logoLink(logo), _jsx("span", { className: "ml-auto", children: toggle })] })), _jsx(SideMenu, { items: items, link: link, collapsed: collapsed, footer: sideFooter })] })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [topBar, _jsx("main", { id: "main", tabIndex: -1, className: cn("min-w-0 flex-1 outline-none", side ? "" : "max-md:pb-[calc(56px+env(safe-area-inset-bottom))]"), children: children })] }), !side && items.length ? _jsx(BottomBar, { items: items, link: link }) : null, side ? (_jsx(DialogPrimitive.Root, { open: menuOpen, onOpenChange: setMenuOpen, children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[60] bg-black/30 transition-opacity duration-300 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 md:hidden" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "app-shell-menu-sheet", className: cn("fixed inset-y-0 left-0 z-[60] flex w-72 max-w-[85vw] flex-col bg-[var(--surface-elevated)] shadow-[var(--shadow-drawer)] outline-none md:hidden", "transition-[translate] duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full motion-reduce:transition-none"), children: [_jsxs("div", { className: "flex h-14 shrink-0 items-center justify-between gap-3 border-b border-[var(--border-divider)] px-4 pt-[env(safe-area-inset-top)]", children: [_jsx(DialogPrimitive.Title, { className: "sr-only", children: "Menu" }), link({ href: homeHref, onClick: () => setMenuOpen(false), className: "flex items-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: logo }), _jsx(DialogPrimitive.Close, { render: _jsx(IconButton, { size: "sm", "aria-label": "Close menu", children: _jsx(X, {}) }) })] }), _jsx(SideMenu, { items: items, link: link, collapsed: false, footer: sideFooter, onNavigate: () => setMenuOpen(false) })] })] }) })) : null] }));
162
+ return (_jsxs("div", { "data-slot": "app-shell", "data-nav": nav, "data-fill-screen": fillScreen || undefined, className: cn("flex", fillScreen ? "h-dvh overflow-hidden" : "min-h-dvh", side ? "flex-row" : "flex-col"), children: [_jsx(SkipLink, {}), side ? (_jsxs("nav", { "aria-label": "Main", "data-slot": "app-shell-side-menu", "data-collapsed": collapsed || undefined, className: cn("sticky top-0 hidden h-dvh shrink-0 flex-col border-r border-[var(--border-divider)] bg-[var(--surface-primary)] transition-[width] duration-200 ease-out motion-reduce:transition-none md:flex", collapsed ? "w-14" : "w-56"), children: [collapsed ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex h-14 shrink-0 items-center justify-center border-b border-[var(--glass-border)] [&_img]:h-4 [&_img]:w-auto [&_svg]:h-4 [&_svg]:w-auto", children: logoMark ? logoLink(logoMark) : null }), _jsx("div", { className: "flex shrink-0 justify-center pt-3", children: toggle })] })) : (_jsxs("div", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-[var(--glass-border)] pr-3 pl-4", children: [logoLink(logo), _jsx("span", { className: "ml-auto", children: toggle })] })), _jsx(SideMenu, { items: items, link: link, collapsed: collapsed, footer: sideFooter })] })) : null, _jsxs("div", { className: cn("flex min-w-0 flex-1 flex-col", fillScreen && "min-h-0"), children: [topBar, banner ? (_jsx("div", { "data-slot": "app-shell-banner", className: "sticky top-14 z-30", children: banner })) : null, _jsx("main", { id: "main", tabIndex: -1, className: cn("min-w-0 flex-1 outline-none", fillScreen && "flex min-h-0 flex-col overflow-hidden", side ? "" : "max-md:pb-[calc(56px+env(safe-area-inset-bottom))]"), children: children })] }), !side && items.length ? _jsx(BottomBar, { items: items, link: link }) : null, side ? (_jsx(DialogPrimitive.Root, { open: menuOpen, onOpenChange: setMenuOpen, children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[60] bg-black/30 transition-opacity duration-300 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 md:hidden" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "app-shell-menu-sheet", className: cn("fixed inset-y-0 left-0 z-[60] flex w-72 max-w-[85vw] flex-col bg-[var(--surface-elevated)] shadow-[var(--shadow-drawer)] outline-none md:hidden", "transition-[translate] duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full motion-reduce:transition-none"), children: [_jsxs("div", { className: "flex h-14 shrink-0 items-center justify-between gap-3 border-b border-[var(--border-divider)] px-4 pt-[env(safe-area-inset-top)]", children: [_jsx(DialogPrimitive.Title, { className: "sr-only", children: "Menu" }), link({ href: homeHref, onClick: () => setMenuOpen(false), className: "flex items-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: logo }), _jsx(DialogPrimitive.Close, { render: _jsx(IconButton, { size: "sm", "aria-label": "Close menu", children: _jsx(X, {}) }) })] }), _jsx(SideMenu, { items: items, link: link, collapsed: false, footer: sideFooter, onNavigate: () => setMenuOpen(false) })] })] }) })) : null] }));
163
163
  }
164
164
  export { AppShell };
@@ -46,6 +46,14 @@ type FieldBits = {
46
46
  disabled?: boolean;
47
47
  /** Sends the value with a form as "YYYY-MM-DD". A range sends two: `name` + "Start" and `name` + "End". */
48
48
  name?: string;
49
+ /** The typed field's `id` (a range's start). Inside a Field, leave it off: the Field ties the label to it. */
50
+ id?: string;
51
+ /** The form can't be sent without a date (a range: without both). Pair it with a FieldError that says what's missing. */
52
+ required?: boolean;
53
+ /** Called when a typed field loses focus, after its date is read, for a form library's `onBlur`. */
54
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
55
+ /** The typed field (a range's start), to focus it from your code or a form library. */
56
+ ref?: React.Ref<HTMLInputElement>;
49
57
  /** Only outside a Field. Inside one, the FieldLabel names it. */
50
58
  "aria-label"?: string;
51
59
  /** Layout only: `max-w-60`. */
@@ -287,7 +287,7 @@ function useControlled(value, defaultValue, onChange) {
287
287
  function CalendarButton({ label, open, setOpen, disabled, children }) {
288
288
  return (_jsx(Popover, { title: label, hideTitle: true, align: "end", open: open, onOpenChange: setOpen, trigger: _jsx(IconButton, { type: "button", size: "sm", "aria-label": label, disabled: disabled, "data-slot": "date-picker-button", className: "ml-auto", children: _jsx(CalendarDays, {}) }), children: children }));
289
289
  }
290
- function SinglePicker({ value, defaultValue = null, onValueChange, min, max, disabled, name, className, "aria-label": ariaLabel, ...rest }) {
290
+ function SinglePicker({ value, defaultValue = null, onValueChange, min, max, disabled, name, id, required, onBlur, ref, className, "aria-label": ariaLabel, ...rest }) {
291
291
  const [current, setCurrent] = useControlled(value, defaultValue, onValueChange);
292
292
  const [open, setOpen] = React.useState(false);
293
293
  const minDate = resolveLimit(min);
@@ -295,11 +295,14 @@ function SinglePicker({ value, defaultValue = null, onValueChange, min, max, dis
295
295
  const field = useTypedDate(current ?? null, setCurrent, (d) => problemWith(d, minDate, maxDate, min, max));
296
296
  const errorId = React.useId();
297
297
  const forced = rest["data-force-state"];
298
- return (_jsxs("div", { "data-slot": "date-picker", className: cn("flex w-full min-w-0 flex-col gap-1.5", className), children: [_jsxs("span", { "data-slot": "date-picker-box", "data-force-state": forced, className: boxClasses, children: [_jsx(InputPrimitive, { "data-slot": "date-picker-input", "data-force-state": forced, type: "text", autoComplete: "off", "aria-label": ariaLabel, placeholder: placeholder(), disabled: disabled, value: field.text, "aria-invalid": field.error ? true : undefined, "aria-describedby": field.error ? errorId : undefined, className: typed, onValueChange: (text) => {
298
+ return (_jsxs("div", { "data-slot": "date-picker", className: cn("flex w-full min-w-0 flex-col gap-1.5", className), children: [_jsxs("span", { "data-slot": "date-picker-box", "data-force-state": forced, className: boxClasses, children: [_jsx(InputPrimitive, { ref: ref, id: id, required: required, "data-slot": "date-picker-input", "data-force-state": forced, type: "text", autoComplete: "off", "aria-label": ariaLabel, placeholder: placeholder(), disabled: disabled, value: field.text, "aria-invalid": field.error ? true : undefined, "aria-describedby": field.error ? errorId : undefined, className: typed, onValueChange: (text) => {
299
299
  field.setText(text);
300
300
  if (field.error)
301
301
  field.setError(null);
302
- }, onBlur: field.read, onKeyDown: (e) => {
302
+ }, onBlur: (e) => {
303
+ field.read();
304
+ onBlur?.(e);
305
+ }, onKeyDown: (e) => {
303
306
  if (e.key === "Enter")
304
307
  field.read();
305
308
  } }), _jsx(CalendarButton, { label: "Choose a date", open: open, setOpen: setOpen, disabled: disabled, children: _jsx(Calendar, { value: current, min: min, max: max, autoFocus: true, onValueChange: (iso) => {
@@ -308,7 +311,7 @@ function SinglePicker({ value, defaultValue = null, onValueChange, min, max, dis
308
311
  setOpen(false);
309
312
  } }) })] }), name ? _jsx("input", { type: "hidden", name: name, value: current ?? "" }) : null, field.error ? _jsx(DateError, { id: errorId, children: field.error }) : null] }));
310
313
  }
311
- function RangePicker({ value, defaultValue = { start: null, end: null }, onValueChange, min, max, disabled, name, className, "aria-label": ariaLabel, ...rest }) {
314
+ function RangePicker({ value, defaultValue = { start: null, end: null }, onValueChange, min, max, disabled, name, id, required, onBlur, ref, className, "aria-label": ariaLabel, ...rest }) {
312
315
  const [current, setCurrent] = useControlled(value, defaultValue, onValueChange);
313
316
  const [open, setOpen] = React.useState(false);
314
317
  const minDate = resolveLimit(min);
@@ -337,12 +340,16 @@ function RangePicker({ value, defaultValue = { start: null, end: null }, onValue
337
340
  autoComplete: "off",
338
341
  placeholder: label === "Start date" ? placeholder() : `Mar 11, ${new Date().getFullYear()}`,
339
342
  disabled,
343
+ required,
340
344
  value: f.text,
341
345
  "aria-invalid": f.error ? true : undefined,
342
346
  "aria-describedby": f.error ? errorId : undefined,
343
347
  // Sized to a date ("Sep 30, 2026"), so the two halves read as one range, not two far-apart fields.
344
348
  className: cn(typed, "w-28 flex-none"),
345
- onBlur: f.read,
349
+ onBlur: (e) => {
350
+ f.read();
351
+ onBlur?.(e);
352
+ },
346
353
  onKeyDown: (e) => {
347
354
  if (e.key === "Enter")
348
355
  f.read();
@@ -354,7 +361,7 @@ function RangePicker({ value, defaultValue = { start: null, end: null }, onValue
354
361
  f.setError(null);
355
362
  };
356
363
  // The start is the Field's control, so a FieldLabel and FieldDescription reach it; each half says which end it is.
357
- return primitive ? (_jsx(InputPrimitive, { "data-slot": "date-picker-input", ...common, "aria-label": ariaLabel ? `${ariaLabel}, ${label.toLowerCase()}` : label, onValueChange: onText })) : (_jsx("input", { "data-slot": "date-picker-input", ...common, "aria-label": ariaLabel ? `${ariaLabel}, ${label.toLowerCase()}` : label, onChange: (e) => onText(e.target.value) }));
364
+ return primitive ? (_jsx(InputPrimitive, { ref: ref, id: id, "data-slot": "date-picker-input", ...common, "aria-label": ariaLabel ? `${ariaLabel}, ${label.toLowerCase()}` : label, onValueChange: onText })) : (_jsx("input", { "data-slot": "date-picker-input", ...common, "aria-label": ariaLabel ? `${ariaLabel}, ${label.toLowerCase()}` : label, onChange: (e) => onText(e.target.value) }));
358
365
  };
359
366
  return (_jsxs("div", { "data-slot": "date-picker", className: cn("flex w-full min-w-0 flex-col gap-1.5", className), children: [_jsxs("span", { "data-slot": "date-picker-box", "data-force-state": forced, role: "group", "aria-label": ariaLabel, className: boxClasses, children: [box(startField, "Start date", true), _jsx("span", { "aria-hidden": "true", className: "shrink-0 text-[var(--text-muted)]", children: "\u2013" }), box(endField, "End date", false), _jsx(CalendarButton, { label: "Choose dates", open: open, setOpen: setOpen, disabled: disabled, children: _jsx(Calendar, { range: true, value: { start, end }, min: min, max: max, autoFocus: true, onValueChange: (next) => {
360
367
  startField.setError(null);
@@ -21,15 +21,20 @@ type DrawerProps = {
21
21
  actions?: React.ReactNode;
22
22
  /** For a drawer that edits: the footer's one filled button, bottom right. Spins while `busy`. */
23
23
  primaryAction?: DialogAction;
24
- /** The footer button that closes without saving. Default "Cancel". Shown with `primaryAction`. */
25
- cancelLabel?: string;
24
+ /** The footer button that closes without saving. Default "Cancel". Shown with `primaryAction`; `null` leaves it out. */
25
+ cancelLabel?: string | null;
26
26
  /** A red action, like Remove, alone at the bottom left. Ask with a ConfirmDialog before doing it. */
27
27
  dangerAction?: DialogAction;
28
28
  /** A save is running: the primary action spins and the drawer can't be dismissed until it finishes. */
29
29
  busy?: boolean;
30
+ /**
31
+ * The footer's contents, in place of `primaryAction`, `cancelLabel` and `dangerAction`. Only for what they
32
+ * can't express, such as "Step 2 of 3" with Back and Next. Buttons `md`, the main one last.
33
+ */
34
+ footer?: React.ReactNode;
30
35
  children: React.ReactNode;
31
36
  className?: string;
32
37
  };
33
- declare function Drawer({ open, onClose, title, subtitle, size, actions, toolbar, primaryAction, cancelLabel, dangerAction, busy, children, className, }: DrawerProps): React.JSX.Element;
38
+ declare function Drawer({ open, onClose, title, subtitle, size, actions, toolbar, primaryAction, cancelLabel, dangerAction, busy, footer, children, className, }: DrawerProps): React.JSX.Element;
34
39
  export { Drawer };
35
40
  export type { DrawerProps };
@@ -26,16 +26,27 @@ import { cn } from "@brdgapp/ui/lib/utils";
26
26
  // and always leaves 64px of the page showing on the left. And `toolbar`, pinned under the header so search and
27
27
  // filters stay put while the list scrolls (both Bridge OS list drawers have them). It takes a DataTableToolbar,
28
28
  // the one row for search and filters everywhere, so the drawer adds no styling of its own.
29
+ //
30
+ // Decided 2026-11-24 (Aman, audit section 11.10): the top gap follows the frame (under AppShell's top bar when
31
+ // there is one, from the top of the screen when there isn't); `cancelLabel={null}` hides Cancel, as in Dialog;
32
+ // `footer` replaces the standard buttons for what they can't express, such as a step-by-step import.
29
33
  const WIDTH = { item: "md:max-w-xl", list: "md:max-w-2xl", wide: "md:max-w-[min(1152px,calc(100vw-64px))]" };
34
+ // Whether the page has AppShell's top bar, read when the drawer draws. Nothing to subscribe to: the frame
35
+ // doesn't come and go while a drawer is open.
36
+ const noSubscribe = () => () => { };
37
+ const hasTopBar = () => Boolean(document.querySelector("[data-slot=app-shell-top-bar]"));
30
38
  const FIRST_FIELD = "input:not([disabled]):not([type=hidden]), textarea:not([disabled]), select:not([disabled]), [contenteditable=true]";
31
- function Drawer({ open, onClose, title, subtitle, size = "item", actions, toolbar, primaryAction, cancelLabel = "Cancel", dangerAction, busy = false, children, className, }) {
39
+ function Drawer({ open, onClose, title, subtitle, size = "item", actions, toolbar, primaryAction, cancelLabel = "Cancel", dangerAction, busy = false, footer, children, className, }) {
32
40
  const body = React.useRef(null);
33
- return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => !next && !busy && onClose(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-x-0 top-0 bottom-0 z-[60] md:top-14 bg-black/30 transition-opacity duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "drawer", "data-size": size,
41
+ // Under AppShell's top bar when the page has one; otherwise from the top of the screen.
42
+ const underBar = React.useSyncExternalStore(noSubscribe, hasTopBar, () => true);
43
+ const top = underBar ? "md:top-14" : "md:top-0";
44
+ return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => !next && !busy && onClose(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: cn(top, "fixed inset-x-0 top-0 bottom-0 z-[60] bg-black/30 transition-opacity duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0") }), _jsxs(DialogPrimitive.Popup, { "data-slot": "drawer", "data-size": size,
34
45
  // An edit drawer starts in its first field; a details drawer starts on its first control.
35
46
  initialFocus: (openType) => (openType === "touch" ? true : (body.current?.querySelector(FIRST_FIELD) ?? true)), className: cn(
36
47
  // Phone: the whole screen. Computer: below the top bar, from the right edge.
37
- "fixed inset-0 z-[60] flex w-full flex-col bg-[var(--surface-elevated)] outline-none md:top-14 md:left-auto md:border-l md:border-[var(--border-default)] md:shadow-[var(--shadow-drawer)]", "transition-[translate,opacity] duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:translate-x-full data-[ending-style]:translate-x-full", "motion-reduce:transition-opacity motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0 motion-reduce:data-[starting-style]:opacity-0 motion-reduce:data-[ending-style]:opacity-0", WIDTH[size], className), children: [_jsxs("header", { "data-slot": "drawer-header", className: "flex shrink-0 items-start gap-2 border-b border-[var(--border-divider)] px-6 py-4 max-md:px-5 max-md:pt-[max(16px,env(safe-area-inset-top))]", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(DialogPrimitive.Title, { className: "truncate text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), subtitle ? (_jsx(DialogPrimitive.Description, { className: "mt-0.5 truncate text-12 leading-normal text-[var(--text-muted)]", children: subtitle })) : null] }), actions, _jsx(DialogPrimitive.Close, { disabled: busy, render: _jsx(IconButton, { "aria-label": "Close", size: "sm", children: _jsx(X, {}) }) })] }), toolbar ? (_jsx("div", { "data-slot": "drawer-toolbar", className: "shrink-0", children: toolbar })) : null, _jsx("div", { ref: body, "data-slot": "drawer-body", className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain", size === "wide" ? "" : "px-6 py-5 max-md:px-5"), children: children }), primaryAction || dangerAction ? (_jsxs("footer", { "data-slot": "drawer-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-[var(--border-divider)] px-6 py-4 pb-[max(16px,env(safe-area-inset-bottom))] max-md:px-5", children: [dangerAction ? (_jsx(Button, { variant: "danger-ghost", size: "md", icon: dangerAction.icon, disabled: busy || dangerAction.disabled, onClick: dangerAction.onClick,
48
+ "fixed inset-0 z-[60] flex w-full flex-col bg-[var(--surface-elevated)] outline-none md:left-auto md:border-l md:border-[var(--border-default)] md:shadow-[var(--shadow-drawer)]", "transition-[translate,opacity] duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:translate-x-full data-[ending-style]:translate-x-full", "motion-reduce:transition-opacity motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0 motion-reduce:data-[starting-style]:opacity-0 motion-reduce:data-[ending-style]:opacity-0", WIDTH[size], top, className), children: [_jsxs("header", { "data-slot": "drawer-header", className: "flex shrink-0 items-start gap-2 border-b border-[var(--border-divider)] px-6 py-4 max-md:px-5 max-md:pt-[max(16px,env(safe-area-inset-top))]", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(DialogPrimitive.Title, { className: "truncate text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), subtitle ? (_jsx(DialogPrimitive.Description, { className: "mt-0.5 truncate text-12 leading-normal text-[var(--text-muted)]", children: subtitle })) : null] }), actions, _jsx(DialogPrimitive.Close, { disabled: busy, render: _jsx(IconButton, { "aria-label": "Close", size: "sm", children: _jsx(X, {}) }) })] }), toolbar ? (_jsx("div", { "data-slot": "drawer-toolbar", className: "shrink-0", children: toolbar })) : null, _jsx("div", { ref: body, "data-slot": "drawer-body", className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain", size === "wide" ? "" : "px-6 py-5 max-md:px-5"), children: children }), footer ? (_jsx("footer", { "data-slot": "drawer-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-[var(--border-divider)] px-6 py-4 pb-[max(16px,env(safe-area-inset-bottom))] max-md:px-5", children: footer })) : primaryAction || dangerAction ? (_jsxs("footer", { "data-slot": "drawer-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-[var(--border-divider)] px-6 py-4 pb-[max(16px,env(safe-area-inset-bottom))] max-md:px-5", children: [dangerAction ? (_jsx(Button, { variant: "danger-ghost", size: "md", icon: dangerAction.icon, disabled: busy || dangerAction.disabled, onClick: dangerAction.onClick,
38
49
  // Phone: its own row above Cancel and the main button, so the three never squeeze into one.
39
- className: "mr-auto max-md:mr-0 max-md:w-full", children: dangerAction.label })) : null, primaryAction ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "secondary", size: "md", disabled: busy, onClick: onClose, className: "max-md:flex-1", children: cancelLabel }), _jsx(Button, { size: "md", loading: busy, disabled: primaryAction.disabled, icon: primaryAction.icon, onClick: primaryAction.onClick, className: "max-md:flex-1", children: primaryAction.label })] })) : null] })) : null] })] }) }));
50
+ className: "mr-auto max-md:mr-0 max-md:w-full", children: dangerAction.label })) : null, primaryAction ? (_jsxs(_Fragment, { children: [cancelLabel !== null ? (_jsx(Button, { variant: "secondary", size: "md", disabled: busy, onClick: onClose, className: "max-md:flex-1", children: cancelLabel })) : null, _jsx(Button, { size: "md", loading: busy, disabled: primaryAction.disabled, icon: primaryAction.icon, onClick: primaryAction.onClick, className: "max-md:flex-1", children: primaryAction.label })] })) : null] })) : null] })] }) }));
40
51
  }
41
52
  export { Drawer };
@@ -1,3 +1,4 @@
1
+ import type * as React from "react";
1
2
  import { Toggle } from "@base-ui/react/toggle";
2
3
  type FilterChipProps = Omit<Toggle.Props, "className" | "pressed" | "defaultPressed"> & {
3
4
  /** Whether this filter is on. The parent owns it. */
@@ -6,6 +7,15 @@ type FilterChipProps = Omit<Toggle.Props, "className" | "pressed" | "defaultPres
6
7
  count?: number;
7
8
  className?: string;
8
9
  };
9
- declare function FilterChip({ active, count, className, children, ...props }: FilterChipProps): import("react").JSX.Element;
10
- export { FilterChip };
11
- export type { FilterChipProps };
10
+ declare function FilterChip({ active, count, className, children, ...props }: FilterChipProps): React.JSX.Element;
11
+ type FilterChipGroupProps = {
12
+ /** What the chips filter, for screen readers: "Show", "Sources". */
13
+ label: string;
14
+ /** The FilterChips. Seven at most. */
15
+ children: React.ReactNode;
16
+ /** Layout only. */
17
+ className?: string;
18
+ };
19
+ declare function FilterChipGroup({ label, children, className }: FilterChipGroupProps): React.JSX.Element;
20
+ export { FilterChip, FilterChipGroup };
21
+ export type { FilterChipProps, FilterChipGroupProps };
@@ -4,8 +4,13 @@ import { Toggle } from "@base-ui/react/toggle";
4
4
  import { formatCount } from "@brdgapp/ui/lib/format";
5
5
  import { cn } from "@brdgapp/ui/lib/utils";
6
6
  function FilterChip({ active = false, count, className, children, ...props }) {
7
- return (_jsxs(Toggle, { "data-slot": "filter-chip", pressed: active, className: cn("inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-13 leading-[1.625] font-semibold transition-colors duration-150 outline-none", "focus-visible:ring-2 focus-visible:ring-[var(--primary)]", "border-[var(--text-disabled)] bg-transparent text-[var(--text-secondary)] hover:border-[var(--text-muted)] hover:text-[var(--text-primary)]", "data-[pressed]:border-[var(--text-muted)] data-[pressed]:bg-[var(--surface-tertiary)] data-[pressed]:text-[var(--text-primary)]",
7
+ return (_jsxs(Toggle, { "data-slot": "filter-chip", pressed: active, className: cn("inline-flex items-center gap-1.5 whitespace-nowrap rounded-full border px-3 py-1.5 text-13 leading-[1.625] font-semibold transition-colors duration-150 outline-none", "focus-visible:ring-2 focus-visible:ring-[var(--primary)]", "border-[var(--text-disabled)] bg-transparent text-[var(--text-secondary)] hover:border-[var(--text-muted)] hover:text-[var(--text-primary)]", "data-[pressed]:border-[var(--text-muted)] data-[pressed]:bg-[var(--surface-tertiary)] data-[pressed]:text-[var(--text-primary)]",
8
8
  // An on chip still reacts to the pointer: pressing it turns the filter off.
9
9
  "data-[pressed]:hover:border-[var(--text-secondary)]", "disabled:pointer-events-none disabled:opacity-50", className), ...props, children: [children, count != null ? (_jsx("span", { "data-slot": "filter-chip-count", className: "font-normal tabular-nums text-[var(--text-muted)]", children: formatCount(count) })) : null] }));
10
10
  }
11
- export { FilterChip };
11
+ function FilterChipGroup({ label, children, className }) {
12
+ return (_jsx("div", { role: "group", "aria-label": label, "data-slot": "filter-chip-group",
13
+ // The 2px inside space keeps the focus ring from being cut off by the sideways scroll.
14
+ className: cn("-m-0.5 flex items-center gap-2 overflow-x-auto p-0.5 scrollbar-none md:flex-wrap md:overflow-visible [&>*]:shrink-0", className), children: children }));
15
+ }
16
+ export { FilterChip, FilterChipGroup };
@@ -19,8 +19,10 @@ type TextInputProps = BaseProps & {
19
19
  onValueChange?: InputPrimitive.Props["onValueChange"];
20
20
  };
21
21
  type NumberInputProps = BaseProps & {
22
- /** A whole number, with commas as it's typed ("2,500,000"). Pair it with `prefix="$"` for an amount. */
22
+ /** A number, with commas as it's typed ("2,500,000"). Pair it with `prefix="$"` for an amount. */
23
23
  format: "number";
24
+ /** How many places after the point it takes: `1` for 2.5, `2` for cents. Whole numbers when left out. */
25
+ decimals?: number;
24
26
  /** The number shown, or `null` for an empty field. */
25
27
  value?: number | null;
26
28
  defaultValue?: number | null;
@@ -28,17 +28,44 @@ function Input(props) {
28
28
  // Whole numbers only, left-aligned, US dollars when there's a currency (Aman, 2026-11-19): every app's money
29
29
  // field today is a whole amount with "$" before it (app-portfolio's CurrencyAmountInput, raise's check sizes,
30
30
  // bridge-jobs' salary, Bridge OS's outcome value), and none shows cents. Up to 15 digits, so the number stays exact.
31
+ // `decimals` (1.13.0, Aman 2026-11-25): opt-in places after the point, for Directories' custom number columns (2.5).
31
32
  const groupDigits = (digits) => (digits ? Number(digits).toLocaleString("en-US") : "");
32
- function NumberInput({ format, value, defaultValue, onValueChange, onChange, ...props }) {
33
- const toDigits = (n) => (n == null ? "" : String(Math.trunc(Math.abs(n))));
34
- const [text, setText] = useState(() => groupDigits(toDigits(value !== undefined ? value : defaultValue)));
33
+ const MAX_DECIMALS = 6;
34
+ // "1,250.5" → the parts typed: whole digits, whether there's a point, and the digits after it.
35
+ function readNumber(raw, places) {
36
+ // Whole numbers drop a typed point entirely, so "12.34" doesn't lose the 34.
37
+ const [whole = "", ...rest] = raw.replace(places > 0 ? /[^\d.]/g : /\D/g, "").split(".");
38
+ const point = places > 0 && rest.length > 0;
39
+ const fraction = point ? rest.join("").slice(0, places) : "";
40
+ return { whole: whole.replace(/^0+(?=\d)/, "").slice(0, 15), point, fraction };
41
+ }
42
+ function showNumber({ whole, point, fraction }) {
43
+ if (!point)
44
+ return groupDigits(whole);
45
+ return `${groupDigits(whole) || "0"}.${fraction}`;
46
+ }
47
+ function numberOf({ whole, point, fraction }) {
48
+ if (!whole && !(point && fraction))
49
+ return null;
50
+ return Number(`${whole || "0"}${fraction ? `.${fraction}` : ""}`);
51
+ }
52
+ function NumberInput({ format, decimals = 0, value, defaultValue, onValueChange, onChange, ...props }) {
53
+ const places = Math.max(0, Math.min(MAX_DECIMALS, Math.trunc(decimals)));
54
+ // A number from outside, as it's shown: 2.5, not 2.50; a whole number has no point.
55
+ const toText = (n) => {
56
+ if (n == null)
57
+ return "";
58
+ const plain = places ? Math.abs(n).toFixed(places).replace(/\.?0+$/, "") : String(Math.trunc(Math.abs(n)));
59
+ return showNumber(readNumber(plain, places));
60
+ };
61
+ const [text, setText] = useState(() => toText(value !== undefined ? value : defaultValue));
35
62
  // A new value from outside (a reset, a loaded record) replaces what's shown; the number being typed doesn't.
36
63
  // Adjusted while rendering, not in an effect, so there's no second render with the old text.
37
64
  const [lastValue, setLastValue] = useState(value);
38
65
  if (value !== lastValue) {
39
66
  setLastValue(value);
40
- if (value !== undefined && text.replace(/\D/g, "") !== toDigits(value))
41
- setText(groupDigits(toDigits(value)));
67
+ if (value !== undefined && numberOf(readNumber(text, places)) !== numberOf(readNumber(toText(value), places)))
68
+ setText(toText(value));
42
69
  }
43
70
  // Where the cursor goes once the commas have moved, put back after React has written the new text.
44
71
  const pending = useRef(null);
@@ -50,13 +77,14 @@ function NumberInput({ format, value, defaultValue, onValueChange, onChange, ...
50
77
  }, [text]);
51
78
  if (format !== "number")
52
79
  return null;
53
- return (_jsx(TextInput, { ...props, type: "text", inputMode: "numeric", numeric: true, value: text, onChange: (e) => {
80
+ return (_jsx(TextInput, { ...props, type: "text", inputMode: places ? "decimal" : "numeric", numeric: true, value: text, onChange: (e) => {
54
81
  const el = e.target;
55
82
  let raw = el.value;
56
83
  let caret = el.selectionStart ?? raw.length;
57
84
  // Deleting a comma deletes the digit beside it, as people expect; otherwise the key would seem dead.
58
85
  const kind = e.nativeEvent.inputType;
59
- if (raw.replace(/\D/g, "") === text.replace(/\D/g, "") && raw.length < text.length) {
86
+ const kept = (t) => t.replace(/[^\d.]/g, "");
87
+ if (kept(raw) === kept(text) && raw.length < text.length) {
60
88
  if (kind === "deleteContentBackward" && caret > 0) {
61
89
  raw = raw.slice(0, caret - 1) + raw.slice(caret);
62
90
  caret -= 1;
@@ -65,12 +93,12 @@ function NumberInput({ format, value, defaultValue, onValueChange, onChange, ...
65
93
  raw = raw.slice(0, caret) + raw.slice(caret + 1);
66
94
  }
67
95
  // Keep the cursor beside the same digit once the commas move, and before a comma, not after it.
68
- const digitsAfter = raw.slice(caret).replace(/\D/g, "").length;
69
- const digits = raw.replace(/\D/g, "").replace(/^0+(?=\d)/, "").slice(0, 15);
70
- const next = groupDigits(digits);
96
+ const parts = readNumber(raw, places);
97
+ const next = showNumber(parts);
98
+ const digitsAfter = Math.min(kept(raw.slice(caret)).length, kept(next).length);
71
99
  let at = next.length;
72
100
  for (let seen = 0; at > 0 && seen < digitsAfter;)
73
- if (/\d/.test(next[--at]))
101
+ if (/[\d.]/.test(next[--at]))
74
102
  seen++;
75
103
  if (next[at - 1] === ",")
76
104
  at -= 1;
@@ -84,7 +112,7 @@ function NumberInput({ format, value, defaultValue, onValueChange, onChange, ...
84
112
  }
85
113
  setText(next);
86
114
  onChange?.(e);
87
- onValueChange?.(digits ? Number(digits) : null);
115
+ onValueChange?.(numberOf(parts));
88
116
  } }));
89
117
  }
90
118
  function TextInput({ className, type = "text", reveal = true, secretName = "password", leadingIcon, prefix, disabled, numeric = false, ...props }) {
@@ -24,6 +24,14 @@ type SelectBase<T extends string> = {
24
24
  disabled?: boolean;
25
25
  /** Its name in a submitted form. */
26
26
  name?: string;
27
+ /** The trigger's `id`. Inside a Field, leave it off: the Field ties the label to it. */
28
+ id?: string;
29
+ /** The form can't be sent until something is chosen. Pair it with a FieldError that says what's missing. */
30
+ required?: boolean;
31
+ /** Called when the field loses focus, for checking it then (a form library's `onBlur`). */
32
+ onBlur?: React.FocusEventHandler<HTMLButtonElement>;
33
+ /** The trigger button, to focus it from your code or a form library. */
34
+ ref?: React.Ref<HTMLButtonElement>;
27
35
  /** Use FieldLabel inside a Field; this is for a select with no visible label. */
28
36
  "aria-label"?: string;
29
37
  /** Layout only: `max-w-xs`. */
@@ -45,16 +53,20 @@ type SelectBase<T extends string> = {
45
53
  };
46
54
  type SingleSelectProps<T extends string> = SelectBase<T> & {
47
55
  multiple?: false;
48
- /** The chosen option, or `null` for none yet (the placeholder shows). */
49
- value: T | null;
50
- onChange: (value: NoInfer<T>) => void;
56
+ /** The chosen option, or `null` for none yet (the placeholder shows). Leave it off to let the field keep its own, from `defaultValue`. */
57
+ value?: T | null;
58
+ /** The first choice when you don't pass `value`. */
59
+ defaultValue?: T | null;
60
+ onChange?: (value: NoInfer<T>) => void;
51
61
  };
52
62
  type MultipleSelectProps<T extends string> = SelectBase<T> & {
53
63
  /** Several values: each shows as a Tag in the field with × to remove it; the list stays open while ticking. */
54
64
  multiple: true;
55
- /** The chosen values; empty shows the placeholder. */
56
- value: T[];
57
- onChange: (value: NoInfer<T>[]) => void;
65
+ /** The chosen values; empty shows the placeholder. Leave it off to let the field keep its own, from `defaultValue`. */
66
+ value?: T[];
67
+ /** The first choices when you don't pass `value`. */
68
+ defaultValue?: T[];
69
+ onChange?: (value: NoInfer<T>[]) => void;
58
70
  };
59
71
  type SelectProps<T extends string> = SingleSelectProps<T> | MultipleSelectProps<T>;
60
72
  declare function Select<T extends string>(props: MultipleSelectProps<T>): React.JSX.Element;
@@ -10,15 +10,37 @@ import { SearchInput } from "@brdgapp/ui/components/search-input";
10
10
  import { Tag } from "@brdgapp/ui/components/tag";
11
11
  import { useIsMobile } from "@brdgapp/ui/hooks/use-is-mobile";
12
12
  import { cn } from "@brdgapp/ui/lib/utils";
13
+ /** Hands the trigger to the app's ref too: a function ref, or an object ref. */
14
+ function assignRef(ref, el) {
15
+ if (typeof ref === "function")
16
+ ref(el);
17
+ else if (ref)
18
+ ref.current = el;
19
+ }
13
20
  // The same box as Input: 40px (44 on phones), 8px corners, the field border, blue focus, red when invalid.
14
21
  const triggerClasses = cn("flex h-11 md:h-10 w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-[var(--border-field)] bg-[var(--surface-primary)] px-3.5 text-left", "text-16 md:text-14 text-[var(--text-primary)]", "transition-colors duration-150 ease-out outline-none", "hover:border-[var(--text-muted)]", "focus-visible:border-[var(--primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]/20", "data-[popup-open]:border-[var(--primary)]", "aria-invalid:border-[var(--error)] aria-invalid:hover:border-[var(--error)] aria-invalid:focus-visible:ring-[var(--error)]/20", "data-[invalid]:border-[var(--error)] data-[invalid]:hover:border-[var(--error)] data-[invalid]:focus-visible:ring-[var(--error)]/20", "data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50");
15
22
  function OptionBody({ option, phone = false }) {
16
23
  return (_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [option.icon ? _jsx("span", { className: "flex shrink-0 text-[var(--text-muted)] [&_svg]:size-4", children: option.icon }) : null, _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate", children: option.label }), option.description ? _jsx("span", { className: cn("block truncate font-normal text-[var(--text-muted)]", phone ? "text-13" : "text-12"), children: option.description }) : null] })] }));
17
24
  }
18
25
  function Select(props) {
19
- if (props.multiple)
20
- return _jsx(MultipleSelect, { ...props });
21
- return props.search || props.onCreate ? _jsx(SearchSelect, { ...props }) : _jsx(PlainSelect, { ...props });
26
+ const controlled = props.value !== undefined;
27
+ const [own, setOwn] = React.useState(() => (props.defaultValue !== undefined ? props.defaultValue : props.multiple ? [] : null));
28
+ const current = controlled ? props.value : own;
29
+ if (props.multiple) {
30
+ const onChange = (v) => {
31
+ if (!controlled)
32
+ setOwn(v);
33
+ props.onChange?.(v);
34
+ };
35
+ return _jsx(MultipleSelect, { ...props, value: current ?? [], onChange: onChange });
36
+ }
37
+ const onChange = (v) => {
38
+ if (!controlled)
39
+ setOwn(v);
40
+ props.onChange?.(v);
41
+ };
42
+ const inner = { ...props, value: current ?? null, onChange };
43
+ return props.search || props.onCreate ? _jsx(SearchSelect, { ...inner }) : _jsx(PlainSelect, { ...inner });
22
44
  }
23
45
  function PlainSelect({ value, onChange, options, placeholder = "Choose", disabled = false, name, className, ...props }) {
24
46
  const mobile = useIsMobile();
@@ -26,6 +48,10 @@ function PlainSelect({ value, onChange, options, placeholder = "Choose", disable
26
48
  const [listOpen, setListOpen] = React.useState(false);
27
49
  // The phone sheet's title is the field's label (FieldLabel), read when it opens.
28
50
  const trigger = React.useRef(null);
51
+ const triggerRef = (el) => {
52
+ trigger.current = el;
53
+ assignRef(props.ref, el);
54
+ };
29
55
  const [title, setTitle] = React.useState("");
30
56
  const openSheet = () => {
31
57
  const ids = trigger.current?.getAttribute("aria-labelledby")?.split(" ") ?? [];
@@ -35,10 +61,10 @@ function PlainSelect({ value, onChange, options, placeholder = "Choose", disable
35
61
  };
36
62
  const chosen = options.find((o) => o.value === value);
37
63
  const items = options.map((o) => ({ value: o.value, label: o.label }));
38
- return (_jsxs(_Fragment, { children: [_jsxs(SelectPrimitive.Root, { value: value, onValueChange: (v) => v != null && onChange(v), items: items, disabled: disabled, name: name,
64
+ return (_jsxs(_Fragment, { children: [_jsxs(SelectPrimitive.Root, { value: value, onValueChange: (v) => v != null && onChange(v), items: items, disabled: disabled, name: name, required: props.required,
39
65
  // Phones: the list never opens; the trigger's click opens the bottom sheet instead. (On the click, not
40
66
  // when Base UI would open, on finger-down: the click that follows would land outside the sheet and close it.)
41
- open: mobile ? false : listOpen, onOpenChange: (open) => setListOpen(open), children: [_jsxs(SelectPrimitive.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: cn(triggerClasses, className), onClick: mobile && !disabled ? openSheet : undefined, onKeyDown: mobile && !disabled
67
+ open: mobile ? false : listOpen, onOpenChange: (open) => setListOpen(open), children: [_jsxs(SelectPrimitive.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-label": props["aria-label"], className: cn(triggerClasses, className), onClick: mobile && !disabled ? openSheet : undefined, onKeyDown: mobile && !disabled
42
68
  ? (e) => {
43
69
  if (e.key === "ArrowDown" || e.key === "ArrowUp") {
44
70
  e.preventDefault();
@@ -70,6 +96,10 @@ function SearchSelect({ value, onChange, options, placeholder = "Choose", disabl
70
96
  const [open, setOpen] = React.useState(false);
71
97
  const [title, setTitle] = React.useState("");
72
98
  const trigger = React.useRef(null);
99
+ const triggerRef = (el) => {
100
+ trigger.current = el;
101
+ assignRef(props.ref, el);
102
+ };
73
103
  // The app's results change as people type, so the chosen option is kept here for its label.
74
104
  const [picked, setPicked] = React.useState();
75
105
  const chosen = options.find((o) => o.value === value) ?? (picked && picked.value === value ? picked : undefined);
@@ -97,7 +127,7 @@ function SearchSelect({ value, onChange, options, placeholder = "Choose", disabl
97
127
  const triggerInner = (_jsxs(_Fragment, { children: [_jsx("span", { className: cn("min-w-0 truncate", !chosen && "text-[var(--text-muted)]"), children: chosen ? chosen.label : placeholder }), _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-4 shrink-0 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
98
128
  // Phones: the search field and the options in a bottom sheet, 44px rows.
99
129
  if (mobile) {
100
- return (_jsxs(_Fragment, { children: [_jsx(Combobox.Root, { items: rows, value: chosen ?? null, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, open: false, disabled: disabled, name: name, children: _jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: cn(triggerClasses, className), onClick: () => {
130
+ return (_jsxs(_Fragment, { children: [_jsx(Combobox.Root, { items: rows, value: chosen ?? null, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, open: false, disabled: disabled, name: name, required: props.required, children: _jsx(Combobox.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: cn(triggerClasses, className), onClick: () => {
101
131
  setTitle(labelOf(trigger.current) || props["aria-label"] || placeholder);
102
132
  setOpen(true);
103
133
  }, children: triggerInner }) }), _jsxs(BottomSheet, { open: open, onClose: close, title: title, children: [_jsx("div", { className: "px-5 pb-2", children: _jsx(SearchInput, { placeholder: searchPlaceholder, value: query, loading: server?.loading, onChange: (e) => setQuery(e.target.value), onClear: () => setQuery("") }) }), _jsx(BottomSheetOptions, { children: rows.map((row) => (_jsx(BottomSheetOption, { selected: row.value === value, onSelect: () => pick(row), children: row.create !== undefined ? _jsx(AddBody, { label: row.label, phone: true }) : _jsx(OptionBody, { option: row, phone: true }) }, row.value))) }), note ? (_jsx("p", { role: "status", className: "px-5 pb-4 text-14 text-[var(--text-muted)]", children: note })) : null] })] }));
@@ -117,7 +147,7 @@ function SearchSelect({ value, onChange, options, placeholder = "Choose", disabl
117
147
  // The list is named by the field's label, read when it opens.
118
148
  setTitle(labelOf(trigger.current) || props["aria-label"] || placeholder);
119
149
  setOpen(true);
120
- }, disabled: disabled, name: name, children: [_jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: cn(triggerClasses, className), children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: "flex max-h-[min(380px,var(--available-height))] w-[max(var(--anchor-width),280px)] max-w-[calc(100vw-16px)] flex-col rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none transition-opacity duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (row) => (_jsx(Combobox.Item, { value: row, "data-slot": "select-option", className: optionRow, children: row.create !== undefined ? (_jsx(AddBody, { label: row.label })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "min-w-0", children: _jsx(OptionBody, { option: row }) }), _jsx(Combobox.ItemIndicator, { className: "inline-flex shrink-0", children: _jsx(Check, { "aria-hidden": "true", className: "size-4 text-[var(--primary)]" }) })] })) }, row.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
150
+ }, disabled: disabled, name: name, required: props.required, children: [_jsx(Combobox.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-label": props["aria-label"], className: cn(triggerClasses, className), children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: "flex max-h-[min(380px,var(--available-height))] w-[max(var(--anchor-width),280px)] max-w-[calc(100vw-16px)] flex-col rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none transition-opacity duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (row) => (_jsx(Combobox.Item, { value: row, "data-slot": "select-option", className: optionRow, children: row.create !== undefined ? (_jsx(AddBody, { label: row.label })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "min-w-0", children: _jsx(OptionBody, { option: row }) }), _jsx(Combobox.ItemIndicator, { className: "inline-flex shrink-0", children: _jsx(Check, { "aria-hidden": "true", className: "size-4 text-[var(--primary)]" }) })] })) }, row.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
121
151
  }
122
152
  // The field for several values: a box holding a Tag per choice and the trigger, which fills the rest. The
123
153
  // trigger is the control (FieldLabel names it); each Tag's × is its own button, never inside the trigger.
@@ -133,6 +163,10 @@ function MultipleSelect({ value, onChange, options, placeholder = "Choose", disa
133
163
  const [open, setOpen] = React.useState(false);
134
164
  const [title, setTitle] = React.useState("");
135
165
  const trigger = React.useRef(null);
166
+ const triggerRef = (el) => {
167
+ trigger.current = el;
168
+ assignRef(props.ref, el);
169
+ };
136
170
  // The list lines up with the whole box, not only the trigger beside the Tags.
137
171
  const boxRef = React.useRef(null);
138
172
  const { picked, remember } = usePicked(value, options);
@@ -185,10 +219,10 @@ function MultipleSelect({ value, onChange, options, placeholder = "Choose", disa
185
219
  const popupClass = "flex max-h-[min(380px,var(--available-height))] min-w-[var(--anchor-width)] w-[max(var(--anchor-width),280px)] max-w-[calc(100vw-16px)] flex-col rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none transition-opacity duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0";
186
220
  // Phones: tick rows in a bottom sheet (with the search field on top when there is one).
187
221
  if (mobile) {
188
- return (_jsxs(_Fragment, { children: [box(_jsx(SelectPrimitive.Root, { multiple: true, value: value, items: options.map((o) => ({ value: o.value, label: o.label })), open: false, disabled: disabled, name: name, children: _jsx(SelectPrimitive.Trigger, { ref: trigger, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: tagsTrigger, onClick: () => openList(true), children: triggerInner }) })), _jsxs(BottomSheet, { open: open, onClose: () => openList(false), title: title, children: [searching ? (_jsx("div", { className: "px-5 pb-2", children: _jsx(SearchInput, { placeholder: searchPlaceholder, value: query, loading: server?.loading, onChange: (e) => setQuery(e.target.value), onClear: () => setQuery("") }) })) : null, _jsx(BottomSheetOptions, { multiple: true, children: rows.map((r) => (_jsx(BottomSheetOption, { selected: value.includes(r.value), onSelect: () => toggle(r), children: r.create !== undefined ? _jsx(AddBody, { label: r.label, phone: true }) : _jsx(OptionBody, { option: r, phone: true }) }, r.value))) }), note ? (_jsx("p", { role: "status", className: "px-5 pb-4 text-14 text-[var(--text-muted)]", children: note })) : null] })] }));
222
+ return (_jsxs(_Fragment, { children: [box(_jsx(SelectPrimitive.Root, { multiple: true, value: value, items: options.map((o) => ({ value: o.value, label: o.label })), open: false, disabled: disabled, name: name, required: props.required, children: _jsx(SelectPrimitive.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: tagsTrigger, onClick: () => openList(true), children: triggerInner }) })), _jsxs(BottomSheet, { open: open, onClose: () => openList(false), title: title, children: [searching ? (_jsx("div", { className: "px-5 pb-2", children: _jsx(SearchInput, { placeholder: searchPlaceholder, value: query, loading: server?.loading, onChange: (e) => setQuery(e.target.value), onClear: () => setQuery("") }) })) : null, _jsx(BottomSheetOptions, { multiple: true, children: rows.map((r) => (_jsx(BottomSheetOption, { selected: value.includes(r.value), onSelect: () => toggle(r), children: r.create !== undefined ? _jsx(AddBody, { label: r.label, phone: true }) : _jsx(OptionBody, { option: r, phone: true }) }, r.value))) }), note ? (_jsx("p", { role: "status", className: "px-5 pb-4 text-14 text-[var(--text-muted)]", children: note })) : null] })] }));
189
223
  }
190
224
  if (!searching) {
191
- return box(_jsxs(SelectPrimitive.Root, { multiple: true, value: value, onValueChange: (v) => onChange((v ?? [])), items: options.map((o) => ({ value: o.value, label: o.label })), disabled: disabled, name: name, open: open, onOpenChange: openList, children: [_jsx(SelectPrimitive.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, alignItemWithTrigger: false, className: "z-[95]", children: _jsx(SelectPrimitive.Popup, { "data-slot": "select-menu", className: cn(popupClass, "overflow-y-auto py-1"), children: _jsx(SelectPrimitive.List, { children: options.map((o) => (_jsx(SelectPrimitive.Item, { value: o.value, label: o.label, "data-slot": "select-option", className: optionRow, children: row(o) }, o.value))) }) }) }) })] }));
225
+ return box(_jsxs(SelectPrimitive.Root, { multiple: true, value: value, onValueChange: (v) => onChange((v ?? [])), items: options.map((o) => ({ value: o.value, label: o.label })), disabled: disabled, name: name, required: props.required, open: open, onOpenChange: openList, children: [_jsx(SelectPrimitive.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, alignItemWithTrigger: false, className: "z-[95]", children: _jsx(SelectPrimitive.Popup, { "data-slot": "select-menu", className: cn(popupClass, "overflow-y-auto py-1"), children: _jsx(SelectPrimitive.List, { children: options.map((o) => (_jsx(SelectPrimitive.Item, { value: o.value, label: o.label, "data-slot": "select-option", className: optionRow, children: row(o) }, o.value))) }) }) }) })] }));
192
226
  }
193
227
  return box(_jsxs(Combobox.Root, { multiple: true, items: rows, value: picked, filter: null, autoHighlight: true, itemToStringLabel: (r) => r.label, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, onInputValueChange: (next, details) => {
194
228
  if (details.reason !== "item-press")
@@ -201,7 +235,7 @@ function MultipleSelect({ value, onChange, options, placeholder = "Choose", disa
201
235
  const removed = picked.find((p) => !next.some((r) => r.value === p.value));
202
236
  if (removed)
203
237
  toggle(removed);
204
- }, open: open, onOpenChange: openList, disabled: disabled, name: name, children: [_jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: popupClass, children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (r) => (_jsx(Combobox.Item, { value: r, "data-slot": "select-option", className: optionRow, children: row(r) }, r.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
238
+ }, open: open, onOpenChange: openList, disabled: disabled, name: name, required: props.required, children: [_jsx(Combobox.Trigger, { ref: triggerRef, id: props.id, onBlur: props.onBlur, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: popupClass, children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (r) => (_jsx(Combobox.Item, { value: r, "data-slot": "select-option", className: optionRow, children: row(r) }, r.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
205
239
  }
206
240
  function AddBody({ label, phone = false }) {
207
241
  return (_jsxs("span", { className: cn("flex min-w-0 items-center gap-3 font-semibold text-[var(--primary)]", phone && "text-14"), children: [_jsx(Plus, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "truncate", children: label })] }));
@@ -1,8 +1,19 @@
1
1
  import * as React from "react";
2
2
  type SwitchProps = {
3
- checked: boolean;
4
- onChange: (checked: boolean) => void;
3
+ /** On or off. Leave it off to let the switch keep its own, from `defaultChecked`. */
4
+ checked?: boolean;
5
+ /** Whether it starts on, when you don't pass `checked`. */
6
+ defaultChecked?: boolean;
7
+ onChange?: (checked: boolean) => void;
5
8
  disabled?: boolean;
9
+ /** Its name in a submitted form. Sends "on" when it's on, nothing when it's off. */
10
+ name?: string;
11
+ /** The form can't be sent until it's on: "I agree to the terms". */
12
+ required?: boolean;
13
+ /** Called when it loses focus, for checking it then (a form library's `onBlur`). */
14
+ onBlur?: React.FocusEventHandler<HTMLElement>;
15
+ /** The switch, to focus it from your code or a form library. */
16
+ ref?: React.Ref<HTMLElement>;
6
17
  /** A visible label before the switch, for a toolbar: "Include people's network". Clicking it flips the switch, and it names it. */
7
18
  label?: string;
8
19
  /** A name is required: `label`, `aria-label`, or `aria-labelledby` pointing at the visible label. */
@@ -11,6 +22,6 @@ type SwitchProps = {
11
22
  id?: string;
12
23
  className?: string;
13
24
  };
14
- declare function Switch({ checked, onChange, disabled, label, className, ...props }: SwitchProps): React.JSX.Element;
25
+ declare function Switch({ checked: checkedProp, defaultChecked, onChange: onChangeProp, disabled, label, className, ...props }: SwitchProps): React.JSX.Element;
15
26
  export { Switch };
16
27
  export type { SwitchProps };
@@ -3,8 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { Switch as SwitchPrimitive } from "@base-ui/react/switch";
5
5
  import { cn } from "@brdgapp/ui/lib/utils";
6
- function Switch({ checked, onChange, disabled = false, label, className, ...props }) {
6
+ function Switch({ checked: checkedProp, defaultChecked = false, onChange: onChangeProp, disabled = false, label, className, ...props }) {
7
7
  const labelId = React.useId();
8
+ // Kept here when the app doesn't pass `checked`.
9
+ const [own, setOwn] = React.useState(defaultChecked);
10
+ const checked = checkedProp ?? own;
11
+ const onChange = (next) => {
12
+ if (checkedProp === undefined)
13
+ setOwn(next);
14
+ onChangeProp?.(next);
15
+ };
8
16
  const root = (_jsx(SwitchPrimitive.Root, { "data-slot": "switch", checked: checked, onCheckedChange: (next) => onChange(next), disabled: disabled, className: cn(
9
17
  // Off is mid-grey, not pale: the track's edge has to reach 3:1 against the page (4.8:1 on white). 2026-11-04.
10
18
  "relative inline-flex h-5 w-9 shrink-0 items-center rounded-full bg-[var(--text-muted)] transition-colors duration-200 outline-none",
@@ -1,8 +1,21 @@
1
1
  import type * as React from "react";
2
2
  import { type ElementProps } from "@brdgapp/ui/lib/utils";
3
- type TagInputProps = ElementProps<HTMLDivElement> & {
4
- value: string[];
5
- onChange: (next: string[]) => void;
3
+ type TagInputProps = Omit<ElementProps<HTMLDivElement>, "id" | "onBlur"> & {
4
+ /** The tags. Leave it off to let the field keep its own, from `defaultValue`. */
5
+ value?: string[];
6
+ /** The first tags when you don't pass `value`. */
7
+ defaultValue?: string[];
8
+ onChange?: (next: string[]) => void;
9
+ /** Its name in a submitted form: each tag is sent under this name. */
10
+ name?: string;
11
+ /** The text box's `id`. Inside a Field, leave it off: the Field ties the label to it. */
12
+ id?: string;
13
+ /** The form can't be sent with no tags. Pair it with a FieldError that says what's missing. */
14
+ required?: boolean;
15
+ /** Called when the text box loses focus (after what's typed becomes a tag), for a form library's `onBlur`. */
16
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
17
+ /** The text box, to focus it from your code or a form library. */
18
+ ref?: React.Ref<HTMLInputElement>;
6
19
  placeholder?: string;
7
20
  /** Required unless a visible <label> points at the field. */
8
21
  ariaLabel?: string;
@@ -12,6 +25,6 @@ type TagInputProps = ElementProps<HTMLDivElement> & {
12
25
  disabled?: boolean;
13
26
  className?: string;
14
27
  };
15
- declare function TagInput({ value, onChange, placeholder, ariaLabel, variant, disabled, className, ...rest }: TagInputProps): React.JSX.Element;
28
+ declare function TagInput({ value: valueProp, defaultValue, onChange: onChangeProp, name, id, required, onBlur, ref, placeholder, ariaLabel, variant, disabled, className, ...rest }: TagInputProps): React.JSX.Element;
16
29
  export { TagInput };
17
30
  export type { TagInputProps };
@@ -5,9 +5,24 @@ import { Button as ButtonPrimitive } from "@base-ui/react/button";
5
5
  import { Input as InputPrimitive } from "@base-ui/react/input";
6
6
  import { X } from "lucide-react";
7
7
  import { cn } from "@brdgapp/ui/lib/utils";
8
- function TagInput({ value, onChange, placeholder, ariaLabel, variant = "primary", disabled = false, className, ...rest }) {
8
+ function TagInput({ value: valueProp, defaultValue = [], onChange: onChangeProp, name, id, required = false, onBlur, ref, placeholder, ariaLabel, variant = "primary", disabled = false, className, ...rest }) {
9
9
  const [draft, setDraft] = useState("");
10
10
  const inputRef = useRef(null);
11
+ // Kept here when the app doesn't pass `value`.
12
+ const [own, setOwn] = useState(defaultValue);
13
+ const value = valueProp ?? own;
14
+ const onChange = (next) => {
15
+ if (valueProp === undefined)
16
+ setOwn(next);
17
+ onChangeProp?.(next);
18
+ };
19
+ const setInput = (el) => {
20
+ inputRef.current = el;
21
+ if (typeof ref === "function")
22
+ ref(el);
23
+ else if (ref)
24
+ ref.current = el;
25
+ };
11
26
  /** Adds each entry that isn't already there (ignoring case), then clears the text box. */
12
27
  function addAll(entries) {
13
28
  const next = [...value];
@@ -54,6 +69,11 @@ function TagInput({ value, onChange, placeholder, ariaLabel, variant = "primary"
54
69
  "data-[disabled]:pointer-events-none data-[disabled]:opacity-50 has-[input:disabled]:pointer-events-none has-[input:disabled]:opacity-50", className), children: [value.map((tag, i) => (_jsxs("span", { "data-slot": "tag-input-chip", className: cn("inline-flex items-center gap-0.5 rounded-full py-0.5 pr-0.5 pl-2.5 text-11 leading-normal font-semibold", disabled && "pr-2.5", variant === "primary" ? "bg-[var(--primary)]/[0.08] text-[var(--primary)]" : "bg-[var(--surface-secondary)] text-[var(--text-body)]"), children: [tag, disabled ? null : (_jsx(ButtonPrimitive, { "aria-label": `Remove ${tag}`, onClick: (e) => {
55
70
  e.stopPropagation();
56
71
  removeAt(i);
57
- }, className: "inline-flex size-5 items-center justify-center rounded-full opacity-60 outline-none transition-opacity hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: _jsx(X, { "aria-hidden": "true", className: "size-3" }) }))] }, `${tag}-${i}`))), _jsx(InputPrimitive, { ref: inputRef, "data-slot": "tag-input-field", type: "text", value: draft, "aria-label": ariaLabel, onChange: (e) => setDraft(e.target.value), onKeyDown: onKeyDown, onPaste: onPaste, disabled: disabled, onBlur: () => add(draft), placeholder: value.length === 0 ? placeholder : "", className: "min-w-[80px] flex-1 border-0 bg-transparent px-1.5 py-0.5 text-16 md:text-14 text-[var(--text-primary)] outline-none placeholder:text-[var(--text-muted)]" })] }));
72
+ }, className: "inline-flex size-5 items-center justify-center rounded-full opacity-60 outline-none transition-opacity hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: _jsx(X, { "aria-hidden": "true", className: "size-3" }) }))] }, `${tag}-${i}`))), name ? value.map((tag, i) => _jsx("input", { type: "hidden", name: name, value: tag }, `${tag}-${i}`)) : null, _jsx(InputPrimitive, { ref: setInput, id: id,
73
+ // Only while there are no tags: what's typed becomes a tag, so the text box is usually empty.
74
+ required: required && value.length === 0, "data-slot": "tag-input-field", type: "text", value: draft, "aria-label": ariaLabel, onChange: (e) => setDraft(e.target.value), onKeyDown: onKeyDown, onPaste: onPaste, disabled: disabled, onBlur: (e) => {
75
+ add(draft);
76
+ onBlur?.(e);
77
+ }, placeholder: value.length === 0 ? placeholder : "", className: "min-w-[80px] flex-1 border-0 bg-transparent px-1.5 py-0.5 text-16 md:text-14 text-[var(--text-primary)] outline-none placeholder:text-[var(--text-muted)]" })] }));
58
78
  }
59
79
  export { TagInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brdgapp/ui",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Bridge's shared components, tokens and styles. Documented at handbook.brdg.app.",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://handbook.brdg.app",