DDBS UI
commerce

Cart Line Row

One cart line: image, name, options, quantity stepper, line total and remove. Regular and compact modes.

npx shadcn@latest add https://ui.develop-better-solutions.com/r/store-cart-line.json
Dependencies:lucide-react
Fullscreen

Atlas Canvas Tote

Sand

390 MAD each

780 MAD

2

Souk Linen Shirt

Indigo / M

640 MAD each

640 MAD

1
2

640 MAD

1

Usage

store-cart-line-example.tsx
"use client";

import { useState } from "react";
import { CartLineRow, type CartLineRowLine } from "@dbs/ui";
import { IMG, IMG2, StoreScope, fmt } from "./_store";

const BASE: CartLineRowLine[] = [
  {
    key: "p1|sand|one",
    image: IMG,
    colorLabel: "Sand",
    lineTotal: 780,
    product: { id: "p1", name: "Atlas Canvas Tote" },
    line: { quantity: 2, size: "One size" },
  },
  {
    key: "p2|indigo|M",
    image: IMG2,
    colorLabel: "Indigo",
    lineTotal: 640,
    product: { id: "p2", name: "Souk Linen Shirt" },
    line: { quantity: 1, size: "M" },
  },
];
const UNIT: Record<string, number> = { p1: 390, p2: 640 };

export default function StoreCartLineExample() {
  const [lines, setLines] = useState(BASE);
  const setQuantity = (key: string, q: number) =>
    setLines((ls) =>
      ls.map((l) =>
        l.key === key ? { ...l, line: { ...l.line, quantity: q }, lineTotal: (UNIT[l.product.id] ?? 0) * q } : l,
      ),
    );
  return (
    <div className="grid w-full gap-4 lg:grid-cols-2">
      {[false, true].map((compact) => (
        <StoreScope key={String(compact)} minHeight={0} dark={compact}>
          <div className="flex flex-col gap-4">
            {lines.map((l) => (
              <CartLineRow
                key={l.key}
                line={l}
                compact={compact}
                href="#"
                formatPrice={fmt}
                unitPrice={UNIT[l.product.id] ?? 0}
                maxQuantity={5}
                onQuantity={setQuantity}
                onRemove={(key) => setLines((ls) => ls.filter((x) => x.key !== key))}
                imageWidth={96}
                imageHeight={120}
                imageClassName="h-28 w-24 rounded-lg bg-[var(--store-tile)] object-cover"
                imageCompactClassName="h-20 w-16 rounded-lg bg-[var(--store-tile)] object-cover"
              />
            ))}
            {lines.length === 0 && <p className="text-sm text-[var(--store-muted)]">Everything removed.</p>}
          </div>
        </StoreScope>
      ))}
    </div>
  );
}