@brdgapp/ui 1.11.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 +49 -1
- package/components/app-shell.d.ts +12 -1
- package/components/app-shell.js +2 -2
- package/components/button.js +5 -3
- package/components/column-filter-menu.d.ts +6 -3
- package/components/column-filter-menu.js +4 -4
- package/components/column-sort-button.d.ts +3 -1
- package/components/column-sort-button.js +2 -2
- package/components/data-table.d.ts +8 -1
- package/components/data-table.js +13 -13
- package/components/date-picker.d.ts +8 -0
- package/components/date-picker.js +13 -6
- package/components/drawer.d.ts +8 -3
- package/components/drawer.js +15 -4
- package/components/filter-chip.d.ts +13 -3
- package/components/filter-chip.js +7 -2
- package/components/filter-pill.d.ts +4 -3
- package/components/input.d.ts +3 -1
- package/components/input.js +40 -12
- package/components/network-graph.d.ts +1 -1
- package/components/network-graph.js +13 -5
- package/components/page-header.d.ts +35 -0
- package/components/page-header.js +23 -0
- package/components/select.d.ts +20 -7
- package/components/select.js +44 -10
- package/components/switch.d.ts +14 -3
- package/components/switch.js +9 -1
- package/components/tag-input.d.ts +17 -4
- package/components/tag-input.js +22 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,57 @@
|
|
|
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
|
+
|
|
30
|
+
## 1.12.0
|
|
31
|
+
|
|
32
|
+
2026-11-24. PageHeader, and a table toolbar that sits on the page. Nothing changes for apps already on 1.11.
|
|
33
|
+
|
|
34
|
+
- New: PageHeader (`components/page-header`), the top of every page: `back` ("← Back"), the 22px `title`,
|
|
35
|
+
a `subtitle`, and on the right `action` (the main button) plus at most one `secondaryAction`; on phones
|
|
36
|
+
the buttons go under the title. A page can switch on `media` (an Avatar, or an icon in a blue square), a
|
|
37
|
+
`tag` after the title, and `menu`, a ⋮ ActionMenu for the less-used actions. It replaces apps' own page
|
|
38
|
+
headers (AdminPageHeader, PageHeader, UsersPageShell, hand-made titles from 14 to 30px).
|
|
39
|
+
- New: DataTableToolbar's `onPage`, for a toolbar on the page above a grid of cards or a list that isn't in
|
|
40
|
+
a card: no side space and no divider, so its search lines up with the page's heading. A table in a card
|
|
41
|
+
keeps its toolbar inside the card. It replaces app-directories' PageToolbar.
|
|
42
|
+
- Fix: a state setter passed straight to `onChange` on FilterPill, ColumnFilterMenu or Select with
|
|
43
|
+
`multiple` (`onChange={setPicked}`) could fail to type-check. The values' type now comes from `value` and
|
|
44
|
+
`options` only.
|
|
45
|
+
- Fix: a DataTable with `addColumn` no longer logs a "unique key" warning while an app is in development.
|
|
46
|
+
- Fix: a Button with `render` (a link) draws its `icon`; it used to drop it.
|
|
47
|
+
- Fix: NetworkGraph with more than 16 people shows "+N" in the last outer place, instead of leaving the
|
|
48
|
+
rest out without a word. Its positions are rounded, so a server-drawn page no longer logs a hydration
|
|
49
|
+
warning.
|
|
50
|
+
- New: DataTableToolbar, ColumnFilterMenu and ColumnSortButton take `className`, for layout only, like the
|
|
51
|
+
other components.
|
|
52
|
+
|
|
5
53
|
## 1.11.0
|
|
6
54
|
|
|
7
|
-
2026-11-
|
|
55
|
+
2026-11-24. Spinner; DatePicker; search inside Select; picking several values; ticks in ActionMenu; password fields you can show; icons, prefixes and numbers in Input; copy on Button,
|
|
8
56
|
IconButton and CopyField. Nothing changes for apps already on 1.10, except that a password field now has its own show/hide button:
|
|
9
57
|
delete any the app drew beside it.
|
|
10
58
|
|
|
@@ -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 };
|
package/components/app-shell.js
CHANGED
|
@@ -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 };
|
package/components/button.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
4
4
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
5
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
@@ -66,11 +66,13 @@ function Button({ className, variant, size, fullWidth, icon, loading = false, di
|
|
|
66
66
|
const classes = cn(buttonVariants({ variant, size, fullWidth }), className);
|
|
67
67
|
const copier = useCopy();
|
|
68
68
|
// With `render` (for example a Next `Link`), the element keeps its own semantics: a link stays a
|
|
69
|
-
// link. It
|
|
69
|
+
// link. It draws the icon like any button (audit 11.5: it used to be dropped). A link doesn't wait or
|
|
70
|
+
// copy, so `loading` and `copy` don't apply.
|
|
71
|
+
const linkBody = icon ? (_jsxs(_Fragment, { children: [_jsx("span", { "data-slot": "button-icon", className: "inline-flex shrink-0", "aria-hidden": "true", children: icon }), children] })) : (children);
|
|
70
72
|
const rendered = useRender({
|
|
71
73
|
render: render,
|
|
72
74
|
enabled: render !== undefined,
|
|
73
|
-
props: mergeProps({ className: classes, "data-slot": "button" }, { ...props, onClick }, { children }),
|
|
75
|
+
props: mergeProps({ className: classes, "data-slot": "button" }, { ...props, onClick }, { children: linkBody }),
|
|
74
76
|
});
|
|
75
77
|
if (rendered)
|
|
76
78
|
return rendered;
|
|
@@ -7,12 +7,14 @@ type ColumnFilterBase = ElementProps<HTMLButtonElement> & {
|
|
|
7
7
|
label: string;
|
|
8
8
|
/** Explains the column. Hidden while the menu is open. */
|
|
9
9
|
tooltip?: string;
|
|
10
|
+
/** Layout only: `ml-auto`. */
|
|
11
|
+
className?: string;
|
|
10
12
|
};
|
|
11
13
|
type SingleColumnFilterProps<T extends string> = ColumnFilterBase & {
|
|
12
14
|
multiple?: false;
|
|
13
15
|
value: T;
|
|
14
16
|
options: FilterPillOption<T>[];
|
|
15
|
-
onChange: (value: T) => void;
|
|
17
|
+
onChange: (value: NoInfer<T>) => void;
|
|
16
18
|
};
|
|
17
19
|
type MultipleColumnFilterProps<T extends string> = ColumnFilterBase & {
|
|
18
20
|
/** Several values: tick rows, each tick filters at once, Reset clears them. */
|
|
@@ -21,12 +23,13 @@ type MultipleColumnFilterProps<T extends string> = ColumnFilterBase & {
|
|
|
21
23
|
value: T[];
|
|
22
24
|
/** The values to pick from. No "All" row. */
|
|
23
25
|
options: FilterPillOption<T>[];
|
|
24
|
-
onChange: (value: T[]) => void;
|
|
26
|
+
onChange: (value: NoInfer<T>[]) => void;
|
|
25
27
|
/** A search field on top. `true` filters `options`; an object means the app searches. */
|
|
26
28
|
search?: true | FilterPillSearch;
|
|
27
29
|
searchPlaceholder?: string;
|
|
28
30
|
};
|
|
29
31
|
type ColumnFilterMenuProps<T extends string> = SingleColumnFilterProps<T> | MultipleColumnFilterProps<T>;
|
|
30
|
-
declare function ColumnFilterMenu<T extends string>(props:
|
|
32
|
+
declare function ColumnFilterMenu<T extends string>(props: MultipleColumnFilterProps<T>): React.JSX.Element;
|
|
33
|
+
declare function ColumnFilterMenu<T extends string>(props: SingleColumnFilterProps<T>): React.JSX.Element;
|
|
31
34
|
export { ColumnFilterMenu };
|
|
32
35
|
export type { ColumnFilterMenuProps, MultipleColumnFilterProps, SingleColumnFilterProps };
|
|
@@ -13,13 +13,13 @@ import { cn } from "@brdgapp/ui/lib/utils";
|
|
|
13
13
|
function ColumnFilterMenu(props) {
|
|
14
14
|
return props.multiple ? _jsx(MultipleColumnFilter, { ...props }) : _jsx(SingleColumnFilter, { ...props });
|
|
15
15
|
}
|
|
16
|
-
function MultipleColumnFilter({ multiple, icon: Icon, label, tooltip, value, options, onChange, search, searchPlaceholder, ...rest }) {
|
|
16
|
+
function MultipleColumnFilter({ multiple, icon: Icon, label, tooltip, value, options, onChange, search, searchPlaceholder, className, ...rest }) {
|
|
17
17
|
const [open, setOpen] = useState(false);
|
|
18
18
|
const mobile = useIsMobile();
|
|
19
19
|
const { picked, remember } = usePicked(value, options);
|
|
20
20
|
const active = value.length > 0;
|
|
21
21
|
const name = `Filter by ${label.toLowerCase()}${active ? `: ${summarize(picked.map((o) => o.label)).spoken}` : ""}`;
|
|
22
|
-
const triggerClass = cn(columnHeaderButton, active ? "text-[var(--primary)]" : "text-[var(--text-secondary)]");
|
|
22
|
+
const triggerClass = cn(columnHeaderButton, active ? "text-[var(--primary)]" : "text-[var(--text-secondary)]", className);
|
|
23
23
|
const inner = (_jsxs(_Fragment, { children: [Icon ? _jsx(Icon, { "aria-hidden": "true", className: cn("size-3.5", active ? "text-[var(--primary)]" : "text-[var(--text-muted)]") }) : null, label, active ? _jsx("span", { "aria-hidden": "true", className: "size-1.5 rounded-full bg-[var(--primary)]" }) : null, _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-3.5 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
24
24
|
const panel = (phone) => (_jsx(MultiPanel, { value: value, options: options, onChange: onChange, name: label, search: search, searchPlaceholder: searchPlaceholder, picked: picked, remember: remember, phone: phone }));
|
|
25
25
|
if (mobile) {
|
|
@@ -30,13 +30,13 @@ function MultipleColumnFilter({ multiple, icon: Icon, label, tooltip, value, opt
|
|
|
30
30
|
}
|
|
31
31
|
return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(Tip, { text: tooltip, disabled: open, children: _jsx(PopoverPrimitive.Trigger, { ...rest, "data-slot": "column-filter-menu", "data-multiple": multiple ? "" : undefined, "aria-label": name, onClick: (e) => e.stopPropagation(), className: triggerClass, children: inner }) }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Positioner, { side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsx(PopoverPrimitive.Popup, { "data-slot": "filter-menu", "aria-label": `Filter by ${label.toLowerCase()}`, className: "w-[260px] max-w-[calc(100vw-16px)] 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: panel(false) }) }) })] }));
|
|
32
32
|
}
|
|
33
|
-
function SingleColumnFilter({ multiple, icon: Icon, label, tooltip, value, options, onChange, ...rest }) {
|
|
33
|
+
function SingleColumnFilter({ multiple, icon: Icon, label, tooltip, value, options, onChange, className, ...rest }) {
|
|
34
34
|
const [open, setOpen] = useState(false);
|
|
35
35
|
const mobile = useIsMobile();
|
|
36
36
|
const active = options.length > 0 && value !== options[0]?.value;
|
|
37
37
|
const activeLabel = options.find((o) => o.value === value)?.label;
|
|
38
38
|
const name = `Filter by ${label.toLowerCase()}${active && activeLabel ? `: ${activeLabel}` : ""}`;
|
|
39
|
-
const triggerClass = cn(columnHeaderButton, active ? "text-[var(--primary)]" : "text-[var(--text-secondary)]");
|
|
39
|
+
const triggerClass = cn(columnHeaderButton, active ? "text-[var(--primary)]" : "text-[var(--text-secondary)]", className);
|
|
40
40
|
const inner = (_jsxs(_Fragment, { children: [Icon ? _jsx(Icon, { "aria-hidden": "true", className: cn("size-3.5", active ? "text-[var(--primary)]" : "text-[var(--text-muted)]") }) : null, label, active ? _jsx("span", { "aria-hidden": "true", className: "size-1.5 rounded-full bg-[var(--primary)]" }) : null, _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-3.5 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
41
41
|
// Phones: a bottom sheet instead of a menu. No tooltip: touch has no hover.
|
|
42
42
|
if (mobile) {
|
|
@@ -18,7 +18,9 @@ type ColumnSortButtonProps = ElementProps<HTMLButtonElement> & {
|
|
|
18
18
|
desc: string;
|
|
19
19
|
};
|
|
20
20
|
onClick: () => void;
|
|
21
|
+
/** Layout only: `ml-auto`. */
|
|
22
|
+
className?: string;
|
|
21
23
|
};
|
|
22
|
-
declare function ColumnSortButton({ icon: Icon, label, tooltip, direction, describe, onClick, ...rest }: ColumnSortButtonProps): import("react").JSX.Element;
|
|
24
|
+
declare function ColumnSortButton({ icon: Icon, label, tooltip, direction, describe, onClick, className, ...rest }: ColumnSortButtonProps): import("react").JSX.Element;
|
|
23
25
|
export { ColumnSortButton, columnHeaderButton };
|
|
24
26
|
export type { ColumnSortButtonProps };
|
|
@@ -14,11 +14,11 @@ import { cn } from "@brdgapp/ui/lib/utils";
|
|
|
14
14
|
* it does (⇅, ⌄); the whole thing tints on hover. 24px tall.
|
|
15
15
|
*/
|
|
16
16
|
const columnHeaderButton = "-mx-1.5 inline-flex items-center gap-1.5 rounded px-1.5 py-[3px] text-12 leading-normal font-bold whitespace-nowrap outline-none transition-colors hover:bg-[var(--surface-tertiary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]";
|
|
17
|
-
function ColumnSortButton({ icon: Icon, label, tooltip, direction, describe, onClick, ...rest }) {
|
|
17
|
+
function ColumnSortButton({ icon: Icon, label, tooltip, direction, describe, onClick, className, ...rest }) {
|
|
18
18
|
const state = direction && describe ? `, sorted ${describe[direction]}` : "";
|
|
19
19
|
return (_jsx(Tip, { text: tooltip, children: _jsxs(ButtonPrimitive, { ...rest, "data-slot": "column-sort-button", onClick: (e) => {
|
|
20
20
|
e.stopPropagation();
|
|
21
21
|
onClick();
|
|
22
|
-
}, "aria-label": `Sort by ${label.toLowerCase()}${state}`, className: cn(columnHeaderButton, direction ? "text-[var(--text-primary)]" : "text-[var(--text-secondary)]"), children: [Icon ? _jsx(Icon, { "aria-hidden": "true", className: "size-3.5 text-[var(--text-muted)]" }) : null, label, direction === "desc" ? (_jsx(ArrowDown, { "aria-hidden": "true", className: "size-3 shrink-0 text-[var(--primary)]" })) : direction === "asc" ? (_jsx(ArrowUp, { "aria-hidden": "true", className: "size-3 shrink-0 text-[var(--primary)]" })) : (_jsx(ArrowUpDown, { "aria-hidden": "true", className: "size-3 shrink-0 opacity-40" }))] }) }));
|
|
22
|
+
}, "aria-label": `Sort by ${label.toLowerCase()}${state}`, className: cn(columnHeaderButton, direction ? "text-[var(--text-primary)]" : "text-[var(--text-secondary)]", className), children: [Icon ? _jsx(Icon, { "aria-hidden": "true", className: "size-3.5 text-[var(--text-muted)]" }) : null, label, direction === "desc" ? (_jsx(ArrowDown, { "aria-hidden": "true", className: "size-3 shrink-0 text-[var(--primary)]" })) : direction === "asc" ? (_jsx(ArrowUp, { "aria-hidden": "true", className: "size-3 shrink-0 text-[var(--primary)]" })) : (_jsx(ArrowUpDown, { "aria-hidden": "true", className: "size-3 shrink-0 opacity-40" }))] }) }));
|
|
23
23
|
}
|
|
24
24
|
export { ColumnSortButton, columnHeaderButton };
|
|
@@ -74,14 +74,21 @@ declare function DataTable<T>({ columns, rows, rowKey, onRowClick, onRowPrefetch
|
|
|
74
74
|
* The row at the top of a table's card for finding and acting on rows: search on the left; filters, then
|
|
75
75
|
* buttons, on the right. It is not a title: the page's heading names the table. Put it outside DataState,
|
|
76
76
|
* so it stays while the rows load, fail or filter down to nothing.
|
|
77
|
+
* `onPage` (Aman 2026-11-24): the same row on the page, above a grid of cards or a list that isn't in a card
|
|
78
|
+
* (app-directories' PageToolbar). No side space and no line: the page's own margins line it up with the title.
|
|
79
|
+
* A table in a card keeps its toolbar inside the card.
|
|
77
80
|
*/
|
|
78
|
-
declare function DataTableToolbar({ search, filters, actions, ...rest }: ElementProps<HTMLDivElement> & {
|
|
81
|
+
declare function DataTableToolbar({ search, filters, actions, onPage, className, ...rest }: ElementProps<HTMLDivElement> & {
|
|
79
82
|
/** A SearchInput. It is 288px wide, the whole row on a phone. */
|
|
80
83
|
search?: React.ReactNode;
|
|
81
84
|
/** FilterPills, and one "Clear all" link (search and every filter) when any is on. */
|
|
82
85
|
filters?: React.ReactNode;
|
|
83
86
|
/** Buttons that act on the table: Export, Add people. Use Button `md`, the search's height. */
|
|
84
87
|
actions?: React.ReactNode;
|
|
88
|
+
/** On the page, above a grid of cards or a list not in a card: no side space, no line under it. */
|
|
89
|
+
onPage?: boolean;
|
|
90
|
+
/** Layout only: `sticky top-0`. */
|
|
91
|
+
className?: string;
|
|
85
92
|
}): React.JSX.Element;
|
|
86
93
|
/**
|
|
87
94
|
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
package/components/data-table.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createElement as _createElement } from "react";
|
|
3
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
5
4
|
import * as React from "react";
|
|
@@ -57,7 +56,7 @@ function DataTable({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps,
|
|
|
57
56
|
const [scrolled, setScrolled] = React.useState(false);
|
|
58
57
|
return (_jsx("div", { "data-slot": "data-table", "data-scrolled": scrolled ? "" : undefined, className: cn("group/table", pinned ? "overflow-auto overscroll-contain" : "overflow-x-auto"), style: pinned ? { maxHeight } : undefined, onScroll: pinFirstColumn ? (e) => setScrolled(e.currentTarget.scrollLeft > 0) : undefined,
|
|
59
58
|
// A scroll area must be reachable by keyboard so it can be scrolled with the arrow keys.
|
|
60
|
-
tabIndex: scrollArea ? 0 : undefined, "aria-label": scrollArea ? props["aria-label"] : undefined, role: scrollArea ? "region" : undefined, children: _jsxs("div", { role: "table", "aria-label": props["aria-label"], style: { minWidth: minTableWidth(columns, Boolean(addColumn)) }, children: [_jsx(HeaderRow, { columns: columns, template: template, pinned: pinned, pinFirst: pinFirstColumn, addColumn: addColumn, addRow: addRow }), _jsxs("div", { role: "rowgroup", children: [rows.map((row) => (
|
|
59
|
+
tabIndex: scrollArea ? 0 : undefined, "aria-label": scrollArea ? props["aria-label"] : undefined, role: scrollArea ? "region" : undefined, children: _jsxs("div", { role: "table", "aria-label": props["aria-label"], style: { minWidth: minTableWidth(columns, Boolean(addColumn)) }, children: [_jsx(HeaderRow, { columns: columns, template: template, pinned: pinned, pinFirst: pinFirstColumn, addColumn: addColumn, addRow: addRow }), _jsxs("div", { role: "rowgroup", children: [rows.map((row) => (_jsxs("div", { ...rowProps?.(row), role: "row", "data-slot": "data-table-row", tabIndex: onRowClick ? 0 : undefined, onClick: onRowClick
|
|
61
60
|
? (e) => {
|
|
62
61
|
// A menu opened from the row (ActionMenu) renders outside it, but React still passes
|
|
63
62
|
// its clicks up to the row. Only clicks inside the row open it.
|
|
@@ -74,23 +73,24 @@ function DataTable({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps,
|
|
|
74
73
|
}
|
|
75
74
|
: undefined, onMouseEnter: onRowPrefetch ? () => onRowPrefetch(row) : undefined, onFocus: onRowPrefetch ? () => onRowPrefetch(row) : undefined, className: cn("group/row grid border-b border-[var(--border-divider)] transition-colors last:border-0", onRowClick
|
|
76
75
|
? "cursor-pointer outline-none hover:bg-[var(--surface-tertiary)] focus-visible:bg-[var(--surface-tertiary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-inset"
|
|
77
|
-
: "hover:bg-[var(--surface-secondary)]/40"), style: { gridTemplateColumns: template }
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
: "group-hover/row:bg-[color-mix(in_srgb,var(--surface-secondary)_40%,var(--surface-elevated))]")), children: _jsx("div", { className: "w-full min-w-0", children: c.render(row) }) }, c.key))),
|
|
85
|
-
addColumn ? _jsx("div", { role: "cell" }) : null))), addRow ? (_jsx("div", { role: "row", "data-slot": "data-table-add-row", className: "grid", style: { gridTemplateColumns: template }, children: _jsx("div", { role: "cell", "aria-colspan": count, className: "col-span-full", children: _jsx(ButtonPrimitive, { "data-slot": "data-table-add", onClick: addRow.onClick, className: "flex w-full py-3.5 pl-6 text-left text-13 leading-normal font-semibold text-[var(--text-secondary)] outline-none transition-colors hover:bg-[var(--surface-tertiary)] hover:text-[var(--text-primary)] focus-visible:bg-[var(--surface-tertiary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-inset", children: _jsxs("span", { className: "sticky left-6 flex items-center gap-1.5", children: [_jsx(Plus, { "aria-hidden": "true", className: "size-3.5 text-[var(--text-muted)]" }), addRow.action] }) }) }) })) : null] })] }) }));
|
|
76
|
+
: "hover:bg-[var(--surface-secondary)]/40"), style: { gridTemplateColumns: template }, children: [columns.map((c, i) => (_jsx("div", { role: "cell", className: cn(cellPadding(i, count), "flex min-w-0 items-center py-3.5",
|
|
77
|
+
// The pinned cell is solid and repeats the row's hover and focus, which it would otherwise cover.
|
|
78
|
+
pinFirstColumn &&
|
|
79
|
+
i === 0 &&
|
|
80
|
+
cn(PIN_FIRST, "bg-[var(--surface-elevated)] transition-colors", onRowClick
|
|
81
|
+
? "group-hover/row:bg-[var(--surface-tertiary)] group-focus-visible/row:bg-[var(--surface-tertiary)] group-focus-visible/row:shadow-[inset_2px_0_0_var(--primary),inset_0_2px_0_var(--primary),inset_0_-2px_0_var(--primary)]"
|
|
82
|
+
: "group-hover/row:bg-[color-mix(in_srgb,var(--surface-secondary)_40%,var(--surface-elevated))]")), children: _jsx("div", { className: "w-full min-w-0", children: c.render(row) }) }, c.key))), addColumn ? _jsx("div", { role: "cell" }) : null] }, rowKey(row)))), addRow ? (_jsx("div", { role: "row", "data-slot": "data-table-add-row", className: "grid", style: { gridTemplateColumns: template }, children: _jsx("div", { role: "cell", "aria-colspan": count, className: "col-span-full", children: _jsx(ButtonPrimitive, { "data-slot": "data-table-add", onClick: addRow.onClick, className: "flex w-full py-3.5 pl-6 text-left text-13 leading-normal font-semibold text-[var(--text-secondary)] outline-none transition-colors hover:bg-[var(--surface-tertiary)] hover:text-[var(--text-primary)] focus-visible:bg-[var(--surface-tertiary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-inset", children: _jsxs("span", { className: "sticky left-6 flex items-center gap-1.5", children: [_jsx(Plus, { "aria-hidden": "true", className: "size-3.5 text-[var(--text-muted)]" }), addRow.action] }) }) }) })) : null] })] }) }));
|
|
86
83
|
}
|
|
87
84
|
/**
|
|
88
85
|
* The row at the top of a table's card for finding and acting on rows: search on the left; filters, then
|
|
89
86
|
* buttons, on the right. It is not a title: the page's heading names the table. Put it outside DataState,
|
|
90
87
|
* so it stays while the rows load, fail or filter down to nothing.
|
|
88
|
+
* `onPage` (Aman 2026-11-24): the same row on the page, above a grid of cards or a list that isn't in a card
|
|
89
|
+
* (app-directories' PageToolbar). No side space and no line: the page's own margins line it up with the title.
|
|
90
|
+
* A table in a card keeps its toolbar inside the card.
|
|
91
91
|
*/
|
|
92
|
-
function DataTableToolbar({ search, filters, actions, ...rest }) {
|
|
93
|
-
return (_jsxs("div", { ...rest, "data-slot": "data-table-toolbar", className: "flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-divider)] px-6 py-3", children: [search ? _jsx("div", { className: "w-full md:w-72 [&>*]:w-full", children: search }) : null, filters || actions ? (
|
|
92
|
+
function DataTableToolbar({ search, filters, actions, onPage = false, className, ...rest }) {
|
|
93
|
+
return (_jsxs("div", { ...rest, "data-slot": "data-table-toolbar", "data-on-page": onPage ? "" : undefined, className: cn("flex flex-wrap items-center gap-x-3 gap-y-2", !onPage && "border-b border-[var(--border-divider)] px-6 py-3", className), children: [search ? _jsx("div", { className: "w-full md:w-72 [&>*]:w-full", children: search }) : null, filters || actions ? (
|
|
94
94
|
// Beside a search, filters and actions sit at the right. Without one, filters start at the left
|
|
95
95
|
// (a drawer's row of FilterChips) and actions stay at the right.
|
|
96
96
|
_jsxs("div", { className: cn("flex flex-1 flex-wrap items-center gap-3", search ? "md:justify-end" : ""), children: [filters ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: filters }) : null, actions ? _jsx("div", { className: cn("flex flex-wrap items-center gap-2", search ? "" : "ml-auto"), children: actions }) : null] })) : null] }));
|
|
@@ -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:
|
|
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:
|
|
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);
|
package/components/drawer.d.ts
CHANGED
|
@@ -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 };
|
package/components/drawer.js
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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):
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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 };
|
|
@@ -79,7 +79,7 @@ type SingleFilterPillProps<T extends string> = ElementProps<HTMLButtonElement> &
|
|
|
79
79
|
value: T;
|
|
80
80
|
/** The first option is the resting "All" state. */
|
|
81
81
|
options: FilterPillOption<T>[];
|
|
82
|
-
onChange: (value: T) => void;
|
|
82
|
+
onChange: (value: NoInfer<T>) => void;
|
|
83
83
|
/** What is being filtered: "Degree", "Status". Read as "Degree: 1st". */
|
|
84
84
|
ariaLabel?: string;
|
|
85
85
|
/**
|
|
@@ -96,7 +96,7 @@ type MultipleFilterPillProps<T extends string> = ElementProps<HTMLButtonElement>
|
|
|
96
96
|
value: T[];
|
|
97
97
|
/** The values to pick from. No "All" row: an empty pick is all. */
|
|
98
98
|
options: FilterPillOption<T>[];
|
|
99
|
-
onChange: (value: T[]) => void;
|
|
99
|
+
onChange: (value: NoInfer<T>[]) => void;
|
|
100
100
|
/** What's filtered: "Location". The resting label, then "Location: London, Berlin +1". */
|
|
101
101
|
ariaLabel: string;
|
|
102
102
|
/** A search field on top. `true` filters `options`; an object means the app searches and `options` are its results. */
|
|
@@ -106,6 +106,7 @@ type MultipleFilterPillProps<T extends string> = ElementProps<HTMLButtonElement>
|
|
|
106
106
|
className?: string;
|
|
107
107
|
};
|
|
108
108
|
type FilterPillProps<T extends string> = SingleFilterPillProps<T> | MultipleFilterPillProps<T>;
|
|
109
|
-
declare function FilterPill<T extends string>(props:
|
|
109
|
+
declare function FilterPill<T extends string>(props: MultipleFilterPillProps<T>): React.JSX.Element;
|
|
110
|
+
declare function FilterPill<T extends string>(props: SingleFilterPillProps<T>): React.JSX.Element;
|
|
110
111
|
export { FilterPill, FilterMenuPopup, FilterSheet, MultiPanel, SheetReset, summarize, TickBox, usePicked };
|
|
111
112
|
export type { FilterPillOption, FilterPillProps, FilterPillSearch, MultipleFilterPillProps, SingleFilterPillProps };
|
package/components/input.d.ts
CHANGED
|
@@ -19,8 +19,10 @@ type TextInputProps = BaseProps & {
|
|
|
19
19
|
onValueChange?: InputPrimitive.Props["onValueChange"];
|
|
20
20
|
};
|
|
21
21
|
type NumberInputProps = BaseProps & {
|
|
22
|
-
/** A
|
|
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;
|
package/components/input.js
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
41
|
-
setText(
|
|
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
|
-
|
|
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
|
|
69
|
-
const
|
|
70
|
-
const
|
|
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 (
|
|
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?.(
|
|
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 }) {
|
|
@@ -26,7 +26,7 @@ declare const SIZES: {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
type NetworkGraphProps = {
|
|
29
|
-
/** The people around the middle. The first 6 sit close; up to 10 more sit further out. */
|
|
29
|
+
/** The people around the middle. The first 6 sit close; up to 10 more sit further out. Past 16, the last outer place says "+N" for the people not drawn. */
|
|
30
30
|
people: Person[];
|
|
31
31
|
/** Who is in the middle. Leave it off for "You". */
|
|
32
32
|
center?: Person;
|
|
@@ -6,19 +6,27 @@ const SIZES = {
|
|
|
6
6
|
md: { width: "w-[280px]", center: "xl", inner: "lg", outer: "md", you: "size-12 text-13" },
|
|
7
7
|
lg: { width: "w-[360px]", center: "2xl", inner: "xl", outer: "lg", you: "size-16 text-16" },
|
|
8
8
|
};
|
|
9
|
+
// The "+N" bubble is the size of an outer face.
|
|
10
|
+
const MORE = { sm: "size-6 text-[10px]", md: "size-8 text-12", lg: "size-10 text-14" };
|
|
9
11
|
const INNER = 6;
|
|
10
12
|
const OUTER = 10;
|
|
11
13
|
function place(i, count, radius, offset) {
|
|
12
14
|
const a = offset + (i / count) * Math.PI * 2 - Math.PI / 2;
|
|
13
|
-
|
|
15
|
+
// Rounded, so the server and the browser draw the same numbers (their last digits can differ).
|
|
16
|
+
const r = (v) => Math.round(v * 1000) / 1000;
|
|
17
|
+
return { x: r(50 + radius * Math.cos(a)), y: r(50 + radius * Math.sin(a)) };
|
|
14
18
|
}
|
|
15
19
|
/** A network: you (or someone) in the middle, people around, a line to each. */
|
|
16
20
|
function NetworkGraph({ people, center, highlight = [], size = "md", animate = true, label, className }) {
|
|
17
21
|
const s = SIZES[size];
|
|
18
22
|
const inner = people.slice(0, INNER);
|
|
19
|
-
|
|
23
|
+
// More than fit: the last outer place counts the rest, so nobody is left out without a word (audit 11.5).
|
|
24
|
+
const over = people.length > INNER + OUTER;
|
|
25
|
+
const outer = people.slice(INNER, INNER + OUTER - (over ? 1 : 0));
|
|
26
|
+
const more = over ? people.length - INNER - outer.length : 0;
|
|
27
|
+
const outerCount = outer.length + (more ? 1 : 0);
|
|
20
28
|
const innerAt = inner.map((_, i) => place(i, inner.length, 30, 0));
|
|
21
|
-
const outerAt =
|
|
29
|
+
const outerAt = Array.from({ length: outerCount }, (_, i) => place(i, outerCount, 45, Math.PI / outerCount));
|
|
22
30
|
const lit = new Set(highlight);
|
|
23
31
|
// Outer people hang off the nearest close-in person, so the picture reads as friends of friends.
|
|
24
32
|
const nearest = (p) => innerAt.reduce((best, q, i) => (Math.hypot(q.x - p.x, q.y - p.y) < Math.hypot(innerAt[best].x - p.x, innerAt[best].y - p.y) ? i : best), 0);
|
|
@@ -27,11 +35,11 @@ function NetworkGraph({ people, center, highlight = [], size = "md", animate = t
|
|
|
27
35
|
const fade = animate ? "motion-safe:animate-fade-in [animation-fill-mode:both]" : "";
|
|
28
36
|
const lines = [
|
|
29
37
|
...innerAt.map((p, i) => ({ from: { x: 50, y: 50 }, to: p, on: lit.has(inner[i].name), n: i })),
|
|
30
|
-
...(innerAt.length ? outerAt.map((p, i) => ({ from: innerAt[nearest(p)], to: p, on: lit.has(outer[i].name), n: inner.length + i })) : []),
|
|
38
|
+
...(innerAt.length ? outerAt.map((p, i) => ({ from: innerAt[nearest(p)], to: p, on: i < outer.length && lit.has(outer[i].name), n: inner.length + i })) : []),
|
|
31
39
|
];
|
|
32
40
|
return (_jsxs("div", { "data-slot": "network-graph", role: label ? "img" : undefined, "aria-label": label, "aria-hidden": label ? undefined : true,
|
|
33
41
|
// A set width (not w-full), so it keeps its size inside a parent that shrinks to fit; max-w-full lets it
|
|
34
42
|
// shrink on a narrow screen.
|
|
35
|
-
className: cn("relative aspect-square max-w-full shrink-0", s.width, className), children: [_jsx("svg", { viewBox: "0 0 100 100", className: "absolute inset-0 size-full", "aria-hidden": "true", children: lines.map((l, i) => (_jsx("line", { x1: l.from.x, y1: l.from.y, x2: l.to.x, y2: l.to.y, vectorEffect: "non-scaling-stroke", strokeWidth: l.on ? 1.5 : 1, strokeDasharray: l.on ? undefined : "3 3", className: cn(l.on ? "stroke-[var(--primary)]" : "stroke-[var(--text-disabled)]", fade), style: step(l.n) }, i))) }), _jsxs("div", { "aria-hidden": "true", className: "contents", children: [[...inner.map((p, i) => ({ p, at: innerAt[i], ring: "inner", n: i })), ...outer.map((p, i) => ({ p, at: outerAt[i], ring: "outer", n: inner.length + i }))].map(({ p, at, ring, n }) => (_jsx("span", { className: cn("absolute -translate-x-1/2 -translate-y-1/2", enter), style: { left: `${at.x}%`, top: `${at.y}%`, ...step(n + 1) }, children: _jsx(Avatar, { name: p.name, src: p.src, size: ring === "inner" ? s.inner : s.outer, className: cn(lit.has(p.name) && "outline-2 outline-offset-2 outline-[var(--primary)] outline-solid") }) }, `${p.name}-${n}`))), _jsx("span", { className: cn("absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2", enter), children: center ? (_jsx(Avatar, { name: center.name, src: center.src, size: s.center })) : (_jsx("span", { className: cn("flex items-center justify-center rounded-full bg-[var(--primary-solid)] font-bold text-white", s.you), children: "You" })) })] })] }));
|
|
43
|
+
className: cn("relative aspect-square max-w-full shrink-0", s.width, className), children: [_jsx("svg", { viewBox: "0 0 100 100", className: "absolute inset-0 size-full", "aria-hidden": "true", children: lines.map((l, i) => (_jsx("line", { x1: l.from.x, y1: l.from.y, x2: l.to.x, y2: l.to.y, vectorEffect: "non-scaling-stroke", strokeWidth: l.on ? 1.5 : 1, strokeDasharray: l.on ? undefined : "3 3", className: cn(l.on ? "stroke-[var(--primary)]" : "stroke-[var(--text-disabled)]", fade), style: step(l.n) }, i))) }), _jsxs("div", { "aria-hidden": "true", className: "contents", children: [[...inner.map((p, i) => ({ p, at: innerAt[i], ring: "inner", n: i })), ...outer.map((p, i) => ({ p, at: outerAt[i], ring: "outer", n: inner.length + i }))].map(({ p, at, ring, n }) => (_jsx("span", { className: cn("absolute -translate-x-1/2 -translate-y-1/2", enter), style: { left: `${at.x}%`, top: `${at.y}%`, ...step(n + 1) }, children: _jsx(Avatar, { name: p.name, src: p.src, size: ring === "inner" ? s.inner : s.outer, className: cn(lit.has(p.name) && "outline-2 outline-offset-2 outline-[var(--primary)] outline-solid") }) }, `${p.name}-${n}`))), more ? (_jsxs("span", { "data-slot": "network-graph-more", className: cn("absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border border-[var(--border-default)] bg-[var(--surface-secondary)] font-semibold tabular-nums text-[var(--text-secondary)]", MORE[s.outer], enter), style: { left: `${outerAt[outer.length].x}%`, top: `${outerAt[outer.length].y}%`, ...step(inner.length + outer.length + 1) }, children: ["+", more] })) : null, _jsx("span", { className: cn("absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2", enter), children: center ? (_jsx(Avatar, { name: center.name, src: center.src, size: s.center })) : (_jsx("span", { className: cn("flex items-center justify-center rounded-full bg-[var(--primary-solid)] font-bold text-white", s.you), children: "You" })) })] })] }));
|
|
36
44
|
}
|
|
37
45
|
export { NetworkGraph };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
type PageHeaderBack = {
|
|
3
|
+
/** The words after the arrow. "Back" unless the place is worth naming: "Back to lists". */
|
|
4
|
+
label?: string;
|
|
5
|
+
/** Where it goes. Without `href` or `onClick`, it goes back in the browser's history. */
|
|
6
|
+
href?: string;
|
|
7
|
+
onClick?: () => void;
|
|
8
|
+
/** Your router's link, e.g. `render={<Link href="/lists" />}`. Without it, `href` is a plain `<a>`. */
|
|
9
|
+
render?: React.ReactElement;
|
|
10
|
+
};
|
|
11
|
+
type PageHeaderProps = {
|
|
12
|
+
/** The page's one `<h1>`: what this page is. "Climate founders", "Lanternfield Capital". */
|
|
13
|
+
title: React.ReactNode;
|
|
14
|
+
/** One line under the title: what the page is for, or a count ("128 members"). */
|
|
15
|
+
subtitle?: React.ReactNode;
|
|
16
|
+
/** "← Back" above the title, for a page reached from a list. `true` goes back in history. */
|
|
17
|
+
back?: true | PageHeaderBack;
|
|
18
|
+
/** Before the title: an Avatar `size="xl"` (a person, or an organization with its logo as `src`), or a Lucide icon, drawn in a 48px blue square. */
|
|
19
|
+
media?: React.ReactNode;
|
|
20
|
+
/** After the title: one Tag, such as "Private" or "Manager". */
|
|
21
|
+
tag?: React.ReactNode;
|
|
22
|
+
/** The page's main button: one primary Button (`md`). */
|
|
23
|
+
action?: React.ReactNode;
|
|
24
|
+
/** One other button, before the main one: a secondary Button (`md`). */
|
|
25
|
+
secondaryAction?: React.ReactNode;
|
|
26
|
+
/** ActionMenuItems for the less-used actions (Rename, Delete). They go in a ⋮ menu after the buttons. */
|
|
27
|
+
menu?: React.ReactNode;
|
|
28
|
+
/** Names the ⋮ menu. "More actions" unless the page has a better name: "Actions for Climate founders". */
|
|
29
|
+
menuLabel?: string;
|
|
30
|
+
/** Layout only: `mb-6`. */
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
declare function PageHeader({ title, subtitle, back, media, tag, action, secondaryAction, menu, menuLabel, className }: PageHeaderProps): React.JSX.Element;
|
|
34
|
+
export { PageHeader };
|
|
35
|
+
export type { PageHeaderBack, PageHeaderProps };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { isValidElement, cloneElement } from "react";
|
|
4
|
+
import { ArrowLeft } from "lucide-react";
|
|
5
|
+
import { ActionMenu } from "@brdgapp/ui/components/action-menu";
|
|
6
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
7
|
+
const BACK_CLASS = "mb-6 inline-flex w-fit items-center gap-1.5 rounded-sm text-13 leading-normal font-semibold text-[var(--text-muted)] outline-none transition-colors hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]/40";
|
|
8
|
+
function BackLink({ back }) {
|
|
9
|
+
const { label = "Back", href, onClick, render } = back === true ? {} : back;
|
|
10
|
+
const body = (_jsxs(_Fragment, { children: [_jsx(ArrowLeft, { "aria-hidden": "true", className: "size-3.5" }), label] }));
|
|
11
|
+
if (render && isValidElement(render)) {
|
|
12
|
+
return cloneElement(render, { className: BACK_CLASS, onClick, children: body });
|
|
13
|
+
}
|
|
14
|
+
if (href) {
|
|
15
|
+
return (_jsx("a", { href: href, onClick: onClick, className: BACK_CLASS, children: body }));
|
|
16
|
+
}
|
|
17
|
+
return (_jsx("button", { type: "button", onClick: onClick ?? (() => window.history.back()), className: BACK_CLASS, children: body }));
|
|
18
|
+
}
|
|
19
|
+
function PageHeader({ title, subtitle, back, media, tag, action, secondaryAction, menu, menuLabel = "More actions", className }) {
|
|
20
|
+
const buttons = action || secondaryAction || menu;
|
|
21
|
+
return (_jsxs("header", { "data-slot": "page-header", className: cn("flex flex-col", className), children: [back ? _jsx(BackLink, { back: back }) : null, _jsxs("div", { className: "flex flex-wrap items-start justify-between gap-x-6 gap-y-4", children: [_jsxs("div", { className: "flex min-w-0 flex-[1_1_16rem] items-center gap-3", children: [media ? (_jsx("span", { "data-slot": "page-header-media", className: "flex shrink-0 items-center justify-center has-[>svg]:size-12 has-[>svg]:rounded-xl has-[>svg]:bg-[var(--info-bg)] [&>svg]:size-6 [&>svg]:text-[var(--primary)]", children: media })) : null, _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx("h1", { className: "min-w-0 text-22 leading-tight font-bold tracking-tight break-words text-[var(--text-primary)]", children: title }), tag] }), subtitle ? _jsx("p", { className: "mt-1 text-14 leading-normal text-[var(--text-body)]", children: subtitle }) : null] })] }), buttons ? (_jsxs("div", { "data-slot": "page-header-actions", className: "flex shrink-0 flex-wrap items-center gap-2", children: [secondaryAction, action, menu ? _jsx(ActionMenu, { ariaLabel: menuLabel, children: menu }) : null] })) : null] })] }));
|
|
22
|
+
}
|
|
23
|
+
export { PageHeader };
|
package/components/select.d.ts
CHANGED
|
@@ -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,18 +53,23 @@ 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
|
|
50
|
-
|
|
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
|
|
57
|
-
|
|
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
|
-
declare function Select<T extends string>(props:
|
|
72
|
+
declare function Select<T extends string>(props: MultipleSelectProps<T>): React.JSX.Element;
|
|
73
|
+
declare function Select<T extends string>(props: SingleSelectProps<T>): React.JSX.Element;
|
|
61
74
|
export { Select };
|
|
62
75
|
export type { MultipleSelectProps, SelectOption, SelectProps, SelectSearch, SingleSelectProps };
|
package/components/select.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 })] }));
|
package/components/switch.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
type SwitchProps = {
|
|
3
|
-
|
|
4
|
-
|
|
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 };
|
package/components/switch.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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 };
|
package/components/tag-input.js
CHANGED
|
@@ -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}`))),
|
|
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