Skip to content

Commit

Permalink
Setup shadcn and simplify theming
Browse files Browse the repository at this point in the history
  • Loading branch information
Ucodia committed Aug 2, 2024
1 parent 6071161 commit 49bdc49
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 174 deletions.
17 changes: 17 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": false,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
9 changes: 9 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

198 changes: 78 additions & 120 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
"preview": "vite preview"
},
"dependencies": {
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"d3": "^7.8.2",
"dat.gui": "^0.7.9",
"date-fns": "^2.29.3",
"flowtime": "^1.2.4",
"lucide-react": "^0.419.0",
"p5": "^1.5.0",
"p5.js-svg": "^1.3.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-sizeme": "^3.0.2",
"styled-components": "^5.3.6",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"three": "^0.167.1",
"u5js": "^0.6.1"
},
"devDependencies": {
Expand Down
70 changes: 37 additions & 33 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { Routes, Route } from "react-router-dom";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { ThemeProvider } from "@/contexts/theme";
import Page from "./Page";
import Home from "./Home";
import Alert from "./Alert";
import pages from "../pages";
import ExternalRedirect from "./ExternalRedirect";

const FullScreen = ({ children }) => (
<div className="w-screen h-screen flex items-center justify-center">
Expand All @@ -14,42 +14,46 @@ const FullScreen = ({ children }) => (

const App = () => {
return (
<Routes>
<Route
path="/"
exact
element={
<Page title="You're Home">
<Home />
</Page>
}
/>
{Object.keys(pages).map((page) => {
return (
<ThemeProvider>
<Router>
<Routes>
<Route
key={page}
path={`/${page}`}
path="/"
exact
element={
<Page title={page}>
<FullScreen>{pages[page]}</FullScreen>
<Page title="You're Home">
<Home />
</Page>
}
/>
);
})}
<Route
path="*"
element={
<Page title="404">
<FullScreen>
<Alert title="404">
<p>Ceci n'est pas une page.</p>
</Alert>
</FullScreen>
</Page>
}
/>
</Routes>
{Object.keys(pages).map((page) => {
return (
<Route
key={page}
path={`/${page}`}
element={
<Page title={page}>
<FullScreen>{pages[page]}</FullScreen>
</Page>
}
/>
);
})}
<Route
path="*"
element={
<Page title="404">
<FullScreen>
<Alert title="404">
<p>Ceci n'est pas une page.</p>
</Alert>
</FullScreen>
</Page>
}
/>
</Routes>
</Router>
</ThemeProvider>
);
};

Expand Down
11 changes: 0 additions & 11 deletions src/components/Root.jsx

This file was deleted.

55 changes: 55 additions & 0 deletions src/contexts/theme.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { createContext, useState, useEffect, useContext } from "react";

const ThemeContext = createContext();

export const ThemeProvider = ({ children }) => {
const [theme, setTheme] = useState(() => {
if (typeof window !== "undefined") {
const savedTheme = localStorage.getItem("color-theme");
if (savedTheme) {
return savedTheme;
}
return "system";
}
return "system"; // Default theme
});

useEffect(() => {
const root = window.document.documentElement;
root.classList.remove("light", "dark");

if (theme === "system") {
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";
root.classList.add(systemTheme);
} else {
root.classList.add(theme);
}

localStorage.setItem("color-theme", theme);
}, [theme]);

useEffect(() => {
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
const handleChange = () => {
if (theme === "system") {
const root = window.document.documentElement;
root.classList.remove("light", "dark");
root.classList.add(mediaQuery.matches ? "dark" : "light");
}
};

mediaQuery.addEventListener("change", handleChange);
return () => mediaQuery.removeEventListener("change", handleChange);
}, [theme]);

return (
<ThemeContext.Provider value={{ theme, setTheme }}>
{children}
</ThemeContext.Provider>
);
};

export const useTheme = () => useContext(ThemeContext);
62 changes: 61 additions & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,67 @@
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
--radius: 0.5rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
}

.dark {
--background: 0, 0%, 7%;
--foreground: 0 0% 93%;
--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;
--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;
--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply m-0 p-0 font-sans text-black bg-white dark:text-[#ededed] dark:bg-[#121212];
@apply bg-background text-foreground;
}
}
8 changes: 6 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from "react";
import ReactDOM from "react-dom/client";
import Root from "./components/Root";
import App from "@/components/App";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")).render(<Root />);
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
6 changes: 6 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs) {
return twMerge(clsx(inputs))
}
76 changes: 69 additions & 7 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,77 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./index.html", "./src/**/*.{js,jsx}"],
darkMode: ["class"],
content: [
'./pages/**/*.{js,jsx}',
'./components/**/*.{js,jsx}',
'./app/**/*.{js,jsx}',
'./src/**/*.{js,jsx}',
],
prefix: "",
theme: {
container: {
center: true,
padding: "2rem",
screens: {
"2xl": "1400px",
},
},
extend: {
width: {
"1/10": "10%",
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive))",
foreground: "hsl(var(--destructive-foreground))",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
popover: {
DEFAULT: "hsl(var(--popover))",
foreground: "hsl(var(--popover-foreground))",
},
card: {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
},
borderRadius: {
lg: "var(--radius)",
md: "calc(var(--radius) - 2px)",
sm: "calc(var(--radius) - 4px)",
},
keyframes: {
"accordion-down": {
from: { height: "0" },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
},
height: {
"1/10": "10%",
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
plugins: [require("@tailwindcss/typography")],
};
plugins: [require("tailwindcss-animate")],
}
Loading

0 comments on commit 49bdc49

Please sign in to comment.