feat(TextStatistics): 引入 StatCard 组件以优化统计信息展示
- 新增 StatCard 组件,简化统计信息的展示逻辑。 - 更新 TextStatistics 页面,使用 StatCard 组件替代原有的统计项渲染方式,提升代码可读性和维护性。
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
interface StatCardProps {
|
||||||
|
label: string;
|
||||||
|
value: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StatCard({ label, value }: StatCardProps) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col justify-center items-center p-4 text-center rounded-xl border border-border bg-card shadow-sm text-card-foreground hover:-translate-y-0.5 hover:shadow-md hover:border-primary/50 focus-within:ring-1 focus-within:ring-ring">
|
||||||
|
<span className="text-xs font-medium text-muted-foreground tracking-wider mb-1 select-none">
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
<span className="font-mono text-lg md:text-2xl font-extrabold text-primary break-all tracking-tight leading-none tabular-nums select-all">
|
||||||
|
{value}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,18 +1,11 @@
|
|||||||
import TextInputArea from '@/components/TextInputArea';
|
import TextInputArea from '@/components/TextInputArea';
|
||||||
import { formatBytes } from '@/utils/format';
|
import { formatBytes } from '@/utils/format';
|
||||||
|
import StatCard from './components/StatCard';
|
||||||
import { useTextStatistics } from './useTextStatistics';
|
import { useTextStatistics } from './useTextStatistics';
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { text, stats, setText } = useTextStatistics();
|
const { text, stats, setText } = useTextStatistics();
|
||||||
|
|
||||||
const statItems = [
|
|
||||||
{ label: '字符数', value: stats.characters },
|
|
||||||
{ label: '单词数', value: stats.words },
|
|
||||||
{ label: '行数', value: stats.lines },
|
|
||||||
{ label: '字节大小', value: formatBytes(stats.bytes) },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4 w-full space-y-4">
|
<div className="p-4 w-full space-y-4">
|
||||||
<TextInputArea
|
<TextInputArea
|
||||||
@@ -26,22 +19,10 @@ export default function Index() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||||||
{statItems.map((item) => (
|
<StatCard label="字符数" value={stats.characters} />
|
||||||
<div
|
<StatCard label="单词数" value={stats.words} />
|
||||||
key={item.label}
|
<StatCard label="行数" value={stats.lines} />
|
||||||
className={cn(
|
<StatCard label="字节大小" value={formatBytes(stats.bytes)} />
|
||||||
'flex flex-col justify-center items-center p-4 text-center rounded-xl border border-border bg-card shadow-sm text-card-foreground',
|
|
||||||
'hover:-translate-y-0.5 hover:shadow-md hover:border-primary/50 focus-within:ring-1 focus-within:ring-ring',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span className="text-xs font-medium text-muted-foreground tracking-wider mb-1 select-none">
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
<span className="font-mono text-lg md:text-2xl font-extrabold text-primary break-all tracking-tight leading-none tabular-nums select-all">
|
|
||||||
{item.value}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user