@nayhoo/ui 0.10.0 → 0.10.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/dist/{chunk-DMFP5JKO.mjs → chunk-2BB77GZV.mjs} +3 -3
- package/dist/{chunk-T3GW2EMR.mjs → chunk-2TMFRLMM.mjs} +1 -1
- package/dist/{chunk-T3GW2EMR.mjs.map → chunk-2TMFRLMM.mjs.map} +1 -1
- package/dist/{chunk-ZNKUE6YY.mjs → chunk-3STUDMUG.mjs} +1 -1
- package/dist/{chunk-ZNKUE6YY.mjs.map → chunk-3STUDMUG.mjs.map} +1 -1
- package/dist/{chunk-QMCIR3TI.mjs → chunk-4C5Q6VK2.mjs} +3 -3
- package/dist/{chunk-64TEKDKL.mjs → chunk-52RVZRC4.mjs} +2 -2
- package/dist/{chunk-G4YCF3A2.mjs → chunk-AIOSEM6O.mjs} +1 -1
- package/dist/{chunk-G4YCF3A2.mjs.map → chunk-AIOSEM6O.mjs.map} +1 -1
- package/dist/{chunk-U6MTU5FF.mjs → chunk-CQA7ZREU.mjs} +1 -1
- package/dist/{chunk-U6MTU5FF.mjs.map → chunk-CQA7ZREU.mjs.map} +1 -1
- package/dist/{chunk-QEBSZEY2.mjs → chunk-HFMY3EF3.mjs} +1 -1
- package/dist/{chunk-QEBSZEY2.mjs.map → chunk-HFMY3EF3.mjs.map} +1 -1
- package/dist/{chunk-QBPEU3GK.mjs → chunk-JSUIFF36.mjs} +1 -1
- package/dist/{chunk-QBPEU3GK.mjs.map → chunk-JSUIFF36.mjs.map} +1 -1
- package/dist/{chunk-DC6VQ7BG.mjs → chunk-LF6VSYRD.mjs} +2 -2
- package/dist/{chunk-IEZTYE5I.mjs → chunk-M6OYH5UA.mjs} +1 -1
- package/dist/{chunk-IEZTYE5I.mjs.map → chunk-M6OYH5UA.mjs.map} +1 -1
- package/dist/{chunk-GGJKRS5V.mjs → chunk-PIOIL3MF.mjs} +2 -2
- package/dist/{chunk-MDAIXJU2.mjs → chunk-QCTQCZQV.mjs} +1 -1
- package/dist/{chunk-MDAIXJU2.mjs.map → chunk-QCTQCZQV.mjs.map} +1 -1
- package/dist/{chunk-3HV65JYW.mjs → chunk-RD6HAWH5.mjs} +1 -1
- package/dist/{chunk-3HV65JYW.mjs.map → chunk-RD6HAWH5.mjs.map} +1 -1
- package/dist/{chunk-HRXZ3ELS.mjs → chunk-SC6WBBXG.mjs} +1 -1
- package/dist/{chunk-HRXZ3ELS.mjs.map → chunk-SC6WBBXG.mjs.map} +1 -1
- package/dist/{chunk-YO4LZRGU.mjs → chunk-SI36SYJ2.mjs} +1 -1
- package/dist/{chunk-YO4LZRGU.mjs.map → chunk-SI36SYJ2.mjs.map} +1 -1
- package/dist/{chunk-PGCB7RGD.mjs → chunk-TPPKQCXG.mjs} +1 -1
- package/dist/{chunk-PGCB7RGD.mjs.map → chunk-TPPKQCXG.mjs.map} +1 -1
- package/dist/{chunk-6UOQ737G.mjs → chunk-UVLWN6WJ.mjs} +1 -1
- package/dist/{chunk-6UOQ737G.mjs.map → chunk-UVLWN6WJ.mjs.map} +1 -1
- package/dist/{chunk-XX6PQF7O.mjs → chunk-VSQHQBZX.mjs} +1 -1
- package/dist/{chunk-XX6PQF7O.mjs.map → chunk-VSQHQBZX.mjs.map} +1 -1
- package/dist/{chunk-RYAY35UB.mjs → chunk-WUIQQ7C2.mjs} +2 -2
- package/dist/{chunk-IQLI5J2V.mjs → chunk-YZNF3EIN.mjs} +1 -1
- package/dist/{chunk-IQLI5J2V.mjs.map → chunk-YZNF3EIN.mjs.map} +1 -1
- package/dist/components/avatar.css +1 -1
- package/dist/components/avatar.css.map +1 -1
- package/dist/components/avatar.js.map +1 -1
- package/dist/components/avatar.mjs +1 -1
- package/dist/components/badge.css +1 -1
- package/dist/components/badge.css.map +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/badge.mjs +1 -1
- package/dist/components/button.css +2 -2
- package/dist/components/button.css.map +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/button.mjs +4 -4
- package/dist/components/checkbox.css +1 -1
- package/dist/components/checkbox.css.map +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/checkbox.mjs +1 -1
- package/dist/components/dropdown-menu.css +2 -2
- package/dist/components/dropdown-menu.css.map +1 -1
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/dropdown-menu.mjs +3 -3
- package/dist/components/flex.css +1 -1
- package/dist/components/flex.css.map +1 -1
- package/dist/components/flex.js.map +1 -1
- package/dist/components/flex.mjs +2 -2
- package/dist/components/grid.css +1 -1
- package/dist/components/grid.css.map +1 -1
- package/dist/components/grid.js.map +1 -1
- package/dist/components/grid.mjs +1 -1
- package/dist/components/heading.css +1 -1
- package/dist/components/heading.css.map +1 -1
- package/dist/components/heading.js.map +1 -1
- package/dist/components/heading.mjs +2 -2
- package/dist/components/icon-button.css +2 -2
- package/dist/components/icon-button.css.map +1 -1
- package/dist/components/icon-button.js.map +1 -1
- package/dist/components/icon-button.mjs +4 -4
- package/dist/components/label.css +1 -1
- package/dist/components/label.css.map +1 -1
- package/dist/components/label.js.map +1 -1
- package/dist/components/label.mjs +1 -1
- package/dist/components/link.css +1 -1
- package/dist/components/link.css.map +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/link.mjs +1 -1
- package/dist/components/menu.css +2 -2
- package/dist/components/menu.css.map +1 -1
- package/dist/components/menu.js.map +1 -1
- package/dist/components/menu.mjs +3 -3
- package/dist/components/paragraph.css +1 -1
- package/dist/components/paragraph.css.map +1 -1
- package/dist/components/paragraph.js.map +1 -1
- package/dist/components/paragraph.mjs +1 -1
- package/dist/components/popover.css +1 -1
- package/dist/components/popover.css.map +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/popover.mjs +1 -1
- package/dist/components/select.css +3 -3
- package/dist/components/select.css.map +1 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/select.mjs +5 -5
- package/dist/components/skeleton.css +1 -1
- package/dist/components/skeleton.css.map +1 -1
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/skeleton.mjs +1 -1
- package/dist/components/spinner.css +1 -1
- package/dist/components/spinner.css.map +1 -1
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/spinner.mjs +2 -2
- package/dist/components/switch.css +1 -1
- package/dist/components/switch.css.map +1 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/switch.mjs +1 -1
- package/dist/components/text-field.css +1 -1
- package/dist/components/text-field.css.map +1 -1
- package/dist/components/text-field.js.map +1 -1
- package/dist/components/text-field.mjs +1 -1
- package/dist/components/text.css +1 -1
- package/dist/components/text.css.map +1 -1
- package/dist/components/text.js.map +1 -1
- package/dist/components/text.mjs +2 -2
- package/dist/components/tooltip.css +1 -1
- package/dist/components/tooltip.css.map +1 -1
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/tooltip.mjs +2 -2
- package/dist/providers/index.css +8 -8
- package/dist/providers/index.css.map +1 -1
- package/dist/providers/index.d.mts +23 -14
- package/dist/providers/index.d.ts +23 -14
- package/dist/providers/index.js +157 -77
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +165 -91
- package/dist/providers/index.mjs.map +1 -1
- package/dist/theme/index.css +20 -20
- package/dist/theme/index.css.map +1 -1
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/index.mjs +15 -15
- package/dist/theme/index.mjs.map +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-DMFP5JKO.mjs.map → chunk-2BB77GZV.mjs.map} +0 -0
- /package/dist/{chunk-QMCIR3TI.mjs.map → chunk-4C5Q6VK2.mjs.map} +0 -0
- /package/dist/{chunk-64TEKDKL.mjs.map → chunk-52RVZRC4.mjs.map} +0 -0
- /package/dist/{chunk-DC6VQ7BG.mjs.map → chunk-LF6VSYRD.mjs.map} +0 -0
- /package/dist/{chunk-GGJKRS5V.mjs.map → chunk-PIOIL3MF.mjs.map} +0 -0
- /package/dist/{chunk-RYAY35UB.mjs.map → chunk-WUIQQ7C2.mjs.map} +0 -0
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import react__default from 'react';
|
|
4
3
|
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
5
4
|
|
|
6
5
|
type Theme = "light" | "dark" | "system";
|
|
7
6
|
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
type SystemTheme = Exclude<Theme, "system">;
|
|
8
|
+
|
|
9
|
+
interface ScriptProps extends react.DetailedHTMLProps<react.ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement> {
|
|
10
|
+
}
|
|
11
|
+
interface UseThemeProps {
|
|
12
|
+
/** List of all available theme names */
|
|
13
13
|
themes: Theme[];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/** Update the theme */
|
|
15
|
+
setTheme: (value: Theme) => void;
|
|
16
|
+
/** Active theme name */
|
|
17
|
+
theme?: Theme | undefined;
|
|
18
|
+
/** If the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
|
|
19
|
+
resolvedTheme?: Theme | undefined;
|
|
20
|
+
/** Returns the System theme preference ("dark" or "light"), regardless what the active theme is */
|
|
21
|
+
systemTheme?: SystemTheme | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface ThemeProviderProps extends react.PropsWithChildren {
|
|
24
|
+
/** Props to pass the inline script */
|
|
25
|
+
scriptProps?: ScriptProps;
|
|
26
|
+
}
|
|
27
|
+
declare const useTheme: () => UseThemeProps;
|
|
28
|
+
declare const ThemeProvider: (props: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
|
|
20
29
|
|
|
21
30
|
type AddToastPayload = Omit<Toast, "status">;
|
|
22
31
|
type ToastContextProps = ((payload: AddToastPayload) => void) & {
|
|
23
32
|
error: (payload: AddToastPayload) => void;
|
|
24
33
|
success: (payload: AddToastPayload) => void;
|
|
25
34
|
};
|
|
26
|
-
declare const
|
|
35
|
+
declare const useToast: () => ToastContextProps;
|
|
27
36
|
declare const ToastProvider: ({ children, ...props }: ToastPrimitives.ToastProviderProps) => react_jsx_runtime.JSX.Element;
|
|
28
37
|
type Toast = {
|
|
29
38
|
title?: string;
|
|
@@ -36,4 +45,4 @@ declare const Toast: (props: ToastPrimitives.ToastProps & {
|
|
|
36
45
|
}) => react_jsx_runtime.JSX.Element;
|
|
37
46
|
declare const ToastAction: ({ ...props }: Omit<ToastPrimitives.ToastActionProps, "asChild">) => react_jsx_runtime.JSX.Element;
|
|
38
47
|
|
|
39
|
-
export {
|
|
48
|
+
export { ThemeProvider, type ThemeProviderProps, ToastAction, ToastProvider, type UseThemeProps, useTheme, useToast };
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import react__default from 'react';
|
|
4
3
|
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
5
4
|
|
|
6
5
|
type Theme = "light" | "dark" | "system";
|
|
7
6
|
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
type SystemTheme = Exclude<Theme, "system">;
|
|
8
|
+
|
|
9
|
+
interface ScriptProps extends react.DetailedHTMLProps<react.ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement> {
|
|
10
|
+
}
|
|
11
|
+
interface UseThemeProps {
|
|
12
|
+
/** List of all available theme names */
|
|
13
13
|
themes: Theme[];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/** Update the theme */
|
|
15
|
+
setTheme: (value: Theme) => void;
|
|
16
|
+
/** Active theme name */
|
|
17
|
+
theme?: Theme | undefined;
|
|
18
|
+
/** If the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
|
|
19
|
+
resolvedTheme?: Theme | undefined;
|
|
20
|
+
/** Returns the System theme preference ("dark" or "light"), regardless what the active theme is */
|
|
21
|
+
systemTheme?: SystemTheme | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface ThemeProviderProps extends react.PropsWithChildren {
|
|
24
|
+
/** Props to pass the inline script */
|
|
25
|
+
scriptProps?: ScriptProps;
|
|
26
|
+
}
|
|
27
|
+
declare const useTheme: () => UseThemeProps;
|
|
28
|
+
declare const ThemeProvider: (props: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
|
|
20
29
|
|
|
21
30
|
type AddToastPayload = Omit<Toast, "status">;
|
|
22
31
|
type ToastContextProps = ((payload: AddToastPayload) => void) & {
|
|
23
32
|
error: (payload: AddToastPayload) => void;
|
|
24
33
|
success: (payload: AddToastPayload) => void;
|
|
25
34
|
};
|
|
26
|
-
declare const
|
|
35
|
+
declare const useToast: () => ToastContextProps;
|
|
27
36
|
declare const ToastProvider: ({ children, ...props }: ToastPrimitives.ToastProviderProps) => react_jsx_runtime.JSX.Element;
|
|
28
37
|
type Toast = {
|
|
29
38
|
title?: string;
|
|
@@ -36,4 +45,4 @@ declare const Toast: (props: ToastPrimitives.ToastProps & {
|
|
|
36
45
|
}) => react_jsx_runtime.JSX.Element;
|
|
37
46
|
declare const ToastAction: ({ ...props }: Omit<ToastPrimitives.ToastActionProps, "asChild">) => react_jsx_runtime.JSX.Element;
|
|
38
47
|
|
|
39
|
-
export {
|
|
48
|
+
export { ThemeProvider, type ThemeProviderProps, ToastAction, ToastProvider, type UseThemeProps, useTheme, useToast };
|
package/dist/providers/index.js
CHANGED
|
@@ -30,11 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/providers/index.ts
|
|
31
31
|
var providers_exports = {};
|
|
32
32
|
__export(providers_exports, {
|
|
33
|
-
ThemeContext: () => ThemeContext,
|
|
34
33
|
ThemeProvider: () => ThemeProvider,
|
|
35
34
|
ToastAction: () => ToastAction,
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
ToastProvider: () => ToastProvider,
|
|
36
|
+
useTheme: () => useTheme,
|
|
37
|
+
useToast: () => useToast
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(providers_exports);
|
|
40
40
|
|
|
@@ -45,98 +45,151 @@ var darkTheme = "dark-theme__1mh7hnp0";
|
|
|
45
45
|
var lightTheme = "light-theme__6in2mz0";
|
|
46
46
|
|
|
47
47
|
// src/providers/theme-provider.tsx
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
// src/providers/script.ts
|
|
51
|
-
var script = (storageKey2, defaultTheme2, classes2) => {
|
|
52
|
-
const el = document.documentElement;
|
|
53
|
-
function updateDOM(theme) {
|
|
54
|
-
el.classList.remove(...Object.values(classes2));
|
|
55
|
-
el.classList.add(classes2[theme]);
|
|
56
|
-
}
|
|
57
|
-
function getSystemTheme2() {
|
|
58
|
-
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const themeName = localStorage.getItem(storageKey2) || defaultTheme2;
|
|
62
|
-
const isSystem = themeName === "system";
|
|
63
|
-
const theme = isSystem ? getSystemTheme2() : themeName;
|
|
64
|
-
updateDOM(theme);
|
|
65
|
-
} catch (e) {
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/providers/theme-provider.tsx
|
|
48
|
+
var React = __toESM(require("react"));
|
|
70
49
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
71
|
-
var MEDIA = "(prefers-color-scheme: dark)";
|
|
72
|
-
var isServer = typeof window === "undefined";
|
|
73
|
-
var storageKey = "nayhoo-theme";
|
|
74
|
-
var themes = ["light", "dark", "system"];
|
|
75
|
-
var defaultTheme = "system";
|
|
76
50
|
var classes = {
|
|
77
51
|
light: lightTheme,
|
|
78
52
|
dark: darkTheme
|
|
79
53
|
};
|
|
80
|
-
var
|
|
81
|
-
|
|
54
|
+
var defaultTheme = "system";
|
|
55
|
+
var storageKey = "nayhoo-theme";
|
|
56
|
+
var systemThemes = ["light", "dark"];
|
|
57
|
+
var themes = [...systemThemes, "system"];
|
|
58
|
+
var colorSchemes = ["light", "dark"];
|
|
59
|
+
var MEDIA = "(prefers-color-scheme: dark)";
|
|
60
|
+
var isServer = typeof window === "undefined";
|
|
61
|
+
var ThemeContext = React.createContext(void 0);
|
|
62
|
+
var defaultContext = {
|
|
82
63
|
setTheme: () => {
|
|
83
64
|
},
|
|
84
|
-
resolvedTheme: "light",
|
|
85
65
|
themes
|
|
86
|
-
}
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
};
|
|
67
|
+
var saveToLS = (storageKey2, value) => {
|
|
68
|
+
try {
|
|
69
|
+
localStorage.setItem(storageKey2, value);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var useTheme = () => {
|
|
74
|
+
var _a;
|
|
75
|
+
return (_a = React.useContext(ThemeContext)) != null ? _a : defaultContext;
|
|
76
|
+
};
|
|
77
|
+
var ThemeProvider = (props) => {
|
|
78
|
+
const context = React.useContext(ThemeContext);
|
|
79
|
+
if (context) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children });
|
|
80
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Theme, { ...props });
|
|
81
|
+
};
|
|
82
|
+
var Theme = ({ children, scriptProps }) => {
|
|
83
|
+
const [theme, setThemeState] = React.useState(() => getTheme());
|
|
84
|
+
const [resolvedTheme, setResolvedTheme] = React.useState(
|
|
90
85
|
() => theme === "system" ? getSystemTheme() : theme
|
|
91
86
|
);
|
|
92
|
-
const applyTheme =
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
const applyTheme = React.useCallback((theme2) => {
|
|
88
|
+
let resolved = theme2;
|
|
89
|
+
if (!resolved) return;
|
|
90
|
+
if (theme2 === "system") {
|
|
91
|
+
resolved = getSystemTheme();
|
|
92
|
+
}
|
|
95
93
|
const d = document.documentElement;
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
const handleAttribute = () => {
|
|
95
|
+
d.classList.remove(...Object.values(classes));
|
|
96
|
+
if (resolved) d.classList.add(classes[resolved]);
|
|
97
|
+
};
|
|
98
|
+
handleAttribute();
|
|
99
|
+
const colorScheme = colorSchemes.some(
|
|
100
|
+
(colorScheme2) => colorScheme2 === resolved
|
|
101
|
+
) ? resolved : null;
|
|
102
|
+
if (colorScheme) d.style.colorScheme = colorScheme;
|
|
98
103
|
}, []);
|
|
99
|
-
|
|
104
|
+
const setTheme = React.useCallback((value) => {
|
|
105
|
+
setThemeState(value);
|
|
106
|
+
saveToLS(storageKey, value);
|
|
107
|
+
}, []);
|
|
108
|
+
const handleMediaQuery = React.useCallback(
|
|
109
|
+
(e) => {
|
|
110
|
+
const resolved = getSystemTheme(e);
|
|
111
|
+
setResolvedTheme(resolved);
|
|
112
|
+
if (theme === "system") {
|
|
113
|
+
applyTheme("system");
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
+
[theme]
|
|
118
|
+
);
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
const media = window.matchMedia(MEDIA);
|
|
121
|
+
media.addListener(handleMediaQuery);
|
|
122
|
+
handleMediaQuery(media);
|
|
123
|
+
return () => media.removeListener(handleMediaQuery);
|
|
124
|
+
}, [handleMediaQuery]);
|
|
125
|
+
React.useEffect(() => {
|
|
126
|
+
const handleStorage = (e) => {
|
|
127
|
+
if (e.key !== storageKey) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!e.newValue || !isTheme(e.newValue)) {
|
|
131
|
+
setTheme(defaultTheme);
|
|
132
|
+
} else {
|
|
133
|
+
setThemeState(e.newValue);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
window.addEventListener("storage", handleStorage);
|
|
137
|
+
return () => window.removeEventListener("storage", handleStorage);
|
|
138
|
+
}, [setTheme]);
|
|
139
|
+
React.useEffect(() => {
|
|
100
140
|
applyTheme(theme);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} catch {
|
|
104
|
-
}
|
|
105
|
-
}, [applyTheme, theme]);
|
|
106
|
-
const value = (0, import_react.useMemo)(
|
|
141
|
+
}, [theme]);
|
|
142
|
+
const providerValue = React.useMemo(
|
|
107
143
|
() => ({
|
|
108
144
|
theme,
|
|
109
145
|
setTheme,
|
|
110
146
|
resolvedTheme: theme === "system" ? resolvedTheme : theme,
|
|
111
|
-
themes
|
|
147
|
+
themes,
|
|
148
|
+
systemTheme: resolvedTheme
|
|
112
149
|
}),
|
|
113
150
|
[theme, setTheme, resolvedTheme]
|
|
114
151
|
);
|
|
115
|
-
|
|
116
|
-
1,
|
|
117
|
-
-1
|
|
118
|
-
);
|
|
119
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThemeContext, { value, children: [
|
|
152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThemeContext.Provider, { value: providerValue, children: [
|
|
120
153
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
121
|
-
|
|
154
|
+
ThemeScript,
|
|
122
155
|
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
__html: `(${script.toString()})(${scriptArgs})`
|
|
156
|
+
...{
|
|
157
|
+
scriptProps
|
|
126
158
|
}
|
|
127
159
|
}
|
|
128
160
|
),
|
|
129
161
|
children
|
|
130
162
|
] });
|
|
131
163
|
};
|
|
164
|
+
var ThemeScript = React.memo(
|
|
165
|
+
({ scriptProps }) => {
|
|
166
|
+
const scriptArgs = JSON.stringify([
|
|
167
|
+
storageKey,
|
|
168
|
+
defaultTheme,
|
|
169
|
+
systemThemes,
|
|
170
|
+
classes
|
|
171
|
+
]).slice(1, -1);
|
|
172
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
|
+
"script",
|
|
174
|
+
{
|
|
175
|
+
...scriptProps,
|
|
176
|
+
suppressHydrationWarning: true,
|
|
177
|
+
dangerouslySetInnerHTML: {
|
|
178
|
+
__html: `(${script.toString()})(${scriptArgs})`
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
ThemeScript.displayName = "ThemeScript";
|
|
132
185
|
var getTheme = () => {
|
|
133
|
-
if (isServer) return
|
|
134
|
-
let
|
|
186
|
+
if (isServer) return void 0;
|
|
187
|
+
let theme;
|
|
135
188
|
try {
|
|
136
|
-
|
|
189
|
+
theme = localStorage.getItem(storageKey) || void 0;
|
|
137
190
|
} catch (e) {
|
|
138
191
|
}
|
|
139
|
-
return
|
|
192
|
+
return theme !== void 0 && isTheme(theme) ? theme : defaultTheme;
|
|
140
193
|
};
|
|
141
194
|
var getSystemTheme = (e) => {
|
|
142
195
|
if (!e) e = window.matchMedia(MEDIA);
|
|
@@ -144,12 +197,32 @@ var getSystemTheme = (e) => {
|
|
|
144
197
|
const systemTheme = isDark ? "dark" : "light";
|
|
145
198
|
return systemTheme;
|
|
146
199
|
};
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
200
|
+
var isTheme = (value) => themes.some((theme) => theme === value);
|
|
201
|
+
var script = (storageKey2, defaultTheme2, systemThemes2, classes2) => {
|
|
202
|
+
const el = document.documentElement;
|
|
203
|
+
function updateDOM(theme) {
|
|
204
|
+
el.classList.remove(...Object.values(classes2));
|
|
205
|
+
el.classList.add(classes2[theme]);
|
|
206
|
+
setColorScheme(theme);
|
|
207
|
+
}
|
|
208
|
+
function setColorScheme(theme) {
|
|
209
|
+
if (systemThemes2.some((systemTheme) => systemTheme === theme)) {
|
|
210
|
+
el.style.colorScheme = theme;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function getSystemTheme2() {
|
|
214
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
215
|
+
}
|
|
216
|
+
function isSystemTheme(value) {
|
|
217
|
+
return systemThemes2.some((theme) => theme === value);
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const themeName = localStorage.getItem(storageKey2) || defaultTheme2;
|
|
221
|
+
const isSystem = themeName === "system";
|
|
222
|
+
const theme = isSystem || !isSystemTheme(themeName) ? getSystemTheme2() : themeName;
|
|
223
|
+
updateDOM(theme);
|
|
224
|
+
} catch (e) {
|
|
151
225
|
}
|
|
152
|
-
return resolved;
|
|
153
226
|
};
|
|
154
227
|
|
|
155
228
|
// src/theme/recipes/spinner.css.ts
|
|
@@ -293,14 +366,21 @@ var import_react_icons = require("@radix-ui/react-icons");
|
|
|
293
366
|
var ToastPrimitives = __toESM(require("@radix-ui/react-toast"));
|
|
294
367
|
var React2 = __toESM(require("react"));
|
|
295
368
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
success: () => {
|
|
369
|
+
var defaultContext2 = Object.assign(
|
|
370
|
+
() => {
|
|
299
371
|
},
|
|
300
|
-
|
|
372
|
+
{
|
|
373
|
+
success: () => {
|
|
374
|
+
},
|
|
375
|
+
error: () => {
|
|
376
|
+
}
|
|
301
377
|
}
|
|
302
|
-
|
|
303
|
-
var ToastContext = React2.createContext(
|
|
378
|
+
);
|
|
379
|
+
var ToastContext = React2.createContext(defaultContext2);
|
|
380
|
+
var useToast = () => {
|
|
381
|
+
var _a;
|
|
382
|
+
return (_a = React2.useContext(ToastContext)) != null ? _a : defaultContext2;
|
|
383
|
+
};
|
|
304
384
|
var toastElementsMapRef = React2.createRef();
|
|
305
385
|
var defaultToastImpl = {
|
|
306
386
|
toastElementsMapRef,
|
|
@@ -509,10 +589,10 @@ var ToastAction = ({
|
|
|
509
589
|
};
|
|
510
590
|
// Annotate the CommonJS export names for ESM import in node:
|
|
511
591
|
0 && (module.exports = {
|
|
512
|
-
ThemeContext,
|
|
513
592
|
ThemeProvider,
|
|
514
593
|
ToastAction,
|
|
515
|
-
|
|
516
|
-
|
|
594
|
+
ToastProvider,
|
|
595
|
+
useTheme,
|
|
596
|
+
useToast
|
|
517
597
|
});
|
|
518
598
|
//# sourceMappingURL=index.js.map
|