error fix
This commit is contained in:
+3
-42
@@ -6,6 +6,7 @@ import i18nConfig from "../../i18nConfig";
|
|||||||
import initTranslations from '@/lib/i18n';
|
import initTranslations from '@/lib/i18n';
|
||||||
import TranslationsProvider from "@/components/utils/TranslationsProdiver";
|
import TranslationsProvider from "@/components/utils/TranslationsProdiver";
|
||||||
import ToastContainer from "@/components/Toast";
|
import ToastContainer from "@/components/Toast";
|
||||||
|
import { ThemeColorSetter } from "@/components/ThemeColorSetter";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: 'Dashboard',
|
title: 'Dashboard',
|
||||||
@@ -42,48 +43,7 @@ export default async function RootLayout({
|
|||||||
dir='rtl'
|
dir='rtl'
|
||||||
className="h-svh overflow-hidden"
|
className="h-svh overflow-hidden"
|
||||||
data-theme="light" >
|
data-theme="light" >
|
||||||
<head>
|
<head />
|
||||||
<script
|
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: `
|
|
||||||
(function() {
|
|
||||||
try {
|
|
||||||
const savedColor = localStorage.getItem('theme-primary-color');
|
|
||||||
if (savedColor) {
|
|
||||||
const hex = savedColor.replace('#', '');
|
|
||||||
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
||||||
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
||||||
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
||||||
|
|
||||||
const lightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
||||||
const max = Math.max(r, g, b);
|
|
||||||
const min = Math.min(r, g, b);
|
|
||||||
const chroma = (max - min) * 0.15;
|
|
||||||
|
|
||||||
let hue = 0;
|
|
||||||
if (chroma !== 0) {
|
|
||||||
if (max === r) {
|
|
||||||
hue = ((g - b) / (max - min) + (g < b ? 6 : 0)) * 60;
|
|
||||||
} else if (max === g) {
|
|
||||||
hue = ((b - r) / (max - min) + 2) * 60;
|
|
||||||
} else {
|
|
||||||
hue = ((r - g) / (max - min) + 4) * 60;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const oklchColor = 'oklch(' + lightness.toFixed(3) + ' ' + chroma.toFixed(3) + ' ' + hue.toFixed(1) + ')';
|
|
||||||
document.documentElement.style.setProperty('--primary', oklchColor);
|
|
||||||
|
|
||||||
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
|
|
||||||
const foregroundOklch = brightness > 0.5 ? 'oklch(0 0 0)' : 'oklch(1 0 0)';
|
|
||||||
document.documentElement.style.setProperty('--primary-foreground', foregroundOklch);
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
})();
|
|
||||||
`,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</head>
|
|
||||||
<body
|
<body
|
||||||
|
|
||||||
className={`antialiased bg-background h-svh overflow-hidden`}
|
className={`antialiased bg-background h-svh overflow-hidden`}
|
||||||
@@ -93,6 +53,7 @@ export default async function RootLayout({
|
|||||||
namespaces={i18nNamespaces}
|
namespaces={i18nNamespaces}
|
||||||
locale={locale}
|
locale={locale}
|
||||||
resources={resources}>
|
resources={resources}>
|
||||||
|
<ThemeColorSetter />
|
||||||
<div id="root" className="h-svh overflow-hidden">
|
<div id="root" className="h-svh overflow-hidden">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
|
export function ThemeColorSetter() {
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
const savedColor = localStorage.getItem('theme-primary-color')
|
||||||
|
if (savedColor) {
|
||||||
|
const hex = savedColor.replace('#', '')
|
||||||
|
const r = parseInt(hex.substring(0, 2), 16) / 255
|
||||||
|
const g = parseInt(hex.substring(2, 4), 16) / 255
|
||||||
|
const b = parseInt(hex.substring(4, 6), 16) / 255
|
||||||
|
|
||||||
|
const lightness = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||||
|
const max = Math.max(r, g, b)
|
||||||
|
const min = Math.min(r, g, b)
|
||||||
|
const chroma = (max - min) * 0.15
|
||||||
|
|
||||||
|
let hue = 0
|
||||||
|
if (chroma !== 0) {
|
||||||
|
if (max === r) {
|
||||||
|
hue = ((g - b) / (max - min) + (g < b ? 6 : 0)) * 60
|
||||||
|
} else if (max === g) {
|
||||||
|
hue = ((b - r) / (max - min) + 2) * 60
|
||||||
|
} else {
|
||||||
|
hue = ((r - g) / (max - min) + 4) * 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const oklchColor = `oklch(${lightness.toFixed(3)} ${chroma.toFixed(3)} ${hue.toFixed(1)})`
|
||||||
|
document.documentElement.style.setProperty('--primary', oklchColor)
|
||||||
|
|
||||||
|
const brightness = (r * 299 + g * 587 + b * 114) / 1000
|
||||||
|
const foregroundOklch = brightness > 0.5 ? 'oklch(0 0 0)' : 'oklch(1 0 0)'
|
||||||
|
document.documentElement.style.setProperty('--primary-foreground', foregroundOklch)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Silent fail
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user