import React from 'react'; import { formatSize } from '@/utils/storageCleaner'; import { useI18n } from '@/utils/chromeI18n'; import { cn } from '@/lib/utils'; // 引入官方的 Checkbox 原子组件 import { Checkbox } from '@/components/ui/checkbox'; interface OptionItemProps extends React.HTMLAttributes { labelKey: string; checked: boolean; size?: number; isCount?: boolean; onChange: () => void; } export default function OptionItem({ labelKey, checked, size, isCount = false, onChange, className, ...props }: OptionItemProps) { const { t } = useI18n('storageCleaner'); return (
{/* 左侧数据区域 */}
{t(labelKey)} {/* 底部容量大小或计数标识 */} {size !== undefined && size > 0 ? ( {isCount ? `${size} ${t('storageCleaner:countUnit')}` : formatSize(size)} ) : ( {t('storageCleaner:noData')} )}
{/* 5. 超进化:全面替换原生 input 标签 完美调用 shadcn 的 Checkbox 组件。它自带全站统一的主色(Primary)、 打钩选中时的平滑微放大缩放动效(Scale Animation), 并且阻止冒泡,防范与外层的全局覆盖点击事件产生双重冲突。 */} e.stopPropagation()} onCheckedChange={onChange} className="h-4 w-4 shrink-0 rounded border-input data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground" />
); }