Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark mode #75

Merged
merged 11 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"next": "14.0.3",
"next-themes": "^0.2.1",
"react": "^18",
"react-dom": "^18"
},
Expand Down
8 changes: 5 additions & 3 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import FormAuth from '@/components/Pages/Auth/FormAuth'
import ImageCard from '@/components/Pages/Auth/ImageCard'
import ButtonThemeToggle from '@/components/UI/ButtonThemeToggle'
import IconGolub from '@/components/UI/Icons/IconGolub'
import Layout from '@/components/UI/Layout'

export default function Auth() {
return (
<section className="h-screen w-screen bg-gradient-blue-white">
<Layout className="flex items-center justify-center">
<div className="card p-7 sm:p-10 flex gap-7 md:gap-[3.75rem] bg-white">
<ImageCard className="hidden sm:block -my-[4.375rem] flex-shrink-0">
<Layout className="flex items-center justify-center dark:bg-none dark:bg-base-gray-8">
<div className="card p-7 sm:p-10 flex gap-7 md:gap-[3.75rem] bg-base-white dark:bg-base-black">
<ImageCard className="-my-[4.375rem] flex-shrink-0 hidden sm:flex items-center justify-center">
<IconGolub />
</ImageCard>
<div>
<h1 className="title-lg">Authentication</h1>
<FormAuth />
<ButtonThemeToggle />
</div>
</div>
</Layout>
Expand Down
2 changes: 1 addition & 1 deletion src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@tailwind utilities;

body {
@apply font-text text-[1.0625rem] leading-tight tracking-[0.0063em] text-base-black;
@apply font-text text-[1.0625rem] leading-tight tracking-[0.0063em] text-base-black dark:text-base-white;
}

.title-lg {
Expand Down
8 changes: 6 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Metadata } from 'next'

import Providers from '@/store/Providers'

import { text, title } from './fonts'
import './globals.css'

Expand All @@ -14,8 +16,10 @@ export default function RootLayout({
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={`${title.variable} ${text.variable}`}>{children}</body>
<html lang="en" suppressHydrationWarning>
<body className={`${title.variable} ${text.variable}`}>
<Providers>{children}</Providers>
</body>
</html>
)
}
10 changes: 9 additions & 1 deletion src/components/UI/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type ButtonProps = {
children: ReactNode
className?: string
disabled?: boolean
onClick?: () => void
type?: 'button' | 'reset' | 'submit'
}

Expand All @@ -13,7 +14,13 @@ const THEMES = {
light: 'disabled:bg-none disabled:text-base-gray-4 disabled:bg-base-gray-3',
}

const Button: FC<ButtonProps> = ({ children, className, disabled, type }) => {
const Button: FC<ButtonProps> = ({
children,
className,
disabled,
onClick,
type,
}) => {
return (
<button
className={classnames(
Expand All @@ -22,6 +29,7 @@ const Button: FC<ButtonProps> = ({ children, className, disabled, type }) => {
className
)}
disabled={disabled}
onClick={onClick}
type={type || 'button'}
>
{children}
Expand Down
24 changes: 24 additions & 0 deletions src/components/UI/ButtonThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client'

import Theme, { THEME } from '@/types/enums/Theme'
import { useTheme } from 'next-themes'

import Button from './Button'

const ButtonThemeToggle = () => {
const { resolvedTheme, setTheme } = useTheme()

const toggleTheme = () => {
setTheme(
(resolvedTheme as Theme) === THEME.light ? THEME.dark : THEME.light
)
}

return (
<Button className="mt-4 w-full" onClick={toggleTheme}>
Toggle Theme
</Button>
)
}

export default ButtonThemeToggle
4 changes: 2 additions & 2 deletions src/components/UI/Form/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const FormInput: FC<FormInputProps> = ({
<div className="relative">
<input
className={classnames(
'peer pt-5 pb-2.5 px-4 w-full rounded-2xl border border-gray-3 placeholder:opacity-0',
'relative z-[5] peer pt-5 pb-2.5 px-4 w-full outline-none rounded-2xl border border-base-gray-3 focus:border-base-gray-5 dark:border-base-gray-7 bg-transparent placeholder:opacity-0 transition-colors',
className
)}
placeholder={placeholder}
{...props}
/>
<span className="input-placeholder absolute top-1/2 peer-focus:top-[0.375rem] left-4 -translate-y-1/2 peer-focus:translate-y-0 peer-focus:text-[0.6875rem] peer-focus:leading-[0.8125rem] text-base-gray-5 transition-all">
<span className="input-placeholder absolute z-0 top-1/2 peer-focus:top-[0.375rem] left-4 -translate-y-1/2 peer-focus:translate-y-0 peer-focus:text-[0.6875rem] peer-focus:leading-[0.8125rem] text-base-gray-5 transition-all">
{placeholder}
</span>
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/store/Providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'

import { ThemeProvider } from 'next-themes'
import { FC, ReactNode } from 'react'

type ProvidersProps = {
children: ReactNode
}

const Providers: FC<ProvidersProps> = ({ children }) => {
return <ThemeProvider attribute="class">{children}</ThemeProvider>
}

export default Providers
8 changes: 8 additions & 0 deletions src/types/enums/Theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const THEME = {
dark: 'dark',
light: 'light',
} as const

type Theme = keyof typeof THEME

export default Theme
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config: Config = {
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: 'class',
plugins: [],
theme: {
extend: {
Expand Down