- 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
27 lines
954 B
TypeScript
27 lines
954 B
TypeScript
import { clsx, type ClassValue } from 'clsx';
|
|
import { twMerge } from 'tailwind-merge';
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function formatBytes(bytes: number, decimals = 1): string {
|
|
if (!Number.isFinite(bytes) || bytes <= 0) return '0 B';
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
const i = Math.min(units.length - 1, Math.floor(Math.log(bytes) / Math.log(1024)));
|
|
const v = bytes / Math.pow(1024, i);
|
|
return `${v.toFixed(decimals)} ${units[i]}`;
|
|
}
|
|
|
|
export function formatUptime(seconds: number): string {
|
|
if (!Number.isFinite(seconds) || seconds <= 0) return '0 秒';
|
|
const d = Math.floor(seconds / 86400);
|
|
const h = Math.floor((seconds % 86400) / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const parts: string[] = [];
|
|
if (d) parts.push(`${d} 天`);
|
|
if (h) parts.push(`${h} 时`);
|
|
if (m || (!d && !h)) parts.push(`${m} 分`);
|
|
return parts.join(' ');
|
|
}
|