@brdgapp/ui 1.0.0 → 1.1.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 +58 -0
- package/components/action-menu.d.ts +9 -2
- package/components/action-menu.js +14 -5
- package/components/avatar.d.ts +1 -1
- package/components/avatar.js +7 -5
- package/components/badge.js +2 -1
- package/components/bottom-sheet.d.ts +21 -4
- package/components/bottom-sheet.js +90 -6
- package/components/button-group.d.ts +2 -2
- package/components/button-group.js +1 -1
- package/components/button.d.ts +2 -2
- package/components/button.js +8 -6
- package/components/card.d.ts +2 -2
- package/components/card.js +1 -1
- package/components/checkbox.js +2 -2
- package/components/collapsible.js +4 -3
- package/components/column-filter-menu.d.ts +2 -1
- package/components/column-filter-menu.js +3 -2
- package/components/column-sort-button.d.ts +8 -2
- package/components/column-sort-button.js +12 -2
- package/components/confirm-dialog.d.ts +11 -3
- package/components/confirm-dialog.js +41 -6
- package/components/copy-field.js +4 -2
- package/components/data-state.js +2 -2
- package/components/data-table.d.ts +54 -5
- package/components/data-table.js +79 -30
- package/components/dialog.d.ts +29 -5
- package/components/dialog.js +27 -3
- package/components/drawer.d.ts +16 -6
- package/components/drawer.js +26 -9
- package/components/expandable-bio.js +2 -1
- package/components/field.js +3 -3
- package/components/filter-chip.js +4 -1
- package/components/filter-pill.js +6 -6
- package/components/hover-card.js +4 -2
- package/components/icon-button.d.ts +2 -2
- package/components/icon-button.js +6 -1
- package/components/info-hint.d.ts +8 -1
- package/components/info-hint.js +22 -7
- package/components/input.js +1 -1
- package/components/network-graph.js +1 -1
- package/components/page-banner.js +11 -5
- package/components/scene.d.ts +3 -1
- package/components/scene.js +2 -2
- package/components/search-input.d.ts +2 -2
- package/components/search-input.js +24 -3
- package/components/segmented-control.js +5 -1
- package/components/skeleton.js +3 -1
- package/components/skip-link.js +3 -1
- package/components/stat-box.d.ts +23 -5
- package/components/stat-box.js +33 -16
- package/components/switch.js +5 -1
- package/components/tabs.js +10 -2
- package/components/tag-input.d.ts +3 -1
- package/components/tag-input.js +27 -8
- package/components/tag.js +4 -2
- package/components/textarea.js +2 -2
- package/components/toast.d.ts +9 -5
- package/components/toast.js +10 -5
- package/package.json +1 -1
- package/styles/globals.css +26 -3
|
@@ -4,11 +4,21 @@ import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
|
4
4
|
import { ArrowDown, ArrowUp, ArrowUpDown } from "lucide-react";
|
|
5
5
|
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
6
6
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
7
|
+
// A table column header that sorts: icon + label + an arrow (faint ⇅ when this column isn't the sort,
|
|
8
|
+
// a blue ↓ or ↑ when it is). Ported from Bridge OS src/components/ui/column-sort-button.tsx with the
|
|
9
|
+
// same API, then rebuilt on Base UI Button like Button. It only shows the state; the owner of the rows decides what a click does.
|
|
10
|
+
// 2026-11-05: `icon` is optional (the apps' sortable headers have none; Bridge OS's all do), and DataTable
|
|
11
|
+
// columns take `sort` so the header cell tells screen readers which column is sorted (aria-sort).
|
|
12
|
+
/**
|
|
13
|
+
* The one look for a button in a column header: sort and filter. Icon, name, then a small sign of what
|
|
14
|
+
* it does (⇅, ⌄); the whole thing tints on hover. 24px tall.
|
|
15
|
+
*/
|
|
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)]";
|
|
7
17
|
function ColumnSortButton({ icon: Icon, label, tooltip, direction, describe, onClick, ...rest }) {
|
|
8
18
|
const state = direction && describe ? `, sorted ${describe[direction]}` : "";
|
|
9
19
|
return (_jsx(Tip, { text: tooltip, children: _jsxs(ButtonPrimitive, { ...rest, "data-slot": "column-sort-button", onClick: (e) => {
|
|
10
20
|
e.stopPropagation();
|
|
11
21
|
onClick();
|
|
12
|
-
}, "aria-label": `Sort by ${label.toLowerCase()}${state}`, className: cn(
|
|
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" }))] }) }));
|
|
13
23
|
}
|
|
14
|
-
export { ColumnSortButton };
|
|
24
|
+
export { ColumnSortButton, columnHeaderButton };
|
|
@@ -9,12 +9,20 @@ type ConfirmDialogProps = {
|
|
|
9
9
|
/** The action, naming the object: "Stop sharing". Never "OK" or "Yes". */
|
|
10
10
|
confirmLabel: string;
|
|
11
11
|
confirmIcon?: React.ReactNode;
|
|
12
|
+
/** The other button. "Cancel" unless a clearer phrase fits: "Keep editing" on a discard. */
|
|
13
|
+
cancelLabel?: string;
|
|
14
|
+
/**
|
|
15
|
+
* For a permanent delete of something big (a firm, a workspace): the person types this exact text,
|
|
16
|
+
* usually its name, before the confirm button works.
|
|
17
|
+
*/
|
|
18
|
+
requireText?: string;
|
|
12
19
|
/** Red confirm button and a warning icon, for things that can't be undone. */
|
|
13
20
|
destructive?: boolean;
|
|
14
|
-
/** The action is running: the confirm button spins, and the dialog can't be dismissed. */
|
|
21
|
+
/** The action is running: the confirm button spins, and the dialog can't be dismissed. Not needed when `onConfirm` returns a promise. */
|
|
15
22
|
busy?: boolean;
|
|
16
|
-
|
|
23
|
+
/** Do the action. Return a promise and the dialog spins until it settles; throw to keep the dialog open. */
|
|
24
|
+
onConfirm: () => void | Promise<unknown>;
|
|
17
25
|
};
|
|
18
|
-
declare function ConfirmDialog({ open, onClose, title, body, confirmLabel, confirmIcon, destructive, busy, onConfirm }: ConfirmDialogProps): React.JSX.Element;
|
|
26
|
+
declare function ConfirmDialog({ open, onClose, title, body, confirmLabel, confirmIcon, cancelLabel, requireText, destructive, busy, onConfirm, }: ConfirmDialogProps): React.JSX.Element;
|
|
19
27
|
export { ConfirmDialog };
|
|
20
28
|
export type { ConfirmDialogProps };
|
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useRef, useState } from "react";
|
|
3
4
|
import { AlertDialog } from "@base-ui/react/alert-dialog";
|
|
4
5
|
import { TriangleAlert } from "lucide-react";
|
|
6
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
5
7
|
import { Button } from "@brdgapp/ui/components/button";
|
|
6
|
-
|
|
8
|
+
import { Input } from "@brdgapp/ui/components/input";
|
|
9
|
+
function ConfirmDialog({ open, onClose, title, body, confirmLabel, confirmIcon, cancelLabel = "Cancel", requireText, destructive = false, busy = false, onConfirm, }) {
|
|
10
|
+
const [pending, setPending] = useState(false);
|
|
11
|
+
const [typed, setTyped] = useState("");
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const inputId = useId();
|
|
14
|
+
const working = busy || pending;
|
|
15
|
+
const matches = !requireText || typed.trim() === requireText;
|
|
16
|
+
async function confirm() {
|
|
17
|
+
if (working || !matches)
|
|
18
|
+
return;
|
|
19
|
+
setPending(true);
|
|
20
|
+
try {
|
|
21
|
+
await onConfirm();
|
|
22
|
+
onClose();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// The action failed: stay open so the person can try again. The app says what went wrong (a toast).
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
setPending(false);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
7
31
|
return (_jsx(AlertDialog.Root, { open: open, onOpenChange: (next) => {
|
|
8
32
|
// Escape and Cancel close it — but never mid-request: hiding the dialog then would hide the
|
|
9
33
|
// outcome, and the person can't tell whether the thing happened.
|
|
10
|
-
if (!next && !
|
|
34
|
+
if (!next && !working)
|
|
11
35
|
onClose();
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
36
|
+
},
|
|
37
|
+
// Every opening starts with an empty box: clear it once the dialog has finished closing.
|
|
38
|
+
onOpenChangeComplete: (isOpen) => {
|
|
39
|
+
if (!isOpen)
|
|
40
|
+
setTyped("");
|
|
41
|
+
}, children: _jsxs(AlertDialog.Portal, { children: [_jsx(AlertDialog.Backdrop, { className: "fixed inset-0 z-[90] bg-black/40 backdrop-blur-sm transition-opacity duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" }), _jsxs(AlertDialog.Popup, { "data-slot": "confirm-dialog",
|
|
42
|
+
// With a box to type in, focus starts there; otherwise on Cancel, the safe choice.
|
|
43
|
+
initialFocus: requireText ? inputRef : true, className: cn("fixed z-[90] border border-[var(--border-default)] bg-[var(--surface-elevated)] p-6 shadow-[var(--shadow-dialog)] outline-none",
|
|
44
|
+
// Computer: a small box in the middle.
|
|
45
|
+
"md:top-1/2 md:left-1/2 md:w-[88vw] md:max-w-sm md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl", "md:transition-[opacity,scale] md:duration-300 md:ease-out md:data-[ending-style]:duration-200 md:data-[starting-style]:scale-95 md:data-[starting-style]:opacity-0 md:data-[ending-style]:opacity-0",
|
|
46
|
+
// Phone: slides up from the bottom, like iOS's action sheet, with the buttons under the thumb.
|
|
47
|
+
"max-md:inset-x-0 max-md:bottom-0 max-md:rounded-t-2xl max-md:border-x-0 max-md:border-b-0 max-md:pb-[max(24px,env(safe-area-inset-bottom))]", "max-md:transition-transform max-md:duration-300 max-md:ease-out max-md:data-[ending-style]:duration-200 max-md:data-[starting-style]:translate-y-full max-md:data-[ending-style]:translate-y-full motion-reduce:transition-none"), children: [destructive ? (_jsx("span", { "aria-hidden": "true", className: "mb-4 flex size-10 items-center justify-center rounded-full bg-[var(--error-bg)] text-[var(--danger-text)]", children: _jsx(TriangleAlert, { className: "size-5" }) })) : null, _jsx(AlertDialog.Title, { className: "text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), _jsx(AlertDialog.Description, { render: _jsx("div", {}), className: "mt-2 text-13 leading-relaxed text-[var(--text-body)]", children: body }), requireText ? (_jsxs("form", { className: "mt-4 flex flex-col gap-1.5", onSubmit: (e) => {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
void confirm();
|
|
50
|
+
}, children: [_jsxs("label", { htmlFor: inputId, className: "text-13 leading-relaxed text-[var(--text-secondary)]", children: ["Type ", _jsx("span", { className: "font-semibold text-[var(--text-primary)]", children: requireText }), " to confirm"] }), _jsx(Input, { ref: inputRef, id: inputId, value: typed, onChange: (e) => setTyped(e.target.value), disabled: working, autoComplete: "off", autoCapitalize: "off", spellCheck: false })] })) : null, _jsxs("div", { className: "mt-5 flex gap-2 max-md:mt-6 max-md:flex-col-reverse", children: [_jsx(AlertDialog.Close, { disabled: working, render: _jsx(Button, { variant: "secondary", size: "md", fullWidth: true, children: cancelLabel }) }), _jsx(Button, { variant: destructive ? "destructive" : "primary", size: "md", fullWidth: true, loading: working, disabled: !matches, icon: confirmIcon, onClick: () => void confirm(), children: confirmLabel })] })] })] }) }));
|
|
16
51
|
}
|
|
17
52
|
export { ConfirmDialog };
|
package/components/copy-field.js
CHANGED
|
@@ -25,11 +25,13 @@ function CopyField({ value, kind, variant = "row", strong = false, size = 12, sh
|
|
|
25
25
|
const label = `Copy ${kind === "email" ? "email" : "phone number"}`;
|
|
26
26
|
const announcement = (_jsx("span", { className: "sr-only", "aria-live": "polite", children: copied ? "Copied" : "" }));
|
|
27
27
|
if (variant === "inline") {
|
|
28
|
-
return (_jsxs(ButtonPrimitive, { ...rest, "data-slot": "copy-field", onClick: copy, "aria-label": `${label}: ${value}`, className: cn(
|
|
28
|
+
return (_jsxs(ButtonPrimitive, { ...rest, "data-slot": "copy-field", onClick: copy, "aria-label": `${label}: ${value}`, className: cn(
|
|
29
|
+
// An outline with a 2px gap, so the ring clears the text without moving it (as on HoverCard).
|
|
30
|
+
"inline-flex min-w-0 items-center gap-1.5 rounded-sm outline-none transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid focus-visible:outline-[var(--primary)]", size === 14 ? "text-14 leading-[1.625]" : "text-12 leading-[1.625]", strong
|
|
29
31
|
? "text-[var(--text-body)] hover:text-[var(--text-primary)]"
|
|
30
32
|
: "text-[var(--text-muted)] hover:text-[var(--text-secondary)]", className), children: [copied ? (_jsx(Check, { "aria-hidden": "true", className: "size-3.5 shrink-0 text-[var(--success)]" })) : showIcon ? (_jsx(Icon, { "aria-hidden": "true", className: "size-3.5 shrink-0" })) : null, _jsx("span", { className: "truncate", children: copied ? "Copied" : value }), announcement] }));
|
|
31
33
|
}
|
|
32
|
-
return (_jsxs(ButtonPrimitive, { ...rest, "data-slot": "copy-field", onClick: copy, "aria-label": `${label}: ${value}`, className: cn("group flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left outline-none transition-colors", "hover:bg-[var(--surface-secondary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]", className), children: [_jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-[var(--text-disabled)]" }), _jsx("span", { className: "min-w-0 flex-1 truncate text-[
|
|
34
|
+
return (_jsxs(ButtonPrimitive, { ...rest, "data-slot": "copy-field", onClick: copy, "aria-label": `${label}: ${value}`, className: cn("group flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left outline-none transition-colors", "hover:bg-[var(--surface-secondary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]", className), children: [_jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-[var(--text-disabled)]" }), _jsx("span", { className: "min-w-0 flex-1 truncate text-13 leading-[1.625] text-[var(--text-body)] group-hover:text-[var(--text-primary)]", children: value }), _jsxs("span", { "aria-hidden": "true", className: cn("inline-flex shrink-0 items-center gap-1 text-12 leading-[1.625] font-semibold transition-opacity", copied
|
|
33
35
|
? "text-[var(--success-text)] opacity-100"
|
|
34
36
|
: "text-[var(--text-muted)] [@media(hover:hover)]:opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"), children: [copied ? _jsx(Check, { className: "size-3.5" }) : _jsx(Copy, { className: "size-3.5" }), copied ? "Copied" : "Copy"] }), announcement] }));
|
|
35
37
|
}
|
package/components/data-state.js
CHANGED
|
@@ -17,9 +17,9 @@ function DataState({ status, data, skeleton, isEmpty = defaultIsEmpty, empty, er
|
|
|
17
17
|
return (_jsxs("div", { "data-slot": "data-state", "data-state": state, "aria-busy": state === "loading" || undefined, "aria-live": "polite", className: cn("min-w-0", className), children: [state === "loading" ? skeleton : null, state === "error" ? _jsx(DataStateError, { subject: errorSubject, onRetry: onRetry }) : null, state === "empty" ? _jsx(DataStateEmpty, { ...empty }) : null, state === "ready" ? children(data) : null] }));
|
|
18
18
|
}
|
|
19
19
|
function DataStateEmpty({ icon, illustration, illustrationSize = "md", title, description, action }) {
|
|
20
|
-
return (_jsxs("div", { "data-slot": "data-state-empty", className: "flex flex-col items-center gap-4 px-6 py-10 text-center", children: [illustration ? (_jsx(Illustration, { name: illustration, size: illustrationSize })) : icon ? (_jsx("span", { "aria-hidden": "true", className: "flex size-12 items-center justify-center rounded-full bg-[var(--surface-secondary)] text-[var(--text-disabled)] [&_svg]:size-6", children: icon })) : null, _jsxs("div", { children: [_jsx("p", { className: "text-16 font-bold tracking-tight text-[var(--text-primary)]", children: title }), description ? (_jsx("p", { className: "mx-auto mt-1 max-w-xs text-
|
|
20
|
+
return (_jsxs("div", { "data-slot": "data-state-empty", className: "flex flex-col items-center gap-4 px-6 py-10 text-center", children: [illustration ? (_jsx(Illustration, { name: illustration, size: illustrationSize })) : icon ? (_jsx("span", { "aria-hidden": "true", className: "flex size-12 items-center justify-center rounded-full bg-[var(--surface-secondary)] text-[var(--text-disabled)] [&_svg]:size-6", children: icon })) : null, _jsxs("div", { children: [_jsx("p", { className: "text-16 font-bold tracking-tight text-[var(--text-primary)]", children: title }), description ? (_jsx("p", { className: "mx-auto mt-1 max-w-xs text-13 leading-relaxed text-[var(--text-body)]", children: description })) : null] }), action] }));
|
|
21
21
|
}
|
|
22
22
|
function DataStateError({ subject, onRetry }) {
|
|
23
|
-
return (_jsxs("div", { "data-slot": "data-state-error", role: "alert", className: "flex flex-col items-center gap-3 px-6 py-10 text-center", children: [_jsx("span", { "aria-hidden": "true", className: "flex size-12 items-center justify-center rounded-full bg-[var(--error-bg)] text-[var(--danger-text)] [&_svg]:size-6", children: _jsx(AlertCircle, {}) }), _jsxs("p", { className: "text-16 font-bold tracking-tight text-[var(--text-primary)]", children: ["Couldn\u2019t load ", subject] }), onRetry ? (_jsx(Button, { variant: "link", size: "sm", onClick: onRetry, children: "Try again" })) : (_jsx("p", { className: "text-[
|
|
23
|
+
return (_jsxs("div", { "data-slot": "data-state-error", role: "alert", className: "flex flex-col items-center gap-3 px-6 py-10 text-center", children: [_jsx("span", { "aria-hidden": "true", className: "flex size-12 items-center justify-center rounded-full bg-[var(--error-bg)] text-[var(--danger-text)] [&_svg]:size-6", children: _jsx(AlertCircle, {}) }), _jsxs("p", { className: "text-16 font-bold tracking-tight text-[var(--text-primary)]", children: ["Couldn\u2019t load ", subject] }), onRetry ? (_jsx(Button, { variant: "link", size: "sm", onClick: onRetry, children: "Try again" })) : (_jsx("p", { className: "text-13 leading-[1.625] text-[var(--text-body)]", children: "Try again shortly." }))] }));
|
|
24
24
|
}
|
|
25
25
|
export { DataState };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
import { type LucideIcon } from "lucide-react";
|
|
3
3
|
import { type ElementProps } from "@brdgapp/ui/lib/utils";
|
|
4
4
|
type DataTableColumn<T> = {
|
|
@@ -13,9 +13,22 @@ type DataTableColumn<T> = {
|
|
|
13
13
|
tooltip?: string;
|
|
14
14
|
/** Replaces the default header, e.g. with ColumnSortButton or ColumnFilterMenu. */
|
|
15
15
|
headerContent?: React.ReactNode;
|
|
16
|
+
/** For a sortable column: its sort now, or null when another column is the sort. Tells screen readers (aria-sort). */
|
|
17
|
+
sort?: "asc" | "desc" | null;
|
|
16
18
|
render: (row: T) => React.ReactNode;
|
|
17
19
|
};
|
|
18
20
|
type ColumnMeta = Pick<DataTableColumn<unknown>, "key" | "label" | "icon" | "minWidth" | "weight" | "tooltip">;
|
|
21
|
+
type AddRow = {
|
|
22
|
+
/** The action, as a short phrase: "Add target". The first column's header shows it as a Tip; the last row shows it as words. */
|
|
23
|
+
action: string;
|
|
24
|
+
/** Opens the form or dialog that adds one. */
|
|
25
|
+
onClick: () => void;
|
|
26
|
+
};
|
|
27
|
+
type AddColumn = AddRow & {
|
|
28
|
+
/** What the column holds, like any column: "Connectors". */
|
|
29
|
+
label: string;
|
|
30
|
+
icon: LucideIcon;
|
|
31
|
+
};
|
|
19
32
|
/** The default column header: icon + label, with an optional explanation. */
|
|
20
33
|
declare function DataTableHeader({ icon: Icon, label, tooltip }: {
|
|
21
34
|
icon: LucideIcon;
|
|
@@ -34,20 +47,56 @@ type DataTableProps<T> = {
|
|
|
34
47
|
rowProps?: (row: T) => ElementProps<HTMLDivElement>;
|
|
35
48
|
/** Names the table for screen readers: "Introductions". */
|
|
36
49
|
"aria-label"?: string;
|
|
50
|
+
/**
|
|
51
|
+
* For a long list: the table scrolls inside a box this tall (px), with the header row pinned at the top.
|
|
52
|
+
* Leave it out and the page scrolls as usual.
|
|
53
|
+
*/
|
|
54
|
+
maxHeight?: number;
|
|
55
|
+
/**
|
|
56
|
+
* For a wide table: the first column (usually the name) stays in place while the others scroll sideways.
|
|
57
|
+
* Keep that column narrow, about 200px, so a phone still has room for the rest.
|
|
58
|
+
*/
|
|
59
|
+
pinFirstColumn?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* For adding one more: the first column's header gets a 24px outline + button after its name (`action` is
|
|
62
|
+
* the Tip), and a last row says the `action` in words. Both run `onClick`. The header one is there so a long
|
|
63
|
+
* list doesn't hide it. The first column shouldn't also have `headerContent`.
|
|
64
|
+
*/
|
|
65
|
+
addRow?: AddRow;
|
|
66
|
+
/**
|
|
67
|
+
* For a grid whose columns are things too, like Raise's connectors: a last column whose header adds one more.
|
|
68
|
+
* It reads like any column (`icon`, `label`) with a 24px outline + button after it; `action` ("Add connector") is its Tip.
|
|
69
|
+
*/
|
|
70
|
+
addColumn?: AddColumn;
|
|
37
71
|
};
|
|
38
|
-
declare function DataTable<T>({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps, ...props }: DataTableProps<T>): React.JSX.Element;
|
|
72
|
+
declare function DataTable<T>({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps, maxHeight, pinFirstColumn, addRow, addColumn, ...props }: DataTableProps<T>): React.JSX.Element;
|
|
73
|
+
/**
|
|
74
|
+
* The row at the top of a table's card for finding and acting on rows: search on the left; filters, then
|
|
75
|
+
* buttons, on the right. It is not a title: the page's heading names the table. Put it outside DataState,
|
|
76
|
+
* so it stays while the rows load, fail or filter down to nothing.
|
|
77
|
+
*/
|
|
78
|
+
declare function DataTableToolbar({ search, filters, actions, ...rest }: ElementProps<HTMLDivElement> & {
|
|
79
|
+
/** A SearchInput. It is 288px wide, the whole row on a phone. */
|
|
80
|
+
search?: React.ReactNode;
|
|
81
|
+
/** FilterPills, and a "Clear filters" link when more than one is on. */
|
|
82
|
+
filters?: React.ReactNode;
|
|
83
|
+
/** Buttons that act on the table: Export, Add people. Use Button `md`, the search's height. */
|
|
84
|
+
actions?: React.ReactNode;
|
|
85
|
+
}): React.JSX.Element;
|
|
39
86
|
/**
|
|
40
87
|
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
|
41
88
|
* column count can't drift from the real table. To make the swap to real data jump-free, pass the
|
|
42
89
|
* loaded row's `rowHeight` and, if the table has a pager, `pagination`.
|
|
43
90
|
*/
|
|
44
|
-
declare function DataTableSkeleton({ columns, rows, rowHeight, pagination, }: {
|
|
91
|
+
declare function DataTableSkeleton({ columns, rows, rowHeight, pagination, addColumn, }: {
|
|
45
92
|
columns: ColumnMeta[];
|
|
46
93
|
rows?: number;
|
|
47
94
|
/** A loaded row's height in px, not counting its 1px divider (a row with a 28px avatar is 56). */
|
|
48
95
|
rowHeight?: number;
|
|
49
96
|
/** Reserve the pager's 52px under the rows. */
|
|
50
97
|
pagination?: boolean;
|
|
98
|
+
/** The table has `addColumn`: keep its space, so the columns line up. */
|
|
99
|
+
addColumn?: boolean;
|
|
51
100
|
}): React.JSX.Element;
|
|
52
101
|
/**
|
|
53
102
|
* The pager under a DataTable: "1–15 of 34", previous, page numbers, next. Needs an EXACT total: with
|
|
@@ -61,5 +110,5 @@ declare function DataTablePagination({ page, pageSize, totalCount, loading, onPa
|
|
|
61
110
|
loading?: boolean;
|
|
62
111
|
onPageChange: (page: number) => void;
|
|
63
112
|
}): React.JSX.Element | null;
|
|
64
|
-
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination };
|
|
65
|
-
export type { DataTableColumn, DataTableProps };
|
|
113
|
+
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination, DataTableToolbar };
|
|
114
|
+
export type { DataTableColumn, DataTableProps, AddRow as DataTableAddRow, AddColumn as DataTableAddColumn };
|
package/components/data-table.js
CHANGED
|
@@ -2,15 +2,34 @@
|
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
5
|
-
import
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { ChevronLeft, ChevronRight, Loader2, Plus } from "lucide-react";
|
|
7
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
6
8
|
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
7
9
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
// The add column's width: room for its label, and a small share of any extra.
|
|
11
|
+
const ADD_COLUMN_WIDTH = 160;
|
|
12
|
+
function gridTemplate(columns, addColumn = false) {
|
|
13
|
+
const tracks = columns.map((c) => `minmax(${c.minWidth}px, ${c.weight ?? 1}fr)`);
|
|
14
|
+
if (addColumn)
|
|
15
|
+
tracks.push(`minmax(${ADD_COLUMN_WIDTH}px, 0.5fr)`);
|
|
16
|
+
return tracks.join(" ");
|
|
10
17
|
}
|
|
11
|
-
function minTableWidth(columns) {
|
|
12
|
-
return columns.reduce((sum, c) => sum + c.minWidth, 0);
|
|
18
|
+
function minTableWidth(columns, addColumn = false) {
|
|
19
|
+
return columns.reduce((sum, c) => sum + c.minWidth, 0) + (addColumn ? ADD_COLUMN_WIDTH : 0);
|
|
13
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A column header that adds one more: the column's usual header (icon and name), then a 24px outline IconButton
|
|
23
|
+
* with a +. The action ("Add target") is its Tip and its name for screen readers.
|
|
24
|
+
*/
|
|
25
|
+
function AddHeader({ icon, label, action, onClick }) {
|
|
26
|
+
return (_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx(DataTableHeader, { icon: icon, label: label }), _jsx(Tip, { text: action, children: _jsx(IconButton, { "data-slot": "data-table-add", "aria-label": action, variant: "outline", size: "xs", onClick: onClick, children: _jsx(Plus, {}) }) })] }));
|
|
27
|
+
}
|
|
28
|
+
// A card is frosted glass over --surface-elevated. A part that stays put while rows slide under it needs a
|
|
29
|
+
// solid fill that looks the same, or the rows would show through.
|
|
30
|
+
const HEADER_SOLID = "bg-[color-mix(in_srgb,var(--surface-secondary)_40%,var(--surface-elevated))]";
|
|
31
|
+
// The pinned first column. Its edge (a line and a soft shadow) shows only once columns have slid under it.
|
|
32
|
+
const PIN_FIRST = "sticky left-0 z-[1] after:pointer-events-none after:absolute after:inset-y-0 after:right-0 after:w-px after:content-[''] after:transition-[background-color,box-shadow] group-data-[scrolled]/table:after:bg-[var(--border-divider)] group-data-[scrolled]/table:after:shadow-[2px_0_8px_rgba(0,0,0,0.12)]";
|
|
14
33
|
function cellPadding(index, count) {
|
|
15
34
|
if (index === 0)
|
|
16
35
|
return "pl-6 pr-3";
|
|
@@ -20,39 +39,69 @@ function cellPadding(index, count) {
|
|
|
20
39
|
}
|
|
21
40
|
/** The default column header: icon + label, with an optional explanation. */
|
|
22
41
|
function DataTableHeader({ icon: Icon, label, tooltip }) {
|
|
23
|
-
return (_jsx(Tip, { text: tooltip, focusable: Boolean(tooltip), children: _jsxs("span", { "data-slot": "data-table-header", className: "inline-flex items-center gap-1.5 text-
|
|
42
|
+
return (_jsx(Tip, { text: tooltip, focusable: Boolean(tooltip), children: _jsxs("span", { "data-slot": "data-table-header", className: "inline-flex items-center gap-1.5 text-12 leading-normal font-bold whitespace-nowrap text-[var(--text-secondary)]", children: [_jsx(Icon, { "aria-hidden": "true", className: "size-3.5 text-[var(--text-muted)]" }), label] }) }));
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
const ARIA_SORT = { asc: "ascending", desc: "descending" };
|
|
45
|
+
function HeaderRow({ columns, template, pinned = false, pinFirst = false, addColumn, addRow, }) {
|
|
46
|
+
const count = columns.length + (addColumn ? 1 : 0);
|
|
47
|
+
return (_jsxs("div", { role: "row", className: cn("grid border-b border-[var(--border-divider)]", pinned ? cn("sticky top-0 z-10", HEADER_SOLID) : "bg-[var(--surface-secondary)]/40"), style: { gridTemplateColumns: template }, children: [columns.map((c, i) => (
|
|
48
|
+
// One height for every header (48px), with or without a sort or filter button.
|
|
49
|
+
_jsx("div", { role: "columnheader", "aria-sort": c.sort === undefined ? undefined : c.sort ? ARIA_SORT[c.sort] : "none", className: cn(cellPadding(i, count), "flex h-12 items-center", pinFirst && i === 0 && cn(PIN_FIRST, HEADER_SOLID)), children: i === 0 && addRow ? (_jsx(AddHeader, { icon: c.icon, label: c.label, action: addRow.action, onClick: addRow.onClick })) : ((c.headerContent ?? _jsx(DataTableHeader, { icon: c.icon, label: c.label, tooltip: c.tooltip }))) }, c.key))), addColumn ? (_jsx("div", { role: "columnheader", className: cn(cellPadding(count - 1, count), "flex h-12 items-center"), children: addColumn === true ? null : _jsx(AddHeader, { ...addColumn }) })) : null] }));
|
|
31
50
|
}
|
|
32
|
-
function DataTable({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps, ...props }) {
|
|
33
|
-
const template = gridTemplate(columns);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
function DataTable({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps, maxHeight, pinFirstColumn = false, addRow, addColumn, ...props }) {
|
|
52
|
+
const template = gridTemplate(columns, Boolean(addColumn));
|
|
53
|
+
const count = columns.length + (addColumn ? 1 : 0);
|
|
54
|
+
const pinned = maxHeight !== undefined;
|
|
55
|
+
// A table with its own scroll area: a tall one (maxHeight) or a wide one made to scroll sideways.
|
|
56
|
+
const scrollArea = pinned || pinFirstColumn;
|
|
57
|
+
const [scrolled, setScrolled] = React.useState(false);
|
|
58
|
+
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
|
+
// 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) => (_createElement("div", { ...rowProps?.(row), key: rowKey(row), role: "row", "data-slot": "data-table-row", tabIndex: onRowClick ? 0 : undefined, onClick: onRowClick
|
|
61
|
+
? (e) => {
|
|
62
|
+
// A menu opened from the row (ActionMenu) renders outside it, but React still passes
|
|
63
|
+
// its clicks up to the row. Only clicks inside the row open it.
|
|
64
|
+
if (e.currentTarget.contains(e.target))
|
|
65
|
+
onRowClick(row);
|
|
66
|
+
}
|
|
67
|
+
: undefined, onKeyDown: onRowClick
|
|
68
|
+
? (e) => {
|
|
69
|
+
// Only the row itself: a button inside the row handles its own keys.
|
|
70
|
+
if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
onRowClick(row);
|
|
73
|
+
}
|
|
40
74
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
75
|
+
: 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
|
+
? "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
|
+
columns.map((c, i) => (_jsx("div", { role: "cell", className: cn(cellPadding(i, count), "flex min-w-0 items-center py-3.5",
|
|
79
|
+
// The pinned cell is solid and repeats the row's hover and focus, which it would otherwise cover.
|
|
80
|
+
pinFirstColumn &&
|
|
81
|
+
i === 0 &&
|
|
82
|
+
cn(PIN_FIRST, "bg-[var(--surface-elevated)] transition-colors", onRowClick
|
|
83
|
+
? "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)]"
|
|
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] })] }) }));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The row at the top of a table's card for finding and acting on rows: search on the left; filters, then
|
|
89
|
+
* buttons, on the right. It is not a title: the page's heading names the table. Put it outside DataState,
|
|
90
|
+
* so it stays while the rows load, fail or filter down to nothing.
|
|
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 ? (_jsxs("div", { className: "flex flex-wrap items-center gap-3 md:ml-auto", children: [filters ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: filters }) : null, actions ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions }) : null] })) : null] }));
|
|
45
94
|
}
|
|
46
95
|
/**
|
|
47
96
|
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
|
48
97
|
* column count can't drift from the real table. To make the swap to real data jump-free, pass the
|
|
49
98
|
* loaded row's `rowHeight` and, if the table has a pager, `pagination`.
|
|
50
99
|
*/
|
|
51
|
-
function DataTableSkeleton({ columns, rows = 5, rowHeight, pagination = false, }) {
|
|
52
|
-
const template = gridTemplate(columns);
|
|
53
|
-
return (_jsxs("div", { "data-slot": "data-table-skeleton", "aria-hidden": "true", className: "overflow-x-auto", children: [_jsxs("div", { style: { minWidth: minTableWidth(columns) }, children: [_jsx(HeaderRow, { columns: columns, template: template }), Array.from({ length: rows }, (_, r) => (_jsx("div", { className: "grid border-b border-[var(--border-divider)] last:border-0", style: { gridTemplateColumns: template }, children: columns.map((c, i) => (
|
|
100
|
+
function DataTableSkeleton({ columns, rows = 5, rowHeight, pagination = false, addColumn = false, }) {
|
|
101
|
+
const template = gridTemplate(columns, addColumn);
|
|
102
|
+
return (_jsxs("div", { "data-slot": "data-table-skeleton", "aria-hidden": "true", className: "overflow-x-auto", children: [_jsxs("div", { style: { minWidth: minTableWidth(columns, addColumn) }, children: [_jsx(HeaderRow, { columns: columns, template: template, addColumn: addColumn || undefined }), Array.from({ length: rows }, (_, r) => (_jsx("div", { className: "grid border-b border-[var(--border-divider)] last:border-0", style: { gridTemplateColumns: template }, children: columns.map((c, i) => (
|
|
54
103
|
// The height goes on the cells, so the row's divider adds to it exactly as in the real table.
|
|
55
|
-
_jsx("div", { className: cn(cellPadding(i, columns.length), "flex min-w-0 items-center py-3.5"), style: { minHeight: rowHeight }, children: _jsx("div", { className: "h-3.5 w-full max-w-[160px] animate-pulse rounded bg-[var(--
|
|
104
|
+
_jsx("div", { className: cn(cellPadding(i, columns.length + (addColumn ? 1 : 0)), "flex min-w-0 items-center py-3.5"), style: { minHeight: rowHeight }, children: _jsx("div", { className: "h-3.5 w-full max-w-[160px] animate-pulse rounded bg-[var(--skeleton)] motion-reduce:animate-none" }) }, c.key))) }, r)))] }), pagination ? (_jsxs("div", { className: "flex h-[52px] items-center justify-between px-6", children: [_jsx("div", { className: "h-3 w-20 animate-pulse rounded bg-[var(--skeleton)] motion-reduce:animate-none" }), _jsx("div", { className: "h-7 w-32 animate-pulse rounded-lg bg-[var(--skeleton)] motion-reduce:animate-none" })] })) : null] }));
|
|
56
105
|
}
|
|
57
106
|
const pagerButton = "flex size-7 items-center justify-center rounded-lg text-[var(--text-muted)] outline-none transition-colors hover:bg-[var(--surface-secondary)] hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)] disabled:cursor-not-allowed disabled:opacity-50";
|
|
58
107
|
/** 1 … 4 5 6 … 12 — first and last always, the current page ±1, an ellipsis for gaps. */
|
|
@@ -79,6 +128,6 @@ function DataTablePagination({ page, pageSize, totalCount, loading = false, onPa
|
|
|
79
128
|
if (totalPages <= 1)
|
|
80
129
|
return null;
|
|
81
130
|
const n = (v) => v.toLocaleString("en-US");
|
|
82
|
-
return (_jsxs("nav", { "data-slot": "data-table-pagination", "aria-label": "Pages", className: "flex items-center justify-between gap-4 px-6 py-3", children: [_jsxs("p", { className: "shrink-0 text-
|
|
131
|
+
return (_jsxs("nav", { "data-slot": "data-table-pagination", "aria-label": "Pages", className: "flex items-center justify-between gap-4 px-6 py-3", children: [_jsxs("p", { className: "shrink-0 text-12 leading-normal tabular-nums text-[var(--text-muted)]", children: [n((page - 1) * pageSize + 1), "\u2013", n(Math.min(page * pageSize, totalCount)), " of ", n(totalCount)] }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(ButtonPrimitive, { onClick: () => onPageChange(page - 1), disabled: page === 1 || loading, "aria-label": "Previous page", className: pagerButton, children: _jsx(ChevronLeft, { "aria-hidden": "true", className: "size-3.5" }) }), pageList(page, totalPages).map((p, i) => p === "…" ? (_jsx("span", { "aria-hidden": "true", className: "flex size-7 items-center justify-center text-12 text-[var(--text-muted)]", children: "\u2026" }, `gap-${i}`)) : (_jsx(ButtonPrimitive, { onClick: () => onPageChange(p), disabled: loading, "aria-label": `Page ${p}`, "aria-current": p === page ? "page" : undefined, className: cn(pagerButton, "w-auto min-w-7 px-1.5 text-12 font-semibold tabular-nums disabled:opacity-100", p === page && "bg-[var(--primary-solid)] text-white hover:bg-[var(--primary-solid)] hover:text-white"), children: loading && p === page ? _jsx(Loader2, { "aria-hidden": "true", className: "mx-auto size-3 animate-spin" }) : p }, p))), _jsx(ButtonPrimitive, { onClick: () => onPageChange(page + 1), disabled: page === totalPages || loading, "aria-label": "Next page", className: pagerButton, children: _jsx(ChevronRight, { "aria-hidden": "true", className: "size-3.5" }) })] })] }));
|
|
83
132
|
}
|
|
84
|
-
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination };
|
|
133
|
+
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination, DataTableToolbar };
|
package/components/dialog.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare const WIDTHS: {
|
|
3
|
+
readonly default: "md:max-w-lg";
|
|
4
|
+
readonly wide: "md:max-w-2xl";
|
|
5
|
+
};
|
|
6
|
+
type DialogAction = {
|
|
7
|
+
/** Names the action: "Add network", "Save", "Remove". Never "OK". */
|
|
8
|
+
label: string;
|
|
9
|
+
onClick: () => void;
|
|
10
|
+
/** A leading icon (a bare Lucide icon). */
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
2
14
|
type DialogProps = {
|
|
3
15
|
open: boolean;
|
|
16
|
+
/** Called on ✕, Cancel, Esc or the backdrop (never while `busy`). */
|
|
4
17
|
onClose: () => void;
|
|
5
18
|
/** What the dialog does: "Add a network", "Edit Saltmarsh Partners". */
|
|
6
19
|
title: string;
|
|
@@ -8,12 +21,23 @@ type DialogProps = {
|
|
|
8
21
|
description?: React.ReactNode;
|
|
9
22
|
/** The form. */
|
|
10
23
|
children: React.ReactNode;
|
|
11
|
-
/** The
|
|
24
|
+
/** The main button, bottom right. Spins while `busy`. */
|
|
25
|
+
primaryAction?: DialogAction;
|
|
26
|
+
/** The button that closes without saving, beside the main one. Default "Cancel". */
|
|
27
|
+
cancelLabel?: string;
|
|
28
|
+
/** A red action, like Remove, alone at the bottom left. Ask with a ConfirmDialog before doing it. */
|
|
29
|
+
dangerAction?: DialogAction;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Buttons you lay out yourself. Use `primaryAction`, `cancelLabel` and `dangerAction`, which keep
|
|
32
|
+
* every dialog's buttons in the same order. Removed in 2.0.
|
|
33
|
+
*/
|
|
12
34
|
footer?: React.ReactNode;
|
|
13
|
-
/** A save is running: the dialog can't be dismissed until it finishes. */
|
|
35
|
+
/** A save is running: the primary action spins and the dialog can't be dismissed until it finishes. */
|
|
14
36
|
busy?: boolean;
|
|
37
|
+
/** `default` is 512px, for a short form. `wide` is 672px, for tabs, a table or two columns of fields. Phones fill the screen either way. */
|
|
38
|
+
size?: keyof typeof WIDTHS;
|
|
15
39
|
className?: string;
|
|
16
40
|
};
|
|
17
|
-
declare function Dialog({ open, onClose, title, description, children, footer, busy, className }: DialogProps): React.JSX.Element;
|
|
41
|
+
declare function Dialog({ open, onClose, title, description, children, primaryAction, cancelLabel, dangerAction, footer, busy, size, className, }: DialogProps): React.JSX.Element;
|
|
18
42
|
export { Dialog };
|
|
19
|
-
export type { DialogProps };
|
|
43
|
+
export type { DialogAction, DialogProps };
|
package/components/dialog.js
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
3
4
|
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
4
5
|
import { X } from "lucide-react";
|
|
6
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
5
7
|
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
6
8
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
// The dialog for creating and editing small records (approved 2026-11-02, "Creating records"). Shape
|
|
10
|
+
// taken from Bridge OS's network-entry-modal: centred, a title + close, a body, and the actions. Built on
|
|
11
|
+
// Base UI Dialog: focus is trapped and returns to the opener. While `busy`, nothing can dismiss it. For
|
|
12
|
+
// "are you sure?" use ConfirmDialog instead. z-[90]: Bridge's layer for confirm and form dialogs.
|
|
13
|
+
//
|
|
14
|
+
// Decisions (Aman, 2026-11-06): two widths, 512px and `wide` 672px (the apps' dialogs are 448px 45 times,
|
|
15
|
+
// 512px 20, 672px 16, mostly with tabs or a table inside). On a phone it fills the screen, as Material's
|
|
16
|
+
// full-screen dialog does, with the same layout as a computer and as Drawer on a phone: the title and ✕ at the
|
|
17
|
+
// top, the form scrolling, and the buttons in a footer pinned at the bottom. Every full-screen panel works
|
|
18
|
+
// the same way. The buttons come from `primaryAction`, `dangerAction` and `cancelLabel`.
|
|
19
|
+
//
|
|
20
|
+
// Opening puts focus in the first field, so people can type at once (Base UI's default was the Close button).
|
|
21
|
+
// Not on touch: the keyboard would cover the dialog before it's been read.
|
|
22
|
+
const WIDTHS = { default: "md:max-w-lg", wide: "md:max-w-2xl" };
|
|
23
|
+
const FIRST_FIELD = "input:not([disabled]):not([type=hidden]), textarea:not([disabled]), select:not([disabled]), [contenteditable=true]";
|
|
24
|
+
function Dialog({ open, onClose, title, description, children, primaryAction, cancelLabel = "Cancel", dangerAction, footer, busy = false, size = "default", className, }) {
|
|
25
|
+
const body = React.useRef(null);
|
|
26
|
+
return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => !next && !busy && onClose(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[90] bg-black/40 backdrop-blur-sm 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": "dialog", initialFocus: (openType) => (openType === "touch" ? true : (body.current?.querySelector(FIRST_FIELD) ?? true)), className: cn("fixed z-[90] flex flex-col bg-[var(--surface-elevated)] outline-none",
|
|
27
|
+
// Phone: the whole screen, sliding up from the bottom.
|
|
28
|
+
"max-md:inset-0 max-md:transition-transform max-md:duration-300 max-md:ease-out max-md:data-[ending-style]:duration-200 max-md:data-[starting-style]:translate-y-full max-md:data-[ending-style]:translate-y-full motion-reduce:transition-none",
|
|
29
|
+
// Computer: a box in the middle.
|
|
30
|
+
"md:top-1/2 md:left-1/2 md:max-h-[calc(100dvh-32px)] md:w-[calc(100vw-32px)] md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl md:border md:border-[var(--border-default)] md:shadow-[var(--shadow-dialog)]", "md:transition-[opacity,scale] md:duration-300 md:ease-out md:data-[ending-style]:duration-200 md:data-[starting-style]:scale-95 md:data-[starting-style]:opacity-0 md:data-[ending-style]:opacity-0", WIDTHS[size], className), children: [_jsxs("header", { "data-slot": "dialog-header", className: "flex shrink-0 items-start gap-3 px-6 pt-6 pb-4 max-md:border-b max-md:border-[var(--border-divider)] 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: "text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), description ? (_jsx(DialogPrimitive.Description, { className: "mt-1 text-13 leading-normal text-[var(--text-body)]", children: description })) : null] }), _jsx(DialogPrimitive.Close, { disabled: busy, render: _jsx(IconButton, { "aria-label": "Close", size: "sm", className: "-mt-1 -mr-2", children: _jsx(X, {}) }) })] }), _jsx("div", { ref: body, "data-slot": "dialog-body", className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 pb-2 max-md:px-5 max-md:pt-5", children: children }), primaryAction || dangerAction || footer ? (_jsxs("footer", { "data-slot": "dialog-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 px-6 pt-4 pb-6 max-md:border-t max-md:border-[var(--border-divider)] max-md:px-5 max-md:pb-[max(16px,env(safe-area-inset-bottom))]", children: [dangerAction ? (_jsx(Button, { variant: "danger-ghost", size: "md", icon: dangerAction.icon, disabled: busy || dangerAction.disabled, onClick: dangerAction.onClick,
|
|
31
|
+
// Phone: its own row above Cancel and the main button, so the three never squeeze into one.
|
|
32
|
+
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, footer] })) : null] })] }) }));
|
|
9
33
|
}
|
|
10
34
|
export { Dialog };
|
package/components/drawer.d.ts
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DialogAction } from "@brdgapp/ui/components/dialog";
|
|
2
3
|
declare const WIDTH: {
|
|
3
|
-
readonly item: "max-w-xl";
|
|
4
|
-
readonly list: "max-w-2xl";
|
|
4
|
+
readonly item: "md:max-w-xl";
|
|
5
|
+
readonly list: "md:max-w-2xl";
|
|
5
6
|
};
|
|
6
7
|
type DrawerProps = {
|
|
7
8
|
open: boolean;
|
|
9
|
+
/** Called on ✕, Cancel, Esc or the scrim (never while `busy`). */
|
|
8
10
|
onClose: () => void;
|
|
9
11
|
title: React.ReactNode;
|
|
10
12
|
/** One line under the title: who, when. */
|
|
11
13
|
subtitle?: React.ReactNode;
|
|
12
|
-
/** `item` 576px for one record; `list` 672px for a list. */
|
|
14
|
+
/** `item` 576px for one record; `list` 672px for a list. A phone fills the screen either way. */
|
|
13
15
|
size?: keyof typeof WIDTH;
|
|
14
|
-
/** Actions beside the close button, such as an ActionMenu. */
|
|
16
|
+
/** Actions beside the close button, such as an ActionMenu. Not Save: that goes in `primaryAction`. */
|
|
15
17
|
actions?: React.ReactNode;
|
|
18
|
+
/** For a drawer that edits: the footer's one filled button, bottom right. Spins while `busy`. */
|
|
19
|
+
primaryAction?: DialogAction;
|
|
20
|
+
/** The footer button that closes without saving. Default "Cancel". Shown with `primaryAction`. */
|
|
21
|
+
cancelLabel?: string;
|
|
22
|
+
/** A red action, like Remove, alone at the bottom left. Ask with a ConfirmDialog before doing it. */
|
|
23
|
+
dangerAction?: DialogAction;
|
|
24
|
+
/** A save is running: the primary action spins and the drawer can't be dismissed until it finishes. */
|
|
25
|
+
busy?: boolean;
|
|
16
26
|
children: React.ReactNode;
|
|
17
27
|
className?: string;
|
|
18
28
|
};
|
|
19
|
-
declare function Drawer({ open, onClose, title, subtitle, size, actions, children, className }: DrawerProps): React.JSX.Element;
|
|
29
|
+
declare function Drawer({ open, onClose, title, subtitle, size, actions, primaryAction, cancelLabel, dangerAction, busy, children, className, }: DrawerProps): React.JSX.Element;
|
|
20
30
|
export { Drawer };
|
|
21
31
|
export type { DrawerProps };
|