Your favorite shift management application!
feat: Adds theme provider and switcher (#50)
panteLa3566dcc015e
diff --git a/app/layout.tsx b/app/layout.tsxindex 2fe3e3c..d058cde 100644--- a/app/layout.tsx+++ b/app/layout.tsx@@ -2,7 +2,8 @@ import type { Metadata, Viewport } from "next";import { Geist, Geist_Mono } from "next/font/google";import { NextIntlClientProvider } from "next-intl";import { getMessages, getLocale } from "next-intl/server";-import { Toaster } from "sonner";+import { ThemeProvider } from "@/components/theme-provider";+import { ThemedToaster } from "@/components/themed-toaster";import "./globals.css";const geistSans = Geist({@@ -37,25 +38,21 @@ export default async function RootLayout({const messages = await getMessages();return (- <html lang={locale} className="dark">+ <html lang={locale} suppressHydrationWarning><bodyclassName={`${geistSans.variable} ${geistMono.variable} antialiased bg-background text-foreground`}>- <NextIntlClientProvider messages={messages} locale={locale}>- {children}- <Toaster- position="bottom-left"- richColors- closeButton- theme="dark"- toastOptions={{- className: "text-sm",- style: {- padding: "12px 16px",- },- }}- />- </NextIntlClientProvider>+ <ThemeProvider+ attribute="class"+ defaultTheme="dark"+ enableSystem={false}+ disableTransitionOnChange={false}+ >+ <NextIntlClientProvider messages={messages} locale={locale}>+ {children}+ <ThemedToaster />+ </NextIntlClientProvider>+ </ThemeProvider></body></html>);diff --git a/components/app-footer.tsx b/components/app-footer.tsxindex 01ce8c1..9e127ab 100644--- a/components/app-footer.tsx+++ b/components/app-footer.tsx@@ -3,6 +3,7 @@import { useTranslations } from "next-intl";import { Coffee, Github } from "lucide-react";import { LanguageSwitcher } from "./language-switcher";+import { ThemeSwitcher } from "./theme-switcher";interface VersionInfo {version: string;@@ -28,9 +29,10 @@ export function AppFooter({ versionInfo }: AppFooterProps) {<div className="container max-w-4xl mx-auto p-3 sm:p-4">{/* Mobile: Two rows (language + links), Desktop: One row */}<div className="flex flex-col gap-2 sm:flex-row sm:justify-between sm:items-center sm:gap-4">- {/* Language switcher */}- <div className="flex justify-center sm:justify-start">+ {/* Language and theme switcher */}+ <div className="flex justify-center sm:justify-start items-center gap-2"><LanguageSwitcher />+ <ThemeSwitcher /></div>{/* Links row - horizontal on all screen sizes */}diff --git a/components/delete-calendar-dialog.tsx b/components/delete-calendar-dialog.tsxindex a42e547..ebf10ea 100644--- a/components/delete-calendar-dialog.tsx+++ b/components/delete-calendar-dialog.tsx@@ -58,7 +58,10 @@ export function DeleteCalendarDialog({<div className="space-y-2.5 pt-2 pl-12"><div className="font-semibold text-foreground flex items-center gap-2"><div className="w-1 h-4 bg-gradient-to-b from-destructive to-destructive/50 rounded-full"></div>- {t("calendar.deleteConfirm", { name: calendarName })}+ {t("common.deleteConfirm", {+ item: t("calendar.title"),+ name: calendarName,+ })}</div><div className="text-sm text-muted-foreground bg-destructive/5 p-3 rounded-lg border border-destructive/20">{t("calendar.deleteWarning", {diff --git a/components/theme-provider.tsx b/components/theme-provider.tsxnew file mode 100644index 0000000..b9fed38--- /dev/null+++ b/components/theme-provider.tsx@@ -0,0 +1,10 @@+"use client";++import * as React from "react";+import { ThemeProvider as NextThemesProvider } from "next-themes";++type ThemeProviderProps = Parameters<typeof NextThemesProvider>[0];++export function ThemeProvider({ children, ...props }: ThemeProviderProps) {+ return <NextThemesProvider {...props}>{children}</NextThemesProvider>;+}diff --git a/components/theme-switcher.tsx b/components/theme-switcher.tsxnew file mode 100644index 0000000..dcdd37c--- /dev/null+++ b/components/theme-switcher.tsx@@ -0,0 +1,51 @@+"use client";++import { useTheme } from "next-themes";+import { useTranslations } from "next-intl";+import { Moon, Sun } from "lucide-react";+import { Button } from "@/components/ui/button";+import { useEffect, useState } from "react";++export function ThemeSwitcher() {+ const { theme, setTheme } = useTheme();+ const t = useTranslations();+ const [mounted, setMounted] = useState(false);++ useEffect(() => {+ setMounted(true);+ }, []);++ if (!mounted) {+ return (+ <Button variant="ghost" size="icon" className="h-9 w-9" disabled>+ <Sun className="h-4 w-4" />+ <span className="sr-only">{t("common.loading")}</span>+ </Button>+ );+ }++ const toggleTheme = () => {+ setTheme(theme === "dark" ? "light" : "dark");+ };++ return (+ <Button+ variant="ghost"+ size="icon"+ onClick={toggleTheme}+ className="h-9 w-9"+ title={+ theme === "dark" ? t("theme.switchToLight") : t("theme.switchToDark")+ }+ >+ {theme === "dark" ? (+ <Sun className="h-4 w-4" />+ ) : (+ <Moon className="h-4 w-4" />+ )}+ <span className="sr-only">+ {theme === "dark" ? t("theme.switchToLight") : t("theme.switchToDark")}+ </span>+ </Button>+ );+}diff --git a/components/themed-toaster.tsx b/components/themed-toaster.tsxnew file mode 100644index 0000000..8fbc107--- /dev/null+++ b/components/themed-toaster.tsx@@ -0,0 +1,33 @@+"use client";++import { Toaster } from "sonner";+import { useTheme } from "next-themes";+import { useEffect, useState } from "react";++export function ThemedToaster() {+ const { theme } = useTheme();+ const [mounted, setMounted] = useState(false);++ useEffect(() => {+ setMounted(true);+ }, []);++ if (!mounted) {+ return null;+ }++ return (+ <Toaster+ position="bottom-left"+ richColors+ closeButton+ theme={theme as "light" | "dark" | "system"}+ toastOptions={{+ className: "text-sm",+ style: {+ padding: "12px 16px",+ },+ }}+ />+ );+}diff --git a/messages/de.json b/messages/de.jsonindex 9ed9ad0..5bac790 100644--- a/messages/de.json+++ b/messages/de.json@@ -176,6 +176,10 @@"github": "GitHub","support": "Unterstützen"},+ "theme": {+ "switchToLight": "Zum hellen Modus wechseln",+ "switchToDark": "Zum dunklen Modus wechseln"+ },"externalSync": {"manageTitle": "Externe Kalender verwalten","manageDescription": "Füge mehrere externe Kalender für diesen Kalender hinzu und verwalte sie",diff --git a/messages/en.json b/messages/en.jsonindex 811ff3b..a7661fd 100644--- a/messages/en.json+++ b/messages/en.json@@ -176,6 +176,10 @@"github": "GitHub","support": "Support"},+ "theme": {+ "switchToLight": "Switch to light mode",+ "switchToDark": "Switch to dark mode"+ },"externalSync": {"manageTitle": "Manage External Calendars","manageDescription": "Add and manage multiple external calendars for this calendar",diff --git a/messages/it.json b/messages/it.jsonindex 82a6e04..35ba217 100644--- a/messages/it.json+++ b/messages/it.json@@ -175,6 +175,10 @@"github": "GitHub","support": "Supporto"},+ "theme": {+ "switchToLight": "Passa alla modalità chiara",+ "switchToDark": "Passa alla modalità scura"+ },"externalSync": {"manageTitle": "Gestisci Calendari Esterni","manageDescription": "Aggiungi e gestisci più calendari esterni per questo calendario",diff --git a/package-lock.json b/package-lock.jsonindex 7713e44..5cf8325 100644--- a/package-lock.json+++ b/package-lock.json@@ -26,6 +26,7 @@"motion": "^12.23.25","next": "^16.0.7","next-intl": "^4.5.8",+ "next-themes": "^0.4.6","react": "^19.2.1","react-colorful": "^5.6.1","react-day-picker": "^9.11.3",@@ -7562,6 +7563,16 @@"tslib": "^2.8.0"}},+ "node_modules/next-themes": {+ "version": "0.4.6",+ "resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.4.6.tgz",+ "integrity": "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==",+ "license": "MIT",+ "peerDependencies": {+ "react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc",+ "react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc"+ }+ },"node_modules/next/node_modules/postcss": {"version": "8.4.31","resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",diff --git a/package.json b/package.jsonindex 09c3999..96b10dc 100644--- a/package.json+++ b/package.json@@ -34,6 +34,7 @@"motion": "^12.23.25","next": "^16.0.7","next-intl": "^4.5.8",+ "next-themes": "^0.4.6","react": "^19.2.1","react-colorful": "^5.6.1","react-day-picker": "^9.11.3",