Skip to content

Commit

Permalink
Fix initial colorMode (betaflight#212)
Browse files Browse the repository at this point in the history
fix initial colorMode
  • Loading branch information
asizon committed Aug 12, 2023
1 parent e96c738 commit 8a064c6
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/components/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { useColorMode } from '@docusaurus/theme-common';
import { CameraIcon, CodeBracketIcon, CpuChipIcon, DocumentTextIcon, ShieldCheckIcon, UsersIcon } from '@heroicons/react/24/solid';
import JetIcon from '@site/src/icons/jet.icon.svg';
Expand All @@ -17,10 +17,24 @@ type LogoProps = {
}

function Logo({ sponsor }: LogoProps) {
const { colorMode } = useColorMode();
const [theme, setTheme] = useState('light');
const themeData = useColorMode();
const isDarkTheme = theme === 'dark';

const logoSrc = `/img/betaflight/logo_${colorMode === 'light' ? 'light' : 'dark'}.svg`;
const sponsorLogoSrc = `/img/betaflight/sponsors/bf_partner_${colorMode === 'light' ? 'light' : 'dark'}.svg`;
const logoSrc = `/img/betaflight/logo_${isDarkTheme ? 'dark' : 'light'}.svg`;
const sponsorLogoSrc = `/img/betaflight/sponsors/bf_partner_${isDarkTheme ? 'dark' : 'light'}.svg`;

useLayoutEffect(() => {
const initialTheme = document.documentElement.getAttribute('data-theme');
setTheme(initialTheme);
}, [])

useEffect(() => {
const themeColorMode = themeData.colorMode;
if (themeColorMode !== theme) {
setTheme(themeData.colorMode);
}
}, [themeData.colorMode])

return <img src={sponsor ? sponsorLogoSrc : logoSrc} alt="Betaflight" className={sponsor ? 'max-h-[200px] w-auto' : 'p-6 h-fit w-fit xl:ml-12'} />;
}
Expand Down

0 comments on commit 8a064c6

Please sign in to comment.