refactor: 更新样式和组件结构以提升一致性和可读性

- 在 utils.ts 中引入 twMerge 以合并 Tailwind 类。
- 在 ConverterForm.tsx 中简化类名,移除冗余样式。
- 在 LiveClock.tsx 中调整样式,优化文本显示。
- 在 ResultView.tsx 中更新布局和样式,提升视觉效果。
This commit is contained in:
2026-07-08 23:24:54 +08:00
parent 8424fa219f
commit 83866c8ae0
4 changed files with 19 additions and 28 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
import { type ClassValue, clsx } from 'clsx'; import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
return clsx(inputs); return twMerge(clsx(inputs));
} }
@@ -41,10 +41,7 @@ export default function ConverterForm({
placeholder={INPUT_PLACEHOLDERS[mode]} placeholder={INPUT_PLACEHOLDERS[mode]}
value={input} value={input}
onChange={(e) => setInput(e.target.value)} onChange={(e) => setInput(e.target.value)}
className={cn( className={cn('h-10', error && 'border-destructive')}
'font-mono font-semibold h-10 shadow-sm placeholder:text-muted-foreground/60 focus:bg-background',
error && 'border-destructive focus-visible:ring-destructive',
)}
/> />
{error && <p className="text-destructive text-xs font-medium px-0.5">{error}</p>} {error && <p className="text-destructive text-xs font-medium px-0.5">{error}</p>}
@@ -60,16 +57,13 @@ export default function ConverterForm({
/> />
<Select value={zone} onValueChange={(v: string) => setZone(v as ZoneType)}> <Select value={zone} onValueChange={(v: string) => setZone(v as ZoneType)}>
<SelectTrigger className="flex-1 font-mono font-semibold h-9 shadow-sm bg-background"> <SelectTrigger>
<SelectValue placeholder="选择时区" /> <SelectValue placeholder="选择时区" />
</SelectTrigger> </SelectTrigger>
<SelectContent className="max-h-64 font-mono">
<SelectContent className="max-h-64">
{ZONES.map((z) => ( {ZONES.map((z) => (
<SelectItem <SelectItem key={z} value={z} className="cursor-pointer">
key={z}
value={z}
className="text-xs font-semibold focus:bg-accent cursor-pointer"
>
{z} {z}
</SelectItem> </SelectItem>
))} ))}
+8 -11
View File
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react'; import type { HTMLAttributes } from 'react';
import { useEffect, useState } from 'react';
import { Clock } from 'lucide-react'; import { Clock } from 'lucide-react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { CopyButton } from '@/components/CopyButton'; import { CopyButton } from '@/components/CopyButton';
@@ -7,7 +8,7 @@ import { msToUnit } from '../constants';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
interface LiveClockProps extends React.HTMLAttributes<HTMLDivElement> { interface LiveClockProps extends HTMLAttributes<HTMLDivElement> {
unit: UnitType; unit: UnitType;
onUseNow: (val: number) => void; onUseNow: (val: number) => void;
} }
@@ -28,18 +29,14 @@ export default function LiveClock({ unit, onUseNow, className, ...props }: LiveC
return ( return (
<div <div
className={cn( className={cn(
'flex items-center gap-3 px-3 h-10 rounded-lg border border-border/80 bg-secondary/50', 'flex items-center gap-3 px-3 h-10 rounded-lg font-bold text-[12px] border px-[20px]',
className, className,
)} )}
{...props} {...props}
> >
<span className="text-muted-foreground font-bold text-[10px] uppercase tracking-wider whitespace-nowrap shrink-0 selection:bg-transparent select-none"> <span></span>
</span>
<span className="flex-1 font-mono font-bold text-foreground text-sm tracking-tight leading-none truncate tabular-nums"> <span className="flex-1 text-sm ">{text}</span>
{text}
</span>
<Button <Button
type="button" type="button"
@@ -50,12 +47,12 @@ export default function LiveClock({ unit, onUseNow, className, ...props }: LiveC
title="填充到下方" title="填充到下方"
variant="ghost" variant="ghost"
size="icon" size="icon"
className="h-7 w-7 text-muted-foreground hover:text-foreground" className="h-7 w-7"
> >
<Clock className="w-3.5 h-3.5" /> <Clock className="w-3.5 h-3.5" />
</Button> </Button>
<CopyButton text={text} tooltip="复制时间戳" className="h-7 w-7 rounded-md border" /> <CopyButton text={text} tooltip="复制时间戳" className="h-7 w-7" />
</div> </div>
); );
} }
@@ -34,16 +34,15 @@ export default function ResultView({
</span> </span>
<div className="bg-card text-card-foreground border border-border p-4 sm:p-5 rounded-xl relative shadow-sm flex justify-between items-center gap-4 focus-within:ring-1 focus-within:ring-ring"> <div className="bg-card border p-4 rounded-lg flex items-center gap-3 justify-between">
<span className="font-mono font-extrabold text-foreground break-all text-xl sm:text-2xl tracking-tight leading-tight select-all tabular-nums"> <span className="break-all text-lg select-all flex-1">{result}</span>
{result}
</span>
<CopyButton <CopyButton
text={result} text={result}
tooltip="复制结果" tooltip="复制结果"
variant="ghost" variant="ghost"
size="icon" size="icon"
className="h-7 w-7 text-muted-foreground hover:text-foreground" className="h-7 w-7"
/> />
</div> </div>
</div> </div>