@metacensus/library-ui 0.14.0 → 0.15.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/README.md CHANGED
@@ -43,7 +43,7 @@ Components render on the server: no router, auth or API client, and no browser g
43
43
  - `Button` takes `variant`: `primary` (the default; one per view), `secondary`, `text`, `danger` or `inverse`. A solid Garnet fill marks only a risky action: one that destroys, discards, revokes or cannot be undone. A vote, a filter or a choice between options is not risky. `inverse` is a white fill for the call to action on a `--mc-fill-solid`, `--mc-gradient-hero` or `--mc-night` ground, where `primary` is the ground's own colour or nearly so. Use it on those grounds only: it reads the same in light and dark, and `secondary` inside `.dark` is its quieter sibling.
44
44
  - `Notice` takes `tone`: `alert` (the default, which reads the `--mc-alert-*` roles), `info` (the blue tint) or `success` (the purple tint fill with the accent ink, since the palette has no green). It renders `role="note"`; pass `role="alert"` for an error.
45
45
  - `Button` and `Notice` follow the guidelines' illustrated Actions and Callout patterns. Those patterns do not bind yet: the guidelines have yet to state their shape.
46
- - Theme: inline `themeScript` in `<head>` so a stored override is on `<html>` before first paint. `useTheme` and `ThemeToggle` read and set it: `system` (the OS), `light` or `dark`.
46
+ - Theme: inline `themeScript` in `<head>` so a stored override is on `<html>` before first paint. `useTheme` and `ThemeToggle` read and set it: `system` (the OS), `light` or `dark`. `ThemeToggle` is a round icon button fixed at the viewport's bottom corner, so render it once, from the layout.
47
47
 
