Skip to content

Commit 4c4a225

Browse files
author
Roshan Jossy
committed
add theme toggle button and dark mode backgrounds
1 parent 14d4ed7 commit 4c4a225

File tree

9 files changed

+82
-165
lines changed

9 files changed

+82
-165
lines changed

src/components/Card.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import { ReactNode } from "react";
1+
import { ReactNode } from 'react'
22

3-
export default function Card ({children, classes}: {children: ReactNode, classes?: string}) {
4-
return(
5-
<div className={`py-4 px-8 bg-white rounded-lg ${classes}`}>
6-
{children}
7-
</div>
8-
)
9-
}
3+
export default function Card({
4+
children,
5+
classes,
6+
}: {
7+
children: ReactNode
8+
classes?: string
9+
}) {
10+
return (
11+
<div
12+
className={`py-4 px-8 bg-white dark:bg-slate-800 rounded-lg ${classes}`}
13+
>
14+
{children}
15+
</div>
16+
)
17+
}

src/components/Layout.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import React, { ReactNode } from "react";
2-
import Navbar from "./navbar/Navbar";
1+
import React, { ReactNode } from 'react'
2+
import Navbar from './navbar/Navbar'
33

44
type LayoutProps = {
5-
sidebarContentLeft?: ReactNode
6-
children: ReactNode
5+
sidebarContentLeft?: ReactNode
6+
children: ReactNode
77
sidebarContentRight: ReactNode
88
}
99

10-
export default function Layout ({sidebarContentLeft, children, sidebarContentRight}: LayoutProps) {
11-
return (
12-
<div className="mx-auto bg-gray-100 min-h-screen">
13-
<Navbar />
14-
<div className="grid grid-cols-9 gap-10 mt-10 px-20 pt-10">
15-
{sidebarContentLeft && (
16-
<aside className="col-span-2">
17-
{sidebarContentLeft}
18-
</aside>)}
19-
<main className={ sidebarContentLeft ? "col-span-5": "col-span-7"}>
20-
{children}
21-
</main>
22-
<aside className="col-span-2">
23-
{sidebarContentRight}
24-
</aside>
25-
</div>
26-
<div>
27-
</div>
28-
</div>
29-
)
30-
}
10+
export default function Layout({
11+
sidebarContentLeft,
12+
children,
13+
sidebarContentRight,
14+
}: LayoutProps) {
15+
return (
16+
<div className="mx-auto bg-gray-100 dark:bg-slate-700 min-h-screen">
17+
<Navbar />
18+
<div className="grid grid-cols-9 gap-10 mt-10 px-20 pt-10">
19+
{sidebarContentLeft && (
20+
<aside className="col-span-2">{sidebarContentLeft}</aside>
21+
)}
22+
<main className={sidebarContentLeft ? 'col-span-5' : 'col-span-7'}>
23+
{children}
24+
</main>
25+
<aside className="col-span-2">{sidebarContentRight}</aside>
26+
</div>
27+
<div></div>
28+
</div>
29+
)
30+
}

src/components/UserDetails/Bio.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const Bio = ({ user }: BioProps) => {
3131
)
3232
const onChange = (evt: any) => setBio(evt.target.textContent)
3333
const onSubmit = () => {
34-
console.log(bio)
3534
commitMutation({
3635
variables: {
3736
input: { id: data.id, bio: bio },

src/components/issue/Issue.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Issue = ({ issue }: IssueProps) => {
2020
issue
2121
)
2222
return (
23-
<div className="flex flex-col p-6 rounded-lg shadow-lg hover:shadow-md bg-white">
23+
<div className="flex flex-col p-6 rounded-lg shadow-lg hover:shadow-md bg-white dark:bg-slate-800">
2424
<a href={data.url} target="_blank" rel="noopener noreferrer">
2525
<div className="flex flex-row">
2626
<img

src/components/navbar/Navbar.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
import { useRouter } from 'next/router'
22
import React from 'react'
33
import Button from '../Button'
4+
import ThemeButton from './ThemeButton'
45

56
export default function Navbar() {
67
const router = useRouter()
78
const { pathname } = router
89
return (
9-
<nav className="fixed top-0 left-0 right-0 z-10 w-full h-16 bg-white p-3 shadow-sm">
10+
<nav className="fixed top-0 left-0 right-0 z-10 w-full h-16 bg-white dark:bg-slate-800 p-3 shadow-sm">
1011
<div className="container m-auto flex justify-between">
1112
<a href="/">
1213
<div className="logo w-10 h-10"></div>
1314
</a>
14-
{pathname !== '/story' && (
15-
<Button>
16-
<a href="/story">
17-
<a>Create Post </a>
18-
</a>
19-
</Button>
20-
)}
15+
<div className="space-x-4">
16+
<ThemeButton />
17+
{pathname !== '/story' && (
18+
<Button>
19+
<a href="/story">
20+
<a>Create Post </a>
21+
</a>
22+
</Button>
23+
)}
24+
</div>
2125
</div>
2226
<style jsx>{`
2327
.logo {
2428
background: url('https://avatars1.githubusercontent.com/u/65761570?s=460&u=640f39b808c75c6b86460aa907dd030bcca2f3c7&v=4');
2529
background-repeat: no-repeat;
2630
background-size: contain;
31+
@apply: border;
2732
}
2833
`}</style>
2934
</nav>

src/components/navbar/ThemeButton.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useEffect, useState } from 'react'
2+
import Button from '../Button'
3+
4+
export default function ThemeButton() {
5+
const [darkMode, setDarkMode] = useState<boolean | undefined>(undefined)
6+
useEffect(() => {
7+
setDarkMode(document.documentElement.classList.contains('dark'))
8+
}, [])
9+
useEffect(() => {
10+
if (darkMode) {
11+
window.document.documentElement.classList.add('dark')
12+
localStorage.setItem('vidyaDarkMode', 'true')
13+
} else {
14+
window.document.documentElement.classList.remove('dark')
15+
localStorage.setItem('vidyaDarkMode', 'false')
16+
}
17+
}, [darkMode])
18+
const onClick = () => {
19+
setDarkMode(!darkMode)
20+
}
21+
22+
return <Button onClick={onClick}>toggle dark mode</Button>
23+
}

src/lib/relay.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const makeFetchGraphql = (ctx: NextPageContext) => {
4848
)
4949

5050
const text = await results.text()
51-
console.log('response', text)
5251
const data = JSON.parse(text, withHydrateDatetime) as GraphQLResponse
5352

5453
return data

src/styles/Home.module.css

Lines changed: 0 additions & 116 deletions
This file was deleted.

tailwind.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module.exports = {
22
content: [
3-
"./src/pages/**/*.{js,ts,jsx,tsx}",
4-
"./src/components/**/*.{js,ts,jsx,tsx}",
3+
'./src/pages/**/*.{js,ts,jsx,tsx}',
4+
'./src/components/**/*.{js,ts,jsx,tsx}',
55
],
66
theme: {
77
extend: {},
88
},
9-
plugins: [
10-
require('@tailwindcss/typography'),
11-
],
9+
darkMode: 'class',
10+
plugins: [require('@tailwindcss/typography')],
1211
}

0 commit comments

Comments
 (0)