feat(buyer-tasks): collapsible items-list component

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
SJCoetz 2026-07-29 20:06:10 +02:00
parent 5a08d3651e
commit 6fa44c55ff

View file

@ -0,0 +1,51 @@
"use client";
import { useState } from "react";
import { ChevronDown, ChevronRight } from "lucide-react";
import { cn } from "@/lib/utils";
export type BuyerTaskItem = {
id: string;
description: string;
quantity: number;
costPrice: number;
sellingPrice: number;
};
export function BuyerTaskItemsList({ items }: { items: BuyerTaskItem[] }) {
const [open, setOpen] = useState(false);
return (
<div className="border-t">
<button
type="button"
onClick={() => setOpen((o) => !o)}
className="flex w-full items-center gap-1.5 px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/50"
data-testid="buyer-task-items-toggle"
>
{open ? (
<ChevronDown className="h-3 w-3" />
) : (
<ChevronRight className="h-3 w-3" />
)}
{open ? "Hide" : "Show"} {items.length} item{items.length === 1 ? "" : "s"}
</button>
{open && (
<ul className="divide-y text-xs" data-testid="buyer-task-items-list">
{items.map((item) => (
<li
key={item.id}
className={cn("flex items-center justify-between px-3 py-1.5")}
data-testid="buyer-task-item"
>
<span className="truncate flex-1">{item.description || "(no description)"}</span>
<span className="ml-2 tabular-nums">
{item.quantity} × R{item.costPrice.toFixed(2)}
</span>
</li>
))}
</ul>
)}
</div>
);
}