Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ibm
GitHub Repository: ibm/watson-machine-learning-samples
Path: blob/master/cloud/ai-service-apps/nextjs-carbon-react-ui/src/utils/theme-util.js
6408 views
1
import { Asleep, Awake, Screen } from "@carbon/icons-react";
2
import { THEME } from "./constants";
3
4
export async function updateThemeCookie(newTheme) {
5
await fetch("/api/theme", {
6
method: "POST",
7
body: JSON.stringify({ theme: newTheme }),
8
headers: { "Content-Type": "application/json" },
9
});
10
}
11
12
export async function getThemeCookie() {
13
const data = await fetch("/api/theme", {
14
headers: { "Content-Type": "application/json" },
15
});
16
const result = await data.json();
17
18
return result.theme;
19
}
20
21
export const getThemeIcon = (theme, size) => {
22
if (theme === THEME.DARK) {
23
return <Asleep size={size} />;
24
} else if (theme === THEME.LIGHT) {
25
return <Awake size={size} />;
26
} else if (theme === THEME.SYSTEM) {
27
return <Screen size={size} />;
28
}
29
};
30
31
export const findInitialIndex = () => {};
32
33