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 c8c3c88d99
commit 14d85e5265
4 changed files with 19 additions and 28 deletions
@@ -41,10 +41,7 @@ export default function ConverterForm({
placeholder={INPUT_PLACEHOLDERS[mode]}
value={input}
onChange={(e) => setInput(e.target.value)}
className={cn(
'font-mono font-semibold h-10 shadow-sm placeholder:text-muted-foreground/60 focus:bg-background',
error && 'border-destructive focus-visible:ring-destructive',
)}
className={cn('h-10', error && 'border-destructive')}
/>
{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)}>
<SelectTrigger className="flex-1 font-mono font-semibold h-9 shadow-sm bg-background">
<SelectTrigger>
<SelectValue placeholder="选择时区" />
</SelectTrigger>
<SelectContent className="max-h-64 font-mono">
<SelectContent className="max-h-64">
{ZONES.map((z) => (
<SelectItem
key={z}
value={z}
className="text-xs font-semibold focus:bg-accent cursor-pointer"
>
<SelectItem key={z} value={z} className="cursor-pointer">
{z}
</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 { toast } from 'sonner';
import { CopyButton } from '@/components/CopyButton';
@@ -7,7 +8,7 @@ import { msToUnit } from '../constants';
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
interface LiveClockProps extends React.HTMLAttributes<HTMLDivElement> {
interface LiveClockProps extends HTMLAttributes<HTMLDivElement> {
unit: UnitType;
onUseNow: (val: number) => void;
}
@@ -28,18 +29,14 @@ export default function LiveClock({ unit, onUseNow, className, ...props }: LiveC
return (
<div
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,
)}
{...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">
{text}
</span>
<span className="flex-1 text-sm ">{text}</span>
<Button
type="button"
@@ -50,12 +47,12 @@ export default function LiveClock({ unit, onUseNow, className, ...props }: LiveC
title="填充到下方"
variant="ghost"
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" />
</Button>
<CopyButton text={text} tooltip="复制时间戳" className="h-7 w-7 rounded-md border" />
<CopyButton text={text} tooltip="复制时间戳" className="h-7 w-7" />
</div>
);
}
@@ -34,16 +34,15 @@ export default function ResultView({
</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">
<span className="font-mono font-extrabold text-foreground break-all text-xl sm:text-2xl tracking-tight leading-tight select-all tabular-nums">
{result}
</span>
<div className="bg-card border p-4 rounded-lg flex items-center gap-3 justify-between">
<span className="break-all text-lg select-all flex-1">{result}</span>
<CopyButton
text={result}
tooltip="复制结果"
variant="ghost"
size="icon"
className="h-7 w-7 text-muted-foreground hover:text-foreground"
className="h-7 w-7"
/>
</div>
</div>