Skip to content

Commit

Permalink
Update site-header.tsx
Browse files Browse the repository at this point in the history
dark mode feature added
  • Loading branch information
PAVANTEJ-05 authored Dec 29, 2024
1 parent 5fcfe1f commit 320b39d
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions site/components/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { colors, mediaQueries, styleConstants } from '../util'
import { css } from '@emotion/react'
import { useRouter } from 'next/router'
import { Container } from './container'
import {useState, useEffect} from'react'

Check failure on line 7 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Replace `useState,·useEffect}·from` with `·useState,·useEffect·}·from·`

Check failure on line 7 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Replace `useState,·useEffect}·from` with `·useState,·useEffect·}·from·`
import { Moon, Sun } from 'lucide-react'

Check failure on line 8 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find module 'lucide-react' or its corresponding type declarations.

Check failure on line 8 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find module 'lucide-react' or its corresponding type declarations.

export const animatedUnderline = css({
'&::after': {
Expand Down Expand Up @@ -70,9 +72,8 @@ function UkraineBanner() {
css={{
fontWeight: 'bold',
color: '#fff',
fontSize: 20,

[mediaQueries.mdUp]: {
fontSize: 20,

Check failure on line 75 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Insert `·`

Check failure on line 75 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Insert `·`
[mediaQueries.mdUp]: {

Check failure on line 76 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Insert `·`

Check failure on line 76 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Insert `·`
fontSize: 28
}
}}
Expand All @@ -83,13 +84,26 @@ function UkraineBanner() {
</a>
)
}

export function SiteHeader() {
const router = useRouter()

const path = router.asPath
const onCommunityPage = path === '/docs/community'
const [darkMode, setDarkMode] = useState(false);

Check failure on line 92 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`

Check failure on line 92 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`
useEffect(() => {

Check failure on line 93 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `··`

Check failure on line 93 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `··`
const isDark = localStorage.getItem('darkMode') === 'true';

Check failure on line 94 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`

Check failure on line 94 in site/components/site-header.tsx

View workflow job for this annotation

GitHub Actions / Linting

Delete `;`
setDarkMode(isDark);
if (isDark) {
document.documentElement.classList.add('dark');
}
}, []);

const toggleDarkMode = () => {
const newDarkMode = !darkMode;
setDarkMode(newDarkMode);
localStorage.setItem('darkMode', String(newDarkMode));
document.documentElement.classList.toggle('dark');
};
return (
<>
<UkraineBanner />
Expand All @@ -100,7 +114,6 @@ export function SiteHeader() {
boxShadow: '0 .125rem .25rem rgba(0, 0, 0, .075)',
paddingTop: '0.25rem',
marginBottom: '1.5rem',

[mediaQueries.mdUp]: {
marginBottom: '2.5rem'
}
Expand Down Expand Up @@ -153,7 +166,6 @@ export function SiteHeader() {
css={{
marginLeft: 'auto',
overflowX: 'auto',

// For proper scrollbar placement on mobile. Note, mobile scrollbars
// are pretty different between Safari and Chrome
padding: '0.25rem 0'
Expand All @@ -170,6 +182,20 @@ export function SiteHeader() {
listStyle: 'none'
}}
>

<li>
<button
onClick={toggleDarkMode}
className="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors"
aria-label="Toggle dark mode"
>
{darkMode ? (
<Sun className="h-5 w-5 text-gray-700 dark:text-gray-200" />
) : (
<Moon className="h-5 w-5 text-gray-700 dark:text-gray-200" />
)}
</button>
</li>
<li>
<HeaderLink
href="/docs"
Expand Down

0 comments on commit 320b39d

Please sign in to comment.