@wintermuted/ui-theme 0.22.0 → 1.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 James Onnyeholt
3
+ Copyright (c) 2026 Jameson Nyeholt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Shared plain-CSS design tokens, resets, component styles, and light/dark themes for Wintermuted projects.
4
4
 
5
+ See the [theme architecture guide](https://github.com/wintermuted/wintermuted-ui/blob/main/packages/ui-theme/docs/architecture.md) for CSS layers, token ownership, public-path registration, and extension rules.
6
+
5
7
  ## Install
6
8
 
7
9
  ```sh
@@ -28,16 +30,17 @@ The package exports `index.css`, `styles/tokens.css`, `styles/base.css`, `styles
28
30
 
29
31
  This package lives in `packages/ui-theme` within the [Wintermuted UI monorepo](https://github.com/wintermuted/wintermuted-ui). New monorepo tags are not directly installable as the theme through a GitHub-source npm dependency; use npm releases or a tarball produced by `npm pack --workspace=@wintermuted/ui-theme`.
30
32
 
31
- ## Existing React entry points
33
+ ## Migrating to 1.0
34
+
35
+ Version 1.0.0 removes the legacy `react`, `react/select`, and `theme` entry points, their TypeScript mappings, and all React-related peer dependencies. CSS imports and `--wm-*` tokens are unchanged. CSS-only consumers need no React packages.
32
36
 
33
- The optional React API remains available for existing consumers:
37
+ React components and theme runtime helpers now come exclusively from `@wintermuted/ui-react`:
34
38
 
35
39
  ```js
36
- import { Button, ThemeProvider } from "@wintermuted/ui-theme/react";
37
- import { MultiSelect } from "@wintermuted/ui-theme/react/select";
38
- import { initTheme } from "@wintermuted/ui-theme/theme";
40
+ import "@wintermuted/ui-theme/index.css";
41
+ import { Button, ThemeProvider } from "@wintermuted/ui-react";
42
+ import { MultiSelect } from "@wintermuted/ui-react/select";
43
+ import { initTheme } from "@wintermuted/ui-react/theme";
39
44
  ```
40
45
 
41
- Install React/React DOM 18.3 or 19 for the React API, and react-select 5.8 or newer only for the select adapter. These peers remain optional for CSS-only consumers.
42
-
43
- The canonical implementation lives in the separate `@wintermuted/ui-react` workspace. Theme packaging includes compatibility copies, preserving runtime exports and legacy TypeScript declaration mappings without maintaining two implementations. Standalone React publication is deferred.
46
+ Install `@wintermuted/ui-react` and React/React DOM 18.3 or 19; add react-select 5.8 or newer only for the select adapter. See the [1.0 migration guide](https://github.com/wintermuted/wintermuted-ui/blob/main/docs/migration-to-v1.md) for installation, import mappings, test tooling, and release ordering.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wintermuted/ui-theme",
3
- "version": "0.22.0",
3
+ "version": "1.0.0",
4
4
  "description": "Shared Wintermuted UI theme (design tokens, base resets, and component styles) derived from the CV styling language.",
5
5
  "type": "module",
6
6
  "volta": {
@@ -18,8 +18,6 @@
18
18
  "index.js",
19
19
  "index.css",
20
20
  "styles/**/*.css",
21
- "react/**/*.js",
22
- "react/**/*.d.ts",
23
21
  "README.md",
24
22
  "LICENSE"
25
23
  ],
@@ -38,18 +36,6 @@
38
36
  },
39
37
  "exports": {
40
38
  ".": "./index.js",
41
- "./react": {
42
- "types": "./react/index.d.ts",
43
- "default": "./react/index.js"
44
- },
45
- "./react/select": {
46
- "types": "./react/select.d.ts",
47
- "default": "./react/select.js"
48
- },
49
- "./theme": {
50
- "types": "./react/theme.d.ts",
51
- "default": "./react/theme.js"
52
- },
53
39
  "./index.css": "./index.css",
54
40
  "./styles/tokens.css": "./styles/tokens.css",
55
41
  "./styles/base.css": "./styles/base.css",
@@ -90,43 +76,12 @@
90
76
  "./styles/components/dialog.css": "./styles/components/dialog.css",
91
77
  "./styles/components/search-select.css": "./styles/components/search-select.css"
92
78
  },
93
- "typesVersions": {
94
- "*": {
95
- "react": [
96
- "react/index.d.ts"
97
- ],
98
- "react/select": [
99
- "react/select.d.ts"
100
- ],
101
- "theme": [
102
- "react/theme.d.ts"
103
- ]
104
- }
105
- },
106
- "peerDependencies": {
107
- "react": "^18.3.0 || ^19.0.0",
108
- "react-dom": "^18.3.0 || ^19.0.0",
109
- "react-select": "^5.8.0"
110
- },
111
- "peerDependenciesMeta": {
112
- "react": {
113
- "optional": true
114
- },
115
- "react-dom": {
116
- "optional": true
117
- },
118
- "react-select": {
119
- "optional": true
120
- }
121
- },
122
79
  "scripts": {
123
- "prepack": "node ../../scripts/prepare-theme-react.mjs",
124
80
  "lint": "stylelint \"styles/**/*.css\" \"index.css\""
125
81
  },
126
82
  "nx": {
127
83
  "name": "ui-theme",
128
84
  "tags": ["type:library"],
129
- "implicitDependencies": ["ui-react"],
130
85
  "targets": {
131
86
  "pack": {
132
87
  "command": "npm pack --workspace=@wintermuted/ui-theme"
package/react/index.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import type * as React from "react";
2
- import type { ThemePreference, ResolvedTheme } from "./theme";
3
- export type { ThemePreference, ResolvedTheme } from "./theme";
4
-
5
- export type Tone = "neutral" | "info" | "success" | "warning" | "danger";
6
- type Primitive<Default extends React.ElementType> = {
7
- (props: { as?: Default } & React.ComponentPropsWithRef<Default>): React.ReactElement | null;
8
- <T extends React.ElementType>(
9
- props: { as: T } & Omit<React.ComponentPropsWithRef<T>, "as">
10
- ): React.ReactElement | null;
11
- };
12
- export const Card: Primitive<"section">;
13
- export const CardHeader: Primitive<"header">;
14
- export const CardBody: Primitive<"div">;
15
- export const CardTitle: Primitive<"h3">;
16
- export const CardText: Primitive<"p">;
17
- export const CardFooter: Primitive<"footer">;
18
- export const ListGroup: Primitive<"ul">;
19
- export const ListItem: Primitive<"li">;
20
- export const Nav: Primitive<"nav">;
21
- export const Input: Primitive<"input">;
22
- export const Select: Primitive<"select">;
23
-
24
- export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
25
- variant?: "primary" | "secondary" | "ghost" | "danger" | "success" | "warning" | "link";
26
- size?: "sm";
27
- icon?: React.ReactNode;
28
- }
29
- export const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
30
- export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> { tone?: Tone }
31
- export const Badge: React.ForwardRefExoticComponent<BadgeProps & React.RefAttributes<HTMLSpanElement>>;
32
- export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> { tone?: Tone }
33
- export const Alert: React.ForwardRefExoticComponent<AlertProps & React.RefAttributes<HTMLDivElement>>;
34
- export function Spinner(props: React.HTMLAttributes<HTMLSpanElement> & { label?: string }): React.ReactElement;
35
- export function ProgressBar(props: React.ProgressHTMLAttributes<HTMLProgressElement> & {
36
- value?: number; max?: number; label?: string;
37
- }): React.ReactElement;
38
- export const Table: React.ForwardRefExoticComponent<React.TableHTMLAttributes<HTMLTableElement> & {
39
- responsive?: boolean;
40
- } & React.RefAttributes<HTMLTableElement>>;
41
- export interface FieldGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
42
- label: React.ReactNode; htmlFor?: string; hint?: React.ReactNode; error?: React.ReactNode;
43
- children: React.ReactElement;
44
- }
45
- export function FieldGroup(props: FieldGroupProps): React.ReactElement;
46
- export function Accordion(props: Omit<React.DetailsHTMLAttributes<HTMLDetailsElement>, "title"> & {
47
- title: React.ReactNode;
48
- }): React.ReactElement;
49
- export interface TabItem { id: string; label: React.ReactNode; content: React.ReactNode; disabled?: boolean }
50
- export interface TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange"> {
51
- items: TabItem[]; value?: string; defaultValue?: string;
52
- onValueChange?: (id: string) => void; label: string;
53
- }
54
- export function Tabs(props: TabsProps): React.ReactElement;
55
- export interface MenuItem {
56
- id: string; label: React.ReactNode; href?: string; disabled?: boolean;
57
- onSelect?: (event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
58
- }
59
- export function Menu(props: Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
60
- label: React.ReactNode; items: MenuItem[];
61
- }): React.ReactElement;
62
- export function Tooltip(props: { text: string; children: React.ReactElement }): React.ReactElement;
63
- export function Dialog(props: Omit<React.DialogHTMLAttributes<HTMLDialogElement>, "open" | "onClose" | "title"> & {
64
- open: boolean; onClose: () => void; title: React.ReactNode;
65
- }): React.ReactElement;
66
- export interface ThemeContextValue {
67
- preference: ThemePreference;
68
- setPreference: (preference: ThemePreference) => void;
69
- resolvedTheme: ResolvedTheme;
70
- }
71
- export function ThemeProvider(props: { children: React.ReactNode; storageKey?: string }): React.ReactElement;
72
- export function useTheme(): ThemeContextValue;
73
- export function ThemeSelect(props: Omit<React.SelectHTMLAttributes<HTMLSelectElement>,
74
- "value" | "defaultValue" | "onChange"> & { label?: string }): React.ReactElement;
package/react/index.js DELETED
@@ -1,325 +0,0 @@
1
- import {
2
- Children, cloneElement, createContext, createElement as h, forwardRef,
3
- useContext, useEffect, useId, useLayoutEffect, useRef, useState,
4
- } from "react";
5
- import {
6
- DEFAULT_THEME_KEY, applyTheme, isThemePreference, readThemePreference, resolveTheme,
7
- } from "./theme.js";
8
-
9
- const cx = (...values) => values.filter(Boolean).join(" ");
10
- const useClientLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11
-
12
- function primitive(tag, baseClass) {
13
- return forwardRef(function Primitive({ as = tag, className, ...props }, ref) {
14
- return h(as, { ...props, ref, className: cx(baseClass, className) });
15
- });
16
- }
17
-
18
- export const Card = primitive("section", "wm-card");
19
- export const CardHeader = primitive("header", "wm-card-header");
20
- export const CardBody = primitive("div", "wm-card-body");
21
- export const CardTitle = primitive("h3", "wm-card-title");
22
- export const CardText = primitive("p", "wm-card-text");
23
- export const CardFooter = primitive("footer", "wm-card-footer");
24
- export const ListGroup = primitive("ul", "wm-list-group");
25
- export const ListItem = primitive("li", "wm-list-item");
26
- export const Nav = primitive("nav", "wm-nav");
27
- export const Input = primitive("input", "wm-input");
28
- export const Select = primitive("select", "wm-select");
29
-
30
- export const Button = forwardRef(function Button({
31
- variant = "primary", size, icon, className, children, type = "button", ...props
32
- }, ref) {
33
- return h("button", {
34
- ...props, ref, type,
35
- className: cx("wm-btn", `wm-btn-${variant}`, size && `wm-btn-${size}`, className),
36
- }, icon && h("span", { "aria-hidden": true, className: "wm-btn-icon" }, icon), children);
37
- });
38
-
39
- export const Badge = forwardRef(function Badge({ tone = "neutral", className, ...props }, ref) {
40
- return h("span", { ...props, ref, className: cx("wm-badge", `wm-badge-${tone}`, className) });
41
- });
42
-
43
- export const Alert = forwardRef(function Alert({ tone = "info", className, role = "status", ...props }, ref) {
44
- return h("div", { ...props, ref, role, className: cx("wm-alert", `wm-alert-${tone}`, className) });
45
- });
46
-
47
- export function Spinner({ label = "Loading", className, ...props }) {
48
- return h("span", { ...props, role: "status", className: cx("wm-spinner", className) },
49
- h("span", { "aria-hidden": true, className: "wm-spinner-indicator" }),
50
- h("span", { className: "wm-sr-only" }, label));
51
- }
52
-
53
- export function ProgressBar({ value = 0, max = 100, label, className, ...props }) {
54
- if (!Number.isFinite(max) || max <= 0 || !Number.isFinite(value)) {
55
- throw new RangeError("ProgressBar requires a finite value and a positive finite max.");
56
- }
57
- return h("progress", { ...props, className: cx("wm-progress", className),
58
- value: Math.min(max, Math.max(0, value)), max, "aria-label": label ?? props["aria-label"] });
59
- }
60
-
61
- export const Table = forwardRef(function Table({ responsive = false, className, ...props }, ref) {
62
- const table = h("table", { ...props, ref, className: cx("wm-table", className) });
63
- return responsive ? h("div", { className: "wm-table-responsive", tabIndex: 0,
64
- role: "region", "aria-label": props["aria-label"] || "Scrollable table" }, table) : table;
65
- });
66
-
67
- export function FieldGroup({ label, htmlFor, hint, error, className, children, ...props }) {
68
- const id = useId();
69
- const descriptionId = `${id}-description`;
70
- const child = Children.only(children);
71
- const controlId = htmlFor || child.props.inputId || child.props.id || `${id}-control`;
72
- const describedBy = cx(child.props["aria-describedby"], (hint || error) && descriptionId) || undefined;
73
- return h("div", { ...props, className: cx("wm-field", className) },
74
- h("label", { htmlFor: controlId }, label),
75
- cloneElement(child, {
76
- id: controlId, "aria-describedby": describedBy,
77
- ...(child.props.inputId !== undefined ? { inputId: controlId } : {}),
78
- "aria-invalid": error ? true : child.props["aria-invalid"],
79
- }),
80
- (hint || error) && h("div", { id: descriptionId, className: error ? "wm-field-error" : "wm-field-hint" }, error || hint));
81
- }
82
-
83
- export function Accordion({ title, children, className, ...props }) {
84
- return h("details", { ...props, className: cx("wm-accordion", className) },
85
- h("summary", null, title), h("div", { className: "wm-accordion-body" }, children));
86
- }
87
-
88
- export function Tabs({ items, value, defaultValue, onValueChange, label, className, ...props }) {
89
- const prefix = useId();
90
- const [internal, setInternal] = useState(defaultValue);
91
- const requested = value === undefined ? internal : value;
92
- const active = items.find(item => item.id === requested && !item.disabled)?.id
93
- ?? items.find(item => !item.disabled)?.id;
94
- const refs = useRef([]);
95
- function activate(item) {
96
- if (value === undefined) setInternal(item.id);
97
- onValueChange?.(item.id);
98
- }
99
- function navigate(event, index) {
100
- const enabled = items.map((item, i) => item.disabled ? -1 : i).filter(i => i !== -1);
101
- const position = enabled.indexOf(index);
102
- let target;
103
- if (event.key === "ArrowRight") target = enabled[(position + 1) % enabled.length];
104
- if (event.key === "ArrowLeft") target = enabled[(position - 1 + enabled.length) % enabled.length];
105
- if (event.key === "Home") target = enabled[0];
106
- if (event.key === "End") target = enabled[enabled.length - 1];
107
- if (target === undefined) return;
108
- event.preventDefault();
109
- refs.current[target]?.focus();
110
- activate(items[target]);
111
- }
112
- return h("div", { ...props, className: cx("wm-tabs", className) },
113
- h("div", { role: "tablist", "aria-label": label, className: "wm-tab-bar" },
114
- items.map((item, index) => h("button", {
115
- key: item.id, id: `${prefix}-tab-${item.id}`, type: "button", role: "tab",
116
- "aria-selected": active === item.id, "aria-controls": `${prefix}-panel-${item.id}`,
117
- tabIndex: active === item.id ? 0 : -1, disabled: item.disabled,
118
- className: cx("wm-tab-btn", active === item.id && "wm-tab-btn-active"),
119
- ref: node => { refs.current[index] = node; },
120
- onKeyDown: event => navigate(event, index), onClick: () => activate(item),
121
- }, item.label))),
122
- items.map(item => h("div", { key: item.id, id: `${prefix}-panel-${item.id}`,
123
- role: "tabpanel", "aria-labelledby": `${prefix}-tab-${item.id}`,
124
- hidden: active !== item.id, tabIndex: 0, className: "wm-tab-panel" }, item.content)));
125
- }
126
-
127
- export function Menu({ label, items, className, ...props }) {
128
- const id = useId();
129
- const [open, setOpen] = useState(false);
130
- const trigger = useRef(null);
131
- const root = useRef(null);
132
- const refs = useRef([]);
133
- const focusLast = useRef(false);
134
- useClientLayoutEffect(() => {
135
- if (!open) return;
136
- const enabled = refs.current.filter(node => node && node.getAttribute("aria-disabled") !== "true");
137
- (focusLast.current ? enabled.at(-1) : enabled[0])?.focus();
138
- }, [open]);
139
- useEffect(() => {
140
- if (!open) return;
141
- const outside = event => { if (!root.current?.contains(event.target)) setOpen(false); };
142
- document.addEventListener("pointerdown", outside);
143
- return () => document.removeEventListener("pointerdown", outside);
144
- }, [open]);
145
- function close(restore = false) {
146
- setOpen(false);
147
- if (restore) trigger.current?.focus();
148
- }
149
- function navigate(event) {
150
- if (event.key === "Escape") { event.preventDefault(); close(true); return; }
151
- if (event.key === "Tab") { close(true); return; }
152
- const enabled = refs.current.filter(node => node && node.getAttribute("aria-disabled") !== "true");
153
- const index = enabled.indexOf(document.activeElement);
154
- let next;
155
- if (event.key === "ArrowDown") next = enabled[(index + 1) % enabled.length];
156
- if (event.key === "ArrowUp") next = enabled[(index - 1 + enabled.length) % enabled.length];
157
- if (event.key === "Home") next = enabled[0];
158
- if (event.key === "End") next = enabled.at(-1);
159
- if (next) { event.preventDefault(); next.focus(); }
160
- }
161
- return h("div", { ...props, ref: root, className: cx("wm-menu", className),
162
- onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget)) close(); } },
163
- h(Button, { ref: trigger, variant: "secondary", "aria-haspopup": "menu",
164
- "aria-expanded": open, "aria-controls": open ? id : undefined,
165
- onClick: () => { focusLast.current = false; setOpen(!open); },
166
- onKeyDown: event => {
167
- if (open && event.key === "Escape") { event.preventDefault(); close(true); return; }
168
- if (event.key === "ArrowDown" || event.key === "ArrowUp") {
169
- event.preventDefault(); focusLast.current = event.key === "ArrowUp"; setOpen(true);
170
- }
171
- } }, label),
172
- open && h("ul", { id, role: "menu", "aria-label": typeof label === "string" ? label : "Actions",
173
- className: "wm-menu-items", onKeyDown: navigate },
174
- items.map((item, index) => h("li", { key: item.id, role: "none" },
175
- h(item.href && !item.disabled ? "a" : "button", {
176
- href: item.disabled ? undefined : item.href,
177
- type: item.href && !item.disabled ? undefined : "button",
178
- role: "menuitem", tabIndex: -1, "aria-disabled": item.disabled || undefined,
179
- ref: node => { refs.current[index] = node; },
180
- onClick: event => {
181
- if (item.disabled) { event.preventDefault(); return; }
182
- close(true); item.onSelect?.(event);
183
- },
184
- }, item.label)))));
185
- }
186
-
187
- export function Tooltip({ text, children }) {
188
- const id = useId();
189
- const [hovered, setHovered] = useState(false);
190
- const [focused, setFocused] = useState(false);
191
- const [dismissed, setDismissed] = useState(false);
192
- const visible = (hovered || focused) && !dismissed;
193
- const child = Children.only(children);
194
- useEffect(() => {
195
- if (!visible) return;
196
- const dismiss = event => { if (event.key === "Escape") setDismissed(true); };
197
- document.addEventListener("keydown", dismiss);
198
- return () => document.removeEventListener("keydown", dismiss);
199
- }, [visible]);
200
- return h("span", { className: "wm-tooltip-anchor",
201
- onMouseEnter: () => { setHovered(true); setDismissed(false); },
202
- onMouseLeave: () => setHovered(false),
203
- onFocus: () => { setFocused(true); setDismissed(false); },
204
- onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false); } },
205
- cloneElement(child, { "aria-describedby": cx(child.props["aria-describedby"], visible && id) || undefined }),
206
- visible && h("span", { id, role: "tooltip", className: "wm-tooltip" }, text));
207
- }
208
-
209
- export function Dialog({ open, onClose, title, children, className, ...props }) {
210
- const ref = useRef(null);
211
- const restoreTarget = useRef(null);
212
- const internalCloses = useRef(0);
213
- const titleId = useId();
214
- useClientLayoutEffect(() => {
215
- const dialog = ref.current;
216
- if (!open) return;
217
- if (!restoreTarget.current || !dialog.contains(document.activeElement)) {
218
- restoreTarget.current = document.activeElement;
219
- }
220
- const previous = restoreTarget.current;
221
- dialog.showModal();
222
- return () => {
223
- if (dialog.open) { internalCloses.current += 1; dialog.close(); }
224
- // Restore after React's commit-time focus restoration, including unmount.
225
- queueMicrotask(() => {
226
- if (dialog.open) return;
227
- if (previous?.isConnected) previous.focus();
228
- restoreTarget.current = null;
229
- });
230
- };
231
- }, [open]);
232
- function trapFocus(event) {
233
- props.onKeyDown?.(event);
234
- if (event.defaultPrevented || event.key !== "Tab") return;
235
- const dialog = ref.current;
236
- const candidates = Array.from(dialog.querySelectorAll(
237
- "a[href], area[href], button, input, select, textarea, summary, iframe, object, embed, audio[controls], video[controls], [tabindex], [contenteditable='true']",
238
- )).filter(node => (node.tabIndex >= 0 || (node.isContentEditable && !node.hasAttribute("tabindex")))
239
- && !node.matches(":disabled")
240
- && !node.closest("[inert]") && node.getClientRects().length > 0
241
- && window.getComputedStyle(node).visibility === "visible");
242
- const tabbable = candidates.filter(node => {
243
- if (node.tagName !== "INPUT" || node.type !== "radio" || !node.name) return true;
244
- const group = candidates.filter(other => other.tagName === "INPUT" && other.type === "radio"
245
- && other.name === node.name && other.form === node.form);
246
- return node === (group.find(other => other.checked) || group[0]);
247
- }).sort((a, b) => (a.tabIndex > 0 ? a.tabIndex : Infinity) - (b.tabIndex > 0 ? b.tabIndex : Infinity));
248
- const first = tabbable[0];
249
- const last = tabbable[tabbable.length - 1];
250
- if (!first) { event.preventDefault(); dialog.focus(); return; }
251
- if (event.shiftKey && (document.activeElement === first || document.activeElement === dialog)) {
252
- event.preventDefault(); last.focus();
253
- } else if (!event.shiftKey && (document.activeElement === last || document.activeElement === dialog)) {
254
- event.preventDefault(); first.focus();
255
- }
256
- }
257
- return h("dialog", { ...props, ref, "aria-labelledby": titleId,
258
- tabIndex: props.tabIndex ?? -1, onKeyDown: trapFocus,
259
- className: cx("wm-dialog", className),
260
- onCancel: event => {
261
- props.onCancel?.(event);
262
- const cancelled = event.defaultPrevented;
263
- event.preventDefault();
264
- if (!cancelled) onClose();
265
- },
266
- onClose: () => {
267
- if (internalCloses.current > 0) internalCloses.current -= 1;
268
- else if (open) onClose();
269
- } },
270
- h("header", { className: "wm-dialog-header" }, h("h3", { id: titleId }, title),
271
- h(Button, { variant: "ghost", onClick: onClose, "aria-label": "Close dialog" }, "Close")),
272
- h("div", { className: "wm-dialog-body" }, children));
273
- }
274
-
275
- const ThemeContext = createContext(null);
276
-
277
- export function ThemeProvider({ children, storageKey = DEFAULT_THEME_KEY }) {
278
- const [preference, setPreferenceState] = useState(() => readThemePreference(storageKey));
279
- const currentPreference = useRef(preference);
280
- const [resolvedTheme, setResolvedTheme] = useState(() => resolveTheme(preference));
281
- useClientLayoutEffect(() => {
282
- const sync = () => {
283
- const current = readThemePreference(storageKey);
284
- currentPreference.current = current;
285
- setPreferenceState(current);
286
- setResolvedTheme(applyTheme(current));
287
- };
288
- sync();
289
- const query = window.matchMedia?.("(prefers-color-scheme: dark)");
290
- const systemChange = () => setResolvedTheme(applyTheme(currentPreference.current));
291
- const storage = event => { if (event.key === storageKey || event.key === null) sync(); };
292
- query?.addEventListener("change", systemChange);
293
- window.addEventListener("storage", storage);
294
- return () => {
295
- query?.removeEventListener("change", systemChange);
296
- window.removeEventListener("storage", storage);
297
- };
298
- }, [storageKey]);
299
- function setPreference(next) {
300
- if (!isThemePreference(next)) throw new TypeError("Theme preference must be system, light, or dark.");
301
- try { window.localStorage.setItem(storageKey, next); }
302
- catch (error) { console.warn("Wintermuted theme preference could not be saved.", error); }
303
- currentPreference.current = next;
304
- setPreferenceState(next);
305
- setResolvedTheme(applyTheme(next));
306
- }
307
- return h(ThemeContext.Provider, { value: { preference, setPreference, resolvedTheme } }, children);
308
- }
309
-
310
- export function useTheme() {
311
- const theme = useContext(ThemeContext);
312
- if (!theme) throw new Error("useTheme must be used inside ThemeProvider.");
313
- return theme;
314
- }
315
-
316
- export function ThemeSelect({ label = "Appearance", id, ...props }) {
317
- const generated = useId();
318
- const { preference, setPreference } = useTheme();
319
- const controlId = id || generated;
320
- return h(FieldGroup, { label, htmlFor: controlId },
321
- h(Select, { ...props, id: controlId, value: preference, onChange: event => setPreference(event.target.value) },
322
- h("option", { value: "system" }, "System"),
323
- h("option", { value: "light" }, "Light"),
324
- h("option", { value: "dark" }, "Dark")));
325
- }
package/react/select.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { ReactElement } from "react";
2
- import type { GroupBase, Props } from "react-select";
3
-
4
- export type MultiSelectProps<Option = unknown, IsMulti extends boolean = true,
5
- Group extends GroupBase<Option> = GroupBase<Option>> = Props<Option, IsMulti, Group>;
6
-
7
- export function MultiSelect<Option = unknown, IsMulti extends boolean = true,
8
- Group extends GroupBase<Option> = GroupBase<Option>>(
9
- props: MultiSelectProps<Option, IsMulti, Group>
10
- ): ReactElement;
package/react/select.js DELETED
@@ -1,38 +0,0 @@
1
- import { createElement, useId } from "react";
2
- import ReactSelect, { mergeStyles } from "react-select";
3
-
4
- // Inline values are CSS variables so open menus follow a theme change immediately.
5
- const styles = {
6
- control: (base, state) => ({ ...base,
7
- backgroundColor: "var(--wm-color-bg)", color: "var(--wm-color-text)",
8
- borderColor: state.isFocused ? "var(--wm-color-accent)" : "var(--wm-color-border-strong)",
9
- borderRadius: "var(--wm-radius-xs)",
10
- boxShadow: state.isFocused ? "0 0 0 2px var(--wm-color-accent-border)" : "none",
11
- ":hover": { borderColor: "var(--wm-color-accent)" },
12
- }),
13
- menu: base => ({ ...base, backgroundColor: "var(--wm-color-surface-solid)",
14
- color: "var(--wm-color-text)", border: "1px solid var(--wm-color-border)" }),
15
- menuPortal: base => ({ ...base, color: "var(--wm-color-text)" }),
16
- option: (base, state) => ({ ...base,
17
- backgroundColor: state.isSelected ? "var(--wm-color-accent-soft)"
18
- : state.isFocused ? "var(--wm-color-surface-strong)" : "transparent",
19
- color: state.isDisabled ? "var(--wm-color-text-muted)" : "var(--wm-color-text)",
20
- ":active": { backgroundColor: "var(--wm-color-accent-soft)" },
21
- }),
22
- singleValue: base => ({ ...base, color: "var(--wm-color-text)" }),
23
- input: base => ({ ...base, color: "var(--wm-color-text)" }),
24
- placeholder: base => ({ ...base, color: "var(--wm-color-text-muted)" }),
25
- multiValue: base => ({ ...base, backgroundColor: "var(--wm-color-surface-strong)" }),
26
- multiValueLabel: base => ({ ...base, color: "var(--wm-color-text)" }),
27
- multiValueRemove: base => ({ ...base, color: "var(--wm-color-text-secondary)",
28
- ":hover": { backgroundColor: "var(--wm-color-danger-soft)", color: "var(--wm-color-danger)" } }),
29
- };
30
-
31
- export function MultiSelect({ styles: overrides, isMulti = true, id, className, ...props }) {
32
- const generated = useId();
33
- return createElement(ReactSelect, {
34
- instanceId: generated, ...props, inputId: props.inputId ?? id,
35
- className: ["wm-search-select", className].filter(Boolean).join(" "),
36
- isMulti, styles: mergeStyles(styles, overrides),
37
- });
38
- }
package/react/theme.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export type ThemePreference = "system" | "light" | "dark";
2
- export type ResolvedTheme = "light" | "dark";
3
- export const DEFAULT_THEME_KEY: string;
4
- export function isThemePreference(value: unknown): value is ThemePreference;
5
- export function readThemePreference(storageKey?: string): ThemePreference;
6
- export function resolveTheme(preference: ThemePreference): ResolvedTheme;
7
- export function applyTheme(preference: ThemePreference): ResolvedTheme;
8
- export function initTheme(options?: { storageKey?: string }): ResolvedTheme;
9
- export function getThemeScript(storageKey?: string): string;
package/react/theme.js DELETED
@@ -1,41 +0,0 @@
1
- export const DEFAULT_THEME_KEY = "wintermuted:theme";
2
-
3
- export function isThemePreference(value) {
4
- return value === "system" || value === "light" || value === "dark";
5
- }
6
-
7
- export function readThemePreference(storageKey = DEFAULT_THEME_KEY) {
8
- if (typeof window === "undefined") return "system";
9
- try {
10
- const stored = window.localStorage.getItem(storageKey);
11
- return isThemePreference(stored) ? stored : "system";
12
- } catch (error) {
13
- console.warn("Wintermuted theme preference could not be read.", error);
14
- return "system";
15
- }
16
- }
17
-
18
- export function resolveTheme(preference) {
19
- return preference === "system"
20
- ? (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light")
21
- : preference;
22
- }
23
-
24
- export function applyTheme(preference) {
25
- const resolved = resolveTheme(preference);
26
- if (typeof document !== "undefined") {
27
- document.documentElement.dataset.theme = resolved;
28
- document.documentElement.style.colorScheme = resolved;
29
- }
30
- return resolved;
31
- }
32
-
33
- export function initTheme({ storageKey = DEFAULT_THEME_KEY } = {}) {
34
- return applyTheme(readThemePreference(storageKey));
35
- }
36
-
37
- // Keep this synchronous bootstrap self-contained so SSR can emit it before CSS.
38
- export function getThemeScript(storageKey = DEFAULT_THEME_KEY) {
39
- const key = JSON.stringify(storageKey).replace(/</g, "\\u003c");
40
- return `(function(){var p="system";try{var s=localStorage.getItem(${key});if(s==="light"||s==="dark")p=s;}catch(e){console.warn("Wintermuted theme preference could not be read.",e);}var t=p==="system"?(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"):p;document.documentElement.dataset.theme=t;document.documentElement.style.colorScheme=t;})();`;
41
- }