2022-07-26 08:27:57 +00:00
|
|
|
import { useTheme as useNextTheme } from "next-themes";
|
|
|
|
import { useEffect } from "react";
|
2021-07-09 22:59:21 +00:00
|
|
|
|
2022-05-27 15:37:02 +00:00
|
|
|
import { useEmbedTheme } from "@calcom/embed-core/embed-iframe";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { Maybe } from "@calcom/trpc/server";
|
2021-10-14 19:22:01 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
// makes sure the ui doesn't flash
|
2021-09-27 16:09:19 +00:00
|
|
|
export default function useTheme(theme?: Maybe<string>) {
|
2022-07-26 08:27:57 +00:00
|
|
|
theme = theme || "system";
|
|
|
|
const { theme: currentTheme, setTheme } = useNextTheme();
|
2022-04-08 05:33:24 +00:00
|
|
|
const embedTheme = useEmbedTheme();
|
2022-03-31 08:45:47 +00:00
|
|
|
// Embed UI configuration takes more precedence over App Configuration
|
2022-04-08 05:33:24 +00:00
|
|
|
theme = embedTheme || theme;
|
2022-02-16 15:53:26 +00:00
|
|
|
|
2022-07-26 08:27:57 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (theme) {
|
|
|
|
setTheme(theme);
|
|
|
|
}
|
|
|
|
}, [theme, setTheme]);
|
2021-07-09 22:59:21 +00:00
|
|
|
|
|
|
|
return {
|
2022-07-26 08:27:57 +00:00
|
|
|
currentTheme,
|
|
|
|
setTheme,
|
2021-07-11 19:35:56 +00:00
|
|
|
};
|
|
|
|
}
|