@tearleads/windowing 0.2.13 → 0.2.14
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/README.md +50 -3
- package/icons/ThemeInvertIcon.d.ts +7 -0
- package/icons/ThemeInvertIcon.js +10 -0
- package/icons/ThemeInvertIcon.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +4 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/theme/ThemeProvider.d.ts +40 -0
- package/theme/ThemeProvider.js +67 -0
- package/theme/ThemeProvider.js.map +1 -0
- package/theme/ThemeSwitch.css +22 -0
- package/theme/ThemeSwitch.d.ts +18 -0
- package/theme/ThemeSwitch.js +19 -0
- package/theme/ThemeSwitch.js.map +1 -0
- package/theme/themes.d.ts +28 -0
- package/theme/themes.js +14 -0
- package/theme/themes.js.map +1 -0
- package/theme/useOsColorScheme.d.ts +6 -0
- package/theme/useOsColorScheme.js +26 -0
- package/theme/useOsColorScheme.js.map +1 -0
- package/tokens.css +8 -0
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
App-agnostic window management for React: window state (open, focus order,
|
|
4
4
|
minimize/maximize, a per-window route and Back stack), window chrome (title
|
|
5
5
|
bar, menu bar, toolbar, sidebar, status bar, resize handles), the menu and
|
|
6
|
-
sidebar primitives that chrome renders with, a taskbar's start menu
|
|
7
|
-
launcher that runs a set of mini-apps in windows or in the routed
|
|
8
|
-
phone) shell.
|
|
6
|
+
sidebar primitives that chrome renders with, a taskbar's start menu and theme
|
|
7
|
+
switch, and a launcher that runs a set of mini-apps in windows or in the routed
|
|
8
|
+
(iPad / phone) shell.
|
|
9
9
|
|
|
10
10
|
The package knows nothing about the applications that run inside its windows.
|
|
11
11
|
It depends only on React, react-dom, and Phosphor icons, which draw the
|
|
@@ -274,6 +274,53 @@ Overlays that should fill the content pane rather than the screen portal into
|
|
|
274
274
|
`.routed-pane`, as a grid item or a block with a height. Tearleads dresses it in
|
|
275
275
|
`packages/app/src/shell/layout/routed/AppRoutedPane.tsx`.
|
|
276
276
|
|
|
277
|
+
## Themes
|
|
278
|
+
|
|
279
|
+
A host offers its own color themes. `ThemeProvider` takes them as a list of
|
|
280
|
+
`{ id, label, scheme }`, the scheme `light` or `dark`, and stamps the active one
|
|
281
|
+
as `<html data-theme>` and `<html data-theme-scheme>`. The host styles each
|
|
282
|
+
theme with a block of the design tokens (see [Styles](#styles)):
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
const THEMES: readonly ThemeDefinition<"paper" | "ink">[] = [
|
|
286
|
+
{ id: "paper", label: "Paper", scheme: "light" },
|
|
287
|
+
{ id: "ink", label: "Ink", scheme: "dark" },
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
<ThemeProvider
|
|
291
|
+
defaultTheme={{ dark: "ink", light: "paper" }}
|
|
292
|
+
storageKey="notes.theme"
|
|
293
|
+
themes={THEMES}
|
|
294
|
+
>
|
|
295
|
+
<Desktop />
|
|
296
|
+
<ThemeSwitch />
|
|
297
|
+
</ThemeProvider>;
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
```css
|
|
301
|
+
:root[data-theme="ink"] {
|
|
302
|
+
--color-dark: #e5e5e5;
|
|
303
|
+
--color-light: #161616;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`defaultTheme`, the theme until the user picks one, is an id or an id per OS
|
|
308
|
+
color scheme, followed live. The choice persists under `storageKey`; a stored
|
|
309
|
+
id the host no longer offers counts as none, and a default it does not offer
|
|
310
|
+
falls back to its first theme. Define the list once, outside render.
|
|
311
|
+
|
|
312
|
+
`ThemeSwitch`, for a taskbar's corner, moves to the next theme in order,
|
|
313
|
+
wrapping, and names it ("Switch to Ink theme"). It renders nothing outside a
|
|
314
|
+
provider or for a single theme. It draws a half-filled square unless given an
|
|
315
|
+
`icon`, and is styled as `NavigationModeSwitch` unless given a `className`.
|
|
316
|
+
`useTheme` reads the active and next themes and the list, and sets a theme by
|
|
317
|
+
id; `useOptionalTheme` returns `null` outside a provider.
|
|
318
|
+
|
|
319
|
+
Mount one provider above everything themed. It stamps the attributes before
|
|
320
|
+
the browser paints and removes them on unmount; under a dark scheme,
|
|
321
|
+
`tokens.css` sets `color-scheme: dark`. Tearleads sets its themes per host
|
|
322
|
+
profile in `packages/app/src/host/AppHostConfig.ts`.
|
|
323
|
+
|
|
277
324
|
## Styles
|
|
278
325
|
|
|
279
326
|
Each component imports its own stylesheet, so a bundler that handles CSS imports
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WindowingIconProps } from "./windowingIcon.js";
|
|
2
|
+
/**
|
|
3
|
+
* The theme switch's glyph, the same mark as Tearleads' `ThemeInvertIcon`: a
|
|
4
|
+
* square with one triangular half in `currentColor`. The other half shows the
|
|
5
|
+
* surface beneath, so the mark inverts with the theme.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ThemeInvertIcon({ size, ...props }: WindowingIconProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The theme switch's glyph, the same mark as Tearleads' `ThemeInvertIcon`: a
|
|
4
|
+
* square with one triangular half in `currentColor`. The other half shows the
|
|
5
|
+
* surface beneath, so the mark inverts with the theme.
|
|
6
|
+
*/
|
|
7
|
+
export function ThemeInvertIcon({ size = 20, ...props }) {
|
|
8
|
+
return (_jsxs("svg", { "aria-hidden": "true", focusable: "false", height: size, viewBox: "0 0 256 256", width: size, xmlns: "http://www.w3.org/2000/svg", ...props, children: [_jsx("rect", { fill: "none", height: "168", stroke: "currentColor", strokeWidth: "16", width: "168", x: "44", y: "44" }), _jsx("path", { d: "M212 44V212H44Z", fill: "currentColor" })] }));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ThemeInvertIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeInvertIcon.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/icons/ThemeInvertIcon.tsx"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,KAAK,EAAsB;IACzE,OAAO,CACL,8BACc,MAAM,EAClB,SAAS,EAAC,OAAO,EACjB,MAAM,EAAE,IAAI,EACZ,OAAO,EAAC,aAAa,EACrB,KAAK,EAAE,IAAI,EACX,KAAK,EAAC,4BAA4B,KAC9B,KAAK,aAET,eACE,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,KAAK,EACZ,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,IAAI,EAChB,KAAK,EAAC,KAAK,EACX,CAAC,EAAC,IAAI,EACN,CAAC,EAAC,IAAI,GACN,EACF,eAAM,CAAC,EAAC,iBAAiB,EAAC,IAAI,EAAC,cAAc,GAAG,IAC5C,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { WindowingIconProps } from \"./windowingIcon\";\n\n/**\n * The theme switch's glyph, the same mark as Tearleads' `ThemeInvertIcon`: a\n * square with one triangular half in `currentColor`. The other half shows the\n * surface beneath, so the mark inverts with the theme.\n */\nexport function ThemeInvertIcon({ size = 20, ...props }: WindowingIconProps) {\n return (\n <svg\n aria-hidden=\"true\"\n focusable=\"false\"\n height={size}\n viewBox=\"0 0 256 256\"\n width={size}\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <rect\n fill=\"none\"\n height=\"168\"\n stroke=\"currentColor\"\n strokeWidth=\"16\"\n width=\"168\"\n x=\"44\"\n y=\"44\"\n />\n <path d=\"M212 44V212H44Z\" fill=\"currentColor\" />\n </svg>\n );\n}\n"]}
|
package/index.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export { RoutedPane, type RoutedPaneProps } from "./routed/RoutedPane.js";
|
|
|
25
25
|
export { RoutedPaneOverlayHostProvider, type RoutedPaneOverlayHostValue, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
26
26
|
export type { SubscribeKeyboardVisibility } from "./routed/useMobileKeyboardVisible.js";
|
|
27
27
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
28
|
+
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
29
|
+
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
|
30
|
+
export type { DefaultTheme, ThemeDefinition, ThemeScheme, } from "./theme/themes.js";
|
|
28
31
|
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
29
32
|
export { Window, type WindowContentBoundary } from "./window/Window.js";
|
|
30
33
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./tokens.css";
|
|
2
2
|
// The public windowing API: window state, window chrome and its registration
|
|
3
3
|
// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's
|
|
4
|
-
// start menu, the icons the chrome draws, and a launcher of
|
|
5
|
-
// shows them in windows or in the routed (iPad / phone) shell.
|
|
4
|
+
// start menu and theme switch, the icons the chrome draws, and a launcher of
|
|
5
|
+
// mini-apps that shows them in windows or in the routed (iPad / phone) shell.
|
|
6
6
|
export { createRequiredContext, } from "./createRequiredContext.js";
|
|
7
7
|
export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
|
|
8
8
|
export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
|
|
@@ -28,6 +28,8 @@ export { useContextMenuPositionState, useContextMenuState, } from "./menu/useCon
|
|
|
28
28
|
export { RoutedPane } from "./routed/RoutedPane.js";
|
|
29
29
|
export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
30
30
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
31
|
+
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
32
|
+
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
|
31
33
|
export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
|
|
32
34
|
export { Window } from "./window/Window.js";
|
|
33
35
|
export { WindowTitleBarActionButtons } from "./window/WindowChromeActions.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"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","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu and theme switch, the icons the chrome draws, and a launcher of\n// mini-apps that shows them in windows or in the routed (iPad / phone) shell.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n WINDOWED_LAYOUT_MIN_WIDTH_PX,\n} from \"./launcher/breakpoints\";\nexport {\n DEFAULT_MINI_APP_POSITION,\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n type OpenMiniAppRequest,\n useLauncherNavigationActions,\n useLauncherNavigationState,\n useMiniAppRouteSegments,\n useOptionalLauncherNavigationState,\n} from \"./launcher/LauncherNavigationProvider\";\nexport {\n isLauncherAppId,\n type LauncherDefinition,\n type MiniAppDefinition,\n resolveLauncherHomeAppId,\n resolveLauncherOrder,\n} from \"./launcher/launcherDefinition\";\nexport {\n MiniAppRouteSegmentsProvider,\n useMiniAppWindowRouteSegments,\n} from \"./launcher/MiniAppRouteSegmentsContext\";\nexport { type MiniAppBoundary, MiniAppWindow } from \"./launcher/MiniAppWindow\";\nexport {\n NavigationModeOverrideProvider,\n useNavigationModeOverride,\n useOptionalNavigationModeOverride,\n} from \"./launcher/NavigationModeOverrideProvider\";\nexport { NavigationModeSwitch } from \"./launcher/NavigationModeSwitch\";\nexport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./launcher/navigationMode\";\nexport {\n buildMiniAppPath,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./launcher/routePaths\";\nexport {\n resolveActiveLauncherRoute,\n useActiveLauncherRoute,\n} from \"./launcher/useActiveLauncherRoute\";\nexport { useCompactRoutedMode } from \"./launcher/useCompactRoutedMode\";\nexport {\n type MiniAppRouteSetOptions,\n useMiniAppRouteState,\n} from \"./launcher/useMiniAppRouteState\";\nexport { useNavigationMode } from \"./launcher/useNavigationMode\";\nexport { useNavigationModeDocumentAttribute } from \"./launcher/useNavigationModeDocumentAttribute\";\nexport {\n useRoutedLayoutActive,\n useWindowedLayoutActive,\n} from \"./launcher/useRoutedLayoutActive\";\nexport {\n type RoutedLayoutTier,\n useRoutedLayoutTier,\n} from \"./launcher/useRoutedLayoutTier\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { RoutedPane, type RoutedPaneProps } from \"./routed/RoutedPane\";\nexport {\n RoutedPaneOverlayHostProvider,\n type RoutedPaneOverlayHostValue,\n useRoutedPaneOverlayHost,\n} from \"./routed/RoutedPaneOverlayHost\";\nexport type { SubscribeKeyboardVisibility } from \"./routed/useMobileKeyboardVisible\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n ThemeProvider,\n useOptionalTheme,\n useTheme,\n} from \"./theme/ThemeProvider\";\nexport { ThemeSwitch } from \"./theme/ThemeSwitch\";\nexport type {\n DefaultTheme,\n ThemeDefinition,\n ThemeScheme,\n} from \"./theme/themes\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type PropsWithChildren } from "react";
|
|
2
|
+
import { type DefaultTheme, type ThemeDefinition } from "./themes.js";
|
|
3
|
+
interface ThemeContextValue {
|
|
4
|
+
/** The theme showing: the user's choice, or the host's default. */
|
|
5
|
+
activeTheme: ThemeDefinition;
|
|
6
|
+
/** The theme `toggleTheme` switches to: the next in order, wrapping. */
|
|
7
|
+
nextTheme: ThemeDefinition;
|
|
8
|
+
/** Records a theme the host offers as the user's choice. */
|
|
9
|
+
setTheme: (id: string) => void;
|
|
10
|
+
/** Every theme the host offers, in order. */
|
|
11
|
+
themes: readonly ThemeDefinition[];
|
|
12
|
+
/** Records the next theme as the user's choice. */
|
|
13
|
+
toggleTheme: () => void;
|
|
14
|
+
}
|
|
15
|
+
interface ThemeProviderProps<Id extends string> extends PropsWithChildren {
|
|
16
|
+
/** The theme until the user picks one; see {@link DefaultTheme}. */
|
|
17
|
+
defaultTheme: DefaultTheme<NoInfer<Id>>;
|
|
18
|
+
/** Where the user's choice persists in localStorage. */
|
|
19
|
+
storageKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* The themes the host offers, in the order the switch cycles them. Define
|
|
22
|
+
* the list once, outside render.
|
|
23
|
+
*/
|
|
24
|
+
themes: readonly ThemeDefinition<Id>[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Owns the color theme: the host's `themes`, the user's choice among them, and
|
|
28
|
+
* the `<html data-theme>` and `data-theme-scheme` attributes the host's theme
|
|
29
|
+
* stylesheets select on. Mount a single instance above everything themed, so
|
|
30
|
+
* the attributes have one owner and every {@link ThemeSwitch} drives the one
|
|
31
|
+
* choice.
|
|
32
|
+
*
|
|
33
|
+
* Only an explicit choice persists. Until the user makes one, the provider
|
|
34
|
+
* shows `defaultTheme`, following the OS preference live when that names a
|
|
35
|
+
* theme per scheme. A stored id the host no longer offers counts as no choice.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ThemeProvider<Id extends string>({ children, defaultTheme, storageKey, themes, }: ThemeProviderProps<Id>): import("react").JSX.Element;
|
|
38
|
+
export declare const useTheme: () => ThemeContextValue;
|
|
39
|
+
export declare const useOptionalTheme: () => ThemeContextValue | null;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useLayoutEffect, useMemo, useState, } from "react";
|
|
3
|
+
import { createRequiredContext } from "../createRequiredContext.js";
|
|
4
|
+
import { loadStoredPreference, saveStoredPreference, } from "../launcher/storedPreference.js";
|
|
5
|
+
import { findTheme, nextTheme, resolveDefaultThemeId, } from "./themes.js";
|
|
6
|
+
import { useOsColorScheme } from "./useOsColorScheme.js";
|
|
7
|
+
const themeContext = createRequiredContext("useTheme must be used within a ThemeProvider");
|
|
8
|
+
/**
|
|
9
|
+
* Stamps the theme onto `<html>` before the browser paints, so a page never
|
|
10
|
+
* shows the default tokens first, and clears it on unmount. Stamping the root
|
|
11
|
+
* lets portaled menus and modals inherit the theme too.
|
|
12
|
+
*/
|
|
13
|
+
function useThemeDocumentAttributes({ id, scheme }) {
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
const root = document.documentElement;
|
|
16
|
+
root.setAttribute("data-theme", id);
|
|
17
|
+
root.setAttribute("data-theme-scheme", scheme);
|
|
18
|
+
return () => {
|
|
19
|
+
root.removeAttribute("data-theme");
|
|
20
|
+
root.removeAttribute("data-theme-scheme");
|
|
21
|
+
};
|
|
22
|
+
}, [id, scheme]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Owns the color theme: the host's `themes`, the user's choice among them, and
|
|
26
|
+
* the `<html data-theme>` and `data-theme-scheme` attributes the host's theme
|
|
27
|
+
* stylesheets select on. Mount a single instance above everything themed, so
|
|
28
|
+
* the attributes have one owner and every {@link ThemeSwitch} drives the one
|
|
29
|
+
* choice.
|
|
30
|
+
*
|
|
31
|
+
* Only an explicit choice persists. Until the user makes one, the provider
|
|
32
|
+
* shows `defaultTheme`, following the OS preference live when that names a
|
|
33
|
+
* theme per scheme. A stored id the host no longer offers counts as no choice.
|
|
34
|
+
*/
|
|
35
|
+
export function ThemeProvider({ children, defaultTheme, storageKey, themes, }) {
|
|
36
|
+
const [choice, setChoice] = useState(() => loadStoredPreference(storageKey, (stored) => stored));
|
|
37
|
+
const osScheme = useOsColorScheme();
|
|
38
|
+
const activeTheme = findTheme(themes, choice) ??
|
|
39
|
+
findTheme(themes, resolveDefaultThemeId(defaultTheme, osScheme)) ??
|
|
40
|
+
themes[0];
|
|
41
|
+
if (!activeTheme) {
|
|
42
|
+
throw new Error("ThemeProvider needs at least one theme");
|
|
43
|
+
}
|
|
44
|
+
useThemeDocumentAttributes(activeTheme);
|
|
45
|
+
const setTheme = useCallback((id) => {
|
|
46
|
+
if (!findTheme(themes, id)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
setChoice(id);
|
|
50
|
+
saveStoredPreference(storageKey, id);
|
|
51
|
+
}, [storageKey, themes]);
|
|
52
|
+
const upcomingTheme = nextTheme(themes, activeTheme);
|
|
53
|
+
const toggleTheme = useCallback(() => setTheme(upcomingTheme.id), [setTheme, upcomingTheme]);
|
|
54
|
+
const value = useMemo(() => ({
|
|
55
|
+
activeTheme,
|
|
56
|
+
nextTheme: upcomingTheme,
|
|
57
|
+
setTheme,
|
|
58
|
+
themes,
|
|
59
|
+
toggleTheme,
|
|
60
|
+
}), [activeTheme, setTheme, themes, toggleTheme, upcomingTheme]);
|
|
61
|
+
return (_jsx(themeContext.context.Provider, { value: value, children: children }));
|
|
62
|
+
}
|
|
63
|
+
export const useTheme = themeContext.useRequired;
|
|
64
|
+
// Non-throwing accessor: a surface that may render outside the provider (a
|
|
65
|
+
// pane mounted standalone in tests) gets null, and a switch there hides.
|
|
66
|
+
export const useOptionalTheme = themeContext.useOptional;
|
|
67
|
+
//# sourceMappingURL=ThemeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/theme/ThemeProvider.tsx"],"names":[],"mappings":"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","sourcesContent":["import {\n type PropsWithChildren,\n useCallback,\n useLayoutEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n loadStoredPreference,\n saveStoredPreference,\n} from \"../launcher/storedPreference\";\nimport {\n type DefaultTheme,\n findTheme,\n nextTheme,\n resolveDefaultThemeId,\n type ThemeDefinition,\n} from \"./themes\";\nimport { useOsColorScheme } from \"./useOsColorScheme\";\n\ninterface ThemeContextValue {\n /** The theme showing: the user's choice, or the host's default. */\n activeTheme: ThemeDefinition;\n /** The theme `toggleTheme` switches to: the next in order, wrapping. */\n nextTheme: ThemeDefinition;\n /** Records a theme the host offers as the user's choice. */\n setTheme: (id: string) => void;\n /** Every theme the host offers, in order. */\n themes: readonly ThemeDefinition[];\n /** Records the next theme as the user's choice. */\n toggleTheme: () => void;\n}\n\nconst themeContext = createRequiredContext<ThemeContextValue>(\n \"useTheme must be used within a ThemeProvider\",\n);\n\ninterface ThemeProviderProps<Id extends string> extends PropsWithChildren {\n /** The theme until the user picks one; see {@link DefaultTheme}. */\n defaultTheme: DefaultTheme<NoInfer<Id>>;\n /** Where the user's choice persists in localStorage. */\n storageKey: string;\n /**\n * The themes the host offers, in the order the switch cycles them. Define\n * the list once, outside render.\n */\n themes: readonly ThemeDefinition<Id>[];\n}\n\n/**\n * Stamps the theme onto `<html>` before the browser paints, so a page never\n * shows the default tokens first, and clears it on unmount. Stamping the root\n * lets portaled menus and modals inherit the theme too.\n */\nfunction useThemeDocumentAttributes({ id, scheme }: ThemeDefinition): void {\n useLayoutEffect(() => {\n const root = document.documentElement;\n root.setAttribute(\"data-theme\", id);\n root.setAttribute(\"data-theme-scheme\", scheme);\n return () => {\n root.removeAttribute(\"data-theme\");\n root.removeAttribute(\"data-theme-scheme\");\n };\n }, [id, scheme]);\n}\n\n/**\n * Owns the color theme: the host's `themes`, the user's choice among them, and\n * the `<html data-theme>` and `data-theme-scheme` attributes the host's theme\n * stylesheets select on. Mount a single instance above everything themed, so\n * the attributes have one owner and every {@link ThemeSwitch} drives the one\n * choice.\n *\n * Only an explicit choice persists. Until the user makes one, the provider\n * shows `defaultTheme`, following the OS preference live when that names a\n * theme per scheme. A stored id the host no longer offers counts as no choice.\n */\nexport function ThemeProvider<Id extends string>({\n children,\n defaultTheme,\n storageKey,\n themes,\n}: ThemeProviderProps<Id>) {\n const [choice, setChoice] = useState(() =>\n loadStoredPreference(storageKey, (stored) => stored),\n );\n const osScheme = useOsColorScheme();\n const activeTheme =\n findTheme(themes, choice) ??\n findTheme(themes, resolveDefaultThemeId(defaultTheme, osScheme)) ??\n themes[0];\n if (!activeTheme) {\n throw new Error(\"ThemeProvider needs at least one theme\");\n }\n\n useThemeDocumentAttributes(activeTheme);\n\n const setTheme = useCallback(\n (id: string) => {\n if (!findTheme(themes, id)) {\n return;\n }\n setChoice(id);\n saveStoredPreference(storageKey, id);\n },\n [storageKey, themes],\n );\n\n const upcomingTheme = nextTheme(themes, activeTheme);\n const toggleTheme = useCallback(\n () => setTheme(upcomingTheme.id),\n [setTheme, upcomingTheme],\n );\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n activeTheme,\n nextTheme: upcomingTheme,\n setTheme,\n themes,\n toggleTheme,\n }),\n [activeTheme, setTheme, themes, toggleTheme, upcomingTheme],\n );\n\n return (\n <themeContext.context.Provider value={value}>\n {children}\n </themeContext.context.Provider>\n );\n}\n\nexport const useTheme = themeContext.useRequired;\n\n// Non-throwing accessor: a surface that may render outside the provider (a\n// pane mounted standalone in tests) gets null, and a switch there hides.\nexport const useOptionalTheme = themeContext.useOptional;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* The theme switch: a square, borderless control the height of the bar's
|
|
2
|
+
controls, lit while hovered or focused, as the start menu's button. */
|
|
3
|
+
.theme-switch {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
flex: 0 0 auto;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
width: var(--control-height);
|
|
9
|
+
height: var(--control-height);
|
|
10
|
+
padding: 0;
|
|
11
|
+
border: 0;
|
|
12
|
+
border-radius: var(--app-radius-control);
|
|
13
|
+
background: transparent;
|
|
14
|
+
color: inherit;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.theme-switch:hover,
|
|
19
|
+
.theme-switch:focus-visible {
|
|
20
|
+
background: var(--emphasis-surface);
|
|
21
|
+
color: var(--emphasis-text);
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WindowingIcon } from "../icons/windowingIcon.js";
|
|
2
|
+
interface ThemeSwitchProps {
|
|
3
|
+
/**
|
|
4
|
+
* Classes for the button. They replace the default `theme-switch` styling,
|
|
5
|
+
* so a host's own button styles apply alone.
|
|
6
|
+
*/
|
|
7
|
+
className?: string | undefined;
|
|
8
|
+
/** The glyph; by default a square half filled in the text color. */
|
|
9
|
+
icon?: WindowingIcon | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The theme switch, for a taskbar's corner: each click moves to the next of
|
|
13
|
+
* the host's themes with the nearest {@link ThemeProvider}, and the button
|
|
14
|
+
* names the theme it switches to. It renders nothing outside a provider, or
|
|
15
|
+
* when the host offers a single theme.
|
|
16
|
+
*/
|
|
17
|
+
export declare function ThemeSwitch({ className, icon: Icon, }: ThemeSwitchProps): import("react").JSX.Element | null;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeInvertIcon } from "../icons/ThemeInvertIcon.js";
|
|
3
|
+
import { useOptionalTheme } from "./ThemeProvider.js";
|
|
4
|
+
import "./ThemeSwitch.css";
|
|
5
|
+
/**
|
|
6
|
+
* The theme switch, for a taskbar's corner: each click moves to the next of
|
|
7
|
+
* the host's themes with the nearest {@link ThemeProvider}, and the button
|
|
8
|
+
* names the theme it switches to. It renders nothing outside a provider, or
|
|
9
|
+
* when the host offers a single theme.
|
|
10
|
+
*/
|
|
11
|
+
export function ThemeSwitch({ className, icon: Icon = ThemeInvertIcon, }) {
|
|
12
|
+
const theme = useOptionalTheme();
|
|
13
|
+
if (!theme || theme.themes.length < 2) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const label = `Switch to ${theme.nextTheme.label} theme`;
|
|
17
|
+
return (_jsx("button", { "aria-label": label, className: className ?? "theme-switch", title: label, type: "button", onClick: theme.toggleTheme, children: _jsx(Icon, { "aria-hidden": "true", focusable: "false", size: 20 }) }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ThemeSwitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeSwitch.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/theme/ThemeSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,mBAAmB,CAAC;AAY3B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,SAAS,EACT,IAAI,EAAE,IAAI,GAAG,eAAe,GACX;IACjB,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;IACjC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,aAAa,KAAK,CAAC,SAAS,CAAC,KAAK,QAAQ,CAAC;IAEzD,OAAO,CACL,+BACc,KAAK,EACjB,SAAS,EAAE,SAAS,IAAI,cAAc,EACtC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,KAAK,CAAC,WAAW,YAE1B,KAAC,IAAI,mBAAa,MAAM,EAAC,SAAS,EAAC,OAAO,EAAC,IAAI,EAAE,EAAE,GAAI,GAChD,CACV,CAAC;AACJ,CAAC","sourcesContent":["import { ThemeInvertIcon } from \"../icons/ThemeInvertIcon\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport { useOptionalTheme } from \"./ThemeProvider\";\nimport \"./ThemeSwitch.css\";\n\ninterface ThemeSwitchProps {\n /**\n * Classes for the button. They replace the default `theme-switch` styling,\n * so a host's own button styles apply alone.\n */\n className?: string | undefined;\n /** The glyph; by default a square half filled in the text color. */\n icon?: WindowingIcon | undefined;\n}\n\n/**\n * The theme switch, for a taskbar's corner: each click moves to the next of\n * the host's themes with the nearest {@link ThemeProvider}, and the button\n * names the theme it switches to. It renders nothing outside a provider, or\n * when the host offers a single theme.\n */\nexport function ThemeSwitch({\n className,\n icon: Icon = ThemeInvertIcon,\n}: ThemeSwitchProps) {\n const theme = useOptionalTheme();\n if (!theme || theme.themes.length < 2) {\n return null;\n }\n\n const label = `Switch to ${theme.nextTheme.label} theme`;\n\n return (\n <button\n aria-label={label}\n className={className ?? \"theme-switch\"}\n title={label}\n type=\"button\"\n onClick={theme.toggleTheme}\n >\n <Icon aria-hidden=\"true\" focusable=\"false\" size={20} />\n </button>\n );\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Whether a theme paints light or dark surfaces. */
|
|
2
|
+
export type ThemeScheme = "light" | "dark";
|
|
3
|
+
/**
|
|
4
|
+
* A color theme a host offers. The package knows themes only by id: the host
|
|
5
|
+
* styles each one with a `:root[data-theme="<id>"]` block of the design tokens
|
|
6
|
+
* the chrome reads (see `tokens.css`), and {@link ThemeProvider} stamps the
|
|
7
|
+
* active theme's id and scheme onto `<html>`.
|
|
8
|
+
*/
|
|
9
|
+
export interface ThemeDefinition<Id extends string = string> {
|
|
10
|
+
readonly id: Id;
|
|
11
|
+
/** The theme's name, as the switch announces it ("Switch to Dark theme"). */
|
|
12
|
+
readonly label: string;
|
|
13
|
+
/**
|
|
14
|
+
* Stamped as `<html data-theme-scheme>`, so rules that care only whether
|
|
15
|
+
* surfaces are dark (shadow depth, native controls) cover every dark theme
|
|
16
|
+
* without listing ids.
|
|
17
|
+
*/
|
|
18
|
+
readonly scheme: ThemeScheme;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The theme shown until the user picks one: a theme id, or one id per OS color
|
|
22
|
+
* scheme, which the provider follows as the OS preference changes.
|
|
23
|
+
*/
|
|
24
|
+
export type DefaultTheme<Id extends string = string> = Id | Readonly<Record<ThemeScheme, Id>>;
|
|
25
|
+
export declare function findTheme<Id extends string>(themes: readonly ThemeDefinition<Id>[], id: string | null | undefined): ThemeDefinition<Id> | undefined;
|
|
26
|
+
export declare function resolveDefaultThemeId<Id extends string>(defaultTheme: DefaultTheme<Id>, osScheme: ThemeScheme): Id;
|
|
27
|
+
/** The theme after `current` in the host's order, wrapping to the first. */
|
|
28
|
+
export declare function nextTheme<Id extends string>(themes: readonly ThemeDefinition<Id>[], current: ThemeDefinition<Id>): ThemeDefinition<Id>;
|
package/theme/themes.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function findTheme(themes, id) {
|
|
2
|
+
return themes.find((theme) => theme.id === id);
|
|
3
|
+
}
|
|
4
|
+
export function resolveDefaultThemeId(defaultTheme, osScheme) {
|
|
5
|
+
return typeof defaultTheme === "string"
|
|
6
|
+
? defaultTheme
|
|
7
|
+
: defaultTheme[osScheme];
|
|
8
|
+
}
|
|
9
|
+
/** The theme after `current` in the host's order, wrapping to the first. */
|
|
10
|
+
export function nextTheme(themes, current) {
|
|
11
|
+
const index = themes.indexOf(current);
|
|
12
|
+
return themes[(index + 1) % themes.length] ?? current;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=themes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themes.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/theme/themes.ts"],"names":[],"mappings":"AA6BA,MAAM,UAAU,SAAS,CACvB,MAAsC,EACtC,EAA6B;IAE7B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,YAA8B,EAC9B,QAAqB;IAErB,OAAO,OAAO,YAAY,KAAK,QAAQ;QACrC,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CACvB,MAAsC,EACtC,OAA4B;IAE5B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC;AACxD,CAAC","sourcesContent":["/** Whether a theme paints light or dark surfaces. */\nexport type ThemeScheme = \"light\" | \"dark\";\n\n/**\n * A color theme a host offers. The package knows themes only by id: the host\n * styles each one with a `:root[data-theme=\"<id>\"]` block of the design tokens\n * the chrome reads (see `tokens.css`), and {@link ThemeProvider} stamps the\n * active theme's id and scheme onto `<html>`.\n */\nexport interface ThemeDefinition<Id extends string = string> {\n readonly id: Id;\n /** The theme's name, as the switch announces it (\"Switch to Dark theme\"). */\n readonly label: string;\n /**\n * Stamped as `<html data-theme-scheme>`, so rules that care only whether\n * surfaces are dark (shadow depth, native controls) cover every dark theme\n * without listing ids.\n */\n readonly scheme: ThemeScheme;\n}\n\n/**\n * The theme shown until the user picks one: a theme id, or one id per OS color\n * scheme, which the provider follows as the OS preference changes.\n */\nexport type DefaultTheme<Id extends string = string> =\n | Id\n | Readonly<Record<ThemeScheme, Id>>;\n\nexport function findTheme<Id extends string>(\n themes: readonly ThemeDefinition<Id>[],\n id: string | null | undefined,\n): ThemeDefinition<Id> | undefined {\n return themes.find((theme) => theme.id === id);\n}\n\nexport function resolveDefaultThemeId<Id extends string>(\n defaultTheme: DefaultTheme<Id>,\n osScheme: ThemeScheme,\n): Id {\n return typeof defaultTheme === \"string\"\n ? defaultTheme\n : defaultTheme[osScheme];\n}\n\n/** The theme after `current` in the host's order, wrapping to the first. */\nexport function nextTheme<Id extends string>(\n themes: readonly ThemeDefinition<Id>[],\n current: ThemeDefinition<Id>,\n): ThemeDefinition<Id> {\n const index = themes.indexOf(current);\n return themes[(index + 1) % themes.length] ?? current;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
const DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
|
|
3
|
+
function darkSchemeQuery() {
|
|
4
|
+
return typeof window.matchMedia === "function"
|
|
5
|
+
? window.matchMedia(DARK_SCHEME_QUERY)
|
|
6
|
+
: null;
|
|
7
|
+
}
|
|
8
|
+
function subscribe(onChange) {
|
|
9
|
+
const query = darkSchemeQuery();
|
|
10
|
+
query?.addEventListener("change", onChange);
|
|
11
|
+
return () => query?.removeEventListener("change", onChange);
|
|
12
|
+
}
|
|
13
|
+
function getSnapshot() {
|
|
14
|
+
return darkSchemeQuery()?.matches ? "dark" : "light";
|
|
15
|
+
}
|
|
16
|
+
function getServerSnapshot() {
|
|
17
|
+
return "light";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The OS color-scheme preference, tracked live, so a default theme chosen per
|
|
21
|
+
* scheme follows a system on an automatic light/dark schedule.
|
|
22
|
+
*/
|
|
23
|
+
export function useOsColorScheme() {
|
|
24
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=useOsColorScheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsColorScheme.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/theme/useOsColorScheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAG7C,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEzD,SAAS,eAAe;IACtB,OAAO,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QAC5C,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,SAAS,CAAC,QAAoB;IACrC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO,GAAG,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,WAAW;IAClB,OAAO,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AACvD,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport type { ThemeScheme } from \"./themes\";\n\nconst DARK_SCHEME_QUERY = \"(prefers-color-scheme: dark)\";\n\nfunction darkSchemeQuery(): MediaQueryList | null {\n return typeof window.matchMedia === \"function\"\n ? window.matchMedia(DARK_SCHEME_QUERY)\n : null;\n}\n\nfunction subscribe(onChange: () => void): () => void {\n const query = darkSchemeQuery();\n query?.addEventListener(\"change\", onChange);\n return () => query?.removeEventListener(\"change\", onChange);\n}\n\nfunction getSnapshot(): ThemeScheme {\n return darkSchemeQuery()?.matches ? \"dark\" : \"light\";\n}\n\nfunction getServerSnapshot(): ThemeScheme {\n return \"light\";\n}\n\n/**\n * The OS color-scheme preference, tracked live, so a default theme chosen per\n * scheme follows a system on an automatic light/dark schedule.\n */\nexport function useOsColorScheme(): ThemeScheme {\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"]}
|
package/tokens.css
CHANGED
|
@@ -80,6 +80,14 @@
|
|
|
80
80
|
--control-icon-size: 24px;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/*
|
|
84
|
+
* A dark theme (see ThemeProvider) darkens the browser's own controls, such as
|
|
85
|
+
* form fields. Zero specificity, so a theme that sets its own wins.
|
|
86
|
+
*/
|
|
87
|
+
:where(:root[data-theme-scheme="dark"]) {
|
|
88
|
+
color-scheme: dark;
|
|
89
|
+
}
|
|
90
|
+
|
|
83
91
|
@media (prefers-reduced-motion: reduce) {
|
|
84
92
|
:where(:root) {
|
|
85
93
|
--transition: 0s;
|