Skip to content

Commit

Permalink
Fix theme meta toggle, fix navbar padding (#132)
Browse files Browse the repository at this point in the history
* Fix theme meta toggle, fix navbar padding

* Add comment
  • Loading branch information
alexzhang1618 authored Jan 20, 2024
1 parent de92a4a commit 2484444
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/common/ThemeToggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useEffect, useId, useState } from 'react';
import styles from './style.module.scss';

const ThemeToggle = () => {
const { theme = 'system', setTheme } = useTheme();
const { theme = 'system', resolvedTheme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);

const lightId = `light${useId()}`;
Expand All @@ -24,6 +24,17 @@ const ThemeToggle = () => {
const switchPos = themeToSwitch[theme];
const currAltText = `Icon representing ${theme} theme is on.`;

useEffect(() => {
// Adjusting the <meta name="theme-color"> tag.
// This affects the color of the safe zone on iPhone 15.
const metaThemeColor = document.querySelector('meta[name="theme-color"]');
if (metaThemeColor && resolvedTheme === 'dark') {
metaThemeColor.setAttribute('content', '#37393e');
} else if (metaThemeColor) {
metaThemeColor.setAttribute('content', '#fff');
}
}, [resolvedTheme]);

useEffect(() => {
setMounted(true);
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Navbar = ({ accessType }: NavbarProps) => {
</Link>
<ThemeToggle />
</div>
<hr className={styles.wainbow} />
<hr className={`${styles.wainbow} ${styles.loggedOut}`} />
</header>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/layout/Navbar/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
height: 0.25rem;
margin: 0 -1rem;
width: 100vw;

&.loggedOut {
margin: 0;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/layout/Navbar/style.module.scss.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Styles = {
icon: string;
iconLink: string;
iconLinks: string;
loggedOut: string;
mobileNav: string;
mobileNavItem: string;
navLeft: string;
Expand Down

1 comment on commit 2484444

@vercel
Copy link

@vercel vercel bot commented on 2484444 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.