48
48
  ```astro
49
49
  ---
@@ -9,7 +9,9 @@ export declare function useTheme(): {
9
9
  theme: Theme;
10
10
  setTheme: typeof write;
11
11
  };
12
- /** A button that cycles system, light, dark. Hydrate it alone. */
12
+ /** A round button fixed at the bottom of the viewport: the current theme's
13
+ * icon, its name on hover or focus, and a click to the next of system, light,
14
+ * dark. Render it once per page, from the layout; hydrate it alone. */
13
15
  export declare function ThemeToggle({ className }: {
14
16
  className?: string;
15
17
  }): import("react").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useSyncExternalStore } from 'react';
3
3
  import { cn } from './cn.js';
4
4
  const KEY = 'mc-theme';
@@ -45,9 +45,24 @@ const NEXT = {
45
45
  light: 'dark',
46
46
  dark: 'system',
47
47
  };
48
- /** A button that cycles system, light, dark. Hydrate it alone. */
48
+ const NAMES = {
49
+ system: 'System',
50
+ light: 'Light',
51
+ dark: 'Dark',
52
+ };
53
+ /** Lucide's `monitor`, `sun` and `moon` on a 24-unit square, under the ISC
54
+ * license in LICENSES/ISC.txt. */
55
+ const ICONS = {
56
+ system: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2" }), _jsx("path", { d: "M8 21h8M12 17v4" })] })),
57
+ light: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" })] })),
58
+ dark: _jsx("path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" }),
59
+ };
60
+ /** A round button fixed at the bottom of the viewport: the current theme's
61
+ * icon, its name on hover or focus, and a click to the next of system, light,
62
+ * dark. Render it once per page, from the layout; hydrate it alone. */
49
63
  export function ThemeToggle({ className }) {
50
64
  const { theme, setTheme } = useTheme();
51
- return (_jsxs("button", { type: "button", className: cn('mc-theme-toggle', className), onClick: () => setTheme(NEXT[theme]), children: ["Theme: ", theme] }));
65
+ const name = NAMES[theme];
66
+ return (_jsxs("button", { type: "button", className: cn('mc-theme-toggle', className), "aria-label": `Theme: ${name}. Switch to ${NAMES[NEXT[theme]]}`, onClick: () => setTheme(NEXT[theme]), children: [_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: ICONS[theme] }), _jsx("span", { className: "mc-theme-toggle-name", children: name })] }));
52
67
  }
53
68
  //# sourceMappingURL=theme.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/tools/theme.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAK5B,MAAM,GAAG,GAAG,UAAU,CAAA;AAEtB;yEACyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG,kCAAkC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mFAAmF,CAAA;AAEnK,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;AAEvC,SAAS,SAAS,CAAC,QAAoB;IACrC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACvB,OAAO,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC9C,CAAC;AAED,2EAA2E;AAC3E,SAAS,IAAI;IACX,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAA;IAClD,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC7B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;YACzB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,QAAQ,CAAA;AAChB,CAAC;AAED,SAAS,KAAK,CAAC,KAAY;IACzB,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAA;IACrC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACtC,IAAI,KAAK,KAAK,QAAQ;QAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,IAAI,KAAK,K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nB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAE,CAAC,EACd,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,iBACV,MAAM,YAEjB,KAAK,CAAC,KAAK,CAAC,GACT,EACN,eAAM,SAAS,EAAC,sBAAsB,YAAE,IAAI,GAAQ,IAC7C,CACV,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metacensus/library-ui",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "MetaCensus brand layer and UI tools for React.",
5
5
  "license": "AGPL-3.0-only AND LicenseRef-MetaCensus-Marks",
6
6
  "repository": {
@@ -321,21 +321,58 @@
321
321
  font-size: 0.875rem;
322
322
  }
323
323
 
324
- /* Theme toggle. */
324
+ /* Theme toggle: a round icon button fixed at the viewport's bottom corner
325
+ that widens to show the theme's name on hover or focus. */
325
326
  .mc-theme-toggle {
326
- padding: 0.375rem 0.75rem;
327
- border: 1px solid var(--mc-ink);
328
- border-radius: var(--mc-radius);
329
- background: transparent;
327
+ position: fixed;
328
+ inset-block-end: 1rem;
329
+ inset-inline-end: 1rem;
330
+ z-index: 40;
331
+ display: inline-flex;
332
+ align-items: center;
333
+ min-width: 2.75rem;
334
+ height: 2.75rem;
335
+ padding: 0 0.6875rem;
336
+ border: 1px solid var(--mc-hairline);
337
+ border-radius: 999px;
338
+ background: var(--mc-card);
330
339
  color: var(--mc-ink);
340
+ box-shadow: 0 2px 8px color-mix(in srgb, var(--mc-ink) 20%, transparent);
331
341
  font: inherit;
342
+ font-weight: 500;
332
343
  white-space: nowrap;
333
344
  cursor: pointer;
334
345
  }
346
+ .mc-theme-toggle svg {
347
+ flex: none;
348
+ width: 1.25rem;
349
+ height: 1.25rem;
350
+ }
351
+ .mc-theme-toggle-name {
352
+ max-width: 0;
353
+ overflow: hidden;
354
+ transition:
355
+ max-width 200ms ease,
356
+ margin 200ms ease;
357
+ }
358
+ .mc-theme-toggle:hover .mc-theme-toggle-name,
359
+ .mc-theme-toggle:focus-visible .mc-theme-toggle-name {
360
+ max-width: 4rem;
361
+ margin-inline: 0.5rem 0.25rem;
362
+ }
335
363
  .mc-theme-toggle:focus-visible {
336
364
  outline: 2px solid var(--mc-ink-accent);
337
365
  outline-offset: 2px;
338
366
  }
367
+ @media (prefers-reduced-motion: reduce) {
368
+ .mc-theme-toggle-name {
369
+ transition: none;
370
+ }
371
+ }
372
+ /* The footer's last line stays clear of the toggle at the page's end. */
373
+ :root:has(.mc-theme-toggle) .mc-footer {
374
+ padding-block-end: 5rem;
375
+ }
339
376
 
340
377
  /* Audience icon. */
341
378
  .mc-audience-icon {