Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement app theme handling #8

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8123035
Update Calendar.tsx
lazaroysr96 Nov 24, 2024
94d42e7
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Nov 24, 2024
e957ba7
feat: Implement Component ButtonSwitchTheme
lazaroysr96 Nov 24, 2024
8a9b8aa
feat: Implement dark mode in input
lazaroysr96 Nov 25, 2024
195b570
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Nov 25, 2024
d79201d
feat: update useTheme
lazaroysr96 Dec 1, 2024
5931392
feat: update calendar
lazaroysr96 Dec 2, 2024
ffc429a
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Dec 2, 2024
7963265
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Dec 6, 2024
e7230ff
feat: Update Calendar
lazaroysr96 Dec 6, 2024
4f1c01d
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Dec 8, 2024
75ea181
fix: obtain token sepolia
lazaroysr96 Dec 8, 2024
af8baff
feat: Implement Resposive mode in Navbar
lazaroysr96 Dec 8, 2024
00fd6cc
feat: update useTheme
lazaroysr96 Dec 13, 2024
b58946b
feat: update nav buttons in calendar
lazaroysr96 Dec 15, 2024
758c184
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Dec 15, 2024
902acb8
feat: fix dark mode in calendar
lazaroysr96 Dec 15, 2024
9343654
feat: update buttonSwitchTheme
lazaroysr96 Dec 15, 2024
60eae2e
fix: Calendar selected rounded
lazaroysr96 Dec 22, 2024
ace22b2
Merge branch 'master' into lazaroysr96/resolving_bugs_and_optimizing_…
lazaroysr96 Dec 22, 2024
912702b
feat: Update ButtonSwitchTheme
lazaroysr96 Dec 22, 2024
2146611
feat: remove useThemeReturnType
lazaroysr96 Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/ButtonSwitchTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FC } from "react";
import Button from "./Button";
import useTheme from "@/hooks/useTheme";
import { Icon } from "@radix-ui/react-select";
import { IoIosMoon, IoIosSunny } from "react-icons/io";

const ButtonSwitchTheme: FC = () => {
const { toggleTheme, theme } = useTheme();

return (
<Button onClick={toggleTheme} variant="ghost" size="icon">
<Icon>{theme === "dark" ? <IoIosSunny /> : <IoIosMoon />}</Icon>
</Button>
);
};

export default ButtonSwitchTheme;
49 changes: 26 additions & 23 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,42 @@ const Calendar: FC<CalendarProps> = ({ className, selected, onSelect }) => {
showOutsideDays={true}
className={cn("w-max rounded-md border p-3 shadow", className)}
classNames={{
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
months: "flex flex-col relative sm:flex-row space-y-4 sm:space-y-0",
month: "space-y-4",
caption: "flex justify-center pt-1 relative items-center",
month_caption: "flex justify-center pt-1 relative items-center",
caption_label: "text-sm font-medium",
nav: "space-x-1 flex items-center",
nav_button: cn(
button_previous: cn(
buttonVariants({ variant: "outline" }),
"size-7 bg-transparent p-0 opacity-50 hover:opacity-100"
"size-7 bg-transparent dark:bg-slate-600 p-0 opacity-50 hover:opacity-100",
"absolute left-1 z-10"
),
nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1",
table: "w-full border-collapse space-y-1",
head_row: "flex",
head_cell:
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
row: "flex w-full mt-2",
cell: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50"
button_next: cn(
buttonVariants({ variant: "outline" }),
"size-7 bg-transparent dark:bg-slate-600 p-0 opacity-50 hover:opacity-100",
"absolute right-1 z-10"
),
month_grid: "w-full border-collapse space-y-1",
weekdays: "flex",
weekday:
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
week: "flex w-full mt-2",
day: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50",
),
day_button: cn(
buttonVariants({ variant: "ghost" }),
"size-8 p-0 font-normal aria-selected:opacity-100"
"size-8 p-0 font-normal aria-selected:opacity-100",
),
day_range_start: "day-range-start",
day_selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
day_today: "bg-accent text-accent-foreground",
day_outside:
range_start: "day-range-start",
selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground rounded-lg",
today: "bg-accent text-accent-foreground",
outside:
"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",
day_disabled: "text-muted-foreground opacity-50",
day_range_middle:
disabled: "text-muted-foreground opacity-50",
range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
hidden: "invisible",
}}
/>
);
Expand Down
24 changes: 24 additions & 0 deletions src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useCallback, useEffect, useState } from "react";

export const THEME_KEY = "theme_mode";

const DARK_MODE = "dark";
const LIGHT_MODE = "light";
const savedTheme = localStorage.getItem(THEME_KEY);

const useTheme = () => {
const [theme, setTheme] = useState(savedTheme ?? LIGHT_MODE);

useEffect(() => {
document.documentElement.className = theme;
localStorage.setItem(THEME_KEY, theme);
}, [theme]);

const toggleTheme = useCallback(() => {
setTheme(theme === DARK_MODE ? LIGHT_MODE : DARK_MODE);
}, [theme]);

return { toggleTheme, theme };
};

export default useTheme;