@brdgapp/ui 0.1.2 → 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 +141 -0
- package/README.md +37 -201
- package/components/action-menu.d.ts +72 -0
- package/components/action-menu.js +57 -0
- package/components/avatar.d.ts +50 -0
- package/components/avatar.js +93 -0
- package/components/badge.d.ts +12 -0
- package/components/badge.js +24 -0
- package/components/bottom-sheet.d.ts +34 -0
- package/components/bottom-sheet.js +96 -0
- package/components/brand-mark.d.ts +20 -0
- package/components/brand-mark.js +44 -0
- package/components/button-group.d.ts +25 -0
- package/components/button-group.js +53 -0
- package/components/button.d.ts +33 -0
- package/components/button.js +84 -0
- package/components/card.d.ts +78 -0
- package/components/card.js +75 -0
- package/components/checkbox.d.ts +22 -0
- package/components/checkbox.js +35 -0
- package/components/collapsible.d.ts +29 -0
- package/components/collapsible.js +39 -0
- package/components/column-filter-menu.d.ts +16 -0
- package/components/column-filter-menu.js +31 -0
- package/components/column-sort-button.d.ts +24 -0
- package/components/column-sort-button.js +24 -0
- package/components/confirm-dialog.d.ts +28 -0
- package/components/confirm-dialog.js +52 -0
- package/components/copy-field.d.ts +17 -0
- package/components/copy-field.js +38 -0
- package/components/data-state.d.ts +44 -0
- package/components/data-state.js +25 -0
- package/components/data-table.d.ts +114 -0
- package/components/data-table.js +133 -0
- package/components/dialog.d.ts +43 -0
- package/components/dialog.js +34 -0
- package/components/drawer.d.ts +31 -0
- package/components/drawer.js +34 -0
- package/components/expandable-bio.d.ts +8 -0
- package/components/expandable-bio.js +27 -0
- package/components/field.d.ts +29 -0
- package/components/field.js +27 -0
- package/components/filter-chip.d.ts +11 -0
- package/components/filter-chip.js +11 -0
- package/components/filter-pill.d.ts +34 -0
- package/components/filter-pill.js +35 -0
- package/components/hover-card.d.ts +21 -0
- package/components/hover-card.js +22 -0
- package/components/icon-button.d.ts +16 -0
- package/components/icon-button.js +37 -0
- package/components/illustration.d.ts +33 -0
- package/components/illustration.js +70 -0
- package/components/info-hint.d.ts +36 -0
- package/components/info-hint.js +57 -0
- package/components/input.d.ts +9 -0
- package/components/input.js +15 -0
- package/components/network-graph.d.ts +48 -0
- package/components/network-graph.js +37 -0
- package/components/page-banner.d.ts +20 -0
- package/components/page-banner.js +35 -0
- package/components/scene.d.ts +14 -0
- package/components/scene.js +7 -0
- package/components/search-input.d.ts +8 -0
- package/components/search-input.js +35 -0
- package/components/segmented-control.d.ts +18 -0
- package/components/segmented-control.js +18 -0
- package/components/skeleton.d.ts +12 -0
- package/components/skeleton.js +23 -0
- package/components/skip-link.d.ts +8 -0
- package/components/skip-link.js +9 -0
- package/components/stat-box.d.ts +41 -0
- package/components/stat-box.js +46 -0
- package/components/switch.d.ts +13 -0
- package/components/switch.js +12 -0
- package/components/tabs.d.ts +6 -0
- package/components/tabs.js +33 -0
- package/components/tag-input.d.ts +17 -0
- package/components/tag-input.js +59 -0
- package/components/tag.d.ts +27 -0
- package/components/tag.js +37 -0
- package/components/textarea.d.ts +12 -0
- package/components/textarea.js +78 -0
- package/components/theme-switch.d.ts +6 -0
- package/components/theme-switch.js +16 -0
- package/components/toast.d.ts +29 -0
- package/components/toast.js +49 -0
- package/hooks/use-is-mobile.d.ts +2 -0
- package/hooks/use-is-mobile.js +16 -0
- package/hooks/use-mock-query.d.ts +23 -0
- package/hooks/use-mock-query.js +36 -0
- package/hooks/use-theme.d.ts +11 -0
- package/hooks/use-theme.js +34 -0
- package/lib/demo-controls.d.ts +24 -0
- package/lib/demo-controls.js +24 -0
- package/lib/format.d.ts +17 -0
- package/lib/format.js +55 -0
- package/lib/layout.d.ts +19 -0
- package/lib/layout.js +24 -0
- package/lib/motion.d.ts +16 -0
- package/lib/motion.js +18 -0
- package/lib/theme.d.ts +21 -0
- package/lib/theme.js +63 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +27 -0
- package/package.json +32 -16
- package/styles/globals.css +618 -0
- package/src/index.ts +0 -18
- package/src/network-people-helper/README.md +0 -130
- package/src/network-people-helper/api.ts +0 -174
- package/src/network-people-helper/contact-avatar.tsx +0 -63
- package/src/network-people-helper/domain.ts +0 -14
- package/src/network-people-helper/icons.tsx +0 -130
- package/src/network-people-helper/index.ts +0 -6
- package/src/network-people-helper/network-people-helper.tsx +0 -397
- package/src/network-people-helper/network-people-nudge.tsx +0 -98
- package/src/network-people-helper/open-helper.ts +0 -22
- package/src/network-people-helper/person-menu.tsx +0 -211
- package/src/network-people-helper/styles.css +0 -848
- package/src/network-people-helper/types.ts +0 -23
- package/src/network-people-helper/use-network-people-list.ts +0 -122
- package/src/network-people-helper/use-network-preview.ts +0 -43
- package/src/provider.tsx +0 -59
- package/src/styles.css +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type LucideIcon } from "lucide-react";
|
|
3
|
+
import { type ElementProps } from "@brdgapp/ui/lib/utils";
|
|
4
|
+
type DataTableColumn<T> = {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon: LucideIcon;
|
|
8
|
+
/** Comfortable width in px. The column never gets narrower; below the total, the table scrolls. */
|
|
9
|
+
minWidth: number;
|
|
10
|
+
/** Share of any extra width on wide screens. Default 1; a small badge column might use 0.3. */
|
|
11
|
+
weight?: number;
|
|
12
|
+
/** Explains the column in a tooltip on its header. */
|
|
13
|
+
tooltip?: string;
|
|
14
|
+
/** Replaces the default header, e.g. with ColumnSortButton or ColumnFilterMenu. */
|
|
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;
|
|
18
|
+
render: (row: T) => React.ReactNode;
|
|
19
|
+
};
|
|
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
|
+
};
|
|
32
|
+
/** The default column header: icon + label, with an optional explanation. */
|
|
33
|
+
declare function DataTableHeader({ icon: Icon, label, tooltip }: {
|
|
34
|
+
icon: LucideIcon;
|
|
35
|
+
label: string;
|
|
36
|
+
tooltip?: string;
|
|
37
|
+
}): React.JSX.Element;
|
|
38
|
+
type DataTableProps<T> = {
|
|
39
|
+
columns: DataTableColumn<T>[];
|
|
40
|
+
rows: T[];
|
|
41
|
+
rowKey: (row: T) => string;
|
|
42
|
+
/** Makes rows clickable (and reachable with Tab, opened with Enter). */
|
|
43
|
+
onRowClick?: (row: T) => void;
|
|
44
|
+
/** Called on hover or focus, to warm data a click will need. Keep it cheap and repeatable. */
|
|
45
|
+
onRowPrefetch?: (row: T) => void;
|
|
46
|
+
/** Extra attributes for each row (`data-*`, `aria-*`, `id`). The table's own row props win. */
|
|
47
|
+
rowProps?: (row: T) => ElementProps<HTMLDivElement>;
|
|
48
|
+
/** Names the table for screen readers: "Introductions". */
|
|
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;
|
|
71
|
+
};
|
|
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;
|
|
86
|
+
/**
|
|
87
|
+
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
|
88
|
+
* column count can't drift from the real table. To make the swap to real data jump-free, pass the
|
|
89
|
+
* loaded row's `rowHeight` and, if the table has a pager, `pagination`.
|
|
90
|
+
*/
|
|
91
|
+
declare function DataTableSkeleton({ columns, rows, rowHeight, pagination, addColumn, }: {
|
|
92
|
+
columns: ColumnMeta[];
|
|
93
|
+
rows?: number;
|
|
94
|
+
/** A loaded row's height in px, not counting its 1px divider (a row with a 28px avatar is 56). */
|
|
95
|
+
rowHeight?: number;
|
|
96
|
+
/** Reserve the pager's 52px under the rows. */
|
|
97
|
+
pagination?: boolean;
|
|
98
|
+
/** The table has `addColumn`: keep its space, so the columns line up. */
|
|
99
|
+
addColumn?: boolean;
|
|
100
|
+
}): React.JSX.Element;
|
|
101
|
+
/**
|
|
102
|
+
* The pager under a DataTable: "1–15 of 34", previous, page numbers, next. Needs an EXACT total: with
|
|
103
|
+
* an estimated count or varying page sizes, the page numbers would lie — use "load more" there.
|
|
104
|
+
* Renders nothing when there is only one page.
|
|
105
|
+
*/
|
|
106
|
+
declare function DataTablePagination({ page, pageSize, totalCount, loading, onPageChange, }: {
|
|
107
|
+
page: number;
|
|
108
|
+
pageSize: number;
|
|
109
|
+
totalCount: number;
|
|
110
|
+
loading?: boolean;
|
|
111
|
+
onPageChange: (page: number) => void;
|
|
112
|
+
}): React.JSX.Element | null;
|
|
113
|
+
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination, DataTableToolbar };
|
|
114
|
+
export type { DataTableColumn, DataTableProps, AddRow as DataTableAddRow, AddColumn as DataTableAddColumn };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { ChevronLeft, ChevronRight, Loader2, Plus } from "lucide-react";
|
|
7
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
8
|
+
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
9
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
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(" ");
|
|
17
|
+
}
|
|
18
|
+
function minTableWidth(columns, addColumn = false) {
|
|
19
|
+
return columns.reduce((sum, c) => sum + c.minWidth, 0) + (addColumn ? ADD_COLUMN_WIDTH : 0);
|
|
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)]";
|
|
33
|
+
function cellPadding(index, count) {
|
|
34
|
+
if (index === 0)
|
|
35
|
+
return "pl-6 pr-3";
|
|
36
|
+
if (index === count - 1)
|
|
37
|
+
return "pl-3 pr-6";
|
|
38
|
+
return "px-3";
|
|
39
|
+
}
|
|
40
|
+
/** The default column header: icon + label, with an optional explanation. */
|
|
41
|
+
function DataTableHeader({ icon: Icon, label, tooltip }) {
|
|
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] }) }));
|
|
43
|
+
}
|
|
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] }));
|
|
50
|
+
}
|
|
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
|
+
}
|
|
74
|
+
}
|
|
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] }));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
|
97
|
+
* column count can't drift from the real table. To make the swap to real data jump-free, pass the
|
|
98
|
+
* loaded row's `rowHeight` and, if the table has a pager, `pagination`.
|
|
99
|
+
*/
|
|
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) => (
|
|
103
|
+
// The height goes on the cells, so the row's divider adds to it exactly as in the real table.
|
|
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] }));
|
|
105
|
+
}
|
|
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";
|
|
107
|
+
/** 1 … 4 5 6 … 12 — first and last always, the current page ±1, an ellipsis for gaps. */
|
|
108
|
+
function pageList(page, totalPages) {
|
|
109
|
+
if (totalPages <= 7)
|
|
110
|
+
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
111
|
+
const pages = [1];
|
|
112
|
+
if (page > 3)
|
|
113
|
+
pages.push("…");
|
|
114
|
+
for (let i = Math.max(2, page - 1); i <= Math.min(totalPages - 1, page + 1); i++)
|
|
115
|
+
pages.push(i);
|
|
116
|
+
if (page < totalPages - 2)
|
|
117
|
+
pages.push("…");
|
|
118
|
+
pages.push(totalPages);
|
|
119
|
+
return pages;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The pager under a DataTable: "1–15 of 34", previous, page numbers, next. Needs an EXACT total: with
|
|
123
|
+
* an estimated count or varying page sizes, the page numbers would lie — use "load more" there.
|
|
124
|
+
* Renders nothing when there is only one page.
|
|
125
|
+
*/
|
|
126
|
+
function DataTablePagination({ page, pageSize, totalCount, loading = false, onPageChange, }) {
|
|
127
|
+
const totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
|
|
128
|
+
if (totalPages <= 1)
|
|
129
|
+
return null;
|
|
130
|
+
const n = (v) => v.toLocaleString("en-US");
|
|
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" }) })] })] }));
|
|
132
|
+
}
|
|
133
|
+
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination, DataTableToolbar };
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
};
|
|
14
|
+
type DialogProps = {
|
|
15
|
+
open: boolean;
|
|
16
|
+
/** Called on ✕, Cancel, Esc or the backdrop (never while `busy`). */
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
/** What the dialog does: "Add a network", "Edit Saltmarsh Partners". */
|
|
19
|
+
title: string;
|
|
20
|
+
/** One optional line under the title. */
|
|
21
|
+
description?: React.ReactNode;
|
|
22
|
+
/** The form. */
|
|
23
|
+
children: React.ReactNode;
|
|
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
|
+
*/
|
|
34
|
+
footer?: React.ReactNode;
|
|
35
|
+
/** A save is running: the primary action spins and the dialog can't be dismissed until it finishes. */
|
|
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;
|
|
39
|
+
className?: string;
|
|
40
|
+
};
|
|
41
|
+
declare function Dialog({ open, onClose, title, description, children, primaryAction, cancelLabel, dangerAction, footer, busy, size, className, }: DialogProps): React.JSX.Element;
|
|
42
|
+
export { Dialog };
|
|
43
|
+
export type { DialogAction, DialogProps };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
5
|
+
import { X } from "lucide-react";
|
|
6
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
7
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
8
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
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] })] }) }));
|
|
33
|
+
}
|
|
34
|
+
export { Dialog };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DialogAction } from "@brdgapp/ui/components/dialog";
|
|
3
|
+
declare const WIDTH: {
|
|
4
|
+
readonly item: "md:max-w-xl";
|
|
5
|
+
readonly list: "md:max-w-2xl";
|
|
6
|
+
};
|
|
7
|
+
type DrawerProps = {
|
|
8
|
+
open: boolean;
|
|
9
|
+
/** Called on ✕, Cancel, Esc or the scrim (never while `busy`). */
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
title: React.ReactNode;
|
|
12
|
+
/** One line under the title: who, when. */
|
|
13
|
+
subtitle?: React.ReactNode;
|
|
14
|
+
/** `item` 576px for one record; `list` 672px for a list. A phone fills the screen either way. */
|
|
15
|
+
size?: keyof typeof WIDTH;
|
|
16
|
+
/** Actions beside the close button, such as an ActionMenu. Not Save: that goes in `primaryAction`. */
|
|
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;
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
declare function Drawer({ open, onClose, title, subtitle, size, actions, primaryAction, cancelLabel, dangerAction, busy, children, className, }: DrawerProps): React.JSX.Element;
|
|
30
|
+
export { Drawer };
|
|
31
|
+
export type { DrawerProps };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
5
|
+
import { X } from "lucide-react";
|
|
6
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
7
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
8
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
|
+
// The right-hand panel for one item's details, a short list, or a longer edit (approved 2026-11-02, "Panes,
|
|
10
|
+
// rails and sheets"). Shape from Bridge OS's intro / relationship / week drawers: slides in from the right,
|
|
11
|
+
// below the 56px top bar, over a dimmed page; Escape, the scrim or ✕ closes it. Two widths: `item` (576px,
|
|
12
|
+
// one intro) and `list` (672px, a relationship or a week of contacts). Built on Base UI Dialog: focus is
|
|
13
|
+
// trapped and returns to the opener; a drawer opened from a drawer closes first on Escape. z-[60], Bridge's
|
|
14
|
+
// layer for search and drawers, so menus (80) and confirms (90) opened from it sit above.
|
|
15
|
+
//
|
|
16
|
+
// Decisions (Aman, 2026-11-06), after Canon's Sheet and shadcn's Sheet: a side panel is for a computer's big
|
|
17
|
+
// screen. On a phone (below 768px) the drawer fills the whole screen, over the top bar too, keeping the same
|
|
18
|
+
// header, body and footer, as Canon keeps a panel's title and actions when it becomes a sheet on a phone. It
|
|
19
|
+
// still slides in from the right, and it is not a dialog: Save stays in the footer. An edit drawer has a footer pinned at the bottom
|
|
20
|
+
// (`primaryAction`, `cancelLabel`, `dangerAction`, the same options as Dialog); Save is never in the header,
|
|
21
|
+
// next to ✕. The header and footer stay put and only the body scrolls. Reduced motion: it fades, no slide.
|
|
22
|
+
const WIDTH = { item: "md:max-w-xl", list: "md:max-w-2xl" };
|
|
23
|
+
const FIRST_FIELD = "input:not([disabled]):not([type=hidden]), textarea:not([disabled]), select:not([disabled]), [contenteditable=true]";
|
|
24
|
+
function Drawer({ open, onClose, title, subtitle, size = "item", actions, primaryAction, cancelLabel = "Cancel", dangerAction, busy = false, children, 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-x-0 top-0 bottom-0 z-[60] md:top-14 bg-black/30 transition-opacity duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "drawer", "data-size": size,
|
|
27
|
+
// An edit drawer starts in its first field; a details drawer starts on its first control.
|
|
28
|
+
initialFocus: (openType) => (openType === "touch" ? true : (body.current?.querySelector(FIRST_FIELD) ?? true)), className: cn(
|
|
29
|
+
// Phone: the whole screen. Computer: below the top bar, from the right edge.
|
|
30
|
+
"fixed inset-0 z-[60] flex w-full flex-col bg-[var(--surface-elevated)] outline-none md:top-14 md:left-auto md:border-l md:border-[var(--border-default)] md:shadow-[var(--shadow-drawer)]", "transition-[translate,opacity] duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:translate-x-full data-[ending-style]:translate-x-full", "motion-reduce:transition-opacity motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0 motion-reduce:data-[starting-style]:opacity-0 motion-reduce:data-[ending-style]:opacity-0", WIDTH[size], className), children: [_jsxs("header", { "data-slot": "drawer-header", className: "flex shrink-0 items-start gap-2 border-b border-[var(--border-divider)] px-6 py-4 max-md:px-5 max-md:pt-[max(16px,env(safe-area-inset-top))]", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(DialogPrimitive.Title, { className: "truncate text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), subtitle ? (_jsx(DialogPrimitive.Description, { className: "mt-0.5 truncate text-12 leading-normal text-[var(--text-muted)]", children: subtitle })) : null] }), actions, _jsx(DialogPrimitive.Close, { disabled: busy, render: _jsx(IconButton, { "aria-label": "Close", size: "sm", children: _jsx(X, {}) }) })] }), _jsx("div", { ref: body, "data-slot": "drawer-body", className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 py-5 max-md:px-5", children: children }), primaryAction || dangerAction ? (_jsxs("footer", { "data-slot": "drawer-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-[var(--border-divider)] px-6 py-4 pb-[max(16px,env(safe-area-inset-bottom))] max-md:px-5", children: [dangerAction ? (_jsx(Button, { variant: "danger-ghost", size: "md", icon: dangerAction.icon, disabled: busy || dangerAction.disabled, onClick: dangerAction.onClick,
|
|
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] })) : null] })] }) }));
|
|
33
|
+
}
|
|
34
|
+
export { Drawer };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
5
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
6
|
+
function ExpandableBio({ text, size = 12, className }) {
|
|
7
|
+
const trimmed = text.trim();
|
|
8
|
+
const [expanded, setExpanded] = useState(false);
|
|
9
|
+
const [truncatable, setTruncatable] = useState(false);
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
const id = useId();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const el = ref.current;
|
|
14
|
+
// Measure only while collapsed, so expanding never flips the flag off.
|
|
15
|
+
if (!el || expanded)
|
|
16
|
+
return;
|
|
17
|
+
// ResizeObserver's first callback runs async, so state isn't set synchronously in the effect.
|
|
18
|
+
const observer = new ResizeObserver(() => setTruncatable(el.scrollHeight > el.clientHeight + 1));
|
|
19
|
+
observer.observe(el);
|
|
20
|
+
return () => observer.disconnect();
|
|
21
|
+
}, [trimmed, expanded]);
|
|
22
|
+
return (_jsxs("div", { "data-slot": "expandable-bio", className: className, children: [_jsx("p", { id: id, ref: ref,
|
|
23
|
+
// Size before line height: the class merger lets a font size override an earlier line height.
|
|
24
|
+
// pre-line keeps the person's own line breaks; a bio with two paragraphs shows both when open.
|
|
25
|
+
className: cn("whitespace-pre-line text-[var(--text-body)]", size === 14 ? "text-14" : "text-12", "leading-relaxed", !expanded && "line-clamp-1"), children: trimmed }), truncatable || expanded ? (_jsx(Button, { variant: "link", size: "xs", className: "mt-1", "aria-expanded": expanded, "aria-controls": id, onClick: () => setExpanded((v) => !v), children: expanded ? "See less" : "See more" })) : null] }));
|
|
26
|
+
}
|
|
27
|
+
export { ExpandableBio };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { Field as FieldPrimitive } from "@base-ui/react/field";
|
|
3
|
+
type FieldProps = Omit<FieldPrimitive.Root.Props, "className"> & {
|
|
4
|
+
/** The value has a problem. Turns the control red and lets FieldError show. */
|
|
5
|
+
invalid?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
/** One field. Put a FieldLabel, the control (Input, TagInput…), and optionally FieldDescription and FieldError inside. */
|
|
9
|
+
declare function Field({ className, invalid, ...props }: FieldProps): React.JSX.Element;
|
|
10
|
+
type FieldLabelProps = Omit<FieldPrimitive.Label.Props, "className"> & {
|
|
11
|
+
/** Adds "(optional)" after the label, in muted text. Required fields get no mark. */
|
|
12
|
+
optional?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
};
|
|
15
|
+
declare function FieldLabel({ className, optional, children, ...props }: FieldLabelProps): React.JSX.Element;
|
|
16
|
+
type FieldDescriptionProps = Omit<FieldPrimitive.Description.Props, "className"> & {
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
/** Help text under the control: what the value is for. Read out with the field. */
|
|
20
|
+
declare function FieldDescription({ className, ...props }: FieldDescriptionProps): React.JSX.Element;
|
|
21
|
+
type FieldErrorProps = Omit<FieldPrimitive.Error.Props, "className" | "match"> & {
|
|
22
|
+
className?: string;
|
|
23
|
+
};
|
|
24
|
+
/** What's wrong and how to fix it. Shows whenever it has text; pair it with `invalid` on the Field. */
|
|
25
|
+
declare function FieldError({ className, children, ...props }: FieldErrorProps): React.JSX.Element | null;
|
|
26
|
+
/** Stacks fields 16px apart. */
|
|
27
|
+
declare function FieldGroup({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
28
|
+
export { Field, FieldDescription, FieldError, FieldGroup, FieldLabel };
|
|
29
|
+
export type { FieldDescriptionProps, FieldErrorProps, FieldLabelProps, FieldProps };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Field as FieldPrimitive } from "@base-ui/react/field";
|
|
4
|
+
import { AlertCircle } from "lucide-react";
|
|
5
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
6
|
+
/** One field. Put a FieldLabel, the control (Input, TagInput…), and optionally FieldDescription and FieldError inside. */
|
|
7
|
+
function Field({ className, invalid, ...props }) {
|
|
8
|
+
return _jsx(FieldPrimitive.Root, { "data-slot": "field", invalid: invalid, className: cn("flex flex-col gap-1.5", className), ...props });
|
|
9
|
+
}
|
|
10
|
+
function FieldLabel({ className, optional, children, ...props }) {
|
|
11
|
+
return (_jsxs(FieldPrimitive.Label, { "data-slot": "field-label", className: cn("text-14 leading-[1.625] font-medium text-[var(--text-primary)] data-[disabled]:opacity-50", className), ...props, children: [children, optional ? _jsx("span", { className: "font-normal text-[var(--text-muted)]", children: " (optional)" }) : null] }));
|
|
12
|
+
}
|
|
13
|
+
/** Help text under the control: what the value is for. Read out with the field. */
|
|
14
|
+
function FieldDescription({ className, ...props }) {
|
|
15
|
+
return _jsx(FieldPrimitive.Description, { "data-slot": "field-description", className: cn("text-12 leading-[1.625] text-[var(--text-muted)]", className), ...props });
|
|
16
|
+
}
|
|
17
|
+
/** What's wrong and how to fix it. Shows whenever it has text; pair it with `invalid` on the Field. */
|
|
18
|
+
function FieldError({ className, children, ...props }) {
|
|
19
|
+
if (!children)
|
|
20
|
+
return null;
|
|
21
|
+
return (_jsxs(FieldPrimitive.Error, { "data-slot": "field-error", match: true, className: cn("flex items-start gap-1.5 text-12 leading-[1.625] text-[var(--danger-text)]", className), ...props, children: [_jsx(AlertCircle, { "aria-hidden": "true", className: "mt-px size-3.5 shrink-0" }), _jsx("span", { children: children })] }));
|
|
22
|
+
}
|
|
23
|
+
/** Stacks fields 16px apart. */
|
|
24
|
+
function FieldGroup({ className, ...props }) {
|
|
25
|
+
return _jsx("div", { "data-slot": "field-group", className: cn("flex flex-col gap-4", className), ...props });
|
|
26
|
+
}
|
|
27
|
+
export { Field, FieldDescription, FieldError, FieldGroup, FieldLabel };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Toggle } from "@base-ui/react/toggle";
|
|
2
|
+
type FilterChipProps = Omit<Toggle.Props, "className" | "pressed" | "defaultPressed"> & {
|
|
3
|
+
/** Whether this filter is on. The parent owns it. */
|
|
4
|
+
active?: boolean;
|
|
5
|
+
/** A count shown after the label, such as "All 128". */
|
|
6
|
+
count?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
declare function FilterChip({ active, count, className, children, ...props }: FilterChipProps): import("react").JSX.Element;
|
|
10
|
+
export { FilterChip };
|
|
11
|
+
export type { FilterChipProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Toggle } from "@base-ui/react/toggle";
|
|
4
|
+
import { formatCount } from "@brdgapp/ui/lib/format";
|
|
5
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
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)]",
|
|
8
|
+
// An on chip still reacts to the pointer: pressing it turns the filter off.
|
|
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
|
+
}
|
|
11
|
+
export { FilterChip };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ElementProps } from "@brdgapp/ui/lib/utils";
|
|
2
|
+
type FilterPillOption<T extends string> = {
|
|
3
|
+
value: T;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
/** The menu body shared by FilterPill and ColumnFilterMenu. */
|
|
7
|
+
declare function FilterMenuPopup<T extends string>({ value, options, onChange, width, align, }: {
|
|
8
|
+
value: T;
|
|
9
|
+
options: FilterPillOption<T>[];
|
|
10
|
+
onChange: (value: T) => void;
|
|
11
|
+
width: number;
|
|
12
|
+
align: "start" | "end";
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
/** The same choices as FilterMenuPopup, as a bottom sheet: what phones get below 768px. */
|
|
15
|
+
declare function FilterSheet<T extends string>({ open, onClose, title, value, options, onChange, }: {
|
|
16
|
+
open: boolean;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
title: string;
|
|
19
|
+
value: T;
|
|
20
|
+
options: FilterPillOption<T>[];
|
|
21
|
+
onChange: (value: T) => void;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
type FilterPillProps<T extends string> = ElementProps<HTMLButtonElement> & {
|
|
24
|
+
value: T;
|
|
25
|
+
/** The first option is the resting "All" state. */
|
|
26
|
+
options: FilterPillOption<T>[];
|
|
27
|
+
onChange: (value: T) => void;
|
|
28
|
+
/** What is being filtered: "Degree", "Status". Read as "Degree: 1st". */
|
|
29
|
+
ariaLabel?: string;
|
|
30
|
+
className?: string;
|
|
31
|
+
};
|
|
32
|
+
declare function FilterPill<T extends string>({ value, options, onChange, ariaLabel, className, ...rest }: FilterPillProps<T>): import("react").JSX.Element;
|
|
33
|
+
export { FilterPill, FilterMenuPopup, FilterSheet };
|
|
34
|
+
export type { FilterPillOption, FilterPillProps };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Menu } from "@base-ui/react/menu";
|
|
5
|
+
import { Check, ChevronDown } from "lucide-react";
|
|
6
|
+
import { BottomSheet, BottomSheetOption, BottomSheetOptions } from "@brdgapp/ui/components/bottom-sheet";
|
|
7
|
+
import { useIsMobile } from "@brdgapp/ui/hooks/use-is-mobile";
|
|
8
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
|
+
/** The menu body shared by FilterPill and ColumnFilterMenu. */
|
|
10
|
+
function FilterMenuPopup({ value, options, onChange, width, align, }) {
|
|
11
|
+
return (_jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { side: "bottom", align: align, sideOffset: 6, collisionPadding: 8, className: "z-[80]", children: _jsx(Menu.Popup, { "data-slot": "filter-menu", style: { minWidth: width }, className: "max-h-[320px] overflow-y-auto rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] py-1 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(Menu.RadioGroup, { value: value, onValueChange: (v) => onChange(v), children: options.map((option) => (_jsxs(Menu.RadioItem, { value: option.value, closeOnClick: true, "data-slot": "filter-menu-option", className: "group flex w-full cursor-default items-center justify-between gap-3 px-3 py-2 text-left text-13 leading-normal text-[var(--text-body)] outline-none transition-colors data-[checked]:font-semibold data-[checked]:text-[var(--text-primary)] data-[highlighted]:bg-[var(--surface-secondary)] hover:bg-[var(--surface-secondary)]", children: [_jsx("span", { className: "truncate", children: option.label }), _jsx(Menu.RadioItemIndicator, { className: "inline-flex shrink-0", children: _jsx(Check, { "aria-hidden": "true", className: "size-4 text-[var(--primary)]" }) })] }, option.value))) }) }) }) }));
|
|
12
|
+
}
|
|
13
|
+
/** The same choices as FilterMenuPopup, as a bottom sheet: what phones get below 768px. */
|
|
14
|
+
function FilterSheet({ open, onClose, title, value, options, onChange, }) {
|
|
15
|
+
return (_jsx(BottomSheet, { open: open, onClose: onClose, title: title, children: _jsx(BottomSheetOptions, { children: options.map((option) => (_jsx(BottomSheetOption, { selected: option.value === value, onSelect: () => {
|
|
16
|
+
onChange(option.value);
|
|
17
|
+
onClose();
|
|
18
|
+
}, children: option.label }, option.value))) }) }));
|
|
19
|
+
}
|
|
20
|
+
function FilterPill({ value, options, onChange, ariaLabel = "Filter", className, ...rest }) {
|
|
21
|
+
const [open, setOpen] = useState(false);
|
|
22
|
+
const mobile = useIsMobile();
|
|
23
|
+
const active = value !== options[0]?.value;
|
|
24
|
+
const label = options.find((o) => o.value === value)?.label ?? options[0]?.label ?? "";
|
|
25
|
+
const triggerClass = cn("inline-flex shrink-0 items-center gap-1.5 rounded-full border px-3 py-1.5 text-13 leading-normal font-semibold outline-none transition-colors duration-150", "focus-visible:ring-2 focus-visible:ring-[var(--primary)]", active
|
|
26
|
+
? "border-[var(--text-muted)] bg-[var(--surface-tertiary)] text-[var(--text-primary)] hover:border-[var(--text-secondary)]"
|
|
27
|
+
: "border-[var(--text-disabled)] bg-transparent text-[var(--text-secondary)] hover:border-[var(--text-muted)] hover:text-[var(--text-primary)]", className);
|
|
28
|
+
const inner = (_jsxs(_Fragment, { children: [label, _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-3.5 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
29
|
+
// Phones: the choices slide up from the bottom, near the thumb, in 44px rows.
|
|
30
|
+
if (mobile) {
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ...rest, type: "button", "data-slot": "filter-pill", "aria-haspopup": "dialog", "aria-label": `${ariaLabel}: ${label}`, className: triggerClass, onClick: () => setOpen(true), children: inner }), _jsx(FilterSheet, { open: open, onClose: () => setOpen(false), title: ariaLabel, value: value, options: options, onChange: onChange })] }));
|
|
32
|
+
}
|
|
33
|
+
return (_jsxs(Menu.Root, { open: open, onOpenChange: setOpen, children: [_jsx(Menu.Trigger, { ...rest, "data-slot": "filter-pill", "aria-label": `${ariaLabel}: ${label}`, className: triggerClass, children: inner }), _jsx(FilterMenuPopup, { value: value, options: options, onChange: onChange, width: 200, align: "end" })] }));
|
|
34
|
+
}
|
|
35
|
+
export { FilterPill, FilterMenuPopup, FilterSheet };
|