feat(web): add mobile theme toggle (#274)
This commit is contained in:
committed by
GitHub
parent
2ae8e14158
commit
a416695400
@@ -21,6 +21,12 @@ const ModeToggle = dynamic(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
const MobileModeToggle = dynamic(() =>
|
||||
import('@kit/ui/mobile-mode-toggle').then((mod) => ({
|
||||
default: mod.MobileModeToggle,
|
||||
})),
|
||||
);
|
||||
|
||||
const paths = {
|
||||
home: pathsConfig.app.home,
|
||||
};
|
||||
@@ -57,6 +63,12 @@ function AuthButtons() {
|
||||
</If>
|
||||
</div>
|
||||
|
||||
<div className={'md:hidden'}>
|
||||
<If condition={features.enableThemeToggle}>
|
||||
<MobileModeToggle />
|
||||
</If>
|
||||
</div>
|
||||
|
||||
<div className={'flex gap-x-2.5'}>
|
||||
<Button className={'hidden md:block'} asChild variant={'ghost'}>
|
||||
<Link href={pathsConfig.auth.signIn}>
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
"./loading-overlay": "./src/makerkit/loading-overlay.tsx",
|
||||
"./profile-avatar": "./src/makerkit/profile-avatar.tsx",
|
||||
"./mode-toggle": "./src/makerkit/mode-toggle.tsx",
|
||||
"./mobile-mode-toggle": "./src/makerkit/mobile-mode-toggle.tsx",
|
||||
"./enhanced-data-table": "./src/makerkit/data-table.tsx",
|
||||
"./language-selector": "./src/makerkit/language-selector.tsx",
|
||||
"./stepper": "./src/makerkit/stepper.tsx",
|
||||
|
||||
35
packages/ui/src/makerkit/mobile-mode-toggle.tsx
Normal file
35
packages/ui/src/makerkit/mobile-mode-toggle.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
import { useTheme } from 'next-themes';
|
||||
|
||||
import { cn } from '../lib/utils';
|
||||
import { Button } from '../shadcn/button';
|
||||
|
||||
export function MobileModeToggle(props: { className?: string }) {
|
||||
const { resolvedTheme, setTheme } = useTheme();
|
||||
|
||||
const toggleTheme = () => {
|
||||
const next = resolvedTheme === 'dark' ? 'light' : 'dark';
|
||||
setTheme(next);
|
||||
setCookieTheme(next);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Toggle theme"
|
||||
className={cn(props.className)}
|
||||
onClick={toggleTheme}
|
||||
>
|
||||
<Sun className="h-[0.9rem] w-[0.9rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
||||
<Moon className="absolute h-[0.9rem] w-[0.9rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
||||
<span className="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function setCookieTheme(theme: string) {
|
||||
document.cookie = `theme=${theme}; path=/; max-age=31536000`;
|
||||
}
|
||||
Reference in New Issue
Block a user