margo-ui 5.1.0 → 5.2.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/package.json +1 -1
- package/src/components/chip/style.ts +1 -1
- package/src/hooks/use_theme.ts +26 -18
- package/src/index.ts +2 -2
- package/src/utils/theme/theme.ts +1 -21
- package/src/utils/theme/type.ts +0 -6
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const chipBaseClassName = `bg-on-main/8 margo-text-box-trim flex items-center justify-center px-3 py-0.5
|
|
2
|
-
whitespace-nowrap lowercase flex-none
|
|
2
|
+
whitespace-nowrap lowercase flex-none rounded-margo-sm text-mc leading-none shadow-chip
|
|
3
3
|
focus-visible:outline focus-visible:outline-offset-1 focus-visible:outline-on-main`;
|
|
4
4
|
|
|
5
5
|
export const chipActiveClassName = "bg-on-main text-main";
|
package/src/hooks/use_theme.ts
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { margoTheme } from "../utils/theme/theme.js";
|
|
4
4
|
|
|
5
5
|
import type { MargoTheme } from "../utils/theme/type.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type UseMargoTheme = {
|
|
8
|
+
theme: MargoTheme | undefined;
|
|
9
|
+
set: (next: MargoTheme) => void;
|
|
10
|
+
toggle: () => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getSnapshot = (): MargoTheme =>
|
|
14
|
+
document.documentElement.classList.contains(margoTheme.DARK) ? margoTheme.DARK : margoTheme.LIGHT;
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
if (typeof document === "undefined") return;
|
|
16
|
+
const getServerSnapshot = () => undefined;
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
const subscribe = (onChange: () => void) => {
|
|
19
|
+
const observer = new MutationObserver(onChange);
|
|
20
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
22
|
+
return () => observer.disconnect();
|
|
23
|
+
};
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
const applyTheme = (next: MargoTheme) => {
|
|
26
|
+
const { classList } = document.documentElement;
|
|
27
|
+
|
|
28
|
+
classList.remove(margoTheme.LIGHT, margoTheme.DARK);
|
|
29
|
+
classList.add(next);
|
|
30
|
+
};
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
}, []);
|
|
32
|
+
const toggle = () => applyTheme(getSnapshot() === margoTheme.DARK ? margoTheme.LIGHT : margoTheme.DARK);
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, []);
|
|
34
|
+
export const useMargoTheme = (): UseMargoTheme => {
|
|
35
|
+
const theme = useSyncExternalStore<MargoTheme | undefined>(subscribe, getSnapshot, getServerSnapshot);
|
|
28
36
|
|
|
29
|
-
return
|
|
37
|
+
return { theme, set: applyTheme, toggle };
|
|
30
38
|
};
|
package/src/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ export { useMargoTheme } from "./hooks/use_theme.js";
|
|
|
33
33
|
|
|
34
34
|
export { cn } from "./utils/cn/cn.js";
|
|
35
35
|
export { isMargoLayerSupported } from "./utils/support/support.js";
|
|
36
|
-
export { margoTheme
|
|
36
|
+
export { margoTheme } from "./utils/theme/theme.js";
|
|
37
37
|
|
|
38
38
|
export type { BlockquoteProps } from "./components/blockquote/type.js";
|
|
39
39
|
|
|
@@ -83,4 +83,4 @@ export type { MaskGradientXProps } from "./hoc/mask_gradient_x/type.js";
|
|
|
83
83
|
export type { MaskGradientYProps } from "./hoc/mask_gradient_y/type.js";
|
|
84
84
|
export type { RippleProps } from "./hoc/ripple/type.js";
|
|
85
85
|
|
|
86
|
-
export type { MargoTheme
|
|
86
|
+
export type { MargoTheme } from "./utils/theme/type.js";
|
package/src/utils/theme/theme.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MargoThemeConstants } from "./type.js";
|
|
2
2
|
|
|
3
3
|
export const margoTheme: MargoThemeConstants = {
|
|
4
4
|
LIGHT: "light",
|
|
5
5
|
DARK: "dark",
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
const get = (): MargoTheme => {
|
|
9
|
-
if (typeof document === "undefined") return margoTheme.DARK;
|
|
10
|
-
|
|
11
|
-
return document.documentElement.classList.contains(margoTheme.DARK) ? margoTheme.DARK : margoTheme.LIGHT;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const set = (next: MargoTheme) => {
|
|
15
|
-
if (typeof document === "undefined") return;
|
|
16
|
-
|
|
17
|
-
document.documentElement.classList.toggle(margoTheme.DARK, next === margoTheme.DARK);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const toggle = () => set(get() === margoTheme.DARK ? margoTheme.LIGHT : margoTheme.DARK);
|
|
21
|
-
|
|
22
|
-
export const margoThemeClient: MargoThemeClient = {
|
|
23
|
-
get,
|
|
24
|
-
set,
|
|
25
|
-
toggle,
|
|
26
|
-
};
|
package/src/utils/theme/type.ts
CHANGED