From 3f11b25d5a1d898c3fc66c90f1816a856b6ca2fb Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Thu, 22 Aug 2024 18:00:26 +0300 Subject: [PATCH] feat(embed): override theme variables --- src/app/(theme)/embed/sqlite/page.tsx | 22 ++++++++++++++++++++-- src/app/(theme)/theme_layout.tsx | 9 ++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/(theme)/embed/sqlite/page.tsx b/src/app/(theme)/embed/sqlite/page.tsx index e419ff6..abe190a 100644 --- a/src/app/(theme)/embed/sqlite/page.tsx +++ b/src/app/(theme)/embed/sqlite/page.tsx @@ -2,7 +2,11 @@ import ThemeLayout from "../../theme_layout"; import EmbedPageClient from "./page-client"; export default async function EmbedPage(props: { - searchParams: { theme?: string; disableThemeToggle?: string }; + searchParams: { + theme?: string; + disableThemeToggle?: string; + [key: string]: any; + }; }) { let overrideTheme: "dark" | "light" | undefined = undefined; const disableToggle = props.searchParams.disableThemeToggle === "1"; @@ -11,8 +15,22 @@ export default async function EmbedPage(props: { overrideTheme = props.searchParams.theme === "dark" ? "dark" : "light"; } + const overrideThemeVariables: Record = {}; + + for (const key in props.searchParams) { + if (!key.startsWith("themeVariables[")) { + continue; + } + + overrideThemeVariables[key.slice(15, -1)] = props.searchParams[key]; + } + return ( - + ); diff --git a/src/app/(theme)/theme_layout.tsx b/src/app/(theme)/theme_layout.tsx index 685a95d..44fb814 100644 --- a/src/app/(theme)/theme_layout.tsx +++ b/src/app/(theme)/theme_layout.tsx @@ -13,17 +13,24 @@ export default async function ThemeLayout({ children, overrideTheme, disableToggle, + overrideThemeVariables, }: PropsWithChildren<{ overrideTheme?: "dark" | "light"; disableToggle?: boolean; + overrideThemeVariables?: Record; }>) { const cookieStore = cookies(); const theme = overrideTheme ?? (cookieStore.get("theme")?.value === "dark" ? "dark" : "light"); + const style = overrideThemeVariables ?? {}; return ( - + {children}