theme-watcher 0.1.1 → 0.1.2

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
@@ -38,7 +38,7 @@ Mount once near your app root.
38
38
  Props:
39
39
  - `theme?: "light" | "dark"` controlled override
40
40
  - `storageKey?: string` default: `"theme-watcher"`
41
- - `attribute?: "data-theme" | "class"` default: `"data-theme"`
41
+ - `attribute?: "data-theme" | "class" | "both"` default: `"both"`
42
42
  - `defaultTheme?: "light" | "dark" | "system"` default: `"system"`
43
43
  - `enableColorScheme?: boolean` default: `true`
44
44
  - `variables?: { light?: Record<string, string>; dark?: Record<string, string> }`
@@ -50,6 +50,7 @@ Returns:
50
50
  - `resolvedTheme` active applied theme (`"light" | "dark"`)
51
51
  - `source` where the current value came from (`"prop" | "storage" | "default" | "system"`)
52
52
  - `set(theme)` set and persist preference
53
+ - `setTheme(theme)` alias for compatibility with next-themes-style usage
53
54
  - `get()` get persisted preference
54
55
 
55
56
  ## Behavior notes
@@ -57,6 +58,7 @@ Returns:
57
58
  - Priority order: `theme prop` -> `localStorage` -> `defaultTheme` -> system theme.
58
59
  - `system` mode updates live when `prefers-color-scheme` changes.
59
60
  - Cross-tab updates are synced through `storage` events.
61
+ - By default, it applies both `data-theme` and `html.dark` so Tailwind/shadcn and CSS-var setups both work.
60
62
  - Package is ESM-only.
61
63
 
62
64
  ## CSS variable support
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  type Theme = "light" | "dark";
2
2
  type ThemePreference = Theme | "system";
3
3
  type ThemeSource = "prop" | "storage" | "default" | "system";
4
- type ThemeAttribute = "data-theme" | "class";
4
+ type ThemeAttribute = "data-theme" | "class" | "both";
5
5
  type ThemeVariables = Partial<Record<Theme, Record<string, string>>>;
6
6
  interface ThemeState {
7
7
  theme: ThemePreference;
@@ -18,6 +18,7 @@ interface ThemeWatcherProps {
18
18
  }
19
19
  interface ThemeApi extends ThemeState {
20
20
  set: (theme: ThemePreference) => void;
21
+ setTheme: (theme: ThemePreference) => void;
21
22
  get: () => ThemePreference;
22
23
  }
23
24
 
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { useEffect } from "react";
4
4
  // src/theme-store.ts
5
5
  var DEFAULT_CONFIG = {
6
6
  storageKey: "theme-watcher",
7
- attribute: "data-theme",
7
+ attribute: "both",
8
8
  defaultTheme: "system",
9
9
  enableColorScheme: true
10
10
  };
@@ -65,9 +65,11 @@ function resolveTheme(propTheme, stored, defaultTheme) {
65
65
  function applyDomTheme(resolvedTheme) {
66
66
  if (!isBrowserReady()) return;
67
67
  const root = document.documentElement;
68
- if (config.attribute === "class") {
68
+ if (config.attribute === "class" || config.attribute === "both") {
69
69
  root.classList.toggle("dark", resolvedTheme === "dark");
70
- root.classList.toggle("light", resolvedTheme === "light");
70
+ root.classList.remove("light");
71
+ }
72
+ if (config.attribute === "class") {
71
73
  return;
72
74
  }
73
75
  root.setAttribute("data-theme", resolvedTheme);
@@ -185,7 +187,7 @@ function getServerSnapshot() {
185
187
  function ThemeWatcher({
186
188
  theme,
187
189
  storageKey = "theme-watcher",
188
- attribute = "data-theme",
190
+ attribute = "both",
189
191
  defaultTheme = "system",
190
192
  variables,
191
193
  enableColorScheme = true
@@ -203,6 +205,7 @@ function useTheme() {
203
205
  return {
204
206
  ...state2,
205
207
  set: setTheme,
208
+ setTheme,
206
209
  get: getTheme
207
210
  };
208
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theme-watcher",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Plug-and-play theme watcher for React SPAs",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",