Skip to content

Commit

Permalink
feat: add dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Nov 18, 2024
1 parent fc9d692 commit 80e41c6
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 141 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"next": "15.0.3",
"next-themes": "^0.4.3",
"react": "19.0.0-rc-66855b96-20241106",
"react-dom": "19.0.0-rc-66855b96-20241106",
"tailwind-merge": "^2.5.4",
Expand Down
278 changes: 142 additions & 136 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,140 +2,146 @@
@tailwind components;
@tailwind utilities;

@layer base {
html {
scroll-behavior: smooth;
}

:root {
/* Raw colors */
--indigo-50: #eef2ff;
--indigo-100: #e0e7ff;
--indigo-200: #c7d2fe;
--indigo-300: #a5b4fc;
--indigo-400: #818cf8;
--indigo-500: #6366f1;
--indigo-600: #4f46e5;
--indigo-700: #4338ca;
--indigo-800: #3730a3;
--indigo-900: #312e81;

--green-50: #f0fdf4;
--green-100: #dcfce7;
--green-200: #bbf7d0;
--green-300: #86efac;
--green-400: #4ade80;
--green-500: #22c55e;
--green-600: #16a34a;
--green-700: #15803d;
--green-800: #166534;
--green-900: #14532d;

--blue-50: #eff6ff;
--blue-100: #dbeafe;
--blue-200: #bfdbfe;
--blue-300: #93c5fd;
--blue-400: #60a5fa;
--blue-500: #3b82f6;
--blue-600: #2563eb;
--blue-700: #1d4ed8;
--blue-800: #1e40af;
--blue-900: #1e3a8a;

--red-50: #fef2f2;
--red-100: #fee2e2;
--red-200: #fecaca;
--red-300: #fca5a5;
--red-400: #f87171;
--red-500: #ef4444;
--red-600: #dc2626;
--red-700: #b91c1c;
--red-800: #991b1b;
--red-900: #7f1d1d;

--gray-50: #fafafa;
--gray-100: #f4f4f5;
--gray-200: #e4e4e7;
--gray-300: #d4d4d8;
--gray-350: #b0b0b9;
--gray-400: #a1a1aa;
--gray-450: #8a8a96;
--gray-500: #71717a;
--gray-600: #52525b;
--gray-700: #3f3f46;
--gray-800: #27272a;
--gray-900: #18181b;

/* Semantic colors */
--background: var(--gray-100);
--foreground: var(--gray-800);
--card: #fff;
--image: var(--gray-700);
--skeleton: var(--gray-300);

--button-primary: var(--indigo-500);
--button-primary-hover: var(--indigo-600);
--button-primary-active: var(--indigo-700);
--button-primary-foreground: #fff;
--button-primary-subtle: var(--indigo-300);
--button-primary-subtle-foreground: var(--indigo-500);

--button-secondary: rgba(0, 0, 0, 0.06);
--button-secondary-hover: rgba(0, 0, 0, 0.08);
--button-secondary-active: rgba(0, 0, 0, 0.16);
--button-secondary-foreground: var(--foreground);
--button-secondary-subtle: #a1a1aa;
--button-secondary-subtle-foreground: var(--foreground);

--button-destructive: var(--red-500);
--button-destructive-hover: var(--red-600);
--button-destructive-active: var(--red-700);
--button-destructive-foreground: #fff;
--button-destructive-subtle: var(--red-300);
--button-destructive-subtle-foreground: var(--red-500);

--button-success: var(--green-500);
--button-success-hover: var(--green-600);
--button-success-active: var(--green-700);
--button-success-foreground: #fff;
--button-success-subtle: var(--green-300);
--button-success-subtle-foreground: var(--green-500);
}

:root[data-theme="dark"],
[data-theme="dark"] {
--background: var(--gray-800);
--foreground: var(--gray-100);
--card: var(--gray-700);
--image: var(--gray-600);
--skeleton: var(--gray-600);

--button-primary: var(--indigo-500);
--button-primary-hover: var(--indigo-400);
--button-primary-active: var(--indigo-300);
--button-primary-foreground: #fff;
--button-primary-subtle: var(--indigo-300);
--button-primary-subtle-foreground: var(--indigo-500);

--button-secondary: rgba(255, 255, 255, 0.06);
--button-secondary-hover: rgba(255, 255, 255, 0.08);
--button-secondary-active: rgba(255, 255, 255, 0.16);
--button-secondary-foreground: var(--foreground);
--button-secondary-subtle: #a1a1aa;
--button-secondary-subtle-foreground: var(--foreground);

--button-destructive: var(--red-500);
--button-destructive-hover: var(--red-400);
--button-destructive-active: var(--red-300);
--button-destructive-foreground: #fff;
--button-destructive-subtle: var(--red-300);
--button-destructive-subtle-foreground: var(--red-500);

--button-success: var(--green-500);
--button-success-hover: var(--green-400);
--button-success-active: var(--green-300);
--button-success-foreground: #fff;
--button-success-subtle: var(--green-300);
--button-success-subtle-foreground: var(--green-500);
}
html {
scroll-behavior: smooth;
}

:root {
/* Raw colors */
--indigo-50: #eef2ff;
--indigo-100: #e0e7ff;
--indigo-200: #c7d2fe;
--indigo-300: #a5b4fc;
--indigo-400: #818cf8;
--indigo-500: #6366f1;
--indigo-600: #4f46e5;
--indigo-700: #4338ca;
--indigo-800: #3730a3;
--indigo-900: #312e81;

--green-50: #f0fdf4;
--green-100: #dcfce7;
--green-200: #bbf7d0;
--green-300: #86efac;
--green-400: #4ade80;
--green-500: #22c55e;
--green-600: #16a34a;
--green-700: #15803d;
--green-800: #166534;
--green-900: #14532d;

--blue-50: #eff6ff;
--blue-100: #dbeafe;
--blue-200: #bfdbfe;
--blue-300: #93c5fd;
--blue-400: #60a5fa;
--blue-500: #3b82f6;
--blue-600: #2563eb;
--blue-700: #1d4ed8;
--blue-800: #1e40af;
--blue-900: #1e3a8a;

--red-50: #fef2f2;
--red-100: #fee2e2;
--red-200: #fecaca;
--red-300: #fca5a5;
--red-400: #f87171;
--red-500: #ef4444;
--red-600: #dc2626;
--red-700: #b91c1c;
--red-800: #991b1b;
--red-900: #7f1d1d;

--gray-50: #fafafa;
--gray-100: #f4f4f5;
--gray-200: #e4e4e7;
--gray-300: #d4d4d8;
--gray-350: #b0b0b9;
--gray-400: #a1a1aa;
--gray-450: #8a8a96;
--gray-500: #71717a;
--gray-600: #52525b;
--gray-700: #3f3f46;
--gray-800: #27272a;
--gray-900: #18181b;

/* Semantic colors */
--background: var(--gray-100);
--foreground: var(--gray-800);
--card: #fff;
--image: var(--gray-700);
--skeleton: var(--gray-300);

--button-primary: var(--indigo-500);
--button-primary-hover: var(--indigo-600);
--button-primary-active: var(--indigo-700);
--button-primary-foreground: #fff;
--button-primary-subtle: var(--indigo-300);
--button-primary-subtle-foreground: var(--indigo-500);

--button-secondary: rgba(0, 0, 0, 0.06);
--button-secondary-hover: rgba(0, 0, 0, 0.08);
--button-secondary-active: rgba(0, 0, 0, 0.16);
--button-secondary-foreground: var(--foreground);
--button-secondary-subtle: #a1a1aa;
--button-secondary-subtle-foreground: var(--foreground);

--button-destructive: var(--red-500);
--button-destructive-hover: var(--red-600);
--button-destructive-active: var(--red-700);
--button-destructive-foreground: #fff;
--button-destructive-subtle: var(--red-300);
--button-destructive-subtle-foreground: var(--red-500);

--button-success: var(--green-500);
--button-success-hover: var(--green-600);
--button-success-active: var(--green-700);
--button-success-foreground: #fff;
--button-success-subtle: var(--green-300);
--button-success-subtle-foreground: var(--green-500);
}

.dark {
--background: var(--gray-800);
--foreground: var(--gray-100);
--card: var(--gray-700);
--image: var(--gray-600);
--skeleton: var(--gray-600);

--button-primary: var(--indigo-500);
--button-primary-hover: var(--indigo-400);
--button-primary-active: var(--indigo-300);
--button-primary-foreground: #fff;
--button-primary-subtle: var(--indigo-300);
--button-primary-subtle-foreground: var(--indigo-500);

--button-secondary: rgba(255, 255, 255, 0.06);
--button-secondary-hover: rgba(255, 255, 255, 0.08);
--button-secondary-active: rgba(255, 255, 255, 0.16);
--button-secondary-foreground: var(--foreground);
--button-secondary-subtle: #a1a1aa;
--button-secondary-subtle-foreground: var(--foreground);

--button-destructive: var(--red-500);
--button-destructive-hover: var(--red-400);
--button-destructive-active: var(--red-300);
--button-destructive-foreground: #fff;
--button-destructive-subtle: var(--red-300);
--button-destructive-subtle-foreground: var(--red-500);

--button-success: var(--green-500);
--button-success-hover: var(--green-400);
--button-success-active: var(--green-300);
--button-success-foreground: #fff;
--button-success-subtle: var(--green-300);
--button-success-subtle-foreground: var(--green-500);
}

.dark video,
.dark img {
@apply brightness-90 contrast-125;
}

body {
@apply bg-background text-foreground font-sans min-h-screen antialiased selection:bg-foreground selection:text-background;
}
5 changes: 3 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from "next";
import "./globals.css";
import { CsrProviders } from "components/csr-providers";
import { dystopian, inter } from "fonts";
import { cn } from "lib/css-utils";

Expand All @@ -19,15 +20,15 @@ const RootLayout = ({
children: React.ReactNode;
}>) => {
return (
<html lang="en" data-theme="dark">
<html lang="en" suppressHydrationWarning>
<body
className={cn(
dystopian.variable,
inter.variable,
"bg-background text-foreground antialiased",
)}
>
{children}
<CsrProviders>{children}</CsrProviders>
</body>
</html>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/playground/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Playground = () => {
<h1 className="font-display">Hello, Guild!</h1>
<h2 className="font-bold font-display">Hello, Guild!</h2>
<p>Test, one, two, three...</p>
<p className="font-sans">
<p className="border font-sans">
Test, <strong>one</strong>, <em>two</em>, three...
</p>
</main>
Expand Down
19 changes: 19 additions & 0 deletions src/components/csr-providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import { ThemeProvider } from "next-themes";
import type { FunctionComponent, PropsWithChildren } from "react";

export const CsrProviders: FunctionComponent<PropsWithChildren> = ({
children,
}) => {
return (
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{children}
</ThemeProvider>
);
};
4 changes: 2 additions & 2 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Config } from "tailwindcss"
import animatePlugin from "tailwindcss-animate";

const config = {
darkMode: ["selector", "[data-theme='dark']"],
darkMode: ["class"],
content: [
"./pages/**/*.{ts,tsx}",
"./components/**/*.{ts,tsx}",
Expand All @@ -16,7 +16,7 @@ const config = {
display: ["var(--font-dystopian,sans-serif)"],
},
extend: {

colors: {
background: "var(--background)",
foreground: "var(--foreground)",
Expand Down

0 comments on commit 80e41c6

Please sign in to comment.