-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
1,241 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
Oops, something went wrong.