feat: add settings page and theme toggle component
- Implemented a new SettingsPage component for user preferences including appearance, behavior, and account security settings. - Added a ThemeToggle component to switch between light, dark, and system modes. - Created reusable UI components: AlertDialog, Avatar, Badge, Button, Card, Dialog, Input, Label, Progress, ScrollArea, Separator, Sheet, Skeleton, Tooltip. - Introduced utility functions for class name merging and formatting bytes/uptime. - Added a custom hook for media query handling
This commit is contained in:
65 files changed
+4687
-4530
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { Monitor, Moon, Sun } from 'lucide-react';
|
||||
import { motion } from 'motion/react';
|
||||
import { useTheme, type ThemeMode } from '@/contexts/ThemeContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const OPTIONS: { mode: ThemeMode; icon: typeof Sun; label: string }[] = [
|
||||
{ mode: 'system', icon: Monitor, label: '跟随系统' },
|
||||
{ mode: 'light', icon: Sun, label: '浅色' },
|
||||
{ mode: 'dark', icon: Moon, label: '深色' },
|
||||
];
|
||||
|
||||
export function ThemeToggle({ className }: { className?: string }) {
|
||||
const { mode, setMode } = useTheme();
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'relative inline-flex items-center gap-0.5 rounded-full border bg-card/60 p-0.5 shadow-xs',
|
||||
className
|
||||
)}
|
||||
>
|
||||
{OPTIONS.map(({ mode: m, icon: Icon, label }) => {
|
||||
const active = mode === m;
|
||||
return (
|
||||
<button
|
||||
key={m}
|
||||
type="button"
|
||||
title={label}
|
||||
aria-label={label}
|
||||
onClick={() => setMode(m)}
|
||||
className={cn(
|
||||
'relative flex size-7 items-center justify-center rounded-full transition-colors cursor-pointer',
|
||||
active ? 'text-primary-foreground' : 'text-muted-foreground hover:text-foreground'
|
||||
)}
|
||||
>
|
||||
{active && (
|
||||
<motion.span
|
||||
layoutId="theme-toggle-pill"
|
||||
className="absolute inset-0 rounded-full bg-primary"
|
||||
transition={{ type: 'spring', stiffness: 380, damping: 30 }}
|
||||
/>
|
||||
)}
|
||||
<Icon className="relative z-10 size-3.5" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user