From 045c4f15c5feaba1e3c1dce98326a3ac210240d5 Mon Sep 17 00:00:00 2001 From: Mohammed Rabay'a Date: Fri, 5 Apr 2024 23:14:05 +0200 Subject: [PATCH] feat: Add theme change button --- .../organisms/Navigation/Nav.styled.tsx | 8 ++- components/organisms/Navigation/index.tsx | 50 ++++++++++++++++++- package.json | 2 +- templates/ThemeProvider/index.tsx | 2 + 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/components/organisms/Navigation/Nav.styled.tsx b/components/organisms/Navigation/Nav.styled.tsx index 01366de..ed1f6c1 100644 --- a/components/organisms/Navigation/Nav.styled.tsx +++ b/components/organisms/Navigation/Nav.styled.tsx @@ -25,11 +25,15 @@ const Nav = Object.assign( height: ${45 + 15}px; padding: 1em 1em; overflow: hidden; - transition: 0.25s ease; + transition: 0.25s ease height; background-color: var(--nav-background-color); + @media (min-width: ${(props) => props.theme.screens.small}) { + height: 67.5px; + padding: 12px 35px; + } @media (min-width: ${(props) => props.theme.screens.medium}) { height: 75px !important; - padding: 20px 35px; + padding: 15px 35px; } ${(props) => props.isOpen && diff --git a/components/organisms/Navigation/index.tsx b/components/organisms/Navigation/index.tsx index d9d3b8e..f5285a4 100644 --- a/components/organisms/Navigation/index.tsx +++ b/components/organisms/Navigation/index.tsx @@ -25,6 +25,8 @@ const Navigation = ({ hasReadPermission, previous, next }: any) => { const { locale } = useGlobalization(); const isProject = pathname.split("/")?.[1] === "work"; + const isDark = theme === "dark"; + const renderMenu = () => Pages[locale == "ar" ? "ar" : "en"]?.map(({ path, name }, index) => ( { )); const Socials = [ + + +
setTheme(isDark ? "light" : "dark")} + > + + + + + + + +
+
, {
-
+
{Socials}
{
{renderInnerMenu()}
-
+
{Socials}
diff --git a/package.json b/package.json index cb74cc6..709aa53 100644 --- a/package.json +++ b/package.json @@ -48,4 +48,4 @@ "tailwindcss": "^3.4.1", "typescript": "4.6.4" } -} \ No newline at end of file +} diff --git a/templates/ThemeProvider/index.tsx b/templates/ThemeProvider/index.tsx index 8769344..4ccffae 100644 --- a/templates/ThemeProvider/index.tsx +++ b/templates/ThemeProvider/index.tsx @@ -50,12 +50,14 @@ const ThemeProvider: React.FC<{ children: any }> = ({ children, ...rest }) => { const changeTheme = (theme: Theme, storePref = true) => { document.querySelector("html")?.setAttribute("data-theme", theme); + document.querySelector("html")?.setAttribute("class", theme); if (storePref && theme != mediaQueryPreference) { storeUserSetPreference(theme); } else { localStorage.removeItem("theme"); } document.querySelector("html")?.setAttribute("data-theme", theme); + document.querySelector("html")?.setAttribute("class", theme); setTheme(theme); }; const root = typeof window !== "undefined" ? document.documentElement : null;