2022-07-26 08:27:57 +00:00
|
|
|
import { useTheme as useNextTheme } from "next-themes";
|
2022-07-28 10:50:25 +00:00
|
|
|
import { useEffect, useState } 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";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { 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";
|
2022-07-28 10:50:25 +00:00
|
|
|
const { resolvedTheme, setTheme, forcedTheme } = useNextTheme();
|
|
|
|
const [isReady, setIsReady] = useState<boolean>(false);
|
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);
|
|
|
|
}
|
2022-07-28 10:50:25 +00:00
|
|
|
setIsReady(true);
|
2022-07-26 08:27:57 +00:00
|
|
|
}, [theme, setTheme]);
|
2021-07-09 22:59:21 +00:00
|
|
|
|
|
|
|
return {
|
2022-07-28 10:50:25 +00:00
|
|
|
resolvedTheme,
|
2022-07-26 08:27:57 +00:00
|
|
|
setTheme,
|
2022-07-28 10:50:25 +00:00
|
|
|
isReady,
|
|
|
|
forcedTheme,
|
2021-07-11 19:35:56 +00:00
|
|
|
};
|
|
|
|
}
|