@brdgapp/ui 1.3.0 → 1.4.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 +16 -0
- package/components/app-launcher.d.ts +22 -0
- package/components/app-launcher.js +20 -0
- package/components/bottom-sheet.d.ts +3 -1
- package/components/bottom-sheet.js +2 -2
- 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/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
|
|
4
4
|
|
|
5
|
+
## 1.4.0
|
|
6
|
+
|
|
7
|
+
2026-11-12. Three new components. Nothing changes for apps already on 1.3, so they can update without changes.
|
|
8
|
+
|
|
9
|
+
- New: GlobalSearch (`components/global-search`), the ⌘K search for every app. `GlobalSearchTrigger` is the
|
|
10
|
+
search field in the top bar and owns ⌘K (Ctrl+K). `GlobalSearch` shows each kind of thing in its own list,
|
|
11
|
+
two side by side and a third on a row below, with recents or suggestions before anything is typed. ↑ ↓ move
|
|
12
|
+
through the results, as in shadcn's Command. Bridge OS's search overlay, and shadcn's CommandDialog in raise
|
|
13
|
+
and app-portfolio, become this.
|
|
14
|
+
- New: Popover (`components/popover`), a panel that opens from a button: 320px, or `wide` 460px, with an
|
|
15
|
+
optional heading and one link beside it. On a phone it opens as a BottomSheet. For the account menu and the
|
|
16
|
+
app launcher.
|
|
17
|
+
- New: AppLauncher (`components/app-launcher`), the 9-dot button in the top bar that opens every Bridge app in
|
|
18
|
+
one grid. Each app passes in the `apps` it loads from Bridge's app list; icons can be the database's SVG markup.
|
|
19
|
+
- BottomSheet: `action`, one link or small button beside the title.
|
|
20
|
+
|
|
5
21
|
## 1.3.0
|
|
6
22
|
|
|
7
23
|
2026-11-12. Six additions Bridge OS asked for, each found in other apps too. Nothing changes for apps already on
|
|
@@ -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 };
|
|
@@ -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,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/package.json
CHANGED