From 18b110a26944f8b472411974451b392d1a5843b5 Mon Sep 17 00:00:00 2001 From: ner Date: Mon, 4 Nov 2024 13:45:25 +0200 Subject: [PATCH] fix: theme color --- app/layout.tsx | 8 ++++---- .../Header/components/ThemeToggle/index.tsx | 9 ++++++++- components/ThemeColor/index.tsx | 15 +++++++++++++++ public/manifest.json | 2 +- public/sw.js | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 components/ThemeColor/index.tsx diff --git a/app/layout.tsx b/app/layout.tsx index 19c2f9b..82a8b92 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,9 +1,9 @@ import React, { ReactNode } from 'react'; import type { Metadata, Viewport } from 'next'; import { Jost } from 'next/font/google'; -import { cookies } from 'next/headers'; import Header from '@/components/Header'; +import ThemeColor from '@/components/ThemeColor'; import { SITE_URL, TITLE } from '@/env'; import Providers from '@/providers'; @@ -17,7 +17,8 @@ export const metadata: Metadata = { export const viewport: Viewport = { width: 'device-width', initialScale: 1, - viewportFit: 'cover' + viewportFit: 'cover', + themeColor: 'white' }; const font = Jost({ subsets: ['latin', 'cyrillic'], weight: ['400'] }); @@ -26,8 +27,7 @@ const RootLayout = ({ children }: { children: ReactNode }) => { return ( - {/**/} - + { - const { setTheme } = useTheme(); + const { resolvedTheme, setTheme } = useTheme(); + + useEffect(() => { + document + .querySelector('meta[name="theme-color"]')! + .setAttribute('content', resolvedTheme === 'dark' ? 'hsl(222.2 84% 4.9%)' : 'white'); + }, [resolvedTheme]); return ( <> diff --git a/components/ThemeColor/index.tsx b/components/ThemeColor/index.tsx new file mode 100644 index 0000000..f13f4ac --- /dev/null +++ b/components/ThemeColor/index.tsx @@ -0,0 +1,15 @@ +const ThemeColor = () => ( +