@mbao01/common 0.0.11 → 0.0.12
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"react-dom": "^18.2.0",
|
|
128
128
|
"typescript": "^5.2.2"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "529b4ea031970fd4696249033017ce46100c1d47"
|
|
131
131
|
}
|
package/src/utilities/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Theme = "dark" | "light" | "system";
|
|
2
|
+
|
|
3
|
+
export const getTheme = () => {
|
|
4
|
+
if (typeof window === "undefined") return null;
|
|
5
|
+
|
|
6
|
+
let t = window.localStorage.getItem("__theme") as Theme;
|
|
7
|
+
if (!t)
|
|
8
|
+
t = window.matchMedia("(prefers-color-scheme: dark)")?.matches
|
|
9
|
+
? "dark"
|
|
10
|
+
: window.matchMedia("(prefers-color-scheme: light)")?.matches
|
|
11
|
+
? "light"
|
|
12
|
+
: "system";
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const saveTheme = (theme: Theme) => {
|
|
17
|
+
document.body.setAttribute("data-theme", theme);
|
|
18
|
+
localStorage.setItem("__theme", theme);
|
|
19
|
+
};
|