-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add theme and disable theme toggle option (#151)
* feat: add theme and disable theme toggle option * feat(embed): override theme variables (#152) --------- Co-authored-by: Georges KABBOUCHI <[email protected]>
- Loading branch information
Showing
12 changed files
with
152 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { Fragment } from "react"; | ||
import ThemeLayout from "../theme_layout"; | ||
|
||
export default async function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <Fragment>{children}</Fragment>; | ||
return <ThemeLayout>{children}</ThemeLayout>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
import { Studio } from "@/components/gui/studio"; | ||
import IframeDriver from "@/drivers/iframe-driver"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useEffect, useMemo } from "react"; | ||
|
||
export default function EmbedPageClient() { | ||
const searchParams = useSearchParams(); | ||
const driver = useMemo(() => new IframeDriver(), []); | ||
|
||
useEffect(() => { | ||
return driver.listen(); | ||
}, [driver]); | ||
|
||
return ( | ||
<Studio | ||
driver={driver} | ||
name={searchParams.get("name") || "Unnamed Connection"} | ||
color={searchParams.get("color") || "gray"} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
"use client"; | ||
import ThemeLayout from "../../theme_layout"; | ||
import EmbedPageClient from "./page-client"; | ||
|
||
import MyStudio from "@/components/my-studio"; | ||
import IframeDriver from "@/drivers/iframe-driver"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useEffect, useMemo } from "react"; | ||
export default async function EmbedPage(props: { | ||
searchParams: { | ||
theme?: string; | ||
disableThemeToggle?: string; | ||
[key: string]: any; | ||
}; | ||
}) { | ||
let overrideTheme: "dark" | "light" | undefined = undefined; | ||
const disableToggle = props.searchParams.disableThemeToggle === "1"; | ||
|
||
export default function EmbedPageClient() { | ||
const searchParams = useSearchParams(); | ||
const driver = useMemo(() => new IframeDriver(), []); | ||
if (props.searchParams.theme) { | ||
overrideTheme = props.searchParams.theme === "dark" ? "dark" : "light"; | ||
} | ||
|
||
useEffect(() => { | ||
return driver.listen(); | ||
}, [driver]); | ||
const overrideThemeVariables: Record<string, string> = {}; | ||
|
||
for (const key in props.searchParams) { | ||
if (!key.startsWith("themeVariables[")) { | ||
continue; | ||
} | ||
|
||
overrideThemeVariables[key.slice(15, -1)] = props.searchParams[key]; | ||
} | ||
|
||
return ( | ||
<MyStudio | ||
driver={driver} | ||
color={searchParams.get("color") || "gray"} | ||
name={searchParams.get("name") || "Unnamed Connection"} | ||
/> | ||
<ThemeLayout | ||
overrideTheme={overrideTheme} | ||
disableToggle={disableToggle} | ||
overrideThemeVariables={overrideThemeVariables} | ||
> | ||
<EmbedPageClient /> | ||
</ThemeLayout> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Analytics } from "@vercel/analytics/react"; | ||
import { Inter } from "next/font/google"; | ||
import ThemeProvider from "@/context/theme-provider"; | ||
import { cookies } from "next/headers"; | ||
import { Toaster } from "@/components/ui/sonner"; | ||
import { Fragment, PropsWithChildren } from "react"; | ||
import Script from "next/script"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export default async function ThemeLayout({ | ||
children, | ||
overrideTheme, | ||
disableToggle, | ||
overrideThemeVariables, | ||
}: PropsWithChildren<{ | ||
overrideTheme?: "dark" | "light"; | ||
disableToggle?: boolean; | ||
overrideThemeVariables?: Record<string, string>; | ||
}>) { | ||
const cookieStore = cookies(); | ||
const theme = | ||
overrideTheme ?? | ||
(cookieStore.get("theme")?.value === "dark" ? "dark" : "light"); | ||
const style = overrideThemeVariables ?? {}; | ||
|
||
return ( | ||
<body | ||
className={cn(inter.className, theme)} | ||
style={style} | ||
suppressHydrationWarning | ||
> | ||
<ThemeProvider defaultTheme={theme} disableToggle={disableToggle}> | ||
<Fragment>{children}</Fragment> | ||
<Toaster /> | ||
</ThemeProvider> | ||
<Analytics /> | ||
<Script async defer src="https://buttons.github.io/buttons.js" /> | ||
</body> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters