* chore: add next-themes * feat: add next theme provider * fix: modify useTheme hook to use next-themes * fix: use the new hook for theming * remove conditional rendering with isReady boolean flag * remove Theme component returned from useTheme hook * Update missing useTheme usage * Fix theme switching as per system. Also, ensure that booking and non booking pages can maintain their own requirements of theme simulatenously Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
26 lines
670 B
TypeScript
26 lines
670 B
TypeScript
import { useTheme as useNextTheme } from "next-themes";
|
|
import { useEffect } from "react";
|
|
|
|
import { useEmbedTheme } from "@calcom/embed-core/embed-iframe";
|
|
import { Maybe } from "@calcom/trpc/server";
|
|
|
|
// makes sure the ui doesn't flash
|
|
export default function useTheme(theme?: Maybe<string>) {
|
|
theme = theme || "system";
|
|
const { theme: currentTheme, setTheme } = useNextTheme();
|
|
const embedTheme = useEmbedTheme();
|
|
// Embed UI configuration takes more precedence over App Configuration
|
|
theme = embedTheme || theme;
|
|
|
|
useEffect(() => {
|
|
if (theme) {
|
|
setTheme(theme);
|
|
}
|
|
}, [theme, setTheme]);
|
|
|
|
return {
|
|
currentTheme,
|
|
setTheme,
|
|
};
|
|
}
|