60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { useState } from 'react';
|
|
import { ChevronRight, FileText } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
import type { AIMaterial } from '../../types/ai-writing';
|
|
import { MaterialItem } from './MaterialItem';
|
|
import { CollapseTransition } from './CollapseTransition';
|
|
|
|
interface MaterialsCardProps {
|
|
materials: AIMaterial[];
|
|
selectedIds: Set<string>;
|
|
onToggle: (id: string) => void;
|
|
}
|
|
|
|
export function MaterialsCard({ materials, selectedIds, onToggle }: MaterialsCardProps) {
|
|
const [expanded, setExpanded] = useState(false);
|
|
|
|
return (
|
|
<div className="rounded-md border bg-muted/20 overflow-hidden">
|
|
{/* 折叠头 */}
|
|
<button
|
|
type="button"
|
|
onClick={() => setExpanded((v) => !v)}
|
|
className="w-full flex items-center gap-2 px-3 py-2 text-xs font-medium hover:bg-muted/40 transition-colors text-left"
|
|
>
|
|
<FileText className="size-3.5 text-blue-500 shrink-0" />
|
|
<span className="flex-1">
|
|
素材列表
|
|
<span className="ml-1 text-muted-foreground font-normal">
|
|
(共 {materials.length} 条,已选 {selectedIds.size} 条)
|
|
</span>
|
|
</span>
|
|
<ChevronRight
|
|
className={cn(
|
|
'size-3 text-muted-foreground transition-transform duration-200',
|
|
expanded && 'rotate-90',
|
|
)}
|
|
/>
|
|
</button>
|
|
|
|
{/* 列表 */}
|
|
<CollapseTransition open={expanded}>
|
|
<div className="px-2.5 pb-2.5 pt-1.5 space-y-1.5 border-t">
|
|
{materials.length === 0 ? (
|
|
<p className="text-xs text-muted-foreground py-2 text-center">暂无素材</p>
|
|
) : (
|
|
materials.map((m) => (
|
|
<MaterialItem
|
|
key={m.id}
|
|
material={m}
|
|
checked={selectedIds.has(m.id)}
|
|
onToggle={onToggle}
|
|
/>
|
|
))
|
|
)}
|
|
</div>
|
|
</CollapseTransition>
|
|
</div>
|
|
);
|
|
}
|