@brdgapp/ui 1.6.3 → 1.8.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 +17 -0
- package/components/filter-pill.d.ts +27 -4
- package/components/filter-pill.js +52 -2
- package/components/switch.d.ts +5 -2
- package/components/switch.js +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
|
|
4
4
|
|
|
5
|
+
## 1.8.0
|
|
6
|
+
|
|
7
|
+
2026-11-19. A label option on Switch. Nothing changes for apps already on 1.7.
|
|
8
|
+
|
|
9
|
+
- Switch: `label` shows a visible label before the switch, in the toolbar's 13px SemiBold, for one on/off
|
|
10
|
+
view setting in a table toolbar ("Include people's network"). Clicking the label flips it, and it names the
|
|
11
|
+
switch for screen readers.
|
|
12
|
+
|
|
13
|
+
## 1.7.0
|
|
14
|
+
|
|
15
|
+
2026-11-19. A search option on FilterPill. Nothing changes for apps already on 1.6.
|
|
16
|
+
|
|
17
|
+
- FilterPill: `search` adds a search field to its panel, for choices too many to list, like an owner picked
|
|
18
|
+
from all members. The app passes "All …" first and then its results as `options`; each can have a muted
|
|
19
|
+
second line (`description`) and an Avatar (`icon`). It shows a hint under 2 letters, a spinner while
|
|
20
|
+
results load and a line when nothing matches. On phones it opens as a bottom sheet.
|
|
21
|
+
|
|
5
22
|
## 1.6.3
|
|
6
23
|
|
|
7
24
|
2026-11-17. AppShell on narrow phones. Nothing changes for apps already on 1.6.
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
import { type ElementProps } from "@brdgapp/ui/lib/utils";
|
|
2
3
|
type FilterPillOption<T extends string> = {
|
|
3
4
|
value: T;
|
|
4
5
|
label: string;
|
|
6
|
+
/** Search variant only: a second muted line, like an email. */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Search variant only: shown before the label, like an Avatar size="xs". */
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
type FilterPillSearch = {
|
|
12
|
+
/** What's typed. */
|
|
13
|
+
value: string;
|
|
14
|
+
onChange: (value: string) => void;
|
|
15
|
+
/** Results are on their way from the server: a spinner shows in the field. */
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
/** "Search people". */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** Letters needed before the app searches. Default 2; under it the panel says "Type at least 2 letters." */
|
|
20
|
+
minLength?: number;
|
|
21
|
+
/** When nothing matches. Default "No results." */
|
|
22
|
+
emptyText?: string;
|
|
5
23
|
};
|
|
6
24
|
/** The menu body shared by FilterPill and ColumnFilterMenu. */
|
|
7
25
|
declare function FilterMenuPopup<T extends string>({ value, options, onChange, width, align, }: {
|
|
@@ -10,7 +28,7 @@ declare function FilterMenuPopup<T extends string>({ value, options, onChange, w
|
|
|
10
28
|
onChange: (value: T) => void;
|
|
11
29
|
width: number;
|
|
12
30
|
align: "start" | "end";
|
|
13
|
-
}):
|
|
31
|
+
}): React.JSX.Element;
|
|
14
32
|
/** The same choices as FilterMenuPopup, as a bottom sheet: what phones get below 768px. */
|
|
15
33
|
declare function FilterSheet<T extends string>({ open, onClose, title, value, options, onChange, }: {
|
|
16
34
|
open: boolean;
|
|
@@ -19,7 +37,7 @@ declare function FilterSheet<T extends string>({ open, onClose, title, value, op
|
|
|
19
37
|
value: T;
|
|
20
38
|
options: FilterPillOption<T>[];
|
|
21
39
|
onChange: (value: T) => void;
|
|
22
|
-
}):
|
|
40
|
+
}): React.JSX.Element;
|
|
23
41
|
type FilterPillProps<T extends string> = ElementProps<HTMLButtonElement> & {
|
|
24
42
|
value: T;
|
|
25
43
|
/** The first option is the resting "All" state. */
|
|
@@ -27,8 +45,13 @@ type FilterPillProps<T extends string> = ElementProps<HTMLButtonElement> & {
|
|
|
27
45
|
onChange: (value: T) => void;
|
|
28
46
|
/** What is being filtered: "Degree", "Status". Read as "Degree: 1st". */
|
|
29
47
|
ariaLabel?: string;
|
|
48
|
+
/**
|
|
49
|
+
* For choices too many to list, like people: the panel gets a search field, and `options` are the first
|
|
50
|
+
* ("All owners") plus the app's results for what's typed. The pill keeps the chosen label while results change.
|
|
51
|
+
*/
|
|
52
|
+
search?: FilterPillSearch;
|
|
30
53
|
className?: string;
|
|
31
54
|
};
|
|
32
|
-
declare function FilterPill<T extends string>({ value, options, onChange, ariaLabel, className, ...rest }: FilterPillProps<T>):
|
|
55
|
+
declare function FilterPill<T extends string>({ value, options, onChange, ariaLabel, search, className, ...rest }: FilterPillProps<T>): React.JSX.Element;
|
|
33
56
|
export { FilterPill, FilterMenuPopup, FilterSheet };
|
|
34
|
-
export type { FilterPillOption, FilterPillProps };
|
|
57
|
+
export type { FilterPillOption, FilterPillProps, FilterPillSearch };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
3
4
|
import { useState } from "react";
|
|
4
5
|
import { Menu } from "@base-ui/react/menu";
|
|
6
|
+
import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
|
|
5
7
|
import { Check, ChevronDown } from "lucide-react";
|
|
6
8
|
import { BottomSheet, BottomSheetOption, BottomSheetOptions } from "@brdgapp/ui/components/bottom-sheet";
|
|
9
|
+
import { SearchInput } from "@brdgapp/ui/components/search-input";
|
|
7
10
|
import { useIsMobile } from "@brdgapp/ui/hooks/use-is-mobile";
|
|
8
11
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
12
|
/** The menu body shared by FilterPill and ColumnFilterMenu. */
|
|
@@ -17,15 +20,62 @@ function FilterSheet({ open, onClose, title, value, options, onChange, }) {
|
|
|
17
20
|
onClose();
|
|
18
21
|
}, children: option.label }, option.value))) }) }));
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
/** The search variant's panel: the field, then the "All" option and the app's results. */
|
|
24
|
+
function SearchPanel({ value, options, search, onPick, phone = false, }) {
|
|
25
|
+
const listId = React.useId();
|
|
26
|
+
const [at, setAt] = useState(0);
|
|
27
|
+
const min = search.minLength ?? 2;
|
|
28
|
+
const short = search.value.trim().length < min;
|
|
29
|
+
const rows = short ? options.slice(0, 1) : options;
|
|
30
|
+
// Results change under the highlight as people type: past the end, it goes back to the first row.
|
|
31
|
+
const cur = at < rows.length ? at : 0;
|
|
32
|
+
const note = short
|
|
33
|
+
? `Type at least ${min} letters.`
|
|
34
|
+
: !search.loading && rows.length < 2
|
|
35
|
+
? (search.emptyText ?? "No results.")
|
|
36
|
+
: null;
|
|
37
|
+
return (_jsxs("div", { "data-slot": "filter-search", className: "flex flex-col", children: [_jsx("div", { className: phone ? "px-5 pb-2" : "p-2 pb-1", children: _jsx(SearchInput, { autoFocus: !phone, role: "combobox", "aria-expanded": "true", "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": rows[cur] ? `${listId}-${cur}` : undefined, placeholder: search.placeholder ?? "Search", value: search.value, loading: search.loading, onChange: (e) => {
|
|
38
|
+
setAt(0);
|
|
39
|
+
search.onChange(e.target.value);
|
|
40
|
+
}, onClear: () => search.onChange(""), onKeyDown: (e) => {
|
|
41
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
const n = rows.length;
|
|
44
|
+
if (n)
|
|
45
|
+
setAt(e.key === "ArrowDown" ? (cur + 1) % n : (cur - 1 + n) % n);
|
|
46
|
+
}
|
|
47
|
+
else if (e.key === "Enter" && rows[cur]) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onPick(rows[cur]);
|
|
50
|
+
}
|
|
51
|
+
} }) }), _jsx("div", { id: listId, role: "listbox", "aria-label": "Results", className: cn("overflow-y-auto", phone ? "max-h-[50dvh] pb-2" : "max-h-[280px] pb-1"), children: rows.map((option, i) => {
|
|
52
|
+
const selected = option.value === value;
|
|
53
|
+
return (_jsxs("div", { id: `${listId}-${i}`, role: "option", "aria-selected": selected, "data-slot": "filter-search-option", "data-highlighted": i === cur || undefined, onMouseDown: (e) => e.preventDefault(), onMouseMove: () => setAt(i), onClick: () => onPick(option), className: cn("flex w-full cursor-default items-center gap-3 text-left leading-normal transition-colors data-[highlighted]:bg-[var(--surface-secondary)]", phone ? "min-h-11 px-5 py-2 text-14" : "px-3 py-2 text-13", selected ? "font-semibold text-[var(--text-primary)]" : "text-[var(--text-body)]"), children: [option.icon ? _jsx("span", { className: "flex shrink-0", children: option.icon }) : null, _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate", children: option.label }), option.description ? _jsx("span", { className: "block truncate text-12 font-normal text-[var(--text-muted)]", children: option.description }) : null] }), selected ? _jsx(Check, { "aria-hidden": "true", className: "size-4 shrink-0 text-[var(--primary)]" }) : null] }, option.value));
|
|
54
|
+
}) }), note ? _jsx("p", { role: "status", className: cn("text-[var(--text-muted)]", phone ? "px-5 pb-4 text-14" : "px-3 pt-1 pb-3 text-13"), children: note }) : null] }));
|
|
55
|
+
}
|
|
56
|
+
function FilterPill({ value, options, onChange, ariaLabel = "Filter", search, className, ...rest }) {
|
|
21
57
|
const [open, setOpen] = useState(false);
|
|
22
58
|
const mobile = useIsMobile();
|
|
23
59
|
const active = value !== options[0]?.value;
|
|
24
|
-
|
|
60
|
+
// The search variant's results change as people type, so the chosen label is kept here.
|
|
61
|
+
const [picked, setPicked] = useState();
|
|
62
|
+
const label = options.find((o) => o.value === value)?.label ?? (active ? picked : undefined) ?? options[0]?.label ?? "";
|
|
25
63
|
const triggerClass = cn("inline-flex shrink-0 items-center gap-1.5 rounded-full border px-3 py-1.5 text-13 leading-normal font-semibold outline-none transition-colors duration-150", "focus-visible:ring-2 focus-visible:ring-[var(--primary)]", active
|
|
26
64
|
? "border-[var(--text-muted)] bg-[var(--surface-tertiary)] text-[var(--text-primary)] hover:border-[var(--text-secondary)]"
|
|
27
65
|
: "border-[var(--text-disabled)] bg-transparent text-[var(--text-secondary)] hover:border-[var(--text-muted)] hover:text-[var(--text-primary)]", className);
|
|
28
66
|
const inner = (_jsxs(_Fragment, { children: [label, _jsx(ChevronDown, { "aria-hidden": "true", className: cn("size-3.5 text-[var(--text-muted)] transition-transform", open && "rotate-180") })] }));
|
|
67
|
+
if (search) {
|
|
68
|
+
const pick = (option) => {
|
|
69
|
+
setPicked(option.label);
|
|
70
|
+
onChange(option.value);
|
|
71
|
+
search.onChange("");
|
|
72
|
+
setOpen(false);
|
|
73
|
+
};
|
|
74
|
+
if (mobile) {
|
|
75
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ...rest, type: "button", "data-slot": "filter-pill", "aria-haspopup": "dialog", "aria-label": `${ariaLabel}: ${label}`, className: triggerClass, onClick: () => setOpen(true), children: inner }), _jsx(BottomSheet, { open: open, onClose: () => setOpen(false), title: ariaLabel, children: _jsx(SearchPanel, { value: value, options: options, search: search, onPick: pick, phone: true }) })] }));
|
|
76
|
+
}
|
|
77
|
+
return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverPrimitive.Trigger, { ...rest, "data-slot": "filter-pill", "aria-label": `${ariaLabel}: ${label}`, className: triggerClass, children: inner }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Positioner, { side: "bottom", align: "end", sideOffset: 6, collisionPadding: 8, className: "z-[80]", children: _jsx(PopoverPrimitive.Popup, { "data-slot": "filter-menu", "aria-label": ariaLabel, className: "w-[300px] max-w-[calc(100vw-16px)] 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(SearchPanel, { value: value, options: options, search: search, onPick: pick }) }) }) })] }));
|
|
78
|
+
}
|
|
29
79
|
// Phones: the choices slide up from the bottom, near the thumb, in 44px rows.
|
|
30
80
|
if (mobile) {
|
|
31
81
|
return (_jsxs(_Fragment, { children: [_jsx("button", { ...rest, type: "button", "data-slot": "filter-pill", "aria-haspopup": "dialog", "aria-label": `${ariaLabel}: ${label}`, className: triggerClass, onClick: () => setOpen(true), children: inner }), _jsx(FilterSheet, { open: open, onClose: () => setOpen(false), title: ariaLabel, value: value, options: options, onChange: onChange })] }));
|
package/components/switch.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
type SwitchProps = {
|
|
2
3
|
checked: boolean;
|
|
3
4
|
onChange: (checked: boolean) => void;
|
|
4
5
|
disabled?: boolean;
|
|
5
|
-
/** A
|
|
6
|
+
/** A visible label before the switch, for a toolbar: "Include people's network". Clicking it flips the switch, and it names it. */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** A name is required: `label`, `aria-label`, or `aria-labelledby` pointing at the visible label. */
|
|
6
9
|
"aria-label"?: string;
|
|
7
10
|
"aria-labelledby"?: string;
|
|
8
11
|
id?: string;
|
|
9
12
|
className?: string;
|
|
10
13
|
};
|
|
11
|
-
declare function Switch({ checked, onChange, disabled, className, ...props }: SwitchProps):
|
|
14
|
+
declare function Switch({ checked, onChange, disabled, label, className, ...props }: SwitchProps): React.JSX.Element;
|
|
12
15
|
export { Switch };
|
|
13
16
|
export type { SwitchProps };
|
package/components/switch.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
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 * as React from "react";
|
|
3
4
|
import { Switch as SwitchPrimitive } from "@base-ui/react/switch";
|
|
4
5
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
5
|
-
function Switch({ checked, onChange, disabled = false, className, ...props }) {
|
|
6
|
-
|
|
6
|
+
function Switch({ checked, onChange, disabled = false, label, className, ...props }) {
|
|
7
|
+
const labelId = React.useId();
|
|
8
|
+
const root = (_jsx(SwitchPrimitive.Root, { "data-slot": "switch", checked: checked, onCheckedChange: (next) => onChange(next), disabled: disabled, className: cn(
|
|
7
9
|
// Off is mid-grey, not pale: the track's edge has to reach 3:1 against the page (4.8:1 on white). 2026-11-04.
|
|
8
10
|
"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full bg-[var(--text-muted)] transition-colors duration-200 outline-none",
|
|
9
11
|
// Hover steps darker in light and in dark, so the white thumb always stands out from the track.
|
|
10
|
-
"hover:bg-[var(--text-secondary)] dark:hover:bg-[var(--text-disabled)] data-[checked]:hover:bg-[var(--primary-solid-hover)]", "focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--surface-primary)]", "data-[checked]:bg-[var(--primary-solid)]", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: _jsx(SwitchPrimitive.Thumb, { "data-slot": "switch-thumb", className: "inline-block size-4 translate-x-[2px] rounded-full bg-white shadow-[0_1px_2px_rgba(0,0,0,0.3)] transition-transform duration-200 data-[checked]:translate-x-[18px]" }) }));
|
|
12
|
+
"hover:bg-[var(--text-secondary)] dark:hover:bg-[var(--text-disabled)] data-[checked]:hover:bg-[var(--primary-solid-hover)]", "focus-visible:ring-2 focus-visible:ring-[var(--primary)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--surface-primary)]", "data-[checked]:bg-[var(--primary-solid)]", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, "aria-labelledby": label ? labelId : props["aria-labelledby"], children: _jsx(SwitchPrimitive.Thumb, { "data-slot": "switch-thumb", className: "inline-block size-4 translate-x-[2px] rounded-full bg-white shadow-[0_1px_2px_rgba(0,0,0,0.3)] transition-transform duration-200 data-[checked]:translate-x-[18px]" }) }));
|
|
13
|
+
if (!label)
|
|
14
|
+
return root;
|
|
15
|
+
return (_jsxs("span", { "data-slot": "switch-field", className: "inline-flex shrink-0 items-center gap-2", children: [_jsx("span", { id: labelId, onClick: () => !disabled && onChange(!checked), className: cn("text-13 leading-normal font-semibold text-[var(--text-secondary)] select-none", disabled ? "opacity-50" : "cursor-pointer"), children: label }), root] }));
|
|
11
16
|
}
|
|
12
17
|
export { Switch };
|
package/package.json
CHANGED