From fd03b7b9cfe22fddf4e737a6835fd938279ab404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cyril=20=C5=A0ebek?= Date: Sun, 7 Apr 2024 17:23:34 +0200 Subject: [PATCH] almost finished navbar TODO: modify dropdown menus --- src/components/Navbar.astro | 12 +++----- src/components/ThemeSelector.jsx | 47 ++++++++++++++++++++++++++++++++ src/components/ThemeSelector.tsx | 0 src/layouts/MainLayout.astro | 11 ++++++-- src/layouts/SinglePage.astro | 2 +- src/lib/icons.js | 9 ++++-- src/pages/[lang]/index.astro | 2 +- src/style/index.css | 4 +-- 8 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 src/components/ThemeSelector.jsx delete mode 100644 src/components/ThemeSelector.tsx diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 1cc36d1..eed4180 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -1,11 +1,10 @@ --- import { getRelativeLocaleUrl } from "astro:i18n"; -/* import ThemeSelector from "./ThemeSelector" */ +import { ThemeSelector } from "./ThemeSelector" import NavbarSkeleton from "./NavbarSkeleton.astro"; import { LangSwitcher } from "./LangSwitcher"; import { NavButton } from "./NavButton"; - function selected(path) { return ( (Astro.url.pathname @@ -14,7 +13,6 @@ function selected(path) { ); } --- -
@@ -32,10 +30,8 @@ function selected(path) {
-
- +
- +
- -./NavButton \ No newline at end of file + \ No newline at end of file diff --git a/src/components/ThemeSelector.jsx b/src/components/ThemeSelector.jsx new file mode 100644 index 0000000..9a671d3 --- /dev/null +++ b/src/components/ThemeSelector.jsx @@ -0,0 +1,47 @@ +"use client" + +import * as React from "react" + +import { icons } from "../lib/icons" +import { Button } from "./ui/button" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuRadioGroup, + DropdownMenuRadioItem, + DropdownMenuTrigger, +} from "./ui/dropdown-menu" + + +// Please note that clang = lang, it's just for more confusion +export function ThemeSelector() { + function getTheme() { + console.log(localStorage.getItem("data-theme")); + const theme = localStorage.getItem("data-theme") || document.documentElement.getAttribute("data-theme"); + document.documentElement.setAttribute("data-theme", theme); + return theme; + } + + function newTheme(theme) { + setTheme(theme); + document.documentElement.setAttribute("data-theme", theme); + localStorage.setItem("data-theme", theme); + } + + const [theme, setTheme] = React.useState(getTheme()); + + return ( + + +