@mbao01/common 0.6.5 → 0.7.1
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/types/components/Flex/Flex.d.ts +1 -1
- package/dist/types/components/Flex/constants.d.ts +1 -1
- package/dist/types/components/Grid/Grid.d.ts +5 -5
- package/dist/types/components/Grid/constants.d.ts +5 -5
- package/dist/types/components/Skeleton/constants.d.ts +2 -2
- package/dist/types/components/Spacer/Spacer.d.ts +1 -1
- package/dist/types/components/Spacer/constants.d.ts +1 -1
- package/dist/types/components/Status/constants.d.ts +1 -1
- package/dist/types/components/ThemeSwitch/ThemeSwitch.d.ts +1 -1
- package/dist/types/components/ThemeSwitch/constants.d.ts +7 -1
- package/dist/types/components/ThemeSwitch/types.d.ts +13 -2
- package/dist/types/utilities/theme.d.ts +1 -1
- package/package.json +6 -6
- package/src/components/ThemeSwitch/ThemeSwitch.tsx +84 -44
- package/src/components/ThemeSwitch/constants.ts +34 -1
- package/src/components/ThemeSwitch/types.ts +14 -2
- package/src/utilities/theme.ts +16 -2
|
@@ -4,5 +4,5 @@ export declare const Flex: React.ForwardRefExoticComponent<React.HTMLAttributes<
|
|
|
4
4
|
align?: "end" | "center" | "start" | "stretch" | "baseline" | undefined;
|
|
5
5
|
justify?: "end" | "center" | "start" | "between" | "around" | "evenly" | undefined;
|
|
6
6
|
wrap?: "wrap" | "wrap-reverse" | "nowrap" | undefined;
|
|
7
|
-
gap?: 0 | 1 | 4 | 3 | 8 | 2 |
|
|
7
|
+
gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | undefined;
|
|
8
8
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -3,5 +3,5 @@ export declare const getFlexClasses: (props?: ({
|
|
|
3
3
|
align?: "end" | "center" | "start" | "stretch" | "baseline" | null | undefined;
|
|
4
4
|
justify?: "end" | "center" | "start" | "between" | "around" | "evenly" | null | undefined;
|
|
5
5
|
wrap?: "wrap" | "wrap-reverse" | "nowrap" | null | undefined;
|
|
6
|
-
gap?: 0 | 1 | 4 | 3 | 8 | 2 |
|
|
6
|
+
gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | null | undefined;
|
|
7
7
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
export declare const Grid: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
3
|
-
gap?: 0 | 1 | 4 | 3 | 8 | 2 |
|
|
4
|
-
columns?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
5
|
-
rows?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
3
|
+
gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | undefined;
|
|
4
|
+
columns?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
|
|
5
|
+
rows?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
|
|
6
6
|
flow?: "row" | "col" | "dense" | "row-dense" | "col-dense" | undefined;
|
|
7
7
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
8
8
|
export declare const GridItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
9
|
-
colSpan?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
10
|
-
rowSpan?: 1 | 4 | 3 | 2 | 5 | 6 |
|
|
9
|
+
colSpan?: 1 | 4 | 3 | 8 | "full" | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | undefined;
|
|
10
|
+
rowSpan?: 1 | 4 | 3 | "full" | 2 | 5 | 6 | undefined;
|
|
11
11
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const getGridClasses: (props?: ({
|
|
2
|
-
columns?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
3
|
-
rows?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
4
|
-
gap?: 0 | 1 | 4 | 3 | 8 | 2 |
|
|
2
|
+
columns?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
|
|
3
|
+
rows?: 1 | 4 | 3 | 8 | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
|
|
4
|
+
gap?: 0 | 1 | 4 | 3 | 8 | 2 | 12 | 16 | 5 | 6 | 10 | null | undefined;
|
|
5
5
|
flow?: "row" | "col" | "dense" | "row-dense" | "col-dense" | null | undefined;
|
|
6
6
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
7
7
|
export declare const getGridItemClasses: (props?: ({
|
|
8
|
-
colSpan?: 1 | 4 | 3 | 8 | 2 | 5 | 6 | 10 |
|
|
9
|
-
rowSpan?: 1 | 4 | 3 | 2 | 5 | 6 |
|
|
8
|
+
colSpan?: 1 | 4 | 3 | 8 | "full" | 2 | 12 | 5 | 6 | 10 | 7 | 9 | 11 | null | undefined;
|
|
9
|
+
rowSpan?: 1 | 4 | 3 | "full" | 2 | 5 | 6 | null | undefined;
|
|
10
10
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const getSkeletonClasses: (props?: ({
|
|
2
2
|
animate?: "pulse" | null | undefined;
|
|
3
|
-
width?: 4 | 8 | 2 | 12 | 16 |
|
|
4
|
-
height?: 4 | 8 | 2 | 12 | 16 |
|
|
3
|
+
width?: 4 | 8 | "full" | 2 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
|
|
4
|
+
height?: 4 | 8 | "full" | 2 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
|
|
5
5
|
round?: boolean | null | undefined;
|
|
6
6
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
export declare const Spacer: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
3
3
|
axis?: "horizontal" | "vertical" | undefined;
|
|
4
|
-
gap?: 1 | 4 | 3 | 8 | 2 |
|
|
4
|
+
gap?: 1 | 4 | 3 | 8 | 2 | 12 | 16 | 24 | 5 | 6 | 10 | 20 | undefined;
|
|
5
5
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getSpacerClasses: (props?: ({
|
|
2
2
|
axis?: "horizontal" | "vertical" | null | undefined;
|
|
3
|
-
gap?: 1 | 4 | 3 | 8 | 2 |
|
|
3
|
+
gap?: 1 | 4 | 3 | 8 | 2 | 12 | 16 | 24 | 5 | 6 | 10 | 20 | null | undefined;
|
|
4
4
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getStatusClasses: (props?: ({
|
|
2
2
|
variant?: "accent" | "default" | "error" | "ghost" | "info" | "neutral" | "primary" | "secondary" | "success" | "warning" | null | undefined;
|
|
3
3
|
size?: "xs" | "sm" | "md" | "lg" | "xl" | null | undefined;
|
|
4
|
-
animate?: "ping" | "
|
|
4
|
+
animate?: "ping" | "pulse" | "bounce" | "spin" | null | undefined;
|
|
5
5
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ThemeSwitchProps } from './types';
|
|
2
|
-
export declare const ThemeSwitch: ({
|
|
2
|
+
export declare const ThemeSwitch: ({ swap, render, className, theme: defaultTheme, }: ThemeSwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export declare const getThemeSwitchClasses: (props?:
|
|
1
|
+
export declare const getThemeSwitchClasses: (props?: ({
|
|
2
|
+
swap?: boolean | null | undefined;
|
|
3
|
+
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
4
|
+
export declare const getThemeSwitchIconClasses: (props?: ({
|
|
5
|
+
isActive?: boolean | null | undefined;
|
|
6
|
+
swap?: boolean | null | undefined;
|
|
7
|
+
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Theme } from '../../utilities';
|
|
2
|
-
export type
|
|
3
|
-
|
|
2
|
+
export type SwitchProps = {
|
|
3
|
+
id: string;
|
|
4
|
+
icon: React.ReactNode;
|
|
5
|
+
swap?: boolean;
|
|
6
|
+
label: string;
|
|
7
|
+
value: Theme | null;
|
|
8
|
+
theme: Theme | null;
|
|
9
|
+
className?: string;
|
|
10
|
+
changeTheme: (theme: Theme | null) => void;
|
|
11
|
+
};
|
|
12
|
+
export type ThemeSwitchProps = {
|
|
13
|
+
swap?: boolean;
|
|
4
14
|
theme?: Theme;
|
|
15
|
+
className?: string;
|
|
5
16
|
render?: (params: {
|
|
6
17
|
theme: Theme | null;
|
|
7
18
|
setTheme: React.Dispatch<React.SetStateAction<Theme | null>>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -131,8 +131,8 @@
|
|
|
131
131
|
"@types/node": "^25.0.3",
|
|
132
132
|
"@types/react": "^19.2.7",
|
|
133
133
|
"@types/react-dom": "^19.2.3",
|
|
134
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
135
|
-
"@typescript-eslint/parser": "^8.
|
|
134
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
135
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
136
136
|
"@vitejs/plugin-react": "^5.1.2",
|
|
137
137
|
"@vitest/coverage-v8": "^3.2.4",
|
|
138
138
|
"@vitest/ui": "^3.2.4",
|
|
@@ -151,12 +151,12 @@
|
|
|
151
151
|
"prettier": "^3.7.4",
|
|
152
152
|
"react": "^19.2.3",
|
|
153
153
|
"react-dom": "^19.2.3",
|
|
154
|
-
"react-router-dom": "^7.
|
|
154
|
+
"react-router-dom": "^7.12.0",
|
|
155
155
|
"recharts": "^3.6.0",
|
|
156
156
|
"storybook": "^10.1.11",
|
|
157
157
|
"tailwindcss": "^4.1.18",
|
|
158
158
|
"typescript": "^5.9.3",
|
|
159
|
-
"typescript-eslint": "^8.
|
|
159
|
+
"typescript-eslint": "^8.52.0",
|
|
160
160
|
"vite": "^6.4.1",
|
|
161
161
|
"vite-plugin-dts": "^4.5.4",
|
|
162
162
|
"vitest": "^3.2.4"
|
|
@@ -168,5 +168,5 @@
|
|
|
168
168
|
"recharts": "2",
|
|
169
169
|
"typescript": "5"
|
|
170
170
|
},
|
|
171
|
-
"gitHead": "
|
|
171
|
+
"gitHead": "5ccbce52df9f8411ec194b45909b47a0bc7d5b51"
|
|
172
172
|
}
|
|
@@ -1,69 +1,109 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { ChangeEvent } from "react";
|
|
4
3
|
import { useLayoutEffect, useState } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
|
|
5
|
+
import type { SwitchProps, ThemeSwitchProps } from "./types";
|
|
6
|
+
import { cn, getTheme, saveTheme, Theme } from "../../utilities";
|
|
7
|
+
import { Skeleton } from "../Skeleton";
|
|
8
|
+
import { getThemeSwitchClasses, getThemeSwitchIconClasses } from "./constants";
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
className="swap-on h-4 w-4 fill-current"
|
|
12
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
13
|
-
viewBox="0 0 24 24"
|
|
14
|
-
>
|
|
15
|
-
{title && <title>{title}</title>}
|
|
16
|
-
<path d="M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z" />
|
|
17
|
-
</svg>
|
|
18
|
-
);
|
|
10
|
+
const Switcher = ({ id, icon, swap, value, label, theme, changeTheme, className }: SwitchProps) => {
|
|
11
|
+
const isActive = theme === value;
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
return (
|
|
14
|
+
<span
|
|
15
|
+
className={cn("h-full", {
|
|
16
|
+
hidden: swap && isActive,
|
|
17
|
+
})}
|
|
18
|
+
>
|
|
19
|
+
<input
|
|
20
|
+
hidden
|
|
21
|
+
id={id}
|
|
22
|
+
role="checkbox"
|
|
23
|
+
type="checkbox"
|
|
24
|
+
className="theme-controller"
|
|
25
|
+
checked={isActive}
|
|
26
|
+
onChange={() => changeTheme(value)}
|
|
27
|
+
/>
|
|
28
|
+
<label htmlFor={id} className={cn(getThemeSwitchIconClasses({ isActive, swap }), className)}>
|
|
29
|
+
<span className="sr-only">{label}</span>
|
|
30
|
+
{icon}
|
|
31
|
+
</label>
|
|
32
|
+
</span>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
31
35
|
|
|
32
36
|
export const ThemeSwitch = ({
|
|
33
|
-
|
|
37
|
+
swap = false,
|
|
34
38
|
render,
|
|
35
39
|
className,
|
|
36
40
|
theme: defaultTheme,
|
|
37
|
-
...props
|
|
38
41
|
}: ThemeSwitchProps) => {
|
|
39
|
-
const [
|
|
42
|
+
const [isClient, setIsClient] = useState(false);
|
|
43
|
+
const [theme, setTheme] = useState(() => defaultTheme ?? getTheme());
|
|
40
44
|
|
|
41
45
|
useLayoutEffect(() => {
|
|
42
|
-
|
|
46
|
+
saveTheme(theme);
|
|
43
47
|
}, [theme]);
|
|
44
48
|
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
setIsClient(true);
|
|
51
|
+
const observer = new MutationObserver(() => {
|
|
52
|
+
const attr = document.body.getAttribute("data-theme");
|
|
53
|
+
if (attr === "dark" || attr === "light") {
|
|
54
|
+
setTheme(attr);
|
|
55
|
+
} else {
|
|
56
|
+
setTheme(null);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-theme"] });
|
|
60
|
+
|
|
61
|
+
return () => observer.disconnect();
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
if (!isClient) {
|
|
65
|
+
return <Skeleton width={swap ? 4 : 16} />;
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
if (render) {
|
|
46
69
|
return render({ theme, setTheme });
|
|
47
70
|
}
|
|
48
71
|
|
|
49
|
-
const changeTheme = (
|
|
50
|
-
|
|
51
|
-
setTheme(t);
|
|
72
|
+
const changeTheme = (theme: Theme | null) => {
|
|
73
|
+
setTheme(theme);
|
|
52
74
|
};
|
|
53
75
|
|
|
54
76
|
return (
|
|
55
|
-
<
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
<fieldset className={cn(getThemeSwitchClasses({ swap }), className)}>
|
|
78
|
+
{!swap && (
|
|
79
|
+
<Switcher
|
|
80
|
+
id="system"
|
|
81
|
+
swap={swap}
|
|
82
|
+
icon={<MonitorIcon className="h-3.5 w-3.5 shrink-0" />}
|
|
83
|
+
label="Switch to system theme"
|
|
84
|
+
value={null}
|
|
85
|
+
theme={theme}
|
|
86
|
+
changeTheme={changeTheme}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
<Switcher
|
|
90
|
+
id="dark"
|
|
91
|
+
swap={swap}
|
|
92
|
+
icon={<MoonIcon className="h-3.5 w-3.5 shrink-0" />}
|
|
93
|
+
label="Switch to dark theme"
|
|
94
|
+
value="dark"
|
|
95
|
+
theme={theme}
|
|
96
|
+
changeTheme={changeTheme}
|
|
97
|
+
/>
|
|
98
|
+
<Switcher
|
|
99
|
+
id="light"
|
|
100
|
+
swap={swap}
|
|
101
|
+
icon={<SunIcon className="h-3.5 w-3.5 shrink-0" />}
|
|
102
|
+
label="Switch to light theme"
|
|
103
|
+
value="light"
|
|
104
|
+
theme={theme}
|
|
105
|
+
changeTheme={changeTheme}
|
|
64
106
|
/>
|
|
65
|
-
|
|
66
|
-
<SunIcon title="Switch to light theme" />
|
|
67
|
-
</label>
|
|
107
|
+
</fieldset>
|
|
68
108
|
);
|
|
69
109
|
};
|
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
import { cva } from "../../libs";
|
|
2
2
|
|
|
3
|
-
export const getThemeSwitchClasses = cva("
|
|
3
|
+
export const getThemeSwitchClasses = cva("", {
|
|
4
|
+
variants: {
|
|
5
|
+
swap: {
|
|
6
|
+
false:
|
|
7
|
+
"flex flex-row items-center justify-around h-6 w-18 border border-base-content/10 rounded-full",
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const getThemeSwitchIconClasses = cva(
|
|
13
|
+
"cursor-pointer text-base-content/40 hover:text-base-content transition-colors",
|
|
14
|
+
{
|
|
15
|
+
variants: {
|
|
16
|
+
isActive: {
|
|
17
|
+
true: "rounded-[9999px] outline outline-1 outline-base-content/10",
|
|
18
|
+
},
|
|
19
|
+
swap: {
|
|
20
|
+
false: "flex items-center justify-center w-6 h-full",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
compoundVariants: [
|
|
24
|
+
{
|
|
25
|
+
swap: false,
|
|
26
|
+
isActive: true,
|
|
27
|
+
className: "text-base-content",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
swap: true,
|
|
31
|
+
isActive: false,
|
|
32
|
+
className: "text-base-content",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
);
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Theme } from "../../utilities";
|
|
2
2
|
|
|
3
|
-
export type
|
|
4
|
-
|
|
3
|
+
export type SwitchProps = {
|
|
4
|
+
id: string;
|
|
5
|
+
icon: React.ReactNode;
|
|
6
|
+
swap?: boolean;
|
|
7
|
+
label: string;
|
|
8
|
+
value: Theme | null;
|
|
9
|
+
theme: Theme | null;
|
|
10
|
+
className?: string;
|
|
11
|
+
changeTheme: (theme: Theme | null) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ThemeSwitchProps = {
|
|
15
|
+
swap?: boolean;
|
|
5
16
|
theme?: Theme;
|
|
17
|
+
className?: string;
|
|
6
18
|
render?: (params: {
|
|
7
19
|
theme: Theme | null;
|
|
8
20
|
setTheme: React.Dispatch<React.SetStateAction<Theme | null>>;
|
package/src/utilities/theme.ts
CHANGED
|
@@ -4,16 +4,30 @@ export type Theme = "dark" | "light";
|
|
|
4
4
|
|
|
5
5
|
export const THEME_COOKIE_NAME = "data-theme";
|
|
6
6
|
|
|
7
|
+
const getSystemTheme = () => {
|
|
8
|
+
if (typeof window === "undefined") return null;
|
|
9
|
+
|
|
10
|
+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
11
|
+
return prefersDark ? "dark" : "light";
|
|
12
|
+
};
|
|
13
|
+
|
|
7
14
|
export const getTheme = () => {
|
|
8
15
|
if (typeof window === "undefined") return null;
|
|
9
16
|
|
|
10
17
|
const cookies = new Cookies();
|
|
11
|
-
const theme = cookies.get(THEME_COOKIE_NAME) as Theme;
|
|
18
|
+
const theme = (cookies.get(THEME_COOKIE_NAME) ?? getSystemTheme()) as Theme | null;
|
|
12
19
|
return theme;
|
|
13
20
|
};
|
|
14
21
|
|
|
15
|
-
export const saveTheme = (theme: Theme) => {
|
|
22
|
+
export const saveTheme = (theme: Theme | null) => {
|
|
16
23
|
const cookies = new Cookies();
|
|
24
|
+
|
|
25
|
+
if (!theme) {
|
|
26
|
+
cookies.remove(THEME_COOKIE_NAME);
|
|
27
|
+
document.body.removeAttribute(THEME_COOKIE_NAME);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
cookies.set(THEME_COOKIE_NAME, theme, { path: "/", secure: true });
|
|
18
32
|
document.body.setAttribute(THEME_COOKIE_NAME, theme);
|
|
19
33
|
};
|