@brdgapp/ui 1.9.0 → 1.11.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 +54 -1
- package/README.md +6 -1
- package/components/action-menu.d.ts +18 -6
- package/components/action-menu.js +28 -9
- package/components/app-shell.js +1 -1
- package/components/button.d.ts +6 -1
- package/components/button.js +16 -4
- package/components/column-filter-menu.d.ts +20 -4
- package/components/column-filter-menu.js +26 -4
- package/components/copy-field.d.ts +14 -7
- package/components/copy-field.js +25 -22
- package/components/data-table.d.ts +1 -1
- package/components/data-table.js +2 -2
- package/components/date-picker.d.ts +77 -0
- package/components/date-picker.js +367 -0
- package/components/filter-pill.d.ts +58 -4
- package/components/filter-pill.js +115 -10
- package/components/icon-button.d.ts +7 -1
- package/components/icon-button.js +14 -4
- package/components/input.d.ts +27 -3
- package/components/input.js +96 -3
- package/components/search-input.js +2 -2
- package/components/select.d.ts +41 -6
- package/components/select.js +167 -2
- package/components/spinner.d.ts +19 -0
- package/components/spinner.js +20 -0
- package/hooks/use-copy.d.ts +10 -0
- package/hooks/use-copy.js +27 -0
- package/hooks/use-theme.js +3 -3
- package/lib/theme.d.ts +2 -2
- package/lib/theme.js +7 -7
- package/package.json +4 -3
|
@@ -9,8 +9,14 @@ type IconButtonProps = Omit<ButtonPrimitive.Props, "className" | "aria-label"> &
|
|
|
9
9
|
"aria-label": string;
|
|
10
10
|
/** The action is running: shows a spinner, disables the button, sets `aria-busy`. */
|
|
11
11
|
loading?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Text to copy on click. The icon (Copy, unless you pass another) becomes a green check for 1.5 seconds,
|
|
14
|
+
* the name becomes "Copied" and is announced, and a failed copy shows an error toast. Name what's
|
|
15
|
+
* copied: `aria-label="Copy server URL"`. `onClick` still runs.
|
|
16
|
+
*/
|
|
17
|
+
copy?: string;
|
|
12
18
|
className?: string;
|
|
13
19
|
};
|
|
14
|
-
declare function IconButton({ className, variant, size, loading, disabled, children, ...props }: IconButtonProps): import("react").JSX.Element;
|
|
20
|
+
declare function IconButton({ className, variant, size, loading, disabled, children, copy, onClick, "aria-label": label, ...props }: IconButtonProps): import("react").JSX.Element;
|
|
15
21
|
export { IconButton, iconButtonVariants };
|
|
16
22
|
export type { IconButtonProps };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
|
-
import {
|
|
5
|
+
import { Check, Copy, LoaderCircle } from "lucide-react";
|
|
6
|
+
import { useCopy } from "@brdgapp/ui/hooks/use-copy";
|
|
6
7
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
7
8
|
// The one icon-only button: close, kebab, back, copy, sync. Always round. Ported from Bridge OS
|
|
8
9
|
// src/components/ui/icon-button.tsx onto Base UI Button. All sizes meet the 24px minimum target.
|
|
9
10
|
// 2026-11-06 (Aman): `outline`, Button `secondary`'s edge and fill on a circle; `xs`, 24px (the apps draw
|
|
10
11
|
// 24px icon buttons by hand 73 times).
|
|
12
|
+
// `copy` (Aman 2026-11-20): the copy icon beside a value, hand-made in 8 apps; see hooks/use-copy.ts.
|
|
11
13
|
const iconButtonVariants = cva([
|
|
12
14
|
"inline-grid shrink-0 place-items-center rounded-full border border-transparent",
|
|
13
15
|
"transition-colors duration-150 ease-out outline-none",
|
|
@@ -31,7 +33,15 @@ const iconButtonVariants = cva([
|
|
|
31
33
|
},
|
|
32
34
|
defaultVariants: { variant: "default", size: "md" },
|
|
33
35
|
});
|
|
34
|
-
function IconButton({ className, variant, size, loading = false, disabled, children, ...props }) {
|
|
35
|
-
|
|
36
|
+
function IconButton({ className, variant, size, loading = false, disabled, children, copy, onClick, "aria-label": label, ...props }) {
|
|
37
|
+
const copier = useCopy();
|
|
38
|
+
const copying = copy !== undefined;
|
|
39
|
+
const copied = copying && copier.copied;
|
|
40
|
+
return (_jsxs(ButtonPrimitive, { "data-slot": "icon-button", "data-copied": copied || undefined, className: cn(iconButtonVariants({ variant, size }), className), disabled: disabled || loading, "aria-busy": loading || undefined, "aria-label": copied ? "Copied" : label, ...props, onClick: copying
|
|
41
|
+
? (e) => {
|
|
42
|
+
void copier.copy(copy);
|
|
43
|
+
onClick?.(e);
|
|
44
|
+
}
|
|
45
|
+
: onClick, children: [_jsx("span", { "aria-hidden": "true", className: "inline-grid place-items-center", children: loading ? (_jsx(LoaderCircle, { className: "animate-spin" })) : copied ? (_jsx(Check, { className: "text-[var(--success-text)]" })) : copying ? ((children ?? _jsx(Copy, {}))) : (children) }), copying ? (_jsx("span", { className: "sr-only", "aria-live": "polite", children: copied ? "Copied" : "" })) : null] }));
|
|
36
46
|
}
|
|
37
47
|
export { IconButton, iconButtonVariants };
|
package/components/input.d.ts
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
2
|
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
3
|
-
type
|
|
3
|
+
type BaseProps = Omit<InputPrimitive.Props, "className" | "prefix" | "value" | "defaultValue" | "onValueChange"> & {
|
|
4
4
|
/** Layout only: `max-w-sm`, `flex-1`. */
|
|
5
5
|
className?: string;
|
|
6
|
+
/** With `type="password"`: the show/hide button at the field's end. On by default; `false` leaves it out. */
|
|
7
|
+
reveal?: boolean;
|
|
8
|
+
/** What the hidden value is, for the button's name: "password" (the default) or, say, "API key". */
|
|
9
|
+
secretName?: string;
|
|
10
|
+
/** A Lucide icon before the value, saying what kind of value it is: `<Key />` for an API key. */
|
|
11
|
+
leadingIcon?: React.ReactNode;
|
|
12
|
+
/** Text before the value that isn't typed: "$", "https://", "linkedin.com/in/". Say the unit in the label too. */
|
|
13
|
+
prefix?: string;
|
|
6
14
|
};
|
|
7
|
-
|
|
15
|
+
type TextInputProps = BaseProps & {
|
|
16
|
+
format?: undefined;
|
|
17
|
+
value?: InputPrimitive.Props["value"];
|
|
18
|
+
defaultValue?: InputPrimitive.Props["defaultValue"];
|
|
19
|
+
onValueChange?: InputPrimitive.Props["onValueChange"];
|
|
20
|
+
};
|
|
21
|
+
type NumberInputProps = BaseProps & {
|
|
22
|
+
/** A whole number, with commas as it's typed ("2,500,000"). Pair it with `prefix="$"` for an amount. */
|
|
23
|
+
format: "number";
|
|
24
|
+
/** The number shown, or `null` for an empty field. */
|
|
25
|
+
value?: number | null;
|
|
26
|
+
defaultValue?: number | null;
|
|
27
|
+
/** The plain number as it's typed (`2500000`), or `null` when the field is emptied. */
|
|
28
|
+
onValueChange?: (value: number | null) => void;
|
|
29
|
+
};
|
|
30
|
+
type InputProps = TextInputProps | NumberInputProps;
|
|
31
|
+
declare function Input(props: InputProps): React.JSX.Element;
|
|
8
32
|
export { Input };
|
|
9
|
-
export type { InputProps };
|
|
33
|
+
export type { InputProps, NumberInputProps };
|
package/components/input.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
4
|
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
5
|
+
import { Eye, EyeOff } from "lucide-react";
|
|
6
|
+
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
|
+
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
4
8
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
5
9
|
// A one-line text field. Started from shadcn's Base UI input, then put on Bridge's look: Bridge OS's own
|
|
6
10
|
// Input (src/components/ui/input.tsx) and Add a network use a 40px white box with 14px text, 16px on phones
|
|
@@ -8,8 +12,97 @@ import { cn } from "@brdgapp/ui/lib/utils";
|
|
|
8
12
|
// 2026-11-03 over Edit contact's 36px grey box). Same height as SearchInput, so they line up.
|
|
9
13
|
// Inside a Field, the label, help text and error are tied to it automatically.
|
|
10
14
|
// The placeholder uses --text-muted, not --text-disabled as in Bridge OS: disabled grey is 2:1 on white.
|
|
15
|
+
// A password field (`type="password"`) has a show/hide button at its end (Aman 2026-11-19, audit decision 5).
|
|
16
|
+
// Survey (2026-11-19): about 22 password and secret fields in 10 apps, hand-made eye buttons in together (5
|
|
17
|
+
// files, API keys too), raise (3) and bridge-jobs (1), mostly with no name for screen readers. One button
|
|
18
|
+
// for every secret: "Show password", or "Show API key" with `secretName`. The value stays as typed.
|
|
11
19
|
const inputClasses = cn("h-11 md:h-10 w-full min-w-0 rounded-lg border border-[var(--border-field)] bg-[var(--surface-primary)] px-3.5", "text-16 md:text-14 text-[var(--text-primary)] placeholder:text-[var(--text-muted)]", "transition-colors duration-150 ease-out outline-none", "hover:border-[var(--text-muted)]", "focus-visible:border-[var(--primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]/20", "aria-invalid:border-[var(--error)] aria-invalid:hover:border-[var(--error)] aria-invalid:focus-visible:border-[var(--error)] aria-invalid:focus-visible:ring-[var(--error)]/20", "data-[invalid]:border-[var(--error)] data-[invalid]:hover:border-[var(--error)] data-[invalid]:focus-visible:border-[var(--error)] data-[invalid]:focus-visible:ring-[var(--error)]/20", "disabled:cursor-not-allowed disabled:opacity-50");
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
// With an icon, a prefix or the show/hide button, the box is drawn around them and the field together, so
|
|
21
|
+
// any prefix ("$", "https://") fits without guessed padding. The same look and states, read from the field
|
|
22
|
+
// inside it (`has-[…]`).
|
|
23
|
+
const boxClasses = cn("flex h-11 md:h-10 w-full min-w-0 items-center gap-2 rounded-lg border border-[var(--border-field)] bg-[var(--surface-primary)] px-3.5", "transition-colors duration-150 ease-out hover:border-[var(--text-muted)]", "has-[:focus-visible]:border-[var(--primary)] has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-[var(--primary)]/20", "has-[[aria-invalid=true]]:border-[var(--error)] has-[[data-invalid]]:border-[var(--error)]", "has-[[aria-invalid=true]]:hover:border-[var(--error)] has-[[data-invalid]]:hover:border-[var(--error)]", "has-[[aria-invalid=true]:focus-visible]:border-[var(--error)] has-[[data-invalid]:focus-visible]:border-[var(--error)]", "has-[[aria-invalid=true]:focus-visible]:ring-[var(--error)]/20 has-[[data-invalid]:focus-visible]:ring-[var(--error)]/20", "has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50");
|
|
24
|
+
const fieldInBox = cn("h-full w-full min-w-0 flex-1 bg-transparent outline-none", "text-16 md:text-14 text-[var(--text-primary)] placeholder:text-[var(--text-muted)]", "disabled:cursor-not-allowed");
|
|
25
|
+
function Input(props) {
|
|
26
|
+
return props.format === "number" ? _jsx(NumberInput, { ...props }) : _jsx(TextInput, { ...props });
|
|
27
|
+
}
|
|
28
|
+
// Whole numbers only, left-aligned, US dollars when there's a currency (Aman, 2026-11-19): every app's money
|
|
29
|
+
// field today is a whole amount with "$" before it (app-portfolio's CurrencyAmountInput, raise's check sizes,
|
|
30
|
+
// bridge-jobs' salary, Bridge OS's outcome value), and none shows cents. Up to 15 digits, so the number stays exact.
|
|
31
|
+
const groupDigits = (digits) => (digits ? Number(digits).toLocaleString("en-US") : "");
|
|
32
|
+
function NumberInput({ format, value, defaultValue, onValueChange, onChange, ...props }) {
|
|
33
|
+
const toDigits = (n) => (n == null ? "" : String(Math.trunc(Math.abs(n))));
|
|
34
|
+
const [text, setText] = useState(() => groupDigits(toDigits(value !== undefined ? value : defaultValue)));
|
|
35
|
+
// A new value from outside (a reset, a loaded record) replaces what's shown; the number being typed doesn't.
|
|
36
|
+
// Adjusted while rendering, not in an effect, so there's no second render with the old text.
|
|
37
|
+
const [lastValue, setLastValue] = useState(value);
|
|
38
|
+
if (value !== lastValue) {
|
|
39
|
+
setLastValue(value);
|
|
40
|
+
if (value !== undefined && text.replace(/\D/g, "") !== toDigits(value))
|
|
41
|
+
setText(groupDigits(toDigits(value)));
|
|
42
|
+
}
|
|
43
|
+
// Where the cursor goes once the commas have moved, put back after React has written the new text.
|
|
44
|
+
const pending = useRef(null);
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
const c = pending.current;
|
|
47
|
+
if (c && document.activeElement === c.el)
|
|
48
|
+
c.el.setSelectionRange(c.at, c.at);
|
|
49
|
+
pending.current = null;
|
|
50
|
+
}, [text]);
|
|
51
|
+
if (format !== "number")
|
|
52
|
+
return null;
|
|
53
|
+
return (_jsx(TextInput, { ...props, type: "text", inputMode: "numeric", numeric: true, value: text, onChange: (e) => {
|
|
54
|
+
const el = e.target;
|
|
55
|
+
let raw = el.value;
|
|
56
|
+
let caret = el.selectionStart ?? raw.length;
|
|
57
|
+
// Deleting a comma deletes the digit beside it, as people expect; otherwise the key would seem dead.
|
|
58
|
+
const kind = e.nativeEvent.inputType;
|
|
59
|
+
if (raw.replace(/\D/g, "") === text.replace(/\D/g, "") && raw.length < text.length) {
|
|
60
|
+
if (kind === "deleteContentBackward" && caret > 0) {
|
|
61
|
+
raw = raw.slice(0, caret - 1) + raw.slice(caret);
|
|
62
|
+
caret -= 1;
|
|
63
|
+
}
|
|
64
|
+
else if (kind === "deleteContentForward")
|
|
65
|
+
raw = raw.slice(0, caret) + raw.slice(caret + 1);
|
|
66
|
+
}
|
|
67
|
+
// Keep the cursor beside the same digit once the commas move, and before a comma, not after it.
|
|
68
|
+
const digitsAfter = raw.slice(caret).replace(/\D/g, "").length;
|
|
69
|
+
const digits = raw.replace(/\D/g, "").replace(/^0+(?=\d)/, "").slice(0, 15);
|
|
70
|
+
const next = groupDigits(digits);
|
|
71
|
+
let at = next.length;
|
|
72
|
+
for (let seen = 0; at > 0 && seen < digitsAfter;)
|
|
73
|
+
if (/\d/.test(next[--at]))
|
|
74
|
+
seen++;
|
|
75
|
+
if (next[at - 1] === ",")
|
|
76
|
+
at -= 1;
|
|
77
|
+
pending.current = { el, at };
|
|
78
|
+
if (next === text) {
|
|
79
|
+
// Nothing to rewrite (a letter was dropped): the field still puts its old text back, so wait for that.
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
if (document.activeElement === el)
|
|
82
|
+
el.setSelectionRange(at, at);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
setText(next);
|
|
86
|
+
onChange?.(e);
|
|
87
|
+
onValueChange?.(digits ? Number(digits) : null);
|
|
88
|
+
} }));
|
|
89
|
+
}
|
|
90
|
+
function TextInput({ className, type = "text", reveal = true, secretName = "password", leadingIcon, prefix, disabled, numeric = false, ...props }) {
|
|
91
|
+
const [shown, setShown] = useState(false);
|
|
92
|
+
const field = useRef(null);
|
|
93
|
+
const password = type === "password" && reveal;
|
|
94
|
+
if (!password && !leadingIcon && !prefix) {
|
|
95
|
+
return _jsx(InputPrimitive, { "data-slot": "input", type: type, disabled: disabled, className: cn(inputClasses, numeric && "tabular-nums", className), ...props });
|
|
96
|
+
}
|
|
97
|
+
const forced = props["data-force-state"];
|
|
98
|
+
const name = `${shown ? "Hide" : "Show"} ${secretName}`;
|
|
99
|
+
return (_jsxs("span", { "data-slot": "input-box", "data-force-state": forced, className: cn(boxClasses, className),
|
|
100
|
+
// A press on the icon or the prefix goes to the field, as on the field itself.
|
|
101
|
+
onPointerDown: (e) => {
|
|
102
|
+
if (e.target === e.currentTarget || !e.target.closest("button, input")) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
field.current?.focus();
|
|
105
|
+
}
|
|
106
|
+
}, children: [leadingIcon ? _jsx("span", { "aria-hidden": "true", className: "flex shrink-0 text-[var(--text-muted)] [&_svg]:size-4", children: leadingIcon }) : null, prefix ? _jsx("span", { "aria-hidden": "true", className: "-mr-1 shrink-0 text-16 text-[var(--text-muted)] md:text-14", children: prefix }) : null, _jsx(InputPrimitive, { ref: field, "data-slot": "input", type: password && shown ? "text" : type, disabled: disabled, ...(password ? { spellCheck: false, autoCapitalize: "off" } : {}), className: cn(fieldInBox, numeric && "tabular-nums"), ...props }), password ? (_jsx("span", { className: "-mr-2 flex shrink-0", children: _jsx(Tip, { text: name, children: _jsx(IconButton, { type: "button", size: "sm", "aria-label": name, disabled: disabled, onClick: () => setShown((v) => !v), children: shown ? _jsx(EyeOff, {}) : _jsx(Eye, {}) }) }) })) : null] }));
|
|
14
107
|
}
|
|
15
108
|
export { Input };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
5
|
-
import {
|
|
5
|
+
import { LoaderCircle, Search, X } from "lucide-react";
|
|
6
6
|
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
7
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
8
8
|
// `className` goes on the wrapper, not the input, so a width limit keeps the clear button inside the pill.
|
|
@@ -27,7 +27,7 @@ function SearchInput({ className, value, onClear, loading = false, onKeyDown, di
|
|
|
27
27
|
}
|
|
28
28
|
}, className: cn("h-11 md:h-10 w-full rounded-full border border-[var(--border-field)] bg-[var(--surface-secondary)] py-2 pr-10 pl-10", "text-16 md:text-14 text-[var(--text-primary)] placeholder:text-[var(--text-muted)]", "transition-all duration-150 ease-out outline-none hover:border-[var(--text-muted)]", "focus:border-[var(--primary)] focus:bg-[var(--surface-primary)] focus:ring-2 focus:ring-[var(--primary)]/20", "disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-[var(--border-field)]",
|
|
29
29
|
// Hide the browser's own clear button; this component draws its own.
|
|
30
|
-
"[&::-webkit-search-cancel-button]:appearance-none"), ...props }), loading ? (_jsxs("span", { className: "pointer-events-none absolute top-1/2 right-3.5 -translate-y-1/2 text-[var(--text-muted)]", children: [_jsx(
|
|
30
|
+
"[&::-webkit-search-cancel-button]:appearance-none"), ...props }), loading ? (_jsxs("span", { className: "pointer-events-none absolute top-1/2 right-3.5 -translate-y-1/2 text-[var(--text-muted)]", children: [_jsx(LoaderCircle, { "data-slot": "search-input-spinner", "aria-hidden": "true", className: "size-4 animate-spin" }), _jsx("span", { role: "status", className: "sr-only", children: "Searching" })] })) : canClear ? (_jsx(IconButton, { "aria-label": "Clear search", size: "sm", onClick: () => {
|
|
31
31
|
onClear?.();
|
|
32
32
|
inner.current?.focus();
|
|
33
33
|
}, className: "absolute top-1/2 right-1.5 -translate-y-1/2", children: _jsx(X, {}) })) : null] }));
|
package/components/select.d.ts
CHANGED
|
@@ -7,10 +7,17 @@ type SelectOption<T extends string> = {
|
|
|
7
7
|
/** A Lucide icon or small Avatar before the label. */
|
|
8
8
|
icon?: React.ReactNode;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Results from the server as people type, for lists too long to load: people, locations, every VC. */
|
|
11
|
+
type SelectSearch = {
|
|
12
|
+
/** What's typed. */
|
|
13
|
+
value: string;
|
|
14
|
+
onChange: (value: string) => void;
|
|
15
|
+
/** Results are on their way: a spinner shows in the search field. */
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
/** Letters needed before the app searches. Default 2; under it the list says "Type at least 2 letters." */
|
|
18
|
+
minLength?: number;
|
|
19
|
+
};
|
|
20
|
+
type SelectBase<T extends string> = {
|
|
14
21
|
options: SelectOption<T>[];
|
|
15
22
|
/** Shown, muted, until something is chosen: "Choose a type". */
|
|
16
23
|
placeholder?: string;
|
|
@@ -21,7 +28,35 @@ type SelectProps<T extends string> = {
|
|
|
21
28
|
"aria-label"?: string;
|
|
22
29
|
/** Layout only: `max-w-xs`. */
|
|
23
30
|
className?: string;
|
|
31
|
+
/**
|
|
32
|
+
* A search field at the top of the list. `true` filters `options` as people type (by label and
|
|
33
|
+
* description). An object means the app searches: `options` are its results for what's typed.
|
|
34
|
+
*/
|
|
35
|
+
search?: boolean | SelectSearch;
|
|
36
|
+
/** The search field's placeholder: "Search contacts". Default "Search". */
|
|
37
|
+
searchPlaceholder?: string;
|
|
38
|
+
/** What the list says when nothing matches. Default "No results." */
|
|
39
|
+
emptyText?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Adds an "Add “…”" row when what's typed matches no option, and is called with the typed text. The app
|
|
42
|
+
* adds it (to the list, or saves it) and sets `value`. Turns on the search field.
|
|
43
|
+
*/
|
|
44
|
+
onCreate?: (text: string) => void;
|
|
45
|
+
};
|
|
46
|
+
type SingleSelectProps<T extends string> = SelectBase<T> & {
|
|
47
|
+
multiple?: false;
|
|
48
|
+
/** The chosen option, or `null` for none yet (the placeholder shows). */
|
|
49
|
+
value: T | null;
|
|
50
|
+
onChange: (value: T) => void;
|
|
51
|
+
};
|
|
52
|
+
type MultipleSelectProps<T extends string> = SelectBase<T> & {
|
|
53
|
+
/** Several values: each shows as a Tag in the field with × to remove it; the list stays open while ticking. */
|
|
54
|
+
multiple: true;
|
|
55
|
+
/** The chosen values; empty shows the placeholder. */
|
|
56
|
+
value: T[];
|
|
57
|
+
onChange: (value: T[]) => void;
|
|
24
58
|
};
|
|
25
|
-
|
|
59
|
+
type SelectProps<T extends string> = SingleSelectProps<T> | MultipleSelectProps<T>;
|
|
60
|
+
declare function Select<T extends string>(props: SelectProps<T>): React.JSX.Element;
|
|
26
61
|
export { Select };
|
|
27
|
-
export type { SelectOption, SelectProps };
|
|
62
|
+
export type { MultipleSelectProps, SelectOption, SelectProps, SelectSearch, SingleSelectProps };
|
package/components/select.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
+
import { Combobox } from "@base-ui/react/combobox";
|
|
4
5
|
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
|
5
|
-
import { Check, ChevronDown } from "lucide-react";
|
|
6
|
+
import { Check, ChevronDown, Plus, X } from "lucide-react";
|
|
6
7
|
import { BottomSheet, BottomSheetOption, BottomSheetOptions } from "@brdgapp/ui/components/bottom-sheet";
|
|
8
|
+
import { TickBox, usePicked } from "@brdgapp/ui/components/filter-pill";
|
|
9
|
+
import { SearchInput } from "@brdgapp/ui/components/search-input";
|
|
10
|
+
import { Tag } from "@brdgapp/ui/components/tag";
|
|
7
11
|
import { useIsMobile } from "@brdgapp/ui/hooks/use-is-mobile";
|
|
8
12
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
13
|
// The same box as Input: 40px (44 on phones), 8px corners, the field border, blue focus, red when invalid.
|
|
@@ -11,7 +15,12 @@ const triggerClasses = cn("flex h-11 md:h-10 w-full min-w-0 items-center justify
|
|
|
11
15
|
function OptionBody({ option, phone = false }) {
|
|
12
16
|
return (_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [option.icon ? _jsx("span", { className: "flex shrink-0 text-[var(--text-muted)] [&_svg]:size-4", children: option.icon }) : null, _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate", children: option.label }), option.description ? _jsx("span", { className: cn("block truncate font-normal text-[var(--text-muted)]", phone ? "text-13" : "text-12"), children: option.description }) : null] })] }));
|
|
13
17
|
}
|
|
14
|
-
function Select(
|
|
18
|
+
function Select(props) {
|
|
19
|
+
if (props.multiple)
|
|
20
|
+
return _jsx(MultipleSelect, { ...props });
|
|
21
|
+
return props.search || props.onCreate ? _jsx(SearchSelect, { ...props }) : _jsx(PlainSelect, { ...props });
|
|
22
|
+
}
|
|
23
|
+
function PlainSelect({ value, onChange, options, placeholder = "Choose", disabled = false, name, className, ...props }) {
|
|
15
24
|
const mobile = useIsMobile();
|
|
16
25
|
const [sheet, setSheet] = React.useState(false);
|
|
17
26
|
const [listOpen, setListOpen] = React.useState(false);
|
|
@@ -41,4 +50,160 @@ function Select({ value, onChange, options, placeholder = "Choose", disabled = f
|
|
|
41
50
|
setSheet(false);
|
|
42
51
|
}, children: _jsx(OptionBody, { option: option, phone: true }) }, option.value))) }) })) : null] }));
|
|
43
52
|
}
|
|
53
|
+
const CREATE = "\u0000create";
|
|
54
|
+
const optionRow = "flex w-full cursor-default items-center justify-between gap-3 px-3 py-2 text-left text-13 leading-normal text-[var(--text-body)] outline-none transition-colors data-[selected]:font-semibold data-[selected]:text-[var(--text-primary)] data-[highlighted]:bg-[var(--surface-secondary)]";
|
|
55
|
+
const matches = (o, q) => {
|
|
56
|
+
const t = q.toLowerCase();
|
|
57
|
+
return o.label.toLowerCase().includes(t) || (o.description?.toLowerCase().includes(t) ?? false);
|
|
58
|
+
};
|
|
59
|
+
/** The label of the field this Select sits in (FieldLabel), for the phone sheet's title. */
|
|
60
|
+
function labelOf(el) {
|
|
61
|
+
const ids = el?.getAttribute("aria-labelledby")?.split(" ") ?? [];
|
|
62
|
+
return ids.map((id) => document.getElementById(id)?.textContent?.trim()).find(Boolean);
|
|
63
|
+
}
|
|
64
|
+
function SearchSelect({ value, onChange, options, placeholder = "Choose", disabled = false, name, className, search, searchPlaceholder = "Search", emptyText = "No results.", onCreate, ...props }) {
|
|
65
|
+
const mobile = useIsMobile();
|
|
66
|
+
const server = typeof search === "object" ? search : undefined;
|
|
67
|
+
const [ownQuery, setOwnQuery] = React.useState("");
|
|
68
|
+
const query = server ? server.value : ownQuery;
|
|
69
|
+
const setQuery = server ? server.onChange : setOwnQuery;
|
|
70
|
+
const [open, setOpen] = React.useState(false);
|
|
71
|
+
const [title, setTitle] = React.useState("");
|
|
72
|
+
const trigger = React.useRef(null);
|
|
73
|
+
// The app's results change as people type, so the chosen option is kept here for its label.
|
|
74
|
+
const [picked, setPicked] = React.useState();
|
|
75
|
+
const chosen = options.find((o) => o.value === value) ?? (picked && picked.value === value ? picked : undefined);
|
|
76
|
+
const q = query.trim();
|
|
77
|
+
const min = server ? (server.minLength ?? 2) : 0;
|
|
78
|
+
const short = q.length < min;
|
|
79
|
+
const found = server ? (short ? [] : options) : q ? options.filter((o) => matches(o, q)) : options;
|
|
80
|
+
const exact = options.some((o) => o.label.trim().toLowerCase() === q.toLowerCase());
|
|
81
|
+
const addRow = onCreate && q && !exact ? { value: CREATE, label: `Add “${q}”`, create: q } : null;
|
|
82
|
+
const rows = addRow ? [...found, addRow] : found;
|
|
83
|
+
const note = short ? `Type at least ${min} letters.` : !server?.loading && !rows.length ? emptyText : null;
|
|
84
|
+
const close = () => {
|
|
85
|
+
setOpen(false);
|
|
86
|
+
setQuery("");
|
|
87
|
+
};
|
|
88
|
+
const pick = (row) => {
|
|
89
|
+
if (row.create !== undefined)
|
|
90
|
+
onCreate?.(row.create);
|
|
91
|
+
else {
|
|
92
|
+
setPicked(row);
|
|
93
|
+
onChange(row.value);
|
|
94
|
+
}
|
|
95
|
+
close();
|
|
96
|
+
};
|
|
97
|
+
const triggerInner = (_jsxs(_Fragment, { children: [_jsx("span", { className: cn("min-w-0 truncate", !chosen && "text-[var(--text-muted)]"), children: chosen ? chosen.label : placeholder }), _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-4 shrink-0 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
98
|
+
// Phones: the search field and the options in a bottom sheet, 44px rows.
|
|
99
|
+
if (mobile) {
|
|
100
|
+
return (_jsxs(_Fragment, { children: [_jsx(Combobox.Root, { items: rows, value: chosen ?? null, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, open: false, disabled: disabled, name: name, children: _jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: cn(triggerClasses, className), onClick: () => {
|
|
101
|
+
setTitle(labelOf(trigger.current) || props["aria-label"] || placeholder);
|
|
102
|
+
setOpen(true);
|
|
103
|
+
}, children: triggerInner }) }), _jsxs(BottomSheet, { open: open, onClose: close, title: title, children: [_jsx("div", { className: "px-5 pb-2", children: _jsx(SearchInput, { placeholder: searchPlaceholder, value: query, loading: server?.loading, onChange: (e) => setQuery(e.target.value), onClear: () => setQuery("") }) }), _jsx(BottomSheetOptions, { children: rows.map((row) => (_jsx(BottomSheetOption, { selected: row.value === value, onSelect: () => pick(row), children: row.create !== undefined ? _jsx(AddBody, { label: row.label, phone: true }) : _jsx(OptionBody, { option: row, phone: true }) }, row.value))) }), note ? (_jsx("p", { role: "status", className: "px-5 pb-4 text-14 text-[var(--text-muted)]", children: note })) : null] })] }));
|
|
104
|
+
}
|
|
105
|
+
return (_jsxs(Combobox.Root, { items: rows, value: chosen ?? null, filter: null,
|
|
106
|
+
// The first match is highlighted as people type, so Enter picks it (or adds what was typed).
|
|
107
|
+
autoHighlight: true, itemToStringLabel: (r) => r.label, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, onInputValueChange: (next, details) => {
|
|
108
|
+
// Picking an option would write its label into the field; the field is for searching only.
|
|
109
|
+
if (details.reason !== "item-press")
|
|
110
|
+
setQuery(next);
|
|
111
|
+
}, onValueChange: (row) => {
|
|
112
|
+
if (row)
|
|
113
|
+
pick(row);
|
|
114
|
+
}, open: open, onOpenChange: (next) => {
|
|
115
|
+
if (!next)
|
|
116
|
+
return close();
|
|
117
|
+
// The list is named by the field's label, read when it opens.
|
|
118
|
+
setTitle(labelOf(trigger.current) || props["aria-label"] || placeholder);
|
|
119
|
+
setOpen(true);
|
|
120
|
+
}, disabled: disabled, name: name, children: [_jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: cn(triggerClasses, className), children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: "flex max-h-[min(380px,var(--available-height))] w-[max(var(--anchor-width),280px)] max-w-[calc(100vw-16px)] flex-col rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none transition-opacity duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (row) => (_jsx(Combobox.Item, { value: row, "data-slot": "select-option", className: optionRow, children: row.create !== undefined ? (_jsx(AddBody, { label: row.label })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "min-w-0", children: _jsx(OptionBody, { option: row }) }), _jsx(Combobox.ItemIndicator, { className: "inline-flex shrink-0", children: _jsx(Check, { "aria-hidden": "true", className: "size-4 text-[var(--primary)]" }) })] })) }, row.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
|
|
121
|
+
}
|
|
122
|
+
// The field for several values: a box holding a Tag per choice and the trigger, which fills the rest. The
|
|
123
|
+
// trigger is the control (FieldLabel names it); each Tag's × is its own button, never inside the trigger.
|
|
124
|
+
const tagsBox = cn("flex min-h-11 md:min-h-10 w-full min-w-0 flex-wrap items-center gap-1.5 rounded-lg border border-[var(--border-field)] bg-[var(--surface-primary)] py-1.5 pr-3.5 pl-2", "transition-colors duration-150 ease-out hover:border-[var(--text-muted)]", "has-[[data-slot=select]:focus-visible]:border-[var(--primary)] has-[[data-slot=select]:focus-visible]:ring-2 has-[[data-slot=select]:focus-visible]:ring-[var(--primary)]/20", "has-[[data-popup-open]]:border-[var(--primary)]", "has-[[data-invalid]]:border-[var(--error)] has-[[data-invalid]]:hover:border-[var(--error)] has-[[aria-invalid=true]]:border-[var(--error)]", "has-[[data-invalid]:focus-visible]:ring-[var(--error)]/20", "has-[[data-disabled]]:cursor-not-allowed has-[[data-disabled]]:opacity-50");
|
|
125
|
+
const tagsTrigger = "flex min-h-7 min-w-20 flex-1 items-center justify-between gap-2 pl-1.5 text-left text-16 md:text-14 text-[var(--text-primary)] outline-none data-[disabled]:cursor-not-allowed";
|
|
126
|
+
function MultipleSelect({ value, onChange, options, placeholder = "Choose", disabled = false, name, className, search, searchPlaceholder = "Search", emptyText = "No results.", onCreate, ...props }) {
|
|
127
|
+
const mobile = useIsMobile();
|
|
128
|
+
const searching = Boolean(search || onCreate);
|
|
129
|
+
const server = typeof search === "object" ? search : undefined;
|
|
130
|
+
const [ownQuery, setOwnQuery] = React.useState("");
|
|
131
|
+
const query = server ? server.value : ownQuery;
|
|
132
|
+
const setQuery = server ? server.onChange : setOwnQuery;
|
|
133
|
+
const [open, setOpen] = React.useState(false);
|
|
134
|
+
const [title, setTitle] = React.useState("");
|
|
135
|
+
const trigger = React.useRef(null);
|
|
136
|
+
// The list lines up with the whole box, not only the trigger beside the Tags.
|
|
137
|
+
const boxRef = React.useRef(null);
|
|
138
|
+
const { picked, remember } = usePicked(value, options);
|
|
139
|
+
const q = query.trim();
|
|
140
|
+
const min = server ? (server.minLength ?? 2) : 0;
|
|
141
|
+
const short = q.length < min;
|
|
142
|
+
// Before the app has something to search, the list shows what's chosen, so it can be unticked.
|
|
143
|
+
const found = server ? (short ? picked : options) : q ? options.filter((o) => matches(o, q)) : options;
|
|
144
|
+
const exact = options.some((o) => o.label.trim().toLowerCase() === q.toLowerCase());
|
|
145
|
+
const addRow = onCreate && q && !exact ? { value: CREATE, label: `Add “${q}”`, create: q } : null;
|
|
146
|
+
const rows = addRow ? [...found, addRow] : found;
|
|
147
|
+
const note = short && !picked.length ? `Type at least ${min} letters.` : !short && !server?.loading && !rows.length ? emptyText : null;
|
|
148
|
+
const toggle = (row) => {
|
|
149
|
+
if (row.create !== undefined) {
|
|
150
|
+
onCreate?.(row.create);
|
|
151
|
+
setQuery("");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
remember(row);
|
|
155
|
+
const v = row.value;
|
|
156
|
+
onChange(value.includes(v) ? value.filter((x) => x !== v) : [...value, v]);
|
|
157
|
+
};
|
|
158
|
+
const openList = (next) => {
|
|
159
|
+
if (!next) {
|
|
160
|
+
setOpen(false);
|
|
161
|
+
setQuery("");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
setTitle(labelOf(trigger.current) || props["aria-label"] || placeholder);
|
|
165
|
+
setOpen(true);
|
|
166
|
+
};
|
|
167
|
+
const tags = picked.map((o) => (_jsxs(Tag, { size: "sm", className: "max-w-full", children: [_jsx("span", { className: "truncate", children: o.label }), _jsx("button", { type: "button", "aria-label": `Remove ${o.label}`, disabled: disabled, onClick: () => {
|
|
168
|
+
onChange(value.filter((x) => x !== o.value));
|
|
169
|
+
// The Tag and its × go away: focus stays in the field.
|
|
170
|
+
trigger.current?.focus();
|
|
171
|
+
}, className: "-mr-1 ml-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-full text-[var(--text-muted)] outline-none transition-colors hover:bg-[var(--surface-tertiary)] hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: _jsx(X, { "aria-hidden": "true", className: "size-3" }) })] }, o.value)));
|
|
172
|
+
const triggerInner = (_jsxs(_Fragment, { children: [_jsx("span", { className: cn("min-w-0 truncate", "text-[var(--text-muted)]"), children: value.length ? "" : placeholder }), _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-4 shrink-0 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
173
|
+
// A press on the box's empty space opens the list, as on the field itself.
|
|
174
|
+
const box = (control) => (_jsxs("div", { ref: boxRef, "data-slot": "select-tags", className: cn(tagsBox, className), onPointerDown: (e) => {
|
|
175
|
+
if (e.target === e.currentTarget && !disabled) {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
trigger.current?.focus();
|
|
178
|
+
if (mobile)
|
|
179
|
+
openList(true);
|
|
180
|
+
else
|
|
181
|
+
trigger.current?.click();
|
|
182
|
+
}
|
|
183
|
+
}, children: [tags, control] }));
|
|
184
|
+
const row = (r) => r.create !== undefined ? (_jsx(AddBody, { label: r.label })) : (_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [_jsx(TickBox, { on: value.includes(r.value) }), _jsx(OptionBody, { option: r })] }));
|
|
185
|
+
const popupClass = "flex max-h-[min(380px,var(--available-height))] min-w-[var(--anchor-width)] w-[max(var(--anchor-width),280px)] max-w-[calc(100vw-16px)] flex-col rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] shadow-[var(--shadow-menu)] outline-none transition-opacity duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0";
|
|
186
|
+
// Phones: tick rows in a bottom sheet (with the search field on top when there is one).
|
|
187
|
+
if (mobile) {
|
|
188
|
+
return (_jsxs(_Fragment, { children: [box(_jsx(SelectPrimitive.Root, { multiple: true, value: value, items: options.map((o) => ({ value: o.value, label: o.label })), open: false, disabled: disabled, name: name, children: _jsx(SelectPrimitive.Trigger, { ref: trigger, "data-slot": "select", "aria-haspopup": "dialog", "aria-label": props["aria-label"], className: tagsTrigger, onClick: () => openList(true), children: triggerInner }) })), _jsxs(BottomSheet, { open: open, onClose: () => openList(false), title: title, children: [searching ? (_jsx("div", { className: "px-5 pb-2", children: _jsx(SearchInput, { placeholder: searchPlaceholder, value: query, loading: server?.loading, onChange: (e) => setQuery(e.target.value), onClear: () => setQuery("") }) })) : null, _jsx(BottomSheetOptions, { multiple: true, children: rows.map((r) => (_jsx(BottomSheetOption, { selected: value.includes(r.value), onSelect: () => toggle(r), children: r.create !== undefined ? _jsx(AddBody, { label: r.label, phone: true }) : _jsx(OptionBody, { option: r, phone: true }) }, r.value))) }), note ? (_jsx("p", { role: "status", className: "px-5 pb-4 text-14 text-[var(--text-muted)]", children: note })) : null] })] }));
|
|
189
|
+
}
|
|
190
|
+
if (!searching) {
|
|
191
|
+
return box(_jsxs(SelectPrimitive.Root, { multiple: true, value: value, onValueChange: (v) => onChange((v ?? [])), items: options.map((o) => ({ value: o.value, label: o.label })), disabled: disabled, name: name, open: open, onOpenChange: openList, children: [_jsx(SelectPrimitive.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, alignItemWithTrigger: false, className: "z-[95]", children: _jsx(SelectPrimitive.Popup, { "data-slot": "select-menu", className: cn(popupClass, "overflow-y-auto py-1"), children: _jsx(SelectPrimitive.List, { children: options.map((o) => (_jsx(SelectPrimitive.Item, { value: o.value, label: o.label, "data-slot": "select-option", className: optionRow, children: row(o) }, o.value))) }) }) }) })] }));
|
|
192
|
+
}
|
|
193
|
+
return box(_jsxs(Combobox.Root, { multiple: true, items: rows, value: picked, filter: null, autoHighlight: true, itemToStringLabel: (r) => r.label, itemToStringValue: (r) => r.value, isItemEqualToValue: (a, b) => a.value === b.value, inputValue: query, onInputValueChange: (next, details) => {
|
|
194
|
+
if (details.reason !== "item-press")
|
|
195
|
+
setQuery(next);
|
|
196
|
+
}, onValueChange: (next) => {
|
|
197
|
+
// Base UI hands back the whole new list; find the one row that was pressed.
|
|
198
|
+
const added = next.find((r) => !value.includes(r.value));
|
|
199
|
+
if (added)
|
|
200
|
+
return toggle(added);
|
|
201
|
+
const removed = picked.find((p) => !next.some((r) => r.value === p.value));
|
|
202
|
+
if (removed)
|
|
203
|
+
toggle(removed);
|
|
204
|
+
}, open: open, onOpenChange: openList, disabled: disabled, name: name, children: [_jsx(Combobox.Trigger, { ref: trigger, "data-slot": "select", "aria-label": props["aria-label"], className: tagsTrigger, children: triggerInner }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { anchor: boxRef, side: "bottom", align: "start", sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsxs(Combobox.Popup, { "data-slot": "select-menu", "aria-label": title || props["aria-label"] || placeholder, className: popupClass, children: [_jsx("div", { className: "shrink-0 p-2 pb-1", children: _jsx(Combobox.Input, { render: _jsx(SearchInput, { placeholder: searchPlaceholder, loading: server?.loading, onClear: () => setQuery("") }) }) }), _jsx(Combobox.List, { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain pb-1 empty:hidden", children: (r) => (_jsx(Combobox.Item, { value: r, "data-slot": "select-option", className: optionRow, children: row(r) }, r.value)) }), note ? (_jsx("p", { role: "status", className: "px-3 pt-1 pb-3 text-13 text-[var(--text-muted)]", children: note })) : null] }) }) })] }));
|
|
205
|
+
}
|
|
206
|
+
function AddBody({ label, phone = false }) {
|
|
207
|
+
return (_jsxs("span", { className: cn("flex min-w-0 items-center gap-3 font-semibold text-[var(--primary)]", phone && "text-14"), children: [_jsx(Plus, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "truncate", children: label })] }));
|
|
208
|
+
}
|
|
44
209
|
export { Select };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const SIZE: {
|
|
2
|
+
readonly sm: "size-3.5";
|
|
3
|
+
readonly md: "size-4";
|
|
4
|
+
readonly lg: "size-6";
|
|
5
|
+
};
|
|
6
|
+
type SpinnerProps = {
|
|
7
|
+
/** 14, 16 (the default) or 24px. Match the text beside it: 14 by 12–13px text, 16 by 14px, 24 on its own. */
|
|
8
|
+
size?: keyof typeof SIZE;
|
|
9
|
+
/**
|
|
10
|
+
* What's working, said to screen readers when nothing beside the spinner says it: "Signing you in".
|
|
11
|
+
* Leave it out when words beside it already say what's happening ("Syncing 120 of 480…").
|
|
12
|
+
*/
|
|
13
|
+
label?: string;
|
|
14
|
+
/** Layout only: `mx-auto`, `shrink-0`. */
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
declare function Spinner({ size, label, className }: SpinnerProps): import("react").JSX.Element;
|
|
18
|
+
export { Spinner };
|
|
19
|
+
export type { SpinnerProps };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LoaderCircle } from "lucide-react";
|
|
3
|
+
import { cn } from "@brdgapp/ui/lib/utils";
|
|
4
|
+
// Something working whose result has no shape yet: a sync running, signing you in. The same drawing as
|
|
5
|
+
// the spinner inside Button, IconButton, SearchInput and DataTable's pager (LoaderCircle, turning), which
|
|
6
|
+
// size theirs from the control.
|
|
7
|
+
// Survey of all 12 app repos (2026-11-19): about 380 hand-made spinners in 11 apps, all Lucide's
|
|
8
|
+
// Loader2 with `animate-spin` (raise 59 files, app-cc 41, app-directories 34, app-portfolio 31, together 19,
|
|
9
|
+
// bridge-jobs 17, app-perks-v2 13, Bridge OS 10, bridge-signup 8, app-intercom 6, chat 1; the mobile app
|
|
10
|
+
// uses its platform's). Sizes: 16px about 210 times, 14px about 50, 32px 22, 20px 21, 12px 18, 24px 14.
|
|
11
|
+
// About 97 sit beside a button's words (they become Button `loading`) and about 26 are big spinners where
|
|
12
|
+
// a page or card loads (they become skeletons). Approved: Aman 2026-11-19 (audit decision 5).
|
|
13
|
+
// Sizes on the icon scale (Iconography): 14, 16, 24. It takes the color of the text around it, and keeps
|
|
14
|
+
// turning with reduced motion turned on (globals.css leaves `animate-spin` alone): a still spinner reads
|
|
15
|
+
// as stuck.
|
|
16
|
+
const SIZE = { sm: "size-3.5", md: "size-4", lg: "size-6" };
|
|
17
|
+
function Spinner({ size = "md", label, className }) {
|
|
18
|
+
return (_jsxs("span", { "data-slot": "spinner", role: label ? "status" : undefined, "aria-hidden": label ? undefined : true, className: cn("inline-flex shrink-0", className), children: [_jsx(LoaderCircle, { "aria-hidden": "true", className: cn("animate-spin", SIZE[size]) }), label ? _jsx("span", { className: "sr-only", children: label }) : null] }));
|
|
19
|
+
}
|
|
20
|
+
export { Spinner };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type UseCopyOptions = {
|
|
2
|
+
/** The error toast when the browser blocks the copy. Default: "Couldn't copy. Try again." */
|
|
3
|
+
failed?: string;
|
|
4
|
+
};
|
|
5
|
+
declare function useCopy({ failed }?: UseCopyOptions): {
|
|
6
|
+
copied: boolean;
|
|
7
|
+
copy: (text: string) => Promise<boolean>;
|
|
8
|
+
};
|
|
9
|
+
export { useCopy };
|
|
10
|
+
export type { UseCopyOptions };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { toast } from "@brdgapp/ui/components/toast";
|
|
4
|
+
function useCopy({ failed = "Couldn't copy. Try again." } = {}) {
|
|
5
|
+
const [copied, setCopied] = useState(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!copied)
|
|
8
|
+
return;
|
|
9
|
+
const timer = setTimeout(() => setCopied(false), 1500);
|
|
10
|
+
return () => clearTimeout(timer);
|
|
11
|
+
}, [copied]);
|
|
12
|
+
/** Copies `text`. Resolves to `true` once it's on the clipboard, `false` (after the error toast) if not. */
|
|
13
|
+
async function copy(text) {
|
|
14
|
+
try {
|
|
15
|
+
await navigator.clipboard.writeText(text);
|
|
16
|
+
setCopied(true);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Blocked: no permission, or an insecure (http) page. Nothing was copied, so never "Copied".
|
|
21
|
+
toast.error(failed);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { copied, copy };
|
|
26
|
+
}
|
|
27
|
+
export { useCopy };
|
package/hooks/use-theme.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useCallback, useSyncExternalStore } from "react";
|
|
3
3
|
import { applyTheme, DARK_QUERY, readPreference, resolveTheme, writePreference } from "@brdgapp/ui/lib/theme";
|
|
4
4
|
// One small store for the theme, shared by every useTheme() on the page. No provider to wrap the app in.
|
|
5
|
-
// It follows the device while the choice is System, and picks up a choice made in another Bridge app when
|
|
5
|
+
// Light until someone chooses. It follows the device while the choice is System, and picks up a choice made in another Bridge app when
|
|
6
6
|
// people come back to this tab.
|
|
7
7
|
const CHANGE = "bridge-theme-change";
|
|
8
8
|
let listening = false;
|
|
@@ -21,8 +21,8 @@ function subscribe(onChange) {
|
|
|
21
21
|
return () => window.removeEventListener(CHANGE, onChange);
|
|
22
22
|
}
|
|
23
23
|
const snapshot = () => `${readPreference()}:${resolveTheme(readPreference())}`;
|
|
24
|
-
// Before the page has loaded there's no saved choice to read: report
|
|
25
|
-
const serverSnapshot = () => "
|
|
24
|
+
// Before the page has loaded there's no saved choice to read: report the default, Light.
|
|
25
|
+
const serverSnapshot = () => "light:light";
|
|
26
26
|
/** The theme choice, what's drawn, and a way to change it. Needs `themeScript` in the root layout's <head>. */
|
|
27
27
|
export function useTheme() {
|
|
28
28
|
const [theme, resolvedTheme] = useSyncExternalStore(subscribe, snapshot, serverSnapshot).split(":");
|
package/lib/theme.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type ThemePreference = "light" | "dark" | "system";
|
|
|
2
2
|
export type ResolvedTheme = "light" | "dark";
|
|
3
3
|
export declare const THEME_COOKIE = "bridge-theme";
|
|
4
4
|
declare const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
5
|
-
/** The saved choice: the shared cookie, then Bridge OS's old per-app key, then
|
|
5
|
+
/** The saved choice: the shared cookie, then Bridge OS's old per-app key, then Light. */
|
|
6
6
|
export declare function readPreference(): ThemePreference;
|
|
7
7
|
/** Saves the choice for every Bridge app: on brdg.app it's shared by all subdomains; elsewhere (localhost, previews) by this site. */
|
|
8
8
|
export declare function writePreference(preference: ThemePreference): void;
|
|
@@ -17,5 +17,5 @@ export declare function applyTheme(theme: ResolvedTheme): void;
|
|
|
17
17
|
* Runs in <head> before the page paints, so someone in dark never sees a white flash. The same steps as
|
|
18
18
|
* readPreference and resolveTheme, written out because it can't import anything.
|
|
19
19
|
*/
|
|
20
|
-
export declare const themeScript = "(function(){try{var m=document.cookie.match(/(?:^|; )bridge-theme=(light|dark|system)/),p=m?m[1]:null;if(!p){try{p=localStorage.getItem(\"bridge-theme\")}catch(e){}}if(p!==\"light\"&&p!==\"dark\")p=\"
|
|
20
|
+
export declare const themeScript = "(function(){try{var m=document.cookie.match(/(?:^|; )bridge-theme=(light|dark|system)/),p=m?m[1]:null;if(!p){try{p=localStorage.getItem(\"bridge-theme\")}catch(e){}}if(p!==\"light\"&&p!==\"dark\"&&p!==\"system\")p=\"light\";var t=p===\"dark\"||(p===\"system\"&&matchMedia(\"(prefers-color-scheme: dark)\").matches)?\"dark\":\"light\",r=document.documentElement;r.dataset.theme=t;r.style.colorScheme=t}catch(e){}})()";
|
|
21
21
|
export { DARK_QUERY };
|