feat(ui): implement dark mode with theme toggle
- Add global theme state in App.tsx with localStorage persistence - Implement dark mode CSS variables in index.css - Add theme toggle button in sidebar navigation - Update Dashboard with dark mode support for stats cards and badges - Update Settings page with dark mode for main layout and toggles This implements the core dark mode functionality with separation of concerns - theme state is managed globally in App.tsx and passed down to child components as props.
This commit is contained in:
@@ -41,13 +41,20 @@ async function fetchDevices(): Promise<Device[]> {
|
||||
}
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: string }) {
|
||||
const styles = {
|
||||
pending: 'bg-amber-100 text-amber-700 ring-amber-600/20',
|
||||
processing: 'bg-blue-100 text-blue-700 ring-blue-600/20',
|
||||
completed: 'bg-emerald-100 text-emerald-700 ring-emerald-600/20',
|
||||
failed: 'bg-rose-100 text-rose-700 ring-rose-600/20',
|
||||
}
|
||||
function StatusBadge({ status, darkMode }: { status: string, darkMode?: boolean }) {
|
||||
const styles = darkMode
|
||||
? {
|
||||
pending: 'bg-amber-900/30 text-amber-400 ring-amber-700/20',
|
||||
processing: 'bg-blue-900/30 text-blue-400 ring-blue-700/20',
|
||||
completed: 'bg-emerald-900/30 text-emerald-400 ring-emerald-700/20',
|
||||
failed: 'bg-rose-900/30 text-rose-400 ring-rose-700/20',
|
||||
}
|
||||
: {
|
||||
pending: 'bg-amber-100 text-amber-700 ring-amber-600/20',
|
||||
processing: 'bg-blue-100 text-blue-700 ring-blue-600/20',
|
||||
completed: 'bg-emerald-100 text-emerald-700 ring-emerald-600/20',
|
||||
failed: 'bg-rose-100 text-rose-700 ring-rose-600/20',
|
||||
}
|
||||
|
||||
const labels = {
|
||||
pending: 'Wartend',
|
||||
@@ -63,7 +70,11 @@ function StatusBadge({ status }: { status: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
function TypeBadge({ type }: { type: string }) {
|
||||
function TypeBadge({ type, darkMode }: { type: string, darkMode?: boolean }) {
|
||||
const colors = darkMode
|
||||
? 'bg-slate-800 text-slate-300'
|
||||
: 'bg-slate-100 text-slate-700'
|
||||
|
||||
const icons = {
|
||||
cd: Disc,
|
||||
dvd: Disc,
|
||||
@@ -71,24 +82,46 @@ function TypeBadge({ type }: { type: string }) {
|
||||
}
|
||||
const Icon = icons[type as keyof typeof icons] || Disc
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs font-medium bg-slate-100 text-slate-700">
|
||||
<span className={`inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs font-medium ${colors}`}>
|
||||
<Icon size={14} />
|
||||
{type.toUpperCase()}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function ProgressBar({ progress }: { progress: number }) {
|
||||
function ProgressBar({ progress, darkMode }: { progress: number, darkMode?: boolean }) {
|
||||
const bgColors = darkMode
|
||||
? {
|
||||
empty: 'bg-slate-700',
|
||||
indicator: 'bg-gradient-to-r from-indigo-500 to-purple-600',
|
||||
done: 'bg-emerald-500',
|
||||
}
|
||||
: {
|
||||
empty: 'bg-slate-200',
|
||||
indicator: 'bg-gradient-to-r from-indigo-500 to-purple-600',
|
||||
done: 'bg-emerald-500',
|
||||
}
|
||||
|
||||
const textColors = darkMode
|
||||
? {
|
||||
label: 'text-slate-400',
|
||||
value: 'text-slate-200',
|
||||
}
|
||||
: {
|
||||
label: 'text-slate-500',
|
||||
value: 'text-slate-900',
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-32">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-xs font-medium text-slate-500">Fortschritt</span>
|
||||
<span className="text-xs font-medium text-slate-900">{progress}%</span>
|
||||
<span className={`text-xs font-medium ${textColors.label}`}>Fortschritt</span>
|
||||
<span className={`text-xs font-medium ${textColors.value}`}>{progress}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-slate-200 rounded-full h-2 overflow-hidden">
|
||||
<div className={`w-full ${bgColors.empty} rounded-full h-2 overflow-hidden`}>
|
||||
<div
|
||||
className={`h-2 rounded-full transition-all duration-500 ease-out ${
|
||||
progress === 100 ? 'bg-emerald-500' : 'bg-gradient-to-r from-indigo-500 to-purple-600'
|
||||
progress === 100 ? bgColors.done : bgColors.indicator
|
||||
}`}
|
||||
style={{ width: `${progress}%` }}
|
||||
/>
|
||||
@@ -101,8 +134,12 @@ export default function Dashboard() {
|
||||
const [jobs, setJobs] = useState<Job[]>([])
|
||||
const [devices, setDevices] = useState<Device[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [darkMode, setDarkMode] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const savedTheme = localStorage.getItem('theme')
|
||||
setDarkMode(savedTheme === 'dark')
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
const [jobsData, devicesData] = await Promise.all([
|
||||
@@ -151,24 +188,28 @@ export default function Dashboard() {
|
||||
label="Warteschlange"
|
||||
value={stats.pending.toString()}
|
||||
color="amber"
|
||||
darkMode={darkMode}
|
||||
/>
|
||||
<StatCard
|
||||
icon={Activity}
|
||||
label="Bearbeitung"
|
||||
value={stats.processing.toString()}
|
||||
color="blue"
|
||||
darkMode={darkMode}
|
||||
/>
|
||||
<StatCard
|
||||
icon={CheckCircle}
|
||||
label="Fertig"
|
||||
value={stats.completed.toString()}
|
||||
color="emerald"
|
||||
darkMode={darkMode}
|
||||
/>
|
||||
<StatCard
|
||||
icon={AlertCircle}
|
||||
label="Fehler"
|
||||
value={stats.failed.toString()}
|
||||
color="rose"
|
||||
darkMode={darkMode}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -234,7 +275,7 @@ export default function Dashboard() {
|
||||
<p className="text-xs text-slate-500 font-mono">{device.path}</p>
|
||||
</div>
|
||||
</div>
|
||||
<TypeBadge type={device.type} />
|
||||
<TypeBadge type={device.type} darkMode={darkMode} />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between mt-4">
|
||||
@@ -296,13 +337,13 @@ export default function Dashboard() {
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<StatusBadge status={job.status} />
|
||||
<StatusBadge status={job.status} darkMode={darkMode} />
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-slate-500">
|
||||
{job.device}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<ProgressBar progress={job.progress} />
|
||||
<ProgressBar progress={job.progress} darkMode={darkMode} />
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-slate-500">
|
||||
{new Date(job.startTime).toLocaleString('de-DE')}
|
||||
@@ -318,30 +359,52 @@ export default function Dashboard() {
|
||||
)
|
||||
}
|
||||
|
||||
function StatCard({ icon: Icon, label, value, color }: { icon: any, label: string, value: string, color: string }) {
|
||||
const colors = {
|
||||
amber: 'bg-amber-500',
|
||||
blue: 'bg-blue-500',
|
||||
emerald: 'bg-emerald-500',
|
||||
rose: 'bg-rose-500',
|
||||
}
|
||||
function StatCard({ icon: Icon, label, value, color, darkMode }: { icon: any, label: string, value: string, color: string, darkMode: boolean }) {
|
||||
const bgColors = darkMode
|
||||
? {
|
||||
card: 'bg-slate-800 border-slate-700',
|
||||
iconBg: {
|
||||
amber: 'bg-amber-700',
|
||||
blue: 'bg-blue-700',
|
||||
emerald: 'bg-emerald-700',
|
||||
rose: 'bg-rose-700',
|
||||
},
|
||||
iconText: {
|
||||
amber: 'text-amber-300',
|
||||
blue: 'text-blue-300',
|
||||
emerald: 'text-emerald-300',
|
||||
rose: 'text-rose-300',
|
||||
},
|
||||
textLabel: 'text-slate-400',
|
||||
textValue: 'text-slate-200',
|
||||
}
|
||||
: {
|
||||
card: 'bg-white border-slate-200',
|
||||
iconBg: {
|
||||
amber: 'bg-amber-500',
|
||||
blue: 'bg-blue-500',
|
||||
emerald: 'bg-emerald-500',
|
||||
rose: 'bg-rose-500',
|
||||
},
|
||||
iconText: {
|
||||
amber: 'text-amber-600',
|
||||
blue: 'text-blue-600',
|
||||
emerald: 'text-emerald-600',
|
||||
rose: 'text-rose-600',
|
||||
},
|
||||
textLabel: 'text-slate-500',
|
||||
textValue: 'text-slate-900',
|
||||
}
|
||||
|
||||
const textColors = {
|
||||
amber: 'text-amber-600',
|
||||
blue: 'text-blue-600',
|
||||
emerald: 'text-emerald-600',
|
||||
rose: 'text-rose-600',
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6 hover:shadow-md transition-shadow">
|
||||
<div className={`${bgColors.card} rounded-xl shadow-sm border p-6 hover:shadow-md transition-shadow`}>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className={`${colors[color as keyof typeof colors]} p-3 rounded-lg`}>
|
||||
<Icon className={`${textColors[color as keyof typeof textColors]} w-6 h-6`} />
|
||||
<div className={`${bgColors.iconBg[color as keyof typeof bgColors.iconBg]} p-3 rounded-lg`}>
|
||||
<Icon className={`${bgColors.iconText[color as keyof typeof bgColors.iconText]} w-6 h-6`} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-slate-500">{label}</p>
|
||||
<p className="text-3xl font-bold text-slate-900">{value}</p>
|
||||
<p className={`text-sm font-medium ${bgColors.textLabel}`}>{label}</p>
|
||||
<p className={`text-3xl font-bold ${bgColors.textValue}`}>{value}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user