@brdgapp/ui 1.9.0 → 1.10.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 +13 -1
- package/README.md +6 -1
- package/components/action-menu.js +2 -2
- package/components/app-shell.js +1 -1
- package/components/button.js +2 -2
- package/components/data-table.js +2 -2
- package/components/icon-button.js +2 -2
- package/components/search-input.js +2 -2
- package/hooks/use-theme.js +3 -3
- package/lib/theme.d.ts +2 -2
- package/lib/theme.js +7 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
|
|
4
4
|
|
|
5
|
+
## 1.10.0
|
|
6
|
+
|
|
7
|
+
2026-11-19. Light by default, the top bar's edges, and Lucide's current icon names. Nothing to change in an
|
|
8
|
+
app's code.
|
|
9
|
+
|
|
10
|
+
- Changed: someone who hasn't chosen a theme now sees Light, not their device's setting. Light, Dark and
|
|
11
|
+
System are still the three choices in ThemeSwitch, and a saved choice is kept.
|
|
12
|
+
- Fix: AppShell's top bar has the page's edges at every width (16, then 24px from 640px, then 32px from
|
|
13
|
+
1024px), so the logo lines up with the page title between 640 and 768px.
|
|
14
|
+
- Fix: the package draws its spinner and ⋮ with Lucide's current names, `LoaderCircle` and
|
|
15
|
+
`EllipsisVertical`. They look the same.
|
|
16
|
+
|
|
5
17
|
## 1.9.0
|
|
6
18
|
|
|
7
19
|
2026-11-19. Select, and menus open inside dialogs. Nothing changes for apps already on 1.8.
|
|
@@ -32,7 +44,7 @@ Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versi
|
|
|
32
44
|
|
|
33
45
|
## 1.6.3
|
|
34
46
|
|
|
35
|
-
2026-11-17. AppShell on narrow phones.
|
|
47
|
+
2026-11-17. AppShell on narrow phones. Apps with `nav="top"` pass `logoMark` too.
|
|
36
48
|
|
|
37
49
|
- AppShell: on a phone too narrow for the full logo beside search, the launcher and your account, the top
|
|
38
50
|
bar shows `logoMark` instead, and the right of the bar no longer runs over the logo. Pass `logoMark` with
|
package/README.md
CHANGED
|
@@ -45,7 +45,12 @@ as the family is "Mulish".
|
|
|
45
45
|
If Mulish doesn't load, `<Toaster />` says so in the browser console while you develop, and the handbook's
|
|
46
46
|
`check_code` flags a root layout that doesn't load it.
|
|
47
47
|
|
|
48
|
-
Themes follow `data-theme="light"` or `data-theme="dark"` on `<html>`,
|
|
48
|
+
Themes follow `data-theme="light"` or `data-theme="dark"` on `<html>`, set before the page paints by
|
|
49
|
+
`themeScript`: Light until the person picks Light, Dark or System in ThemeSwitch.
|
|
50
|
+
|
|
51
|
+
The root layout also wraps the app in `<TipProvider>` with one `<Toaster />`, and draws AppShell, which
|
|
52
|
+
brings the skip link, the top bar and the one `<main>`. The whole layout, for Next.js and Vite:
|
|
53
|
+
https://handbook.brdg.app/using-the-system#setup
|
|
49
54
|
|
|
50
55
|
## Use
|
|
51
56
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useCallback, useContext, useMemo, useState } from "react";
|
|
4
4
|
import { Menu } from "@base-ui/react/menu";
|
|
5
|
-
import {
|
|
5
|
+
import { EllipsisVertical } from "lucide-react";
|
|
6
6
|
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
7
7
|
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
8
8
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
@@ -36,7 +36,7 @@ function ActionMenu({ ariaLabel = "More options", size = "md", width = 248, alig
|
|
|
36
36
|
const stop = stopPropagation ? (e) => e.stopPropagation() : undefined;
|
|
37
37
|
return (_jsxs(Menu.Root, { open: open, onOpenChange: setOpenAndNotify, children: [renderTrigger ? (_jsx(Menu.Trigger, { render: (props) => renderTrigger(props, { open }) })) : (
|
|
38
38
|
// The same words as the trigger's name, in a Tip, so people who see it and people who hear it get one name.
|
|
39
|
-
_jsx(Tip, { text: ariaLabel, disabled: open, children: _jsx(Menu.Trigger, { render: _jsx(IconButton, { "aria-label": ariaLabel, size: size, className: cn("shrink-0", triggerClassName), children: icon ?? _jsx(
|
|
39
|
+
_jsx(Tip, { text: ariaLabel, disabled: open, children: _jsx(Menu.Trigger, { render: _jsx(IconButton, { "aria-label": ariaLabel, size: size, className: cn("shrink-0", triggerClassName), children: icon ?? _jsx(EllipsisVertical, {}) }), onClick: stop, onPointerDown: stop }) })), _jsx(Menu.Portal, { children: _jsx(Menu.Positioner, { side: "bottom", align: align, sideOffset: 6, collisionPadding: 8, className: "z-[95]", children: _jsx(Menu.Popup, { "data-slot": "action-menu", style: { width }, className: cn("max-w-[calc(100vw-16px)] rounded-xl border border-[var(--border-default)] bg-[var(--surface-elevated)] py-1 shadow-[var(--shadow-menu)] outline-none", "origin-[var(--transform-origin)] transition-[opacity,scale] duration-200 ease-out data-[ending-style]:duration-150 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", menuClassName), children: _jsx(ActionMenuContext.Provider, { value: ctx, children: typeof children === "function" ? children(close) : children }) }) }) })] }));
|
|
40
40
|
}
|
|
41
41
|
function ActionMenuItem({ icon, children, description, onClick, href, external = false, danger = false, disabled = false, closeOnClick = true, render, className, }) {
|
|
42
42
|
const classes = cn(ACTION_MENU_ITEM_CLASS, danger && ACTION_MENU_ITEM_DANGER_CLASS, description && "items-start", className);
|
package/components/app-shell.js
CHANGED
|
@@ -158,7 +158,7 @@ function AppShell({ logo, logoMark, homeHref = "/", items, nav = "top", breadcru
|
|
|
158
158
|
// The right of the top bar, the same in every app: search, the launcher, your account. Under 640px of bar it
|
|
159
159
|
// keeps its own width, so it never runs over the logo; the logo gives way instead (BarLogo).
|
|
160
160
|
const right = (_jsxs("div", { className: "ml-auto flex min-w-0 flex-1 items-center justify-end gap-3 pl-4 @max-[639px]/bar:flex-none md:gap-4 md:pl-8", children: [search ? _jsx("div", { className: "@container/search flex min-w-9 flex-1 items-center justify-end", children: searchSized }) : null, actions ? _jsx("div", { className: "flex shrink-0 items-center gap-2 md:gap-4", children: actions }) : null, account ? (_jsxs(_Fragment, { children: [actions || search ? _jsx("span", { "aria-hidden": "true", className: "h-6 w-px shrink-0 bg-[var(--border-default)]" }) : null, _jsx("div", { className: "flex shrink-0 items-center", children: account })] })) : null] }));
|
|
161
|
-
const topBar = (_jsx("header", { "data-slot": "app-shell-top-bar", className: "glass-chrome @container/bar sticky top-0 z-50 h-14 shrink-0 border-b border-[var(--glass-border)] bg-[var(--glass-bg)] backdrop-blur-2xl backdrop-saturate-150", children: _jsxs("nav", { "aria-label": "Top bar", className: "flex h-full items-center gap-3 px-4
|
|
161
|
+
const topBar = (_jsx("header", { "data-slot": "app-shell-top-bar", className: "glass-chrome @container/bar sticky top-0 z-50 h-14 shrink-0 border-b border-[var(--glass-border)] bg-[var(--glass-bg)] backdrop-blur-2xl backdrop-saturate-150", children: _jsxs("nav", { "aria-label": "Top bar", className: "flex h-full items-center gap-3 px-4 sm:px-6 md:gap-5 lg:px-8", children: [side ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "-ml-1.5 md:hidden", children: _jsx(IconButton, { size: "sm", "aria-label": "Open menu", "aria-expanded": menuOpen, onClick: () => setMenuOpen(true), children: _jsx(Menu, {}) }) }), _jsx(BarLogo, { logo: logo, mark: logoMark, link: (c) => logoLink(c), className: "flex-1 md:hidden" }), breadcrumbs ? _jsx("div", { className: "hidden min-w-0 shrink md:flex", children: breadcrumbs }) : null] })) : (_jsxs(_Fragment, { children: [_jsx(BarLogo, { logo: logo, mark: logoMark, link: (c) => logoLink(c), className: "shrink-0 max-md:flex-1" }), items.length ? (_jsxs(_Fragment, { children: [divider, _jsx(TopTabs, { items: items, link: link })] })) : null] })), right] }) }));
|
|
162
162
|
return (_jsxs("div", { "data-slot": "app-shell", "data-nav": nav, className: cn("flex min-h-dvh", side ? "flex-row" : "flex-col"), children: [_jsx(SkipLink, {}), side ? (_jsxs("nav", { "aria-label": "Main", "data-slot": "app-shell-side-menu", "data-collapsed": collapsed || undefined, className: cn("sticky top-0 hidden h-dvh shrink-0 flex-col border-r border-[var(--border-divider)] bg-[var(--surface-primary)] transition-[width] duration-200 ease-out motion-reduce:transition-none md:flex", collapsed ? "w-14" : "w-56"), children: [collapsed ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex h-14 shrink-0 items-center justify-center border-b border-[var(--glass-border)] [&_img]:h-4 [&_img]:w-auto [&_svg]:h-4 [&_svg]:w-auto", children: logoMark ? logoLink(logoMark) : null }), _jsx("div", { className: "flex shrink-0 justify-center pt-3", children: toggle })] })) : (_jsxs("div", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-[var(--glass-border)] pr-3 pl-4", children: [logoLink(logo), _jsx("span", { className: "ml-auto", children: toggle })] })), _jsx(SideMenu, { items: items, link: link, collapsed: collapsed, footer: sideFooter })] })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [topBar, _jsx("main", { id: "main", tabIndex: -1, className: cn("min-w-0 flex-1 outline-none", side ? "" : "max-md:pb-[calc(56px+env(safe-area-inset-bottom))]"), children: children })] }), !side && items.length ? _jsx(BottomBar, { items: items, link: link }) : null, side ? (_jsx(DialogPrimitive.Root, { open: menuOpen, onOpenChange: setMenuOpen, children: _jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Backdrop, { className: "fixed inset-0 z-[60] bg-black/30 transition-opacity duration-300 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 md:hidden" }), _jsxs(DialogPrimitive.Popup, { "data-slot": "app-shell-menu-sheet", className: cn("fixed inset-y-0 left-0 z-[60] flex w-72 max-w-[85vw] flex-col bg-[var(--surface-elevated)] shadow-[var(--shadow-drawer)] outline-none md:hidden", "transition-[translate] duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full motion-reduce:transition-none"), children: [_jsxs("div", { className: "flex h-14 shrink-0 items-center justify-between gap-3 border-b border-[var(--border-divider)] px-4 pt-[env(safe-area-inset-top)]", children: [_jsx(DialogPrimitive.Title, { className: "sr-only", children: "Menu" }), link({ href: homeHref, onClick: () => setMenuOpen(false), className: "flex items-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]", children: logo }), _jsx(DialogPrimitive.Close, { render: _jsx(IconButton, { size: "sm", "aria-label": "Close menu", children: _jsx(X, {}) }) })] }), _jsx(SideMenu, { items: items, link: link, collapsed: false, footer: sideFooter, onNavigate: () => setMenuOpen(false) })] })] }) })) : null] }));
|
|
163
163
|
}
|
|
164
164
|
export { AppShell };
|
package/components/button.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
|
4
4
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
5
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
6
6
|
import { cva } from "class-variance-authority";
|
|
7
|
-
import {
|
|
7
|
+
import { LoaderCircle } from "lucide-react";
|
|
8
8
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
9
9
|
// Started from shadcn's Base UI button (style base-nova), then moved onto Bridge's tokens and API.
|
|
10
10
|
// Look and API match Bridge OS src/components/ui/button.tsx (components.md, 2026-10-29); `asChild`
|
|
@@ -71,7 +71,7 @@ function Button({ className, variant, size, fullWidth, icon, loading = false, di
|
|
|
71
71
|
});
|
|
72
72
|
if (rendered)
|
|
73
73
|
return rendered;
|
|
74
|
-
return (_jsxs(ButtonPrimitive, { "data-slot": "button", className: classes, disabled: disabled || loading, "aria-busy": loading || undefined, ...props, children: [loading ? (_jsx(
|
|
74
|
+
return (_jsxs(ButtonPrimitive, { "data-slot": "button", className: classes, disabled: disabled || loading, "aria-busy": loading || undefined, ...props, children: [loading ? (_jsx(LoaderCircle, { "data-slot": "button-spinner", className: "animate-spin", "aria-hidden": "true" })) : icon ? (_jsx("span", { "data-slot": "button-icon", className: "inline-flex shrink-0", "aria-hidden": "true", children: icon })) : null, children] }));
|
|
75
75
|
}
|
|
76
76
|
const buttonSkeletonHeights = { xs: "h-7", sm: "h-8", md: "h-11 md:h-10", lg: "h-12" };
|
|
77
77
|
/**
|
package/components/data-table.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createElement as _createElement } from "react";
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import { ChevronLeft, ChevronRight,
|
|
6
|
+
import { ChevronLeft, ChevronRight, LoaderCircle, Plus } from "lucide-react";
|
|
7
7
|
import { IconButton } from "@brdgapp/ui/components/icon-button";
|
|
8
8
|
import { Tip } from "@brdgapp/ui/components/info-hint";
|
|
9
9
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
@@ -131,6 +131,6 @@ function DataTablePagination({ page, pageSize, totalCount, loading = false, onPa
|
|
|
131
131
|
if (totalPages <= 1)
|
|
132
132
|
return null;
|
|
133
133
|
const n = (v) => v.toLocaleString("en-US");
|
|
134
|
-
return (_jsxs("nav", { "data-slot": "data-table-pagination", "aria-label": "Pages", className: "flex items-center justify-between gap-4 px-6 py-3", children: [_jsxs("p", { className: "shrink-0 text-12 leading-normal tabular-nums text-[var(--text-muted)]", children: [n((page - 1) * pageSize + 1), "\u2013", n(Math.min(page * pageSize, totalCount)), " of ", n(totalCount)] }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(ButtonPrimitive, { onClick: () => onPageChange(page - 1), disabled: page === 1 || loading, "aria-label": "Previous page", className: pagerButton, children: _jsx(ChevronLeft, { "aria-hidden": "true", className: "size-3.5" }) }), pageList(page, totalPages).map((p, i) => p === "…" ? (_jsx("span", { "aria-hidden": "true", className: "flex size-7 items-center justify-center text-12 text-[var(--text-muted)]", children: "\u2026" }, `gap-${i}`)) : (_jsx(ButtonPrimitive, { onClick: () => onPageChange(p), disabled: loading, "aria-label": `Page ${p}`, "aria-current": p === page ? "page" : undefined, className: cn(pagerButton, "w-auto min-w-7 px-1.5 text-12 font-semibold tabular-nums disabled:opacity-100", p === page && "bg-[var(--primary-solid)] text-white hover:bg-[var(--primary-solid)] hover:text-white"), children: loading && p === page ? _jsx(
|
|
134
|
+
return (_jsxs("nav", { "data-slot": "data-table-pagination", "aria-label": "Pages", className: "flex items-center justify-between gap-4 px-6 py-3", children: [_jsxs("p", { className: "shrink-0 text-12 leading-normal tabular-nums text-[var(--text-muted)]", children: [n((page - 1) * pageSize + 1), "\u2013", n(Math.min(page * pageSize, totalCount)), " of ", n(totalCount)] }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(ButtonPrimitive, { onClick: () => onPageChange(page - 1), disabled: page === 1 || loading, "aria-label": "Previous page", className: pagerButton, children: _jsx(ChevronLeft, { "aria-hidden": "true", className: "size-3.5" }) }), pageList(page, totalPages).map((p, i) => p === "…" ? (_jsx("span", { "aria-hidden": "true", className: "flex size-7 items-center justify-center text-12 text-[var(--text-muted)]", children: "\u2026" }, `gap-${i}`)) : (_jsx(ButtonPrimitive, { onClick: () => onPageChange(p), disabled: loading, "aria-label": `Page ${p}`, "aria-current": p === page ? "page" : undefined, className: cn(pagerButton, "w-auto min-w-7 px-1.5 text-12 font-semibold tabular-nums disabled:opacity-100", p === page && "bg-[var(--primary-solid)] text-white hover:bg-[var(--primary-solid)] hover:text-white"), children: loading && p === page ? _jsx(LoaderCircle, { "aria-hidden": "true", className: "mx-auto size-3 animate-spin" }) : p }, p))), _jsx(ButtonPrimitive, { onClick: () => onPageChange(page + 1), disabled: page === totalPages || loading, "aria-label": "Next page", className: pagerButton, children: _jsx(ChevronRight, { "aria-hidden": "true", className: "size-3.5" }) })] })] }));
|
|
135
135
|
}
|
|
136
136
|
export { DataTable, DataTableHeader, DataTableSkeleton, DataTablePagination, DataTableToolbar };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } 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 { LoaderCircle } from "lucide-react";
|
|
6
6
|
import { cn } from "@brdgapp/ui/lib/utils";
|
|
7
7
|
// The one icon-only button: close, kebab, back, copy, sync. Always round. Ported from Bridge OS
|
|
8
8
|
// src/components/ui/icon-button.tsx onto Base UI Button. All sizes meet the 24px minimum target.
|
|
@@ -32,6 +32,6 @@ const iconButtonVariants = cva([
|
|
|
32
32
|
defaultVariants: { variant: "default", size: "md" },
|
|
33
33
|
});
|
|
34
34
|
function IconButton({ className, variant, size, loading = false, disabled, children, ...props }) {
|
|
35
|
-
return (_jsx(ButtonPrimitive, { "data-slot": "icon-button", className: cn(iconButtonVariants({ variant, size }), className), disabled: disabled || loading, "aria-busy": loading || undefined, ...props, children: _jsx("span", { "aria-hidden": "true", className: "inline-grid place-items-center", children: loading ? _jsx(
|
|
35
|
+
return (_jsx(ButtonPrimitive, { "data-slot": "icon-button", className: cn(iconButtonVariants({ variant, size }), className), disabled: disabled || loading, "aria-busy": loading || undefined, ...props, children: _jsx("span", { "aria-hidden": "true", className: "inline-grid place-items-center", children: loading ? _jsx(LoaderCircle, { className: "animate-spin" }) : children }) }));
|
|
36
36
|
}
|
|
37
37
|
export { IconButton, iconButtonVariants };
|
|
@@ -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/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 };
|
package/lib/theme.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Light, dark or system, the same in every Bridge app. Decided 2026-11-03 (Aman): every web app offers dark
|
|
2
|
-
// mode; the choice is Light, Dark or System (
|
|
2
|
+
// mode; the choice is Light, Dark or System (following the device); one choice applies across
|
|
3
3
|
// all Bridge apps, so it's kept in a cookie for the whole brdg.app domain. Built on Bridge OS's version
|
|
4
4
|
// (src/lib/hooks/use-theme.tsx and the init script in its root layout), which kept it per app in
|
|
5
5
|
// localStorage under "bridge-theme" and offered Light and Dark only; that key is still read, so people who
|
|
6
|
-
// chose dark in Bridge OS keep it.
|
|
6
|
+
// chose dark in Bridge OS keep it. Light is the default until someone chooses (Aman, 2026-11-19).
|
|
7
7
|
export const THEME_COOKIE = "bridge-theme";
|
|
8
8
|
const ONE_YEAR = 60 * 60 * 24 * 365;
|
|
9
9
|
const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
10
10
|
function isPreference(v) {
|
|
11
11
|
return v === "light" || v === "dark" || v === "system";
|
|
12
12
|
}
|
|
13
|
-
/** The saved choice: the shared cookie, then Bridge OS's old per-app key, then
|
|
13
|
+
/** The saved choice: the shared cookie, then Bridge OS's old per-app key, then Light. */
|
|
14
14
|
export function readPreference() {
|
|
15
15
|
if (typeof document === "undefined")
|
|
16
|
-
return "
|
|
16
|
+
return "light";
|
|
17
17
|
const match = document.cookie.match(new RegExp(`(?:^|; )${THEME_COOKIE}=(light|dark|system)`));
|
|
18
18
|
if (match && isPreference(match[1]))
|
|
19
19
|
return match[1];
|
|
@@ -23,9 +23,9 @@ export function readPreference() {
|
|
|
23
23
|
return old;
|
|
24
24
|
}
|
|
25
25
|
catch {
|
|
26
|
-
// Storage blocked: fall through to
|
|
26
|
+
// Storage blocked: fall through to Light.
|
|
27
27
|
}
|
|
28
|
-
return "
|
|
28
|
+
return "light";
|
|
29
29
|
}
|
|
30
30
|
/** Saves the choice for every Bridge app: on brdg.app it's shared by all subdomains; elsewhere (localhost, previews) by this site. */
|
|
31
31
|
export function writePreference(preference) {
|
|
@@ -59,5 +59,5 @@ export function applyTheme(theme) {
|
|
|
59
59
|
* Runs in <head> before the page paints, so someone in dark never sees a white flash. The same steps as
|
|
60
60
|
* readPreference and resolveTheme, written out because it can't import anything.
|
|
61
61
|
*/
|
|
62
|
-
export const themeScript = `(function(){try{var m=document.cookie.match(/(?:^|; )${THEME_COOKIE}=(light|dark|system)/),p=m?m[1]:null;if(!p){try{p=localStorage.getItem("${THEME_COOKIE}")}catch(e){}}if(p!=="light"&&p!=="dark")p="
|
|
62
|
+
export const themeScript = `(function(){try{var m=document.cookie.match(/(?:^|; )${THEME_COOKIE}=(light|dark|system)/),p=m?m[1]:null;if(!p){try{p=localStorage.getItem("${THEME_COOKIE}")}catch(e){}}if(p!=="light"&&p!=="dark"&&p!=="system")p="light";var t=p==="dark"||(p==="system"&&matchMedia("${DARK_QUERY}").matches)?"dark":"light",r=document.documentElement;r.dataset.theme=t;r.style.colorScheme=t}catch(e){}})()`;
|
|
63
63
|
export { DARK_QUERY };
|
package/package.json
CHANGED