@brdgapp/ui 1.3.0 → 1.5.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 +41 -0
- package/components/account-menu.d.ts +75 -0
- package/components/account-menu.js +69 -0
- package/components/app-launcher.d.ts +22 -0
- package/components/app-launcher.js +20 -0
- package/components/app-shell.d.ts +52 -0
- package/components/app-shell.js +138 -0
- package/components/bottom-sheet.d.ts +3 -1
- package/components/bottom-sheet.js +2 -2
- package/components/breadcrumbs.d.ts +22 -0
- package/components/breadcrumbs.js +16 -0
- package/components/data-table.js +4 -1
- package/components/drawer.d.ts +6 -2
- package/components/drawer.js +10 -3
- package/components/global-search.d.ts +73 -0
- package/components/global-search.js +202 -0
- package/components/popover.d.ts +27 -0
- package/components/popover.js +45 -0
- package/components/tag.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
|
|
4
4
|
|
|
5
|
+
## 1.5.0
|
|
6
|
+
|
|
7
|
+
2026-11-16. AppShell, AccountMenu and Breadcrumbs, and Drawer gains a width and a toolbar. Nothing changes for apps already on 1.4, so they can update without changes.
|
|
8
|
+
|
|
9
|
+
- New: AppShell (`components/app-shell`), every app's navigation. A 56px glass top bar with search,
|
|
10
|
+
`actions` (the AppLauncher) and `account` on its right in every app. `nav="top"`: the logo and the tabs
|
|
11
|
+
(four places or fewer) on its left; five or more use `nav="side"`. `nav="side"`: a full-height 224px side menu, in groups, with the logo and its
|
|
12
|
+
shrink button at the top; it shrinks to 56px of icons (the button or ⌘B, `logoMark` at the top) and
|
|
13
|
+
remembers it, and the top bar beside it takes `breadcrumbs`. Phones: tabs move to a bottom bar; a side
|
|
14
|
+
menu slides in from ☰. `renderLink` takes your router's link. Every app's own header, sidebar and bottom
|
|
15
|
+
bar become this.
|
|
16
|
+
- New: AccountMenu (`components/account-menu`): your account from the top bar's avatar. "Signed in as" always;
|
|
17
|
+
then only the parts an app passes: `tag`, `workspaces`, `profileHref`, `settingsHref`, `adminHref`,
|
|
18
|
+
`bridgeAccountHref`, `connectedAccounts` (with sync and Manage), `extra`, `onSignOut`. Every app's own avatar
|
|
19
|
+
dropdown becomes this, in AppShell's `account`.
|
|
20
|
+
- New: Breadcrumbs (`components/breadcrumbs`): where a page sits, Admin › Directory › Firms, for AppShell's
|
|
21
|
+
`breadcrumbs`.
|
|
22
|
+
- Drawer: `size="wide"`, 1152px (always leaving 64px of the page in view), for a table or a two-pane editor.
|
|
23
|
+
Its body has no padding, so a DataTable runs edge to edge. Bridge OS's "Your contacts" drawer and
|
|
24
|
+
app-directories' page builder become this.
|
|
25
|
+
- Drawer: `toolbar`, pinned under the header. Pass a DataTableToolbar with the search and filters, so they stay
|
|
26
|
+
in view while the list scrolls.
|
|
27
|
+
- DataTableToolbar: with no search, filters start at the left instead of the right (a drawer's row of
|
|
28
|
+
FilterChips). With a search, nothing moves.
|
|
29
|
+
|
|
30
|
+
## 1.4.0
|
|
31
|
+
|
|
32
|
+
2026-11-12. Three new components. Nothing changes for apps already on 1.3, so they can update without changes.
|
|
33
|
+
|
|
34
|
+
- New: GlobalSearch (`components/global-search`), the ⌘K search for every app. `GlobalSearchTrigger` is the
|
|
35
|
+
search field in the top bar and owns ⌘K (Ctrl+K). `GlobalSearch` shows each kind of thing in its own list,
|
|
36
|
+
two side by side and a third on a row below, with recents or suggestions before anything is typed. ↑ ↓ move
|
|
37
|
+
through the results, as in shadcn's Command. Bridge OS's search overlay, and shadcn's CommandDialog in raise
|
|
38
|
+
and app-portfolio, become this.
|
|
39
|
+
- New: Popover (`components/popover`), a panel that opens from a button: 320px, or `wide` 460px, with an
|
|
40
|
+
optional heading and one link beside it. On a phone it opens as a BottomSheet. For the account menu and the
|
|
41
|
+
app launcher.
|
|
42
|
+
- New: AppLauncher (`components/app-launcher`), the 9-dot button in the top bar that opens every Bridge app in
|
|
43
|
+
one grid. Each app passes in the `apps` it loads from Bridge's app list; icons can be the database's SVG markup.
|
|
44
|
+
- BottomSheet: `action`, one link or small button beside the title.
|
|
45
|
+
|
|
5
46
|
## 1.3.0
|
|
6
47
|
|
|
7
48
|
2026-11-12. Six additions Bridge OS asked for, each found in other apps too. Nothing changes for apps already on
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type TagColor } from "@brdgapp/ui/components/tag";
|
|
3
|
+
type AccountMenuUser = {
|
|
4
|
+
name: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
/** Their photo. Without it, initials. */
|
|
7
|
+
avatarUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
type AccountMenuWorkspace = {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
/** A logo or favicon, 24px. Without it, the name's initials. */
|
|
13
|
+
icon?: React.ReactNode;
|
|
14
|
+
/** The one people are in: gets a check. */
|
|
15
|
+
current?: boolean;
|
|
16
|
+
/** Something new there: a count. */
|
|
17
|
+
badge?: number;
|
|
18
|
+
};
|
|
19
|
+
type AccountMenuConnectedAccount = {
|
|
20
|
+
id: string;
|
|
21
|
+
/** The company's domain for a work account ("brdg.app"), or the address for a personal one. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** The line under it: the address, or "Synced 2h ago". */
|
|
24
|
+
detail?: string;
|
|
25
|
+
/** The company's favicon, 20px. */
|
|
26
|
+
icon?: React.ReactNode;
|
|
27
|
+
kind: "work" | "personal";
|
|
28
|
+
primary?: boolean;
|
|
29
|
+
};
|
|
30
|
+
type AccountMenuLinkProps = {
|
|
31
|
+
href: string;
|
|
32
|
+
className: string;
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
onClick?: () => void;
|
|
35
|
+
};
|
|
36
|
+
type AccountMenuProps = {
|
|
37
|
+
/** Who's signed in. Required: the menu always starts with "Signed in as". */
|
|
38
|
+
user: AccountMenuUser;
|
|
39
|
+
/** Their plan or role beside the name: `{ label: "Pro", color: "blue" }`. Free is grey, paid blue, custom purple. */
|
|
40
|
+
tag?: {
|
|
41
|
+
label: string;
|
|
42
|
+
color?: TagColor;
|
|
43
|
+
};
|
|
44
|
+
/** Apps with workspaces: listed under your name. Choosing one calls `onWorkspaceChange`. */
|
|
45
|
+
workspaces?: AccountMenuWorkspace[];
|
|
46
|
+
onWorkspaceChange?: (id: string) => void;
|
|
47
|
+
/** Shows "View profile". */
|
|
48
|
+
profileHref?: string;
|
|
49
|
+
/** Shows "Account settings". */
|
|
50
|
+
settingsHref?: string;
|
|
51
|
+
/** Shows "Bridge account", opening in a new tab: `"https://brdg.app/account"`. */
|
|
52
|
+
bridgeAccountHref?: string;
|
|
53
|
+
/** Shows "Admin controls", for people allowed in. */
|
|
54
|
+
adminHref?: string;
|
|
55
|
+
/** Shows "Connected accounts": the email accounts Bridge reads, under Work and Personal. */
|
|
56
|
+
connectedAccounts?: AccountMenuConnectedAccount[];
|
|
57
|
+
/** While they load, after opening. */
|
|
58
|
+
connectedAccountsLoading?: boolean;
|
|
59
|
+
/** Shows the sync button beside "Connected accounts". Return a promise to show it spinning, then done or failed. */
|
|
60
|
+
onSyncAccounts?: () => void | Promise<unknown>;
|
|
61
|
+
/** Shows "Manage" beside "Connected accounts". */
|
|
62
|
+
manageAccountsHref?: string;
|
|
63
|
+
/** One section of the app's own, before Sign out: a card, a toggle, "Clear cache". */
|
|
64
|
+
extra?: React.ReactNode;
|
|
65
|
+
/** Shows "Sign out", the last row, in red. */
|
|
66
|
+
onSignOut?: () => void;
|
|
67
|
+
/** Your router's link, as in AppShell: `(p) => <Link {...p} />`. Default a plain <a>. */
|
|
68
|
+
renderLink?: (props: AccountMenuLinkProps) => React.ReactElement;
|
|
69
|
+
/** Control it, to load connected accounts when it opens. Leave both out and it opens and closes itself. */
|
|
70
|
+
open?: boolean;
|
|
71
|
+
onOpenChange?: (open: boolean) => void;
|
|
72
|
+
};
|
|
73
|
+
declare function AccountMenu({ user, tag, workspaces, onWorkspaceChange, profileHref, settingsHref, bridgeAccountHref, adminHref, connectedAccounts, connectedAccountsLoading, onSyncAccounts, manageAccountsHref, extra, onSignOut, renderLink, open: openProp, onOpenChange, }: AccountMenuProps): React.JSX.Element;
|
|
74
|
+
export { AccountMenu };
|
|
75
|
+
export type { AccountMenuConnectedAccount, AccountMenuLinkProps, AccountMenuProps, AccountMenuUser, AccountMenuWorkspace };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Check, CircleAlert, CircleCheck, CircleUser, ExternalLink, LogOut, RefreshCw, Settings, Shield, User } from "lucide-react";
|
|
5
|
+
import { Avatar } from "@brdgapp/ui/components/avatar";
|
|
6
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
|
+
import { Popover } from "@brdgapp/ui/components/popover";
|
|
8
|
+
import { Skeleton } from "@brdgapp/ui/components/skeleton";
|
|
9
|
+
import { Tag } from "@brdgapp/ui/components/tag";
|
|
10
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
11
|
+
const plainLink = (props) => _jsx("a", { ...props });
|
|
12
|
+
// The same row as ActionMenu's items, run edge to edge across the panel.
|
|
13
|
+
const ROW = "flex w-full items-center gap-3 px-4 py-2.5 max-md:min-h-11 text-left text-13 font-medium leading-normal text-[var(--text-body)] outline-none transition-colors " +
|
|
14
|
+
"hover:bg-[var(--surface-secondary)] hover:text-[var(--text-primary)] focus-visible:bg-[var(--surface-secondary)] focus-visible:text-[var(--text-primary)] " +
|
|
15
|
+
"[&_svg]:size-4 [&_svg]:shrink-0 [&>svg:first-child]:text-[var(--text-muted)]";
|
|
16
|
+
const HEADING = "px-4 pb-1.5 text-12 font-medium text-[var(--text-muted)]";
|
|
17
|
+
function Divider() {
|
|
18
|
+
return _jsx("div", { "aria-hidden": "true", className: "my-1 border-t border-[var(--border-divider)]" });
|
|
19
|
+
}
|
|
20
|
+
function AccountMenu({ user, tag, workspaces, onWorkspaceChange, profileHref, settingsHref, bridgeAccountHref, adminHref, connectedAccounts, connectedAccountsLoading = false, onSyncAccounts, manageAccountsHref, extra, onSignOut, renderLink, open: openProp, onOpenChange, }) {
|
|
21
|
+
const link = renderLink ?? plainLink;
|
|
22
|
+
const [ownOpen, setOwnOpen] = React.useState(false);
|
|
23
|
+
const open = openProp ?? ownOpen;
|
|
24
|
+
const setOpen = (next) => {
|
|
25
|
+
if (openProp === undefined)
|
|
26
|
+
setOwnOpen(next);
|
|
27
|
+
onOpenChange?.(next);
|
|
28
|
+
};
|
|
29
|
+
const close = () => setOpen(false);
|
|
30
|
+
const links = [
|
|
31
|
+
profileHref ? link({ href: profileHref, onClick: close, className: ROW, children: _jsxs(_Fragment, { children: [_jsx(User, { "aria-hidden": "true" }), "View profile"] }) }) : null,
|
|
32
|
+
settingsHref ? link({ href: settingsHref, onClick: close, className: ROW, children: _jsxs(_Fragment, { children: [_jsx(Settings, { "aria-hidden": "true" }), "Account settings"] }) }) : null,
|
|
33
|
+
adminHref ? link({ href: adminHref, onClick: close, className: ROW, children: _jsxs(_Fragment, { children: [_jsx(Shield, { "aria-hidden": "true" }), "Admin controls"] }) }) : null,
|
|
34
|
+
bridgeAccountHref ? (_jsxs("a", { href: bridgeAccountHref, target: "_blank", rel: "noopener noreferrer", onClick: close, className: ROW, children: [_jsx(CircleUser, { "aria-hidden": "true" }), _jsx("span", { className: "flex-1", children: "Bridge account" }), _jsx(ExternalLink, { "aria-hidden": "true", className: "text-[var(--text-muted)]" }), _jsx("span", { className: "sr-only", children: "(opens in a new tab)" })] })) : null,
|
|
35
|
+
].filter(Boolean);
|
|
36
|
+
return (_jsx(Popover, { open: open, onOpenChange: setOpen, title: "Your account", hideTitle: true, align: "end", trigger: _jsx("button", { type: "button", "aria-label": "Your account", className: "flex shrink-0 rounded-full ring-1 ring-[var(--border-default)] transition-shadow outline-none hover:ring-[var(--border-hover)] focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-offset-2", children: _jsx(Avatar, { name: user.name, src: user.avatarUrl, size: "md" }) }), children: _jsxs("div", { "data-slot": "account-menu", className: "-m-4 py-2", children: [_jsx("p", { className: cn(HEADING, "pt-2"), children: "Signed in as" }), _jsxs("div", { className: "flex items-center gap-3 px-4 pb-3", children: [_jsx(Avatar, { name: user.name, src: user.avatarUrl, size: "lg", className: "shrink-0" }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "truncate text-14 font-semibold text-[var(--text-primary)]", children: user.name }), user.email ? _jsx("p", { className: "truncate text-12 text-[var(--text-muted)]", children: user.email }) : null] }), tag ? (_jsx(Tag, { color: tag.color ?? "grey", size: "sm", className: "shrink-0", children: tag.label })) : null] }), workspaces?.length ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsxs("div", { role: "group", "aria-label": "Workspaces", className: "py-1", children: [_jsx("p", { className: cn(HEADING, "pt-1.5"), children: "Workspaces" }), workspaces.map((w) => (_jsxs("button", { type: "button", "aria-current": w.current ? "true" : undefined, onClick: () => {
|
|
37
|
+
onWorkspaceChange?.(w.id);
|
|
38
|
+
close();
|
|
39
|
+
}, className: cn(ROW, w.current ? "text-[var(--text-primary)]" : ""), children: [_jsx("span", { "aria-hidden": "true", className: "flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-md [&_img]:size-6", children: w.icon ?? _jsx(Avatar, { name: w.name, size: "sm" }) }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: w.name }), w.badge ? (_jsxs("span", { className: "text-12 text-[var(--text-muted)] tabular-nums", children: [w.badge, _jsx("span", { className: "sr-only", children: " new" })] })) : null, w.current ? _jsx(Check, { "aria-hidden": "true", className: "text-[var(--primary)]" }) : _jsx("span", { "aria-hidden": "true", className: "size-4" })] }, w.id)))] })] })) : null, links.length ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx("div", { className: "py-1", children: links.map((l, i) => React.cloneElement(l, { key: i })) })] })) : null, connectedAccounts ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(ConnectedAccounts, { accounts: connectedAccounts, loading: connectedAccountsLoading, onSync: onSyncAccounts, manage: manageAccountsHref ? link({ href: manageAccountsHref, onClick: close, className: "rounded-sm text-12 font-semibold text-[var(--primary)] outline-none hover:underline focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: "Manage" }) : null })] })) : null, extra ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx("div", { className: "px-4 py-2", children: extra })] })) : null, onSignOut ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx("div", { className: "py-1", children: _jsxs("button", { type: "button", onClick: () => {
|
|
40
|
+
close();
|
|
41
|
+
onSignOut();
|
|
42
|
+
}, className: cn(ROW, "text-[var(--danger-text)] hover:bg-[var(--error-bg)] hover:text-[var(--danger-text)] focus-visible:bg-[var(--error-bg)] focus-visible:text-[var(--danger-text)] [&>svg:first-child]:text-[var(--danger-text)]"), children: [_jsx(LogOut, { "aria-hidden": "true" }), "Sign out"] }) })] })) : null] }) }));
|
|
43
|
+
}
|
|
44
|
+
function ConnectedAccounts({ accounts, loading, onSync, manage, }) {
|
|
45
|
+
const [sync, setSync] = React.useState("idle");
|
|
46
|
+
const run = async () => {
|
|
47
|
+
if (!onSync || sync === "syncing")
|
|
48
|
+
return;
|
|
49
|
+
const result = onSync();
|
|
50
|
+
if (!(result instanceof Promise))
|
|
51
|
+
return;
|
|
52
|
+
setSync("syncing");
|
|
53
|
+
try {
|
|
54
|
+
await result;
|
|
55
|
+
setSync("done");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
setSync("error");
|
|
59
|
+
}
|
|
60
|
+
setTimeout(() => setSync("idle"), 3000);
|
|
61
|
+
};
|
|
62
|
+
const work = accounts.filter((a) => a.kind === "work");
|
|
63
|
+
const personal = accounts.filter((a) => a.kind === "personal");
|
|
64
|
+
return (_jsxs("div", { role: "group", "aria-label": "Connected accounts", className: "px-4 py-2", children: [_jsxs("div", { className: "mb-2 flex items-center justify-between gap-2", children: [_jsx("p", { className: "text-12 font-medium text-[var(--text-muted)]", children: "Connected accounts" }), _jsxs("div", { className: "flex items-center gap-2", children: [onSync ? (_jsx(IconButton, { size: "sm", variant: sync === "error" ? "danger" : "default", loading: sync === "syncing", onClick: run, "aria-label": sync === "syncing" ? "Syncing accounts" : sync === "done" ? "Sync started" : sync === "error" ? "Sync failed" : "Sync accounts", children: sync === "done" ? _jsx(CircleCheck, {}) : sync === "error" ? _jsx(CircleAlert, {}) : _jsx(RefreshCw, {}) })) : null, manage] })] }), loading ? (_jsx("div", { className: "space-y-1.5", children: [0, 1].map((i) => (_jsxs("div", { className: "flex items-center gap-2.5 rounded-lg bg-[var(--surface-secondary)] px-3 py-2", children: [_jsx(Skeleton, { className: "size-5 shrink-0" }), _jsxs("div", { className: "flex-1 space-y-1.5", children: [_jsx(Skeleton, { className: "h-3 w-24" }), _jsx(Skeleton, { className: "h-2.5 w-32" })] })] }, i))) })) : accounts.length ? (_jsx("div", { className: "space-y-3", children: [
|
|
65
|
+
{ label: "Work", list: work },
|
|
66
|
+
{ label: "Personal", list: personal },
|
|
67
|
+
].map((g) => g.list.length ? (_jsxs("div", { children: [_jsx("p", { className: "mb-1.5 text-11 font-medium text-[var(--text-muted)]", children: g.label }), _jsx("ul", { className: "space-y-1.5", children: g.list.map((a) => (_jsxs("li", { className: "flex items-center gap-2.5 rounded-lg bg-[var(--surface-secondary)] px-3 py-2", children: [_jsx("span", { "aria-hidden": "true", className: "flex size-5 shrink-0 items-center justify-center overflow-hidden rounded-sm bg-[var(--border-default)] [&_img]:size-5", children: a.icon }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate text-12 font-medium text-[var(--text-secondary)]", children: a.name }), a.detail ? _jsx("span", { className: "block truncate text-11 text-[var(--text-muted)]", children: a.detail }) : null] }), a.primary ? (_jsx(Tag, { color: "blue", size: "sm", className: "shrink-0", children: "Primary" })) : null] }, a.id))) })] }, g.label)) : null) })) : (_jsx("p", { className: "text-12 text-[var(--text-muted)]", children: "No connected accounts" }))] }));
|
|
68
|
+
}
|
|
69
|
+
export { AccountMenu };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type AppLauncherApp = {
|
|
3
|
+
/** Unique: "intros", "raise". */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The app's name, without a version: "Intros", "Raise". */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Where it opens: "https://raise.brdg.app". */
|
|
8
|
+
href: string;
|
|
9
|
+
/** A Lucide icon, or the SVG markup the database stores (`icon_svg`). Drawn in Royal either way. */
|
|
10
|
+
icon: React.ReactNode | string;
|
|
11
|
+
/** Still in beta: a small flask on the icon. */
|
|
12
|
+
beta?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type AppLauncherProps = {
|
|
15
|
+
/** The apps to show, in order. Leave out the app it's in and anything not ready yet. */
|
|
16
|
+
apps: AppLauncherApp[];
|
|
17
|
+
/** A page listing every app with more detail: a "See more" link in the heading. */
|
|
18
|
+
moreHref?: string;
|
|
19
|
+
};
|
|
20
|
+
declare function AppLauncher({ apps, moreHref }: AppLauncherProps): React.JSX.Element;
|
|
21
|
+
export { AppLauncher };
|
|
22
|
+
export type { AppLauncherApp, AppLauncherProps };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { FlaskConical } from "lucide-react";
|
|
5
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
6
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
|
+
import { Popover } from "@brdgapp/ui/components/popover";
|
|
8
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
|
+
function AppIcon({ icon }) {
|
|
10
|
+
// Markup from the database: only an <svg>, drawn with currentColor.
|
|
11
|
+
if (typeof icon === "string") {
|
|
12
|
+
return icon.trimStart().startsWith("<svg") ? (_jsx("span", { "aria-hidden": "true", className: "flex size-[18px] [&>svg]:size-full", dangerouslySetInnerHTML: { __html: icon } })) : null;
|
|
13
|
+
}
|
|
14
|
+
return (_jsx("span", { "aria-hidden": "true", className: "flex [&>svg]:size-[18px]", children: icon }));
|
|
15
|
+
}
|
|
16
|
+
function AppLauncher({ apps, moreHref }) {
|
|
17
|
+
const [open, setOpen] = React.useState(false);
|
|
18
|
+
return (_jsx(Popover, { open: open, onOpenChange: setOpen, title: "All apps", size: "wide", align: "end", action: moreHref ? (_jsx(Button, { variant: "link", size: "xs", render: _jsx("a", { href: moreHref, onClick: () => setOpen(false) }), children: "See more" })) : undefined, trigger: _jsx(IconButton, { size: "sm", "aria-label": "Open app launcher", "data-slot": "app-launcher-trigger", children: _jsx("svg", { viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": "true", children: [1, 6, 11].flatMap((y) => [1, 6, 11].map((x) => _jsx("rect", { x: x, y: y, width: "4", height: "4", rx: "1" }, `${x}-${y}`))) }) }), children: _jsx("ul", { "data-slot": "app-launcher", className: "-m-2 grid grid-cols-3 gap-2", children: apps.map((app) => (_jsx("li", { children: _jsxs("a", { href: app.href, onClick: () => setOpen(false), className: cn("flex flex-col items-center gap-2 rounded-xl p-3 text-center transition-colors outline-none", "hover:bg-[var(--surface-secondary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]"), children: [_jsxs("span", { className: "relative flex size-10 shrink-0 items-center justify-center rounded-xl bg-[var(--info-bg)] text-[var(--primary)]", children: [_jsx(AppIcon, { icon: app.icon }), app.beta ? (_jsx("span", { className: "absolute -right-1 -bottom-1 flex size-4 items-center justify-center rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--purple)]", children: _jsx(FlaskConical, { "aria-hidden": "true", className: "size-2.5 text-white" }) })) : null] }), _jsxs("span", { className: "line-clamp-2 text-12 leading-tight font-semibold text-[var(--text-primary)]", children: [app.name, app.beta ? _jsx("span", { className: "sr-only", children: ", beta" }) : null] })] }) }, app.id))) }) }));
|
|
19
|
+
}
|
|
20
|
+
export { AppLauncher };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type AppShellItem = {
|
|
3
|
+
/** Unique: "activity". */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The place's name: "Activity". Short: one word where possible. */
|
|
6
|
+
label: string;
|
|
7
|
+
href: string;
|
|
8
|
+
/** A Lucide icon. Shown in the bottom bar and the side menu; the top bar's tabs are words only. */
|
|
9
|
+
icon: React.ReactNode;
|
|
10
|
+
/** The page people are on. Set it from your router: the shell doesn't read the address. */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
/** Something new there: `true` is a red dot; a number is a count in the side menu and a dot elsewhere. */
|
|
13
|
+
badge?: boolean | number;
|
|
14
|
+
/** Side menu only: a heading the item sits under ("Directory", "Inbox"). Items with the same group go together. */
|
|
15
|
+
group?: string;
|
|
16
|
+
};
|
|
17
|
+
type AppShellLinkProps = {
|
|
18
|
+
href: string;
|
|
19
|
+
className: string;
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
"aria-current"?: "page";
|
|
22
|
+
onClick?: () => void;
|
|
23
|
+
};
|
|
24
|
+
type AppShellProps = {
|
|
25
|
+
/** The app's lockup: the Bridge icon and the app's name. Links home. */
|
|
26
|
+
logo: React.ReactNode;
|
|
27
|
+
/** Side menu only: the Bridge icon alone, shown at the top when the side menu is shrunk. */
|
|
28
|
+
logoMark?: React.ReactNode;
|
|
29
|
+
/** Where the logo goes. Default "/". */
|
|
30
|
+
homeHref?: string;
|
|
31
|
+
/** The app's main places. */
|
|
32
|
+
items: AppShellItem[];
|
|
33
|
+
/** `top`: tabs in the top bar (and a bottom bar on phones), for four places or fewer. `side`: a full-height side menu with the logo at its top, for five or more, or groups. */
|
|
34
|
+
nav?: "top" | "side";
|
|
35
|
+
/** Side menu only: Breadcrumbs, on the left of the top bar. Hidden on phones. */
|
|
36
|
+
breadcrumbs?: React.ReactNode;
|
|
37
|
+
/** A GlobalSearchTrigger. On the right of the top bar, before the launcher; on a phone it shrinks to an icon. */
|
|
38
|
+
search?: React.ReactNode;
|
|
39
|
+
/** Buttons before your account: the AppLauncher, a notifications button. */
|
|
40
|
+
actions?: React.ReactNode;
|
|
41
|
+
/** Your account: an AccountMenu, or a "Log in" button. Always last. */
|
|
42
|
+
account?: React.ReactNode;
|
|
43
|
+
/** Side menu only: a link at the bottom, such as "Back to Bridge OS" in an admin area. */
|
|
44
|
+
sideFooter?: React.ReactNode;
|
|
45
|
+
/** Draws each link with your router's: `(p) => <Link {...p} />` (Next), `({ href, ...p }) => <Link to={href} {...p} />` (React Router). Default a plain <a>. */
|
|
46
|
+
renderLink?: (props: AppShellLinkProps) => React.ReactElement;
|
|
47
|
+
/** The page. */
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
};
|
|
50
|
+
declare function AppShell({ logo, logoMark, homeHref, items, nav, breadcrumbs, search, actions, account, sideFooter, renderLink, children, }: AppShellProps): React.JSX.Element;
|
|
51
|
+
export { AppShell };
|
|
52
|
+
export type { AppShellItem, AppShellLinkProps, AppShellProps };
|
|
@@ -0,0 +1,138 @@
|
|
|
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 { Menu, PanelLeftClose, PanelLeftOpen, X } from "lucide-react";
|
|
6
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
|
+
import { SkipLink } from "@brdgapp/ui/components/skip-link";
|
|
8
|
+
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
9
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
10
|
+
const plainLink = (props) => _jsx("a", { ...props });
|
|
11
|
+
// GlobalSearchTrigger sized by the top bar (see `searchSized`). The `!` beats the trigger's own window-based sizes.
|
|
12
|
+
const SEARCH_SIZE = [
|
|
13
|
+
"w-9! justify-center! px-0! [&>span]:hidden! [&>kbd]:hidden!",
|
|
14
|
+
"@min-[760px]:w-[240px]! @min-[760px]:justify-start! @min-[760px]:px-3.5! @min-[760px]:[&>span]:block! @min-[760px]:[&>kbd]:inline-flex!",
|
|
15
|
+
"@min-[1200px]:w-[280px]!",
|
|
16
|
+
].join(" ");
|
|
17
|
+
function Dot({ className }) {
|
|
18
|
+
return _jsx("span", { "aria-hidden": "true", className: cn("absolute size-2 rounded-full bg-[var(--error)] ring-2 ring-[var(--surface-primary)]", className) });
|
|
19
|
+
}
|
|
20
|
+
function badgeText(badge) {
|
|
21
|
+
if (!badge)
|
|
22
|
+
return "";
|
|
23
|
+
return typeof badge === "number" ? `, ${badge} new` : ", new";
|
|
24
|
+
}
|
|
25
|
+
// ── The side menu's remembered width ───────────────────────────────────────────────────────────
|
|
26
|
+
const KEY = "brdg-side-nav-collapsed";
|
|
27
|
+
const listeners = new Set();
|
|
28
|
+
function readCollapsed() {
|
|
29
|
+
try {
|
|
30
|
+
return window.localStorage.getItem(KEY) === "1";
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function setCollapsed(next) {
|
|
37
|
+
try {
|
|
38
|
+
window.localStorage.setItem(KEY, next ? "1" : "0");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Storage blocked: it still collapses until the page reloads.
|
|
42
|
+
}
|
|
43
|
+
memory = next;
|
|
44
|
+
listeners.forEach((l) => l());
|
|
45
|
+
}
|
|
46
|
+
let memory = null;
|
|
47
|
+
function subscribe(l) {
|
|
48
|
+
listeners.add(l);
|
|
49
|
+
return () => listeners.delete(l);
|
|
50
|
+
}
|
|
51
|
+
const getCollapsed = () => memory ?? (memory = readCollapsed());
|
|
52
|
+
function useCollapsed() {
|
|
53
|
+
return React.useSyncExternalStore(subscribe, getCollapsed, () => false);
|
|
54
|
+
}
|
|
55
|
+
// ── Pieces ─────────────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
function TopTabs({ items, link }) {
|
|
57
|
+
return (_jsx("div", { className: "hidden shrink-0 items-center gap-6 self-stretch md:flex", children: items.map((item) => React.cloneElement(link({
|
|
58
|
+
href: item.href,
|
|
59
|
+
"aria-current": item.active ? "page" : undefined,
|
|
60
|
+
className: cn("relative flex h-full items-center text-14 leading-5 font-bold tracking-[0.4px] transition-colors outline-none", "focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-offset-2 rounded-sm", item.active ? "text-[var(--text-primary)]" : "text-[var(--text-muted)] hover:text-[var(--text-body)]"),
|
|
61
|
+
children: (_jsxs(_Fragment, { children: [_jsxs("span", { className: "relative", children: [item.label, item.badge ? _jsx(Dot, { className: "-top-1 -right-2.5" }) : null, item.badge ? _jsx("span", { className: "sr-only", children: badgeText(item.badge) }) : null] }), _jsx("span", { "aria-hidden": "true", className: cn("absolute inset-x-0 bottom-0 h-0.5 bg-[var(--text-primary)]", item.active ? "opacity-100" : "opacity-0") })] })),
|
|
62
|
+
}), { key: item.id })) }));
|
|
63
|
+
}
|
|
64
|
+
function BottomBar({ items, link }) {
|
|
65
|
+
if (process.env.NODE_ENV !== "production" && items.length > 4) {
|
|
66
|
+
console.warn(`AppShell: ${items.length} places. Four or fewer use tabs; five or more use nav="side".`);
|
|
67
|
+
}
|
|
68
|
+
return (_jsx("nav", { "aria-label": "Main", "data-slot": "app-shell-bottom-bar", className: "fixed inset-x-0 bottom-0 z-50 border-t border-[var(--glass-border)] bg-[var(--glass-bg)] pb-[env(safe-area-inset-bottom)] backdrop-blur-2xl backdrop-saturate-150 md:hidden", children: _jsx("div", { className: "flex h-14 items-stretch", children: items.map((item) => React.cloneElement(link({
|
|
69
|
+
href: item.href,
|
|
70
|
+
"aria-current": item.active ? "page" : undefined,
|
|
71
|
+
className: cn("flex flex-1 flex-col items-center justify-center gap-0.5 transition-colors outline-none focus-visible:bg-[var(--surface-secondary)]", item.active ? "text-[var(--primary)]" : "text-[var(--text-muted)]"),
|
|
72
|
+
children: (_jsxs(_Fragment, { children: [_jsxs("span", { "aria-hidden": "true", className: cn("relative [&>svg]:size-[22px]", item.active ? "[&>svg]:stroke-[2.4]" : ""), children: [item.icon, item.badge ? _jsx(Dot, { className: "-top-1 -right-1.5" }) : null] }), _jsxs("span", { className: "text-11 leading-none font-semibold tracking-[0.2px]", children: [item.label, item.badge ? _jsx("span", { className: "sr-only", children: badgeText(item.badge) }) : null] })] })),
|
|
73
|
+
}), { key: item.id })) }) }));
|
|
74
|
+
}
|
|
75
|
+
function groupsOf(items) {
|
|
76
|
+
const groups = [];
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
const last = groups.at(-1);
|
|
79
|
+
if (last && last.label === item.group)
|
|
80
|
+
last.items.push(item);
|
|
81
|
+
else
|
|
82
|
+
groups.push({ label: item.group, items: [item] });
|
|
83
|
+
}
|
|
84
|
+
return groups;
|
|
85
|
+
}
|
|
86
|
+
function SideMenu({ items, link, collapsed, footer, onNavigate, }) {
|
|
87
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto overscroll-contain px-2 py-3", children: groupsOf(items).map((group, i) => (_jsxs("div", { role: "group", "aria-label": group.label, className: "flex flex-col gap-px", children: [group.label ? (collapsed ? (i > 0 ? _jsx("span", { "aria-hidden": "true", className: "mx-3 mb-2 h-px bg-[var(--border-divider)]" }) : null) : (_jsx("p", { "aria-hidden": "true", className: "truncate px-2.5 pb-1 text-12 font-medium text-[var(--text-muted)]", children: group.label }))) : null, group.items.map((item) => {
|
|
88
|
+
const row = link({
|
|
89
|
+
href: item.href,
|
|
90
|
+
onClick: onNavigate,
|
|
91
|
+
"aria-current": item.active ? "page" : undefined,
|
|
92
|
+
className: cn("group/item relative flex h-8 items-center gap-2.5 rounded-md px-2.5 text-13 font-medium transition-colors outline-none", "focus-visible:ring-2 focus-visible:ring-[var(--primary)]", collapsed ? "justify-center px-0" : "", item.active
|
|
93
|
+
? "bg-[var(--surface-tertiary)] text-[var(--text-primary)]"
|
|
94
|
+
: "text-[var(--text-secondary)] hover:bg-[var(--surface-secondary)] hover:text-[var(--text-primary)]"),
|
|
95
|
+
children: (_jsxs(_Fragment, { children: [_jsxs("span", { "aria-hidden": "true", className: cn("relative flex shrink-0 [&>svg]:size-4", item.active ? "text-[var(--text-primary)]" : "text-[var(--text-muted)] group-hover/item:text-[var(--text-primary)]"), children: [item.icon, collapsed && item.badge ? _jsx(Dot, { className: "-top-1 -right-1" }) : null] }), _jsx("span", { className: cn("min-w-0 flex-1 truncate", collapsed ? "sr-only" : ""), children: item.label }), item.badge ? (collapsed ? (_jsx("span", { className: "sr-only", children: badgeText(item.badge) })) : typeof item.badge === "number" ? (_jsxs("span", { className: "text-12 text-[var(--text-muted)] tabular-nums", children: [item.badge, _jsx("span", { className: "sr-only", children: " new" })] })) : (_jsx("span", { className: "size-1.5 rounded-full bg-[var(--error)]", children: _jsx("span", { className: "sr-only", children: ", new" }) }))) : null] })),
|
|
96
|
+
});
|
|
97
|
+
return collapsed ? (_jsx(Tip, { text: item.label, children: row }, item.id)) : (React.cloneElement(row, { key: item.id }));
|
|
98
|
+
})] }, `${group.label ?? ""}-${i}`))) }), footer && !collapsed ? _jsx("div", { className: "shrink-0 px-2 pt-2 pb-3", children: footer }) : null] }));
|
|
99
|
+
}
|
|
100
|
+
// ── The shell ──────────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
function AppShell({ logo, logoMark, homeHref = "/", items, nav = "top", breadcrumbs, search, actions, account, sideFooter, renderLink, children, }) {
|
|
102
|
+
const link = renderLink ?? plainLink;
|
|
103
|
+
const side = nav === "side";
|
|
104
|
+
const collapsed = useCollapsed();
|
|
105
|
+
const [menuOpen, setMenuOpen] = React.useState(false);
|
|
106
|
+
// ⌘B / Ctrl+B shrinks or widens the side menu, as in shadcn's Sidebar.
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (!side)
|
|
109
|
+
return;
|
|
110
|
+
const onKey = (e) => {
|
|
111
|
+
if (e.key.toLowerCase() === "b" && (e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey) {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
setCollapsed(!getCollapsed());
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
document.addEventListener("keydown", onKey);
|
|
117
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
118
|
+
}, [side]);
|
|
119
|
+
const divider = _jsx("span", { "aria-hidden": "true", className: "hidden h-6 w-px shrink-0 bg-[var(--border-default)] md:block" });
|
|
120
|
+
const logoLink = (children, onClick) => link({
|
|
121
|
+
href: homeHref,
|
|
122
|
+
onClick,
|
|
123
|
+
className: "flex min-w-0 shrink-0 items-center rounded-sm transition-opacity outline-none hover:opacity-80 focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-offset-2",
|
|
124
|
+
children,
|
|
125
|
+
});
|
|
126
|
+
const toggle = (_jsx(Tip, { text: collapsed ? "Expand menu (⌘B)" : "Collapse menu (⌘B)", children: _jsx(IconButton, { size: "sm", "aria-label": collapsed ? "Expand menu" : "Collapse menu", "aria-keyshortcuts": "Meta+B Control+B", onClick: () => setCollapsed(!collapsed), children: collapsed ? _jsx(PanelLeftOpen, {}) : _jsx(PanelLeftClose, {}) }) }));
|
|
127
|
+
// The search's size follows the top bar's own width (a container query), not the window's, so the bar
|
|
128
|
+
// looks the same in every app and both layouts: an icon below 760px of bar, a 240px pill from 760px,
|
|
129
|
+
// 280px from 1200px. It always sits by the launcher.
|
|
130
|
+
const searchSized = React.isValidElement(search)
|
|
131
|
+
? React.cloneElement(search, { className: cn(search.props.className, SEARCH_SIZE) })
|
|
132
|
+
: search;
|
|
133
|
+
// The right of the top bar, the same in every app: search, the launcher, your account.
|
|
134
|
+
const right = (_jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-3 pl-4 md:gap-4 md:pl-8", children: [search ? _jsx("div", { className: "flex shrink-0 items-center", children: searchSized }) : null, actions ? _jsx("div", { className: "flex shrink-0 items-center gap-2 md:gap-4", children: actions }) : null, account ? (_jsxs(_Fragment, { children: [actions || search ? _jsx("span", { "aria-hidden": "true", className: "h-6 w-px shrink-0 bg-[var(--border-default)]" }) : null, _jsx("div", { className: "flex shrink-0 items-center", children: account })] })) : null] }));
|
|
135
|
+
const topBar = (_jsx("header", { "data-slot": "app-shell-top-bar", className: "glass-chrome @container sticky top-0 z-50 h-14 shrink-0 border-b border-[var(--glass-border)] bg-[var(--glass-bg)] backdrop-blur-2xl backdrop-saturate-150", children: _jsxs("nav", { "aria-label": "Top bar", className: "flex h-full items-center gap-3 px-4 md:gap-5 md:px-6 lg:px-8", children: [side ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "-ml-1.5 md:hidden", children: _jsx(IconButton, { size: "sm", "aria-label": "Open menu", "aria-expanded": menuOpen, onClick: () => setMenuOpen(true), children: _jsx(Menu, {}) }) }), _jsx("span", { className: "flex min-w-0 overflow-hidden md:hidden", children: logoLink(logo) }), breadcrumbs ? _jsx("div", { className: "hidden min-w-0 shrink md:flex", children: breadcrumbs }) : null] })) : (_jsxs(_Fragment, { children: [logoLink(logo), items.length ? (_jsxs(_Fragment, { children: [divider, _jsx(TopTabs, { items: items, link: link })] })) : null] })), right] }) }));
|
|
136
|
+
return (_jsxs("div", { "data-slot": "app-shell", "data-nav": nav, className: cn("flex min-h-dvh", side ? "flex-row" : "flex-col"), children: [_jsx(SkipLink, {}), side ? (_jsxs("nav", { "aria-label": "Main", "data-slot": "app-shell-side-menu", "data-collapsed": collapsed || undefined, className: cn("sticky top-0 hidden h-dvh shrink-0 flex-col border-r border-[var(--border-divider)] bg-[var(--surface-primary)] transition-[width] duration-200 ease-out motion-reduce:transition-none md:flex", collapsed ? "w-14" : "w-56"), children: [collapsed ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex h-14 shrink-0 items-center justify-center border-b border-[var(--glass-border)]", children: logoMark ? logoLink(logoMark) : null }), _jsx("div", { className: "flex shrink-0 justify-center pt-3", children: toggle })] })) : (_jsxs("div", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-[var(--glass-border)] pr-3 pl-4", children: [logoLink(logo), _jsx("span", { className: "ml-auto", children: toggle })] })), _jsx(SideMenu, { items: items, link: link, collapsed: collapsed, footer: sideFooter })] })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [topBar, _jsx("main", { id: "main", tabIndex: -1, className: cn("min-w-0 flex-1 outline-none", side ? "" : "max-md:pb-[calc(56px+env(safe-area-inset-bottom))]"), children: children })] }), !side && items.length ? _jsx(BottomBar, { items: items, link: link }) : null, side ? (_jsx(DialogPrimitive.Root, { open: menuOpen, onOpenChange: setMenuOpen, children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[60] bg-black/30 transition-opacity duration-300 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 md:hidden" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "app-shell-menu-sheet", className: cn("fixed inset-y-0 left-0 z-[60] flex w-72 max-w-[85vw] flex-col bg-[var(--surface-elevated)] shadow-[var(--shadow-drawer)] outline-none md:hidden", "transition-[translate] duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full motion-reduce:transition-none"), children: [_jsxs("div", { className: "flex h-14 shrink-0 items-center justify-between gap-3 border-b border-[var(--border-divider)] px-4 pt-[env(safe-area-inset-top)]", children: [_jsx(DialogPrimitive.Title, { className: "sr-only", children: "Menu" }), link({ href: homeHref, onClick: () => setMenuOpen(false), className: "flex items-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: logo }), _jsx(DialogPrimitive.Close, { render: _jsx(IconButton, { size: "sm", "aria-label": "Close menu", children: _jsx(X, {}) }) })] }), _jsx(SideMenu, { items: items, link: link, collapsed: false, footer: sideFooter, onNavigate: () => setMenuOpen(false) })] })] }) })) : null] }));
|
|
137
|
+
}
|
|
138
|
+
export { AppShell };
|
|
@@ -11,8 +11,10 @@ type BottomSheetProps = {
|
|
|
11
11
|
primaryAction?: DialogAction;
|
|
12
12
|
/** The footer button that closes without applying. Default "Cancel". Shown with `primaryAction`. */
|
|
13
13
|
cancelLabel?: string;
|
|
14
|
+
/** One link or small button beside the title, like a Popover's "See all" on a phone. */
|
|
15
|
+
action?: React.ReactNode;
|
|
14
16
|
};
|
|
15
|
-
declare function BottomSheet({ open, onClose, title, children, primaryAction, cancelLabel }: BottomSheetProps): React.JSX.Element;
|
|
17
|
+
declare function BottomSheet({ open, onClose, title, children, primaryAction, cancelLabel, action }: BottomSheetProps): React.JSX.Element;
|
|
16
18
|
/**
|
|
17
19
|
* The options in a sheet. One choice (default): a list where ↑ and ↓ move and Enter picks; Tab enters at the
|
|
18
20
|
* chosen row. `multiple`: a checkbox per row, ticked and unticked until Apply.
|
|
@@ -11,7 +11,7 @@ const SheetContext = React.createContext({ titleId: "" });
|
|
|
11
11
|
const CLOSE_AT = 1 / 3;
|
|
12
12
|
/** Or how fast, in px per ms: a quick flick closes it from anywhere. */
|
|
13
13
|
const FLICK = 0.5;
|
|
14
|
-
function BottomSheet({ open, onClose, title, children, primaryAction, cancelLabel = "Cancel" }) {
|
|
14
|
+
function BottomSheet({ open, onClose, title, children, primaryAction, cancelLabel = "Cancel", action }) {
|
|
15
15
|
const titleId = React.useId();
|
|
16
16
|
const popup = React.useRef(null);
|
|
17
17
|
const start = React.useRef(null);
|
|
@@ -47,7 +47,7 @@ function BottomSheet({ open, onClose, title, children, primaryAction, cancelLabe
|
|
|
47
47
|
}, onPointerMove: (e) => {
|
|
48
48
|
if (start.current)
|
|
49
49
|
setDrag(Math.max(0, e.clientY - start.current.y));
|
|
50
|
-
}, onPointerUp: (e) => endDrag(e.clientY), onPointerCancel: (e) => endDrag(e.clientY), children: [_jsx("div", { "aria-hidden": "true", className: "mx-auto mt-2 h-1 w-10 rounded-full bg-[var(--border-hover)]" }), _jsx(DialogPrimitive.Title, { id: titleId, className: "
|
|
50
|
+
}, onPointerUp: (e) => endDrag(e.clientY), onPointerCancel: (e) => endDrag(e.clientY), children: [_jsx("div", { "aria-hidden": "true", className: "mx-auto mt-2 h-1 w-10 rounded-full bg-[var(--border-hover)]" }), _jsxs("div", { className: "flex items-center gap-3 px-5 pt-3 pb-2", children: [_jsx(DialogPrimitive.Title, { id: titleId, className: "min-w-0 flex-1 text-16 font-bold tracking-tight text-[var(--text-primary)]", children: title }), action ? (_jsx("div", { className: "shrink-0", onPointerDown: (e) => e.stopPropagation(), children: action })) : null] })] }), _jsx("div", { "data-slot": "bottom-sheet-body", className: "min-h-0 flex-1 overflow-y-auto overscroll-contain", children: _jsx(SheetContext.Provider, { value: { titleId }, children: children }) }), primaryAction ? (_jsxs("footer", { "data-slot": "bottom-sheet-footer", className: "flex shrink-0 gap-2 border-t border-[var(--border-divider)] px-5 pt-3 pb-[max(12px,env(safe-area-inset-bottom))]", children: [_jsx(Button, { variant: "secondary", size: "md", onClick: onClose, className: "flex-1", children: cancelLabel }), _jsx(Button, { size: "md", disabled: primaryAction.disabled, icon: primaryAction.icon, onClick: primaryAction.onClick, className: "flex-1", children: primaryAction.label })] })) : null] })] }) }));
|
|
51
51
|
}
|
|
52
52
|
const OptionsContext = React.createContext({ multiple: false, tabStop: 0, index: 0 });
|
|
53
53
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type BreadcrumbsItem = {
|
|
3
|
+
/** "Firms". */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Leave it out on the last item: that's the page people are on. */
|
|
6
|
+
href?: string;
|
|
7
|
+
};
|
|
8
|
+
type BreadcrumbsLinkProps = {
|
|
9
|
+
href: string;
|
|
10
|
+
className: string;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
};
|
|
13
|
+
type BreadcrumbsProps = {
|
|
14
|
+
/** From the top down; the last is the page people are on. */
|
|
15
|
+
items: BreadcrumbsItem[];
|
|
16
|
+
/** Your router's link, as in AppShell: `(p) => <Link {...p} />`. Default a plain <a>. */
|
|
17
|
+
renderLink?: (props: BreadcrumbsLinkProps) => React.ReactElement;
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
declare function Breadcrumbs({ items, renderLink, className }: BreadcrumbsProps): React.JSX.Element;
|
|
21
|
+
export { Breadcrumbs };
|
|
22
|
+
export type { BreadcrumbsItem, BreadcrumbsLinkProps, BreadcrumbsProps };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronRight } from "lucide-react";
|
|
3
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
4
|
+
const plainLink = (props) => _jsx("a", { ...props });
|
|
5
|
+
function Breadcrumbs({ items, renderLink, className }) {
|
|
6
|
+
const link = renderLink ?? plainLink;
|
|
7
|
+
return (_jsx("nav", { "aria-label": "Breadcrumb", "data-slot": "breadcrumbs", className: cn("min-w-0", className), children: _jsx("ol", { className: "flex min-w-0 items-center gap-1.5 text-13", children: items.map((item, i) => {
|
|
8
|
+
const last = i === items.length - 1;
|
|
9
|
+
return (_jsxs("li", { className: cn("flex min-w-0 items-center gap-1.5", i < items.length - 2 ? "max-lg:hidden" : ""), children: [i > 0 ? _jsx(ChevronRight, { "aria-hidden": "true", className: "size-3.5 shrink-0 text-[var(--text-disabled)]" }) : null, last || !item.href ? (_jsx("span", { "aria-current": last ? "page" : undefined, className: cn("truncate", last ? "font-semibold text-[var(--text-primary)]" : "text-[var(--text-muted)]"), children: item.label })) : (link({
|
|
10
|
+
href: item.href,
|
|
11
|
+
className: "truncate rounded-sm text-[var(--text-muted)] transition-colors outline-none hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]",
|
|
12
|
+
children: item.label,
|
|
13
|
+
}))] }, `${item.label}-${i}`));
|
|
14
|
+
}) }) }));
|
|
15
|
+
}
|
|
16
|
+
export { Breadcrumbs };
|
package/components/data-table.js
CHANGED
|
@@ -90,7 +90,10 @@ function DataTable({ columns, rows, rowKey, onRowClick, onRowPrefetch, rowProps,
|
|
|
90
90
|
* so it stays while the rows load, fail or filter down to nothing.
|
|
91
91
|
*/
|
|
92
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 ? (
|
|
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 ? (
|
|
94
|
+
// Beside a search, filters and actions sit at the right. Without one, filters start at the left
|
|
95
|
+
// (a drawer's row of FilterChips) and actions stay at the right.
|
|
96
|
+
_jsxs("div", { className: cn("flex flex-1 flex-wrap items-center gap-3", search ? "md:justify-end" : ""), children: [filters ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: filters }) : null, actions ? _jsx("div", { className: cn("flex flex-wrap items-center gap-2", search ? "" : "ml-auto"), children: actions }) : null] })) : null] }));
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
96
99
|
* The loading body for a DataTable. Takes the same column list (without `render`), so its widths and
|
package/components/drawer.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { DialogAction } from "@brdgapp/ui/components/dialog";
|
|
|
3
3
|
declare const WIDTH: {
|
|
4
4
|
readonly item: "md:max-w-xl";
|
|
5
5
|
readonly list: "md:max-w-2xl";
|
|
6
|
+
readonly wide: "md:max-w-[min(1152px,calc(100vw-64px))]";
|
|
6
7
|
};
|
|
7
8
|
type DrawerProps = {
|
|
8
9
|
open: boolean;
|
|
@@ -11,8 +12,11 @@ type DrawerProps = {
|
|
|
11
12
|
title: React.ReactNode;
|
|
12
13
|
/** One line under the title: who, when. */
|
|
13
14
|
subtitle?: React.ReactNode;
|
|
14
|
-
/** `item` 576px for one record; `list` 672px for a list
|
|
15
|
+
/** `item` 576px for one record; `list` 672px for a list; `wide` 1152px for a table or a two-pane editor, with
|
|
16
|
+
* no padding round the body so it runs edge to edge. A phone fills the screen either way. */
|
|
15
17
|
size?: keyof typeof WIDTH;
|
|
18
|
+
/** Pinned under the header, above the scrolling body: a DataTableToolbar with the search and filters. */
|
|
19
|
+
toolbar?: React.ReactNode;
|
|
16
20
|
/** Actions beside the close button, such as an ActionMenu. Not Save: that goes in `primaryAction`. */
|
|
17
21
|
actions?: React.ReactNode;
|
|
18
22
|
/** For a drawer that edits: the footer's one filled button, bottom right. Spins while `busy`. */
|
|
@@ -26,6 +30,6 @@ type DrawerProps = {
|
|
|
26
30
|
children: React.ReactNode;
|
|
27
31
|
className?: string;
|
|
28
32
|
};
|
|
29
|
-
declare function Drawer({ open, onClose, title, subtitle, size, actions, primaryAction, cancelLabel, dangerAction, busy, children, className, }: DrawerProps): React.JSX.Element;
|
|
33
|
+
declare function Drawer({ open, onClose, title, subtitle, size, actions, toolbar, primaryAction, cancelLabel, dangerAction, busy, children, className, }: DrawerProps): React.JSX.Element;
|
|
30
34
|
export { Drawer };
|
|
31
35
|
export type { DrawerProps };
|
package/components/drawer.js
CHANGED
|
@@ -19,15 +19,22 @@ import { cn } from "@brdgapp/ui/lib/utils";
|
|
|
19
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
20
|
// (`primaryAction`, `cancelLabel`, `dangerAction`, the same options as Dialog); Save is never in the header,
|
|
21
21
|
// next to ✕. The header and footer stay put and only the body scrolls. Reduced motion: it fades, no slide.
|
|
22
|
-
|
|
22
|
+
//
|
|
23
|
+
// Added 2026-11-16 (Aman: "if a variant can solve the problem do the variant"), for Bridge OS's 1152px
|
|
24
|
+
// "Your contacts" table and app-directories' 896px page builder, the only side panels wider than 672px in
|
|
25
|
+
// the 12 apps: a third width, `wide`, 1152px, whose body runs edge to edge for a table or a two-pane editor,
|
|
26
|
+
// and always leaves 64px of the page showing on the left. And `toolbar`, pinned under the header so search and
|
|
27
|
+
// filters stay put while the list scrolls (both Bridge OS list drawers have them). It takes a DataTableToolbar,
|
|
28
|
+
// the one row for search and filters everywhere, so the drawer adds no styling of its own.
|
|
29
|
+
const WIDTH = { item: "md:max-w-xl", list: "md:max-w-2xl", wide: "md:max-w-[min(1152px,calc(100vw-64px))]" };
|
|
23
30
|
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, }) {
|
|
31
|
+
function Drawer({ open, onClose, title, subtitle, size = "item", actions, toolbar, primaryAction, cancelLabel = "Cancel", dangerAction, busy = false, children, className, }) {
|
|
25
32
|
const body = React.useRef(null);
|
|
26
33
|
return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => !next && !busy && onClose(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-x-0 top-0 bottom-0 z-[60] md:top-14 bg-black/30 transition-opacity duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "drawer", "data-size": size,
|
|
27
34
|
// An edit drawer starts in its first field; a details drawer starts on its first control.
|
|
28
35
|
initialFocus: (openType) => (openType === "touch" ? true : (body.current?.querySelector(FIRST_FIELD) ?? true)), className: cn(
|
|
29
36
|
// 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,
|
|
37
|
+
"fixed inset-0 z-[60] flex w-full flex-col bg-[var(--surface-elevated)] outline-none md:top-14 md:left-auto md:border-l md:border-[var(--border-default)] md:shadow-[var(--shadow-drawer)]", "transition-[translate,opacity] duration-300 ease-out data-[ending-style]:duration-200 data-[starting-style]:translate-x-full data-[ending-style]:translate-x-full", "motion-reduce:transition-opacity motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0 motion-reduce:data-[starting-style]:opacity-0 motion-reduce:data-[ending-style]:opacity-0", WIDTH[size], className), children: [_jsxs("header", { "data-slot": "drawer-header", className: "flex shrink-0 items-start gap-2 border-b border-[var(--border-divider)] px-6 py-4 max-md:px-5 max-md:pt-[max(16px,env(safe-area-inset-top))]", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(DialogPrimitive.Title, { className: "truncate text-18 font-bold tracking-tight text-[var(--text-primary)]", children: title }), subtitle ? (_jsx(DialogPrimitive.Description, { className: "mt-0.5 truncate text-12 leading-normal text-[var(--text-muted)]", children: subtitle })) : null] }), actions, _jsx(DialogPrimitive.Close, { disabled: busy, render: _jsx(IconButton, { "aria-label": "Close", size: "sm", children: _jsx(X, {}) }) })] }), toolbar ? (_jsx("div", { "data-slot": "drawer-toolbar", className: "shrink-0", children: toolbar })) : null, _jsx("div", { ref: body, "data-slot": "drawer-body", className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain", size === "wide" ? "" : "px-6 py-5 max-md:px-5"), children: children }), primaryAction || dangerAction ? (_jsxs("footer", { "data-slot": "drawer-footer", className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-[var(--border-divider)] px-6 py-4 pb-[max(16px,env(safe-area-inset-bottom))] max-md:px-5", children: [dangerAction ? (_jsx(Button, { variant: "danger-ghost", size: "md", icon: dangerAction.icon, disabled: busy || dangerAction.disabled, onClick: dangerAction.onClick,
|
|
31
38
|
// Phone: its own row above Cancel and the main button, so the three never squeeze into one.
|
|
32
39
|
className: "mr-auto max-md:mr-0 max-md:w-full", children: dangerAction.label })) : null, primaryAction ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "secondary", size: "md", disabled: busy, onClick: onClose, className: "max-md:flex-1", children: cancelLabel }), _jsx(Button, { size: "md", loading: busy, disabled: primaryAction.disabled, icon: primaryAction.icon, onClick: primaryAction.onClick, className: "max-md:flex-1", children: primaryAction.label })] })) : null] })) : null] })] }) }));
|
|
33
40
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type GlobalSearchItem = {
|
|
3
|
+
/** Unique within its list. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The name: a person, an organization, a list. */
|
|
6
|
+
title: string;
|
|
7
|
+
/** One line under it: role and company, people you know there. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** An Avatar, a logo or a favicon, up to 40px. */
|
|
10
|
+
leading?: React.ReactNode;
|
|
11
|
+
/** Open it. Add it to the app's recents here. The search closes itself afterwards. */
|
|
12
|
+
onSelect: () => void;
|
|
13
|
+
};
|
|
14
|
+
type GlobalSearchGroup = {
|
|
15
|
+
/** Unique: "people", "orgs". */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Plural, as the chip and heading say it: "People", "Organizations". */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Matches for the query. Shown once two characters are typed. */
|
|
20
|
+
results: GlobalSearchItem[];
|
|
21
|
+
/** What the person opened lately, newest first. Shown before anything is typed. */
|
|
22
|
+
recent: GlobalSearchItem[];
|
|
23
|
+
/** Shown before anything is typed when `recent` is empty, so the list is never blank: the people you know best, your top organizations. */
|
|
24
|
+
suggested: GlobalSearchItem[];
|
|
25
|
+
/** The list being shown is still loading: skeleton rows in its place. */
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
/** The search for this list failed: an error with Try again in its place. */
|
|
28
|
+
failed?: boolean;
|
|
29
|
+
/** Try the failed search again. */
|
|
30
|
+
onRetry?: () => void;
|
|
31
|
+
/** How many match in all, when more can load. Shown in the heading when this list is shown alone. */
|
|
32
|
+
total?: number;
|
|
33
|
+
/** Load the next page of results: a Load more link under them. */
|
|
34
|
+
onLoadMore?: () => void;
|
|
35
|
+
/** The next page is loading: Load more spins. */
|
|
36
|
+
loadingMore?: boolean;
|
|
37
|
+
/** Take one item out of `recent`: a ✕ on the row, and Shift+Delete. */
|
|
38
|
+
onRemoveRecent?: (id: string) => void;
|
|
39
|
+
/** Empty `recent`: a Clear button in the heading. */
|
|
40
|
+
onClearRecent?: () => void;
|
|
41
|
+
/** One thing to try when nothing matches: "Try a different name, company, or spelling." */
|
|
42
|
+
noResultsHint?: string;
|
|
43
|
+
/** A filter for these results, like a FilterPill for 1st or 2nd degree. Shown in the heading while searching. */
|
|
44
|
+
filter?: React.ReactNode;
|
|
45
|
+
};
|
|
46
|
+
type GlobalSearchProps = {
|
|
47
|
+
open: boolean;
|
|
48
|
+
/** Called on Esc, ✕, the backdrop, and after a row is opened. */
|
|
49
|
+
onClose: () => void;
|
|
50
|
+
/** The text typed. You own it, so you can debounce the search. */
|
|
51
|
+
query: string;
|
|
52
|
+
onQueryChange: (query: string) => void;
|
|
53
|
+
/** Names every list it searches: "Search people and organizations". */
|
|
54
|
+
placeholder: string;
|
|
55
|
+
/** One per kind of thing, in the order they should appear. */
|
|
56
|
+
groups: GlobalSearchGroup[];
|
|
57
|
+
};
|
|
58
|
+
declare function GlobalSearch({ open, onClose, query, onQueryChange, placeholder, groups }: GlobalSearchProps): React.JSX.Element;
|
|
59
|
+
type GlobalSearchTriggerProps = {
|
|
60
|
+
/** Open the search. ⌘K (Ctrl+K off a Mac) calls it too, from anywhere in the app. */
|
|
61
|
+
onOpen: () => void;
|
|
62
|
+
/** What it searches: "Search your network". Shown in the field, and read out on phones where only the icon shows. */
|
|
63
|
+
label: string;
|
|
64
|
+
/** Layout only: the width at each screen size. */
|
|
65
|
+
className?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The search field in the top bar that opens GlobalSearch, from Bridge OS's NetworkSearchBar: a slim pill
|
|
69
|
+
* with ⌘K on computers, a round search button on phones. It owns the ⌘K shortcut, so put one in each app.
|
|
70
|
+
*/
|
|
71
|
+
declare function GlobalSearchTrigger({ onOpen, label, className }: GlobalSearchTriggerProps): React.JSX.Element;
|
|
72
|
+
export { GlobalSearch, GlobalSearchTrigger };
|
|
73
|
+
export type { GlobalSearchGroup, GlobalSearchItem, GlobalSearchProps, GlobalSearchTriggerProps };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
5
|
+
import { ChevronRight, Search, X } from "lucide-react";
|
|
6
|
+
import { Button } from "@brdgapp/ui/components/button";
|
|
7
|
+
import { DataStateEmpty, DataStateError } from "@brdgapp/ui/components/data-state";
|
|
8
|
+
import { FilterChip } from "@brdgapp/ui/components/filter-chip";
|
|
9
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
10
|
+
import { Skeleton } from "@brdgapp/ui/components/skeleton";
|
|
11
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
12
|
+
// The ⌘K search, one for every app (Aman, 2026-11-12). The look is Bridge OS's network-search-overlay: the
|
|
13
|
+
// tall input row, All / People / Organizations chips, and the lists side by side under small uppercase
|
|
14
|
+
// headings. Decisions:
|
|
15
|
+
// - ⌘K (Ctrl+K off a Mac) only opens search. No commands, no "go to" actions.
|
|
16
|
+
// - The lists sit in columns, two to a row. A third goes on its own full-width row below; a fourth joins it.
|
|
17
|
+
// - The box fits what's in it: one list is 560px wide, two or more 1040px; it grows with the rows up to 80%
|
|
18
|
+
// of the screen, then scrolls. On a phone it fills the screen, like every full-screen panel.
|
|
19
|
+
// - It's never empty. Before anything is typed each list shows what you opened recently, or suggestions
|
|
20
|
+
// when there's nothing recent yet.
|
|
21
|
+
// - Moving through it works like shadcn's Command (cmdk): focus stays in the input, ↑ ↓ move through every
|
|
22
|
+
// row in reading order (down the first column, then the next), Home and End jump, Enter opens, and the
|
|
23
|
+
// pointer moves the highlight too.
|
|
24
|
+
// Unlike the Bridge OS overlay, it's a real dialog (Base UI): screen readers are told, and Tab stays inside.
|
|
25
|
+
/** Searching starts at two characters, the same in every app. */
|
|
26
|
+
const MIN_QUERY = 2;
|
|
27
|
+
const SKELETON_ROWS = 5;
|
|
28
|
+
function shownFor(group, searching) {
|
|
29
|
+
if (searching)
|
|
30
|
+
return { kind: "results", items: group.results };
|
|
31
|
+
if (group.recent.length > 0)
|
|
32
|
+
return { kind: "recent", items: group.recent };
|
|
33
|
+
return { kind: "suggested", items: group.suggested };
|
|
34
|
+
}
|
|
35
|
+
function headingFor(group, kind) {
|
|
36
|
+
if (kind === "results")
|
|
37
|
+
return group.label;
|
|
38
|
+
const name = group.label.toLowerCase();
|
|
39
|
+
return kind === "recent" ? `Recent ${name}` : `Suggested ${name}`;
|
|
40
|
+
}
|
|
41
|
+
const domId = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
42
|
+
function GlobalSearch({ open, onClose, query, onQueryChange, placeholder, groups }) {
|
|
43
|
+
const baseId = React.useId();
|
|
44
|
+
const inputRef = React.useRef(null);
|
|
45
|
+
const [view, setView] = React.useState("all");
|
|
46
|
+
// The highlighted row, remembered with the rows it was picked from: when the rows change it goes back to
|
|
47
|
+
// the first one, as cmdk does.
|
|
48
|
+
const [picked, setPicked] = React.useState(null);
|
|
49
|
+
const searching = query.trim().length >= MIN_QUERY;
|
|
50
|
+
// A chip for a list that's gone falls back to All.
|
|
51
|
+
const visible = view === "all" ? groups : groups.filter((g) => g.id === view);
|
|
52
|
+
const shownGroups = visible.length > 0 ? visible : groups;
|
|
53
|
+
// Every row in reading order: down the first list, then the next. ↑ ↓ follow this, as cmdk does.
|
|
54
|
+
const rows = shownGroups.flatMap((g) => {
|
|
55
|
+
const shown = shownFor(g, searching);
|
|
56
|
+
if (g.loading || (shown.kind === "results" && g.failed))
|
|
57
|
+
return [];
|
|
58
|
+
return shown.items.map((item) => ({ key: `${g.id}\u0000${item.id}`, group: g, item, kind: shown.kind }));
|
|
59
|
+
});
|
|
60
|
+
const rowKeys = rows.map((r) => r.key).join("\u0001");
|
|
61
|
+
const active = (picked?.rows === rowKeys ? rows.find((r) => r.key === picked.key) : undefined) ?? rows[0];
|
|
62
|
+
const setActiveKey = (key) => setPicked({ key, rows: rowKeys });
|
|
63
|
+
const optionId = (key) => `${baseId}-opt-${domId(key)}`;
|
|
64
|
+
// Each time it closes it goes back to All, ready for the next time.
|
|
65
|
+
const close = () => {
|
|
66
|
+
setView("all");
|
|
67
|
+
onClose();
|
|
68
|
+
};
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (!active)
|
|
71
|
+
return;
|
|
72
|
+
document.getElementById(optionId(active.key))?.scrollIntoView({ block: "nearest" });
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
|
+
}, [active?.key]);
|
|
75
|
+
if (process.env.NODE_ENV !== "production") {
|
|
76
|
+
for (const g of groups) {
|
|
77
|
+
if (!g.loading && g.recent.length === 0 && g.suggested.length === 0) {
|
|
78
|
+
console.warn(`GlobalSearch: "${g.label}" has nothing recent and no suggestions. Give it suggestions, so the search is never empty.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const choose = (item) => {
|
|
83
|
+
item.onSelect();
|
|
84
|
+
close();
|
|
85
|
+
};
|
|
86
|
+
const move = (to) => {
|
|
87
|
+
const next = rows[Math.max(0, Math.min(rows.length - 1, to))];
|
|
88
|
+
if (next)
|
|
89
|
+
setActiveKey(next.key);
|
|
90
|
+
};
|
|
91
|
+
const onKeyDown = (e) => {
|
|
92
|
+
const at = active ? rows.indexOf(active) : -1;
|
|
93
|
+
const ctrl = e.ctrlKey && !e.metaKey && !e.altKey;
|
|
94
|
+
if (e.key === "ArrowDown" || (ctrl && (e.key === "n" || e.key === "j"))) {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
move(at + 1);
|
|
97
|
+
}
|
|
98
|
+
else if (e.key === "ArrowUp" || (ctrl && (e.key === "p" || e.key === "k"))) {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
move(at - 1);
|
|
101
|
+
}
|
|
102
|
+
else if (e.key === "Home" && rows.length > 0) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
move(0);
|
|
105
|
+
}
|
|
106
|
+
else if (e.key === "End" && rows.length > 0) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
move(rows.length - 1);
|
|
109
|
+
}
|
|
110
|
+
else if (e.key === "Enter" && active && !e.nativeEvent.isComposing) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
choose(active.item);
|
|
113
|
+
}
|
|
114
|
+
else if ((e.key === "Delete" || e.key === "Backspace") && e.shiftKey && active?.kind === "recent" && active.group.onRemoveRecent) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
active.group.onRemoveRecent(active.item.id);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const columns = groups.length > 1 ? 2 : 1;
|
|
120
|
+
const announce = searching && shownGroups.every((g) => !g.loading)
|
|
121
|
+
? shownGroups.map((g) => `${g.label}: ${g.failed ? "couldn't load" : g.results.length}`).join(". ")
|
|
122
|
+
: "";
|
|
123
|
+
return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => !next && close(), children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[90] bg-black/40 backdrop-blur-sm transition-opacity duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "global-search", initialFocus: inputRef, "aria-label": placeholder, className: cn("fixed z-[90] flex flex-col overflow-hidden bg-[var(--surface-elevated)] outline-none",
|
|
124
|
+
// Phone: the whole screen.
|
|
125
|
+
"max-md:inset-0",
|
|
126
|
+
// Computer: near the top, as wide as its lists need, as tall as its rows up to 80% of the screen.
|
|
127
|
+
"md:top-[10vh] md:left-1/2 md:max-h-[min(80vh,720px)] md:w-[calc(100vw-32px)] md:-translate-x-1/2 md:rounded-2xl md:border md:border-[var(--border-default)] md:shadow-[var(--shadow-dialog)]", columns === 2 ? "md:max-w-[1040px]" : "md:max-w-[560px]", "transition-[opacity,scale,translate] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)] data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 md:data-[starting-style]:scale-[0.98] md:data-[ending-style]:scale-[0.98] motion-reduce:transition-none"), children: [_jsxs("div", { "data-slot": "global-search-input", className: "relative shrink-0 border-b border-[var(--border-divider)] max-md:pt-[env(safe-area-inset-top)]", children: [_jsx(Search, { "aria-hidden": "true", className: "pointer-events-none absolute bottom-[19px] left-5 size-[18px] text-[var(--text-muted)]" }), _jsx("input", { ref: inputRef, type: "text", role: "combobox", "aria-expanded": "true", "aria-autocomplete": "list", "aria-controls": shownGroups.map((g) => `${baseId}-list-${domId(g.id)}`).join(" "), "aria-activedescendant": active ? optionId(active.key) : undefined, "aria-label": placeholder, autoComplete: "off", spellCheck: false, value: query, placeholder: placeholder, onChange: (e) => onQueryChange(e.target.value), onKeyDown: onKeyDown, className: "h-14 w-full bg-transparent pr-24 pl-[52px] text-16 text-[var(--text-primary)] placeholder:text-[var(--text-muted)] focus:outline-none" }), _jsxs("div", { className: "absolute right-4 bottom-[18px] flex items-center gap-2", children: [query ? (_jsx(IconButton, { size: "xs", "aria-label": "Clear search", onClick: () => {
|
|
128
|
+
onQueryChange("");
|
|
129
|
+
inputRef.current?.focus();
|
|
130
|
+
}, children: _jsx(X, {}) })) : null, _jsx("kbd", { className: "hidden h-5 items-center rounded border border-[var(--border-default)] bg-[var(--surface-secondary)] px-1.5 text-11 font-semibold text-[var(--text-muted)] md:inline-flex", children: "Esc" }), _jsx(DialogPrimitive.Close, { render: _jsx(Button, { variant: "ghost", size: "sm", className: "md:hidden", children: "Cancel" }) })] })] }), groups.length > 1 ? (_jsxs("div", { "data-slot": "global-search-chips", className: "flex shrink-0 items-center gap-1.5 overflow-x-auto border-b border-[var(--border-divider)] px-4 py-2.5", children: [_jsx(FilterChip, { active: view === "all", onClick: () => setView("all"), children: "All" }), groups.map((g) => (_jsx(FilterChip, { active: view === g.id, onClick: () => setView(view === g.id ? "all" : g.id), children: g.label }, g.id)))] })) : null, _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain", children: _jsx("div", { className: cn("grid", shownGroups.length > 1 && "md:grid-cols-2"), children: shownGroups.map((g, i) => {
|
|
131
|
+
const shown = shownFor(g, searching);
|
|
132
|
+
const twoUp = shownGroups.length > 1;
|
|
133
|
+
const spans = twoUp && i === shownGroups.length - 1 && i % 2 === 0;
|
|
134
|
+
return (_jsx(GroupColumn, { group: g, shown: shown, query: query.trim(), alone: shownGroups.length === 1, listId: `${baseId}-list-${domId(g.id)}`, headingId: `${baseId}-heading-${domId(g.id)}`, optionId: (item) => optionId(`${g.id}\u0000${item.id}`), activeId: active?.group.id === g.id ? active.item.id : null, onHover: (item) => setActiveKey(`${g.id}\u0000${item.id}`), onChoose: choose, className: cn(i > 0 && "border-t border-[var(--border-divider)]", twoUp && i === 1 && "md:border-t-0 md:border-l", twoUp && i > 1 && i % 2 === 1 && !spans && "md:border-l", spans && "md:col-span-2") }, g.id));
|
|
135
|
+
}) }) }), _jsx("span", { role: "status", className: "sr-only", children: announce })] })] }) }));
|
|
136
|
+
}
|
|
137
|
+
function GroupColumn({ group, shown, query, alone, listId, headingId, optionId, activeId, onHover, onChoose, className }) {
|
|
138
|
+
const searching = shown.kind === "results";
|
|
139
|
+
const meta = alone && searching && !group.loading && group.total != null && group.total > 0 ? `${group.total.toLocaleString("en-US")} found` : null;
|
|
140
|
+
const action = searching ? group.filter : shown.kind === "recent" && group.onClearRecent ? (_jsx(Button, { variant: "ghost", size: "xs", onClick: group.onClearRecent, children: "Clear" })) : null;
|
|
141
|
+
let body;
|
|
142
|
+
if (group.loading) {
|
|
143
|
+
body = (_jsx("div", { "aria-hidden": "true", children: Array.from({ length: SKELETON_ROWS }, (_, i) => (_jsxs("div", { className: "flex items-center gap-3 px-4 py-3", children: [_jsx(Skeleton, { shape: "circle", className: "size-10 shrink-0" }), _jsxs("div", { className: "flex-1 space-y-2", children: [_jsx(Skeleton, { className: "h-3 w-1/3" }), _jsx(Skeleton, { className: "h-2.5 w-1/2" })] })] }, i))) }));
|
|
144
|
+
}
|
|
145
|
+
else if (searching && group.failed) {
|
|
146
|
+
body = _jsx(DataStateError, { subject: group.label.toLowerCase(), onRetry: group.onRetry });
|
|
147
|
+
}
|
|
148
|
+
else if (searching && shown.items.length === 0) {
|
|
149
|
+
body = (_jsx(DataStateEmpty, { illustration: "search", illustrationSize: "sm", title: `No ${group.label.toLowerCase()} match “${query}”`, description: group.noResultsHint }));
|
|
150
|
+
}
|
|
151
|
+
else if (shown.items.length === 0) {
|
|
152
|
+
// Only when an app gave no suggestions (it's warned in development).
|
|
153
|
+
body = _jsxs("p", { className: "px-4 py-6 text-13 text-[var(--text-muted)]", children: ["Type to search ", group.label.toLowerCase(), "."] });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
body = (_jsxs("div", { id: listId, role: "listbox", "aria-labelledby": headingId, children: [shown.items.map((item) => (_jsx(SearchRow, { id: optionId(item), item: item, active: activeId === item.id, onHover: () => onHover(item), onChoose: () => onChoose(item), onRemove: shown.kind === "recent" && group.onRemoveRecent ? () => group.onRemoveRecent?.(item.id) : undefined }, item.id))), searching && group.onLoadMore ? (_jsx("div", { role: "presentation", className: "flex justify-center px-4 py-3", children: _jsx(Button, { variant: "link", loading: group.loadingMore, onClick: group.onLoadMore, children: group.loadingMore ? "Loading…" : "Load more" }) })) : null] }));
|
|
157
|
+
}
|
|
158
|
+
return (_jsxs("section", { "data-slot": "global-search-group", "aria-labelledby": headingId, className: cn("min-w-0", className), children: [_jsxs("div", { className: "sticky top-0 z-[1] flex h-10 items-center justify-between gap-3 bg-[var(--surface-elevated)] px-4", children: [_jsxs("div", { className: "flex min-w-0 items-baseline gap-2", children: [_jsx("h2", { id: headingId, className: "text-11 font-bold tracking-[0.55px] text-[var(--text-muted)] uppercase", children: headingFor(group, shown.kind) }), meta ? _jsx("span", { className: "truncate text-11 text-[var(--text-muted)]", children: meta }) : null] }), action] }), body] }));
|
|
159
|
+
}
|
|
160
|
+
function SearchRow({ id, item, active, onHover, onChoose, onRemove }) {
|
|
161
|
+
return (_jsxs("div", { id: id, role: "option", "aria-selected": active, "data-slot": "global-search-row", "data-active": active || undefined, onPointerMove: () => !active && onHover(),
|
|
162
|
+
// Keep focus in the input, so typing carries on after a click.
|
|
163
|
+
onMouseDown: (e) => e.preventDefault(), onClick: onChoose, className: "group/row relative flex cursor-pointer items-center gap-3 px-4 py-3 transition-colors data-[active]:bg-[var(--surface-secondary)]", children: [item.leading ? _jsx("span", { className: "flex size-10 shrink-0 items-center justify-center", children: item.leading }) : null, _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate text-14 font-bold tracking-tight text-[var(--text-primary)]", children: item.title }), item.description ? _jsx("span", { className: "mt-0.5 block truncate text-12 text-[var(--text-muted)]", children: item.description }) : null] }), onRemove ? (_jsx(IconButton, { size: "xs", tabIndex: -1, "aria-label": `Remove ${item.title} from recents`, onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
onRemove();
|
|
166
|
+
}, className: "opacity-0 group-hover/row:opacity-100 group-data-[active]/row:opacity-100", children: _jsx(X, {}) })) : null, _jsx(ChevronRight, { "aria-hidden": "true", className: "size-4 shrink-0 text-[var(--text-disabled)]" })] }));
|
|
167
|
+
}
|
|
168
|
+
/** Triggers on the page, oldest first. */
|
|
169
|
+
const MOUNTED = [];
|
|
170
|
+
const noSubscribe = () => () => { };
|
|
171
|
+
const isApple = () => /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
172
|
+
/**
|
|
173
|
+
* The search field in the top bar that opens GlobalSearch, from Bridge OS's NetworkSearchBar: a slim pill
|
|
174
|
+
* with ⌘K on computers, a round search button on phones. It owns the ⌘K shortcut, so put one in each app.
|
|
175
|
+
*/
|
|
176
|
+
function GlobalSearchTrigger({ onOpen, label, className }) {
|
|
177
|
+
const mac = React.useSyncExternalStore(noSubscribe, isApple, () => true);
|
|
178
|
+
const openRef = React.useRef(onOpen);
|
|
179
|
+
React.useEffect(() => {
|
|
180
|
+
openRef.current = onOpen;
|
|
181
|
+
});
|
|
182
|
+
React.useEffect(() => {
|
|
183
|
+
const me = Symbol();
|
|
184
|
+
MOUNTED.push(me);
|
|
185
|
+
const onKey = (e) => {
|
|
186
|
+
// With more than one on a page (a docs page), only the first answers ⌘K.
|
|
187
|
+
if (MOUNTED[0] !== me || e.defaultPrevented)
|
|
188
|
+
return;
|
|
189
|
+
if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === "k") {
|
|
190
|
+
e.preventDefault();
|
|
191
|
+
openRef.current();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
document.addEventListener("keydown", onKey);
|
|
195
|
+
return () => {
|
|
196
|
+
document.removeEventListener("keydown", onKey);
|
|
197
|
+
MOUNTED.splice(MOUNTED.indexOf(me), 1);
|
|
198
|
+
};
|
|
199
|
+
}, []);
|
|
200
|
+
return (_jsxs("button", { type: "button", "data-slot": "global-search-trigger", onClick: onOpen, "aria-label": label, "aria-haspopup": "dialog", "aria-keyshortcuts": mac ? "Meta+K" : "Control+K", className: cn("flex h-9 shrink-0 items-center gap-2 rounded-full border border-[var(--border-hover)] bg-[var(--surface-secondary)] text-[var(--text-muted)] transition-colors outline-none", "hover:border-[var(--primary)] hover:text-[var(--text-body)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]", "w-9 justify-center sm:w-[340px] sm:justify-start sm:px-3.5 lg:w-[440px] xl:w-[520px]", className), children: [_jsx(Search, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "hidden flex-1 truncate text-left text-13 sm:block", children: label }), _jsx("kbd", { "aria-hidden": "true", className: "hidden h-5 shrink-0 items-center rounded border border-[var(--border-default)] bg-[var(--surface-primary)] px-1.5 text-11 font-semibold text-[var(--text-muted)] sm:inline-flex", children: mac ? "⌘K" : "Ctrl K" })] }));
|
|
201
|
+
}
|
|
202
|
+
export { GlobalSearch, GlobalSearchTrigger };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare const WIDTHS: {
|
|
3
|
+
readonly default: "w-80";
|
|
4
|
+
readonly wide: "w-[460px]";
|
|
5
|
+
};
|
|
6
|
+
type PopoverProps = {
|
|
7
|
+
/** The button that opens it: an IconButton, a Button or an Avatar button. One element. */
|
|
8
|
+
trigger: React.ReactElement<React.HTMLAttributes<HTMLElement>>;
|
|
9
|
+
/** Names the panel: "All apps", "Your account". The heading on a computer, and the sheet's title on a phone. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Leave the heading row out on a computer, when the content says what it is (the account menu starts with your name). The phone sheet still shows the title. */
|
|
12
|
+
hideTitle?: boolean;
|
|
13
|
+
/** One link or small button beside the title: "See more". */
|
|
14
|
+
action?: React.ReactNode;
|
|
15
|
+
/** `default` 320px; `wide` 460px, for a grid like the app launcher. Phones use the whole width either way. */
|
|
16
|
+
size?: keyof typeof WIDTHS;
|
|
17
|
+
/** Which edge of the trigger it lines up with. `end` for a button at the right of the top bar. */
|
|
18
|
+
align?: "start" | "center" | "end";
|
|
19
|
+
/** Control it, to close it when a link inside is clicked. Leave both out and it opens and closes itself. */
|
|
20
|
+
open?: boolean;
|
|
21
|
+
onOpenChange?: (open: boolean) => void;
|
|
22
|
+
/** What's inside. */
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
};
|
|
25
|
+
declare function Popover({ trigger, title, hideTitle, action, size, align, open: openProp, onOpenChange, children }: PopoverProps): React.JSX.Element;
|
|
26
|
+
export { Popover };
|
|
27
|
+
export type { PopoverProps };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
|
|
5
|
+
import { BottomSheet } from "@brdgapp/ui/components/bottom-sheet";
|
|
6
|
+
import { useIsMobile } from "@brdgapp/ui/hooks/use-is-mobile";
|
|
7
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
8
|
+
// A panel that opens from a button and holds anything: the account menu, the app launcher, a small form.
|
|
9
|
+
// Asked for by Bridge OS, whose account menu and app launcher were built on a Radix DropdownMenu, which
|
|
10
|
+
// tells screen readers "menu" and then holds tiles and buttons a menu can't move through. About 85 files
|
|
11
|
+
// in six apps build a popover of their own (raise 24, app-portfolio 24, app-cc 18).
|
|
12
|
+
//
|
|
13
|
+
// Decisions (Aman, 2026-11-12):
|
|
14
|
+
// - Two widths: 320px by default (the account menu; the apps' most common is 256–320px) and `wide`
|
|
15
|
+
// 460px (the app launcher).
|
|
16
|
+
// - An optional heading row: the title, with one link or button beside it ("See more").
|
|
17
|
+
// - On a phone (below 768px) it slides up from the bottom as a BottomSheet, like every other sheet.
|
|
18
|
+
// For a list of actions use ActionMenu; for a preview on hover, HoverCard; for a hint, InfoHint.
|
|
19
|
+
// The surface is the menus': --surface-elevated, a border, --shadow-menu, 12px corners, z-[80].
|
|
20
|
+
const WIDTHS = { default: "w-80", wide: "w-[460px]" };
|
|
21
|
+
function Popover({ trigger, title, hideTitle = false, action, size = "default", align = "start", open: openProp, onOpenChange, children }) {
|
|
22
|
+
const mobile = useIsMobile();
|
|
23
|
+
const [ownOpen, setOwnOpen] = React.useState(false);
|
|
24
|
+
const open = openProp ?? ownOpen;
|
|
25
|
+
const setOpen = (next) => {
|
|
26
|
+
if (openProp === undefined)
|
|
27
|
+
setOwnOpen(next);
|
|
28
|
+
onOpenChange?.(next);
|
|
29
|
+
};
|
|
30
|
+
// Phones: the trigger opens a sheet from the bottom, with the same content.
|
|
31
|
+
if (mobile) {
|
|
32
|
+
const props = trigger.props;
|
|
33
|
+
return (_jsxs(_Fragment, { children: [React.cloneElement(trigger, {
|
|
34
|
+
"aria-haspopup": "dialog",
|
|
35
|
+
"aria-expanded": open,
|
|
36
|
+
onClick: (e) => {
|
|
37
|
+
props.onClick?.(e);
|
|
38
|
+
if (!e.defaultPrevented)
|
|
39
|
+
setOpen(true);
|
|
40
|
+
},
|
|
41
|
+
}), _jsx(BottomSheet, { open: open, onClose: () => setOpen(false), title: title, action: action, children: _jsx("div", { "data-slot": "popover-body", className: "px-5 pt-1 pb-3", children: children }) })] }));
|
|
42
|
+
}
|
|
43
|
+
return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverPrimitive.Trigger, { render: trigger }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Positioner, { side: "bottom", align: align, sideOffset: 8, collisionPadding: 12, className: "z-[80]", children: _jsxs(PopoverPrimitive.Popup, { "data-slot": "popover", "aria-label": hideTitle ? title : undefined, className: cn("flex max-h-[min(70vh,var(--available-height))] max-w-[calc(100vw-24px)] origin-[var(--transform-origin)] flex-col overflow-hidden rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none", "transition-[opacity,scale] duration-200 ease-out data-[ending-style]:duration-150 motion-reduce:transition-none", "data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:scale-95 data-[ending-style]:opacity-0", WIDTHS[size]), children: [hideTitle ? null : (_jsxs("div", { "data-slot": "popover-header", className: "flex h-12 shrink-0 items-center justify-between gap-3 border-b border-[var(--border-divider)] px-4", children: [_jsx(PopoverPrimitive.Title, { className: "min-w-0 truncate text-14 font-bold tracking-[-0.01em] text-[var(--text-primary)]", children: title }), action] })), _jsx("div", { "data-slot": "popover-body", className: "min-h-0 flex-1 overflow-y-auto overscroll-contain p-4", children: children })] }) }) })] }));
|
|
44
|
+
}
|
|
45
|
+
export { Popover };
|
package/components/tag.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as React from "react";
|
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
import { type ElementProps } from "@brdgapp/ui/lib/utils";
|
|
4
4
|
declare const tagVariants: (props?: ({
|
|
5
|
-
color?: "
|
|
5
|
+
color?: "grey" | "blue" | "green" | "yellow" | "red" | "purple" | null | undefined;
|
|
6
6
|
size?: "sm" | "md" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
type TagProps = VariantProps<typeof tagVariants> & ElementProps & {
|
package/package.json
CHANGED