Skip to main content
Clever Ops

Cart Summary (Drawerless)

An order summary that lives on the page, line items with real stepper buttons, a promo line, and a totals ledger in tabular figures; fully controlled via callbacks, zero state deps.

Preview & code

Loading Cart Summary (Drawerless) preview

Installation

pnpm dlx shadcn@latest add @cleverui/cart-summary-drawerless

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { CartSummaryDrawerless } from '@/components/ui/cart-summary-drawerless'
Exampletsx
'use client'

import { useMemo, useState } from 'react'
import { CartSummaryDrawerless } from '@/components/ui/cart-summary-drawerless'

const CATALOG: Record<
  string,
  { name: string; variant: string; unitCents: number }
> = {
  jacket: {
    name: 'Field Jacket 02',
    variant: 'Olive · M',
    unitCents: 18900,
  },
  crew: {
    name: 'Merino Crew',
    variant: 'Charcoal · L',
    unitCents: 7800,
  },
  belt: {
    name: 'Saddle Belt',
    variant: 'Tan · 34',
    unitCents: 6200,
  },
}

function formatMoney(cents: number) {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: cents % 100 === 0 ? 0 : 2,
  }).format(cents / 100)
}

export default function CartSummaryDrawerlessDemo() {
  const [qty, setQty] = useState<Record<string, number>>({
    jacket: 1,
    crew: 2,
    belt: 1,
  })

  const { items, subtotal, tax, total } = useMemo(() => {
    const nextItems = Object.entries(qty).map(([id, q]) => {
      const cat = CATALOG[id]!
      return {
        id,
        name: cat.name,
        variant: cat.variant,
        qty: q,
        linePrice: formatMoney(cat.unitCents * q),
      }
    })
    const sub = Object.entries(qty).reduce(
      (sum, [id, q]) => sum + CATALOG[id]!.unitCents * q,
      0
    )
    const promoCents = 2400
    const afterPromo = Math.max(0, sub - promoCents)
    const taxCents = Math.round(afterPromo * 0.1)
    return {
      items: nextItems,
      subtotal: formatMoney(sub),
      tax: `${formatMoney(taxCents)} GST`,
      total: formatMoney(afterPromo + taxCents),
    }
  }, [qty])

  return (
    <div className="mx-auto flex w-full max-w-md justify-center px-4 py-10 sm:px-6 sm:py-14">
      <CartSummaryDrawerless
        heading="Order summary"
        items={items}
        onQtyChange={(id, next) =>
          setQty((prev) => ({
            ...prev,
            [id]: next,
          }))
        }
        promo={{ code: 'WELCOME10', amount: '-$24' }}
        subtotal={subtotal}
        shipping="Free"
        tax={tax}
        total={total}
        note="Duties calculated at checkout · free returns within 30 days"
      />
    </div>
  )
}

API reference

CartSummaryDrawerless accepts the following props.

PropTypeDefaultDescription
headingstring'Order summary'
items*CartSummaryItem[]
onQtyChange*(id: string, qty: number) => voidsteppers fire this with the next quantity; qty state lives with the consumer
minQtynumber1decrement disables (never hides) at this floor
promo{ code: string; amount: string }
subtotal*stringPREFORMATTED
shippingstringPREFORMATTED, e.g. "Free" or "$9.95"
taxstringPREFORMATTED, e.g. "$18.90 GST"
total*stringPREFORMATTED, supplied, never computed
notestringquiet line under the ledger

…plus everything from React.HTMLAttributes<HTMLElement>: className, event handlers, aria attributes and the rest pass straight through.

Referenced types

Typestsx
export interface CartSummaryItem {
  id: string
  name: string
  variant?: string
  qty: number
  /** PREFORMATTED line total, e.g. "$189", the component does no money math */
  linePrice: string
}

Frequently asked questions

How do I install the Cart Summary (Drawerless) component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/cart-summary-drawerless`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Cart Summary (Drawerless) require?

Cart Summary (Drawerless) uses motion and lucide-react on top of React and Tailwind CSS. You don't need to install them manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Cart Summary (Drawerless) to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services