@raxrai/stylelab-ui 0.3.1 → 0.3.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 +6 -0
- package/dist/index.cjs +6 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -417,11 +417,13 @@ type ThemeContextValue = {
|
|
|
417
417
|
theme: StyleLabTheme;
|
|
418
418
|
setTheme: (theme: StyleLabTheme) => void;
|
|
419
419
|
};
|
|
420
|
-
declare function ThemeProvider({ children, defaultTheme, storageKey, }: {
|
|
420
|
+
declare function ThemeProvider({ children, defaultTheme, storageKey, persistTheme, }: {
|
|
421
421
|
children: ReactNode;
|
|
422
422
|
defaultTheme?: StyleLabTheme;
|
|
423
423
|
/** localStorage key for persisting theme. Defaults to "stylelab-theme". */
|
|
424
424
|
storageKey?: string;
|
|
425
|
+
/** When false, theme is not read from or written to localStorage. */
|
|
426
|
+
persistTheme?: boolean;
|
|
425
427
|
}): react.JSX.Element;
|
|
426
428
|
declare function useTheme(): ThemeContextValue;
|
|
427
429
|
|
package/dist/index.d.ts
CHANGED
|
@@ -417,11 +417,13 @@ type ThemeContextValue = {
|
|
|
417
417
|
theme: StyleLabTheme;
|
|
418
418
|
setTheme: (theme: StyleLabTheme) => void;
|
|
419
419
|
};
|
|
420
|
-
declare function ThemeProvider({ children, defaultTheme, storageKey, }: {
|
|
420
|
+
declare function ThemeProvider({ children, defaultTheme, storageKey, persistTheme, }: {
|
|
421
421
|
children: ReactNode;
|
|
422
422
|
defaultTheme?: StyleLabTheme;
|
|
423
423
|
/** localStorage key for persisting theme. Defaults to "stylelab-theme". */
|
|
424
424
|
storageKey?: string;
|
|
425
|
+
/** When false, theme is not read from or written to localStorage. */
|
|
426
|
+
persistTheme?: boolean;
|
|
425
427
|
}): react.JSX.Element;
|
|
426
428
|
declare function useTheme(): ThemeContextValue;
|
|
427
429
|
|
package/dist/index.mjs
CHANGED
|
@@ -285,12 +285,14 @@ function getStoredTheme(storageKey, defaultTheme) {
|
|
|
285
285
|
function ThemeProvider({
|
|
286
286
|
children,
|
|
287
287
|
defaultTheme = "minimal",
|
|
288
|
-
storageKey = "stylelab-theme"
|
|
288
|
+
storageKey = "stylelab-theme",
|
|
289
|
+
persistTheme = true
|
|
289
290
|
}) {
|
|
290
291
|
const [theme, setThemeState] = useState(defaultTheme);
|
|
291
292
|
useEffect(() => {
|
|
293
|
+
if (!persistTheme) return;
|
|
292
294
|
setThemeState((prev) => getStoredTheme(storageKey, prev));
|
|
293
|
-
}, [storageKey]);
|
|
295
|
+
}, [storageKey, persistTheme]);
|
|
294
296
|
useEffect(() => {
|
|
295
297
|
if (typeof document !== "undefined") {
|
|
296
298
|
try {
|
|
@@ -305,12 +307,12 @@ function ThemeProvider({
|
|
|
305
307
|
if (typeof document !== "undefined") {
|
|
306
308
|
try {
|
|
307
309
|
document.documentElement.dataset.stylelabTheme = next;
|
|
308
|
-
localStorage.setItem(storageKey, next);
|
|
310
|
+
if (persistTheme) localStorage.setItem(storageKey, next);
|
|
309
311
|
} catch (_) {
|
|
310
312
|
}
|
|
311
313
|
}
|
|
312
314
|
},
|
|
313
|
-
[storageKey]
|
|
315
|
+
[storageKey, persistTheme]
|
|
314
316
|
);
|
|
315
317
|
const value = useMemo(
|
|
316
318
|
() => ({ theme, setTheme }),
|