Skip to content

Commit

Permalink
themes; puh
Browse files Browse the repository at this point in the history
version-patch
  • Loading branch information
trueberryless committed Jul 7, 2024
1 parent 2499ef4 commit ff1da2b
Show file tree
Hide file tree
Showing 14 changed files with 1,241 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react-dom": "^18",
"react-hook-form": "^7.52.1",
"recharts": "^2.12.7",
"swr": "^2.2.5",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
Expand Down
29 changes: 26 additions & 3 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/app/test_data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"username": "trueberryless",
"lastExported": "2024-07-07T11:59:53.251Z",
"lastExported": "2024-07-05T11:59:53.251Z",
"exportReminder": "monthly",
"projects": [
{
Expand Down
20 changes: 10 additions & 10 deletions src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ export default function Dashboard() {
return (
<div className="flex w-full flex-col">
<main className="flex min-h-[calc(100vh-_theme(spacing.16))] flex-1 flex-col gap-4 bg-muted/40 p-4 md:gap-8 md:p-10">
{shouldShowExportNotification(user) && (
<Alert>
<Terminal className="h-4 w-4" />
<AlertTitle>Notification!</AlertTitle>
<AlertDescription>
We recommend exporting your data regularly. Head to Settings → Data
Management to export your data now. Stay safe!
</AlertDescription>
</Alert>
)}
<div className="flex-1 space-y-4 p-8 pt-6">
{shouldShowExportNotification(user) && (
<Alert className="mb-12">
<Terminal className="h-4 w-4" />
<AlertTitle>Notification!</AlertTitle>
<AlertDescription>
We recommend exporting your data regularly. Head to Settings → Data
Management to export your data now. Stay safe!
</AlertDescription>
</Alert>
)}
<div className="flex items-center justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">Dashboard</h2>
<div className="flex items-center space-x-2">
Expand Down
11 changes: 9 additions & 2 deletions src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import {
} from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
import ModeToggle from "./mode-switch";
import ModeToggle from "./themes/mode-switch";
import { useUser } from "./UserContext";
import ThemeSwitcher from "./themes/theme-switcher";
import { getChartThemes } from "@/lib/chart-themes";

const chartThemes = getChartThemes();

export default function Navbar() {
const { user, setUser } = useUser();
Expand Down Expand Up @@ -185,9 +189,12 @@ export default function Navbar() {
<div className="ml-auto flex-1 sm:flex-initial">
<ModeToggle />
</div>
<div className="flex-1 sm:flex-initial">
<ThemeSwitcher />
</div>
<DropdownMenu>
<DropdownMenuTrigger className="flex items-center gap-4 bg-secondary rounded-full ps-4">
<h5 className="truncate max-w-32 sm:max-w-96 md:max-w-56 lg:max-w-96">
<h5 className="truncate max-w-32 sm:max-w-96 md:max-w-56 lg:max-w-96 text-secondary-foreground">
{user.username}
</h5>
<Button size="icon" className="rounded-full relative">
Expand Down
File renamed without changes.
116 changes: 116 additions & 0 deletions src/components/themes/theme-diamond.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { cn } from "@/lib/utils";

interface ThemeDiamond {
title: string;
color?:
| "current"
| "default"
| "palette"
| "sapphire"
| "ruby"
| "emerald"
| "daylight"
| "midnight";
hover?: boolean;
}

export function ThemeDiamond({ title, color }: ThemeDiamond) {
switch (color) {
case "current":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-45">
<div className="flex h-6 w-6 bg-[--color-1]" />
<div className="flex h-6 w-6 bg-[--color-2]" />
<div className="flex h-6 w-6 bg-[--color-3]" />
<div className="flex h-6 w-6 bg-[--color-4]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "default":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-default]" />
<div className="flex h-6 w-6 bg-[--color-2-default]" />
<div className="flex h-6 w-6 bg-[--color-3-default]" />
<div className="flex h-6 w-6 bg-[--color-4-default]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "palette":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-palette]" />
<div className="flex h-6 w-6 bg-[--color-2-palette]" />
<div className="flex h-6 w-6 bg-[--color-3-palette]" />
<div className="flex h-6 w-6 bg-[--color-4-palette]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "sapphire":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-sapphire]" />
<div className="flex h-6 w-6 bg-[--color-2-sapphire]" />
<div className="flex h-6 w-6 bg-[--color-3-sapphire]" />
<div className="flex h-6 w-6 bg-[--color-4-sapphire]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "ruby":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-ruby]" />
<div className="flex h-6 w-6 bg-[--color-2-ruby]" />
<div className="flex h-6 w-6 bg-[--color-3-ruby]" />
<div className="flex h-6 w-6 bg-[--color-4-ruby]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "emerald":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-emerald]" />
<div className="flex h-6 w-6 bg-[--color-2-emerald]" />
<div className="flex h-6 w-6 bg-[--color-3-emerald]" />
<div className="flex h-6 w-6 bg-[--color-4-emerald]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "daylight":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-daylight]" />
<div className="flex h-6 w-6 bg-[--color-2-daylight]" />
<div className="flex h-6 w-6 bg-[--color-3-daylight]" />
<div className="flex h-6 w-6 bg-[--color-4-daylight]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
case "midnight":
return (
<div className="h-6 w-6 overflow-hidden rounded-sm">
<div className="grid h-12 w-12 -translate-x-1/4 -translate-y-1/4 grid-cols-2 overflow-hidden rounded-md transition-all ease-in-out rotate-0 group-hover:rotate-45">
<div className="flex h-6 w-6 bg-[--color-1-midnight]" />
<div className="flex h-6 w-6 bg-[--color-2-midnight]" />
<div className="flex h-6 w-6 bg-[--color-3-midnight]" />
<div className="flex h-6 w-6 bg-[--color-4-midnight]" />
<div className="sr-only">{title}</div>
</div>
</div>
);
}
}
File renamed without changes.
110 changes: 110 additions & 0 deletions src/components/themes/theme-switcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"use client";

import * as React from "react";
import { Moon, Sun } from "lucide-react";

import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { ThemeDiamond } from "./theme-diamond";

// Utility function to set the theme
function setTheme(theme: any) {
const htmlElement = document.documentElement;
const themes = ["default", "palette", "sapphire", "ruby", "emerald", "daylight", "midnight"];

// Remove all theme classes
themes.forEach((t) => htmlElement.classList.remove(t));

// Add the new theme class if it's not 'gray'
if (theme !== "default") {
htmlElement.classList.add(theme);
}
}

// Utility function to get the current theme
function getCurrentTheme() {
const htmlElement = document.documentElement;
const themes = ["default", "palette", "sapphire", "ruby", "emerald", "daylight", "midnight"];

for (let theme of themes) {
if (htmlElement.classList.contains(theme)) {
return theme;
}
}
return "default";
}

export default function ThemeSwitcher() {
const [currentTheme, setCurrentTheme] = React.useState("default");

React.useEffect(() => {
// Load the current theme on mount
const theme = getCurrentTheme();
setCurrentTheme(theme);
}, []);

const handleThemeChange = (theme: any) => {
setTheme(theme);
setCurrentTheme(theme);
};

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<ThemeDiamond title={currentTheme} color={"current"} />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => handleThemeChange("default")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Default"} color={"default"} />
<div>Default</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("palette")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Palette"} color={"palette"} />
<div>Palette</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("sapphire")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Sapphire"} color={"sapphire"} />
<div>Sapphire</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("ruby")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Ruby"} color={"ruby"} />
<div>Ruby</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("emerald")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Emerald"} color={"emerald"} />
<div>Emerald</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("daylight")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Daylight"} color={"daylight"} />
<div>Daylight</div>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleThemeChange("midnight")}>
<div className="flex items-center space-x-2 group">
<ThemeDiamond title={"Midnight"} color={"midnight"} />
<div>Midnight</div>
</div>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}
Loading

0 comments on commit ff1da2b

Please sign in to comment.