Skip to content
Commerce block

Order Summary With Promo

Subtotal, discount, delivery and tax all derived from the lines, with the free-delivery nudge driven by the same threshold as the charge.

228 lineslucide-reactAdded 8 Aug 2026Updated 11 Sept 2026
  • order summary
  • totals
  • promo code
  • checkout
  • tax

What's included

  • components/order-summary-panel.tsx
  • Needs lucide-react

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add order-summary-panel

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/order-summary-panel.tsx
'use client'

/**
 * <OrderSummaryPanel> — subtotal, shipping, tax, promo code, total.
 *
 * Every figure is derived from the line items and the applied discount.
 * Nothing here is passed in pre-computed, which is what stops a summary
 * disagreeing with the basket beside it — the classic version of that bug
 * is a promo code that updates the total but not the discount row.
 *
 * The "free delivery in £X more" nudge is computed from the same threshold
 * that decides whether shipping is charged, so the two can never contradict
 * each other. Quoting a threshold from a separate constant is how shops end
 * up promising free delivery at £50 and charging it at £50.
 *
 * Tax is shown as a line even when it is included in the price, because a
 * total that silently contains VAT and never says so is the single most
 * common complaint about European checkouts.
 */

import * as React from 'react'
import { Tag, Check, Truck } from 'lucide-react'

export interface SummaryLine {
  price: number
  quantity: number
}

export interface Promo {
  code: string
  /** Fraction off the subtotal, e.g. 0.1 for 10%. */
  rate: number
  label: string
}

export interface OrderSummaryPanelProps {
  lines?: SummaryLine[]
  currency?: string
  locale?: string
  /** Spend at or above this, in minor units, and delivery is free. */
  freeShippingThreshold?: number
  shippingCost?: number
  /** Included in the displayed prices, shown for transparency. */
  taxRate?: number
  promos?: Promo[]
  ctaLabel?: string
  onCheckout?: () => void
  className?: string
}

const DEFAULT_LINES: SummaryLine[] = [
  { price: 8900, quantity: 1 },
  { price: 6500, quantity: 2 },
  { price: 4800, quantity: 1 },
]

const DEFAULT_PROMOS: Promo[] = [
  { code: 'WELCOME10', rate: 0.1, label: '10% off your first order' },
]

function formatPrice(minor: number, currency = 'GBP', locale = 'en-GB'): string {
  return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(minor / 100)
}

export function OrderSummaryPanel({
  lines = DEFAULT_LINES,
  currency = 'GBP',
  locale = 'en-GB',
  freeShippingThreshold = 5000,
  shippingCost = 495,
  taxRate = 0.2,
  promos = DEFAULT_PROMOS,
  ctaLabel = 'Checkout',
  onCheckout,
  className = '',
}: OrderSummaryPanelProps) {
  // Per-instance ids. A literal id in a reusable component is a
  // collision waiting for the second copy on the page — and a <label>
  // then resolves to whichever input rendered first.
  const uid = React.useId()
  const [entered, setEntered] = React.useState('')
  const [applied, setApplied] = React.useState<Promo | null>(null)
  const [error, setError] = React.useState<string | null>(null)

  const subtotal = lines.reduce((n, l) => n + l.price * l.quantity, 0)
  const discount = applied ? Math.round(subtotal * applied.rate) : 0
  const afterDiscount = subtotal - discount

  // One threshold drives both the charge and the nudge below.
  const shippingFree = afterDiscount >= freeShippingThreshold
  const shipping = shippingFree ? 0 : shippingCost
  const remainingForFree = Math.max(0, freeShippingThreshold - afterDiscount)

  const total = afterDiscount + shipping
  // Prices include tax, so this is the portion of the total, not an addition.
  const taxIncluded = Math.round(total - total / (1 + taxRate))

  function apply(event: React.FormEvent) {
    event.preventDefault()
    const match = promos.find((p) => p.code.toLowerCase() === entered.trim().toLowerCase())

    if (!match) {
      setError('That code is not valid or has expired.')
      return
    }

    setApplied(match)
    setError(null)
    setEntered('')
  }

  return (
    <aside
      className={`rounded-2xl border border-border/60 bg-card/60 p-6 ${className}`}
    >
      <h2 className="text-lg font-bold tracking-tight">Order summary</h2>

      {/* Promo */}
      {applied ? (
        <div className="mt-4 flex items-center justify-between gap-3 rounded-xl bg-emerald-500/10 px-3 py-2.5 text-sm">
          <span className="inline-flex min-w-0 items-center gap-2 text-emerald-700 dark:text-emerald-400">
            <Check aria-hidden className="h-4 w-4 shrink-0" />
            <span className="truncate font-medium">{applied.code}</span>
          </span>
          <button
            type="button"
            onClick={() => setApplied(null)}
            className="shrink-0 text-xs text-muted-foreground hover:text-foreground"
          >
            Remove
          </button>
        </div>
      ) : (
        <form onSubmit={apply} className="mt-4">
          <label htmlFor={`${uid}-promo-code`} className="sr-only">
            Promo code
          </label>
          <div className="flex gap-2">
            <div className="relative flex-1">
              <Tag
                aria-hidden
                className="pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
              />
              <input
                id={`${uid}-promo-code`}
                value={entered}
                onChange={(e) => {
                  setEntered(e.target.value)
                  setError(null)
                }}
                placeholder="Promo code"
                aria-invalid={Boolean(error)}
                aria-describedby={`${uid}-promo-error`}
                className="w-full rounded-xl border border-border/60 bg-background py-2 ps-9 pe-3 text-sm outline-none transition-shadow placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-primary"
              />
            </div>
            <button
              type="submit"
              className="shrink-0 rounded-xl border border-border/60 bg-background px-3.5 py-2 text-sm font-medium transition-colors hover:bg-muted"
            >
              Apply
            </button>
          </div>
          <p id={`${uid}-promo-error`} aria-live="polite" className="mt-1.5 min-h-4 text-xs text-destructive">
            {error}
          </p>
        </form>
      )}

      {/* Figures */}
      <dl className="mt-5 space-y-2.5 border-t border-border/60 pt-5 text-sm">
        <div className="flex flex-wrap justify-between gap-x-4 gap-y-0.5">
          <dt className="min-w-0 break-words text-muted-foreground">Subtotal</dt>
          <dd className="tabular-nums">{formatPrice(subtotal, currency, locale)}</dd>
        </div>

        {applied ? (
          <div className="flex flex-wrap justify-between gap-x-4 gap-y-0.5 text-emerald-600 dark:text-emerald-400">
            <dt className="min-w-0 break-words">{applied.label}</dt>
            <dd className="tabular-nums">−{formatPrice(discount, currency, locale)}</dd>
          </div>
        ) : null}

        <div className="flex flex-wrap justify-between gap-x-4 gap-y-0.5">
          <dt className="min-w-0 break-words text-muted-foreground">Delivery</dt>
          <dd className="min-w-0 break-words text-end tabular-nums">
            {shippingFree ? (
              <span className="font-medium text-emerald-600 dark:text-emerald-400">Free</span>
            ) : (
              formatPrice(shipping, currency, locale)
            )}
          </dd>
        </div>

        <div className="flex flex-wrap justify-between gap-x-4 gap-y-0.5 text-xs text-muted-foreground">
          <dt className="min-w-0 break-words">Includes VAT ({Math.round(taxRate * 100)}%)</dt>
          <dd className="tabular-nums">{formatPrice(taxIncluded, currency, locale)}</dd>
        </div>

        <div className="flex flex-wrap justify-between gap-x-4 gap-y-0.5 border-t border-border/60 pt-3 text-base font-bold">
          <dt className="min-w-0 break-words">Total</dt>
          <dd className="tabular-nums">{formatPrice(total, currency, locale)}</dd>
        </div>
      </dl>

      {/* Same threshold as the charge above. */}
      {!shippingFree ? (
        <p className="mt-4 flex items-start gap-2 rounded-xl bg-muted/60 px-3 py-2.5 text-xs text-muted-foreground">
          <Truck aria-hidden className="mt-0.5 h-3.5 w-3.5 shrink-0" />
          Spend {formatPrice(remainingForFree, currency, locale)} more for free delivery.
        </p>
      ) : null}

      <button
        type="button"
        onClick={onCheckout}
        className="mt-5 w-full rounded-xl bg-primary px-4 py-3 text-sm font-semibold text-primary-foreground transition-colors hover:bg-primary/90"
      >
        {ctaLabel}
      </button>

      <p className="mt-3 text-center text-xs text-muted-foreground">
        Taxes and delivery calculated at checkout for your region.
      </p>
    </aside>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Install: npm i lucide-react
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/order-summary-panel.tsx and import it where you need the section:

import { OrderSummaryPanel } from '@/components/order-summary-panel'

Customize

6 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
linesSummaryLine[]DEFAULT_LINES
currencystring'GBP'
localestring'en-GB'
freeShippingThresholdSpend at or above this, in minor units, and delivery is free.number5000
shippingCostnumber495
taxRateIncluded in the displayed prices, shown for transparency.number0.2
promosPromo[]DEFAULT_PROMOS
ctaLabelstring'Checkout'
onCheckout() => void—
classNamestring''

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

order-summary-panel.html
<!--
  Order Summary With Promo — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<aside class="rounded-2xl border border-border/60 bg-card/60 p-6 ">
  <h2 class="text-lg font-bold tracking-tight">Order summary</h2>
  <form class="mt-4">
    <label for="_R_0_-promo-code" class="sr-only">Promo code</label>
    <div class="flex gap-2">
      <div class="relative flex-1">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-tag pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden="true">
          <path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"></path>
          <circle cx="7.5" cy="7.5" r=".5" fill="currentColor"></circle>
        </svg>
        <input id="_R_0_-promo-code" placeholder="Promo code" aria-invalid="false" aria-describedby="_R_0_-promo-error" class="w-full rounded-xl border border-border/60 bg-background py-2 ps-9 pe-3 text-sm outline-none transition-shadow placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-primary" value="" />
      </div>
      <button type="submit" class="shrink-0 rounded-xl border border-border/60 bg-background px-3.5 py-2 text-sm font-medium transition-colors hover:bg-muted">Apply</button>
    </div>
    <p id="_R_0_-promo-error" aria-live="polite" class="mt-1.5 min-h-4 text-xs text-destructive"></p>
  </form>
  <dl class="mt-5 space-y-2.5 border-t border-border/60 pt-5 text-sm">
    <div class="flex flex-wrap justify-between gap-x-4 gap-y-0.5">
      <dt class="min-w-0 break-words text-muted-foreground">Subtotal</dt>
      <dd class="tabular-nums">£267.00</dd>
    </div>
    <div class="flex flex-wrap justify-between gap-x-4 gap-y-0.5">
      <dt class="min-w-0 break-words text-muted-foreground">Delivery</dt>
      <dd class="min-w-0 break-words text-end tabular-nums">
        <span class="font-medium text-emerald-600 dark:text-emerald-400">Free</span>
      </dd>
    </div>
    <div class="flex flex-wrap justify-between gap-x-4 gap-y-0.5 text-xs text-muted-foreground">
      <dt class="min-w-0 break-words">Includes VAT (20%)</dt>
      <dd class="tabular-nums">£44.50</dd>
    </div>
    <div class="flex flex-wrap justify-between gap-x-4 gap-y-0.5 border-t border-border/60 pt-3 text-base font-bold">
      <dt class="min-w-0 break-words">Total</dt>
      <dd class="tabular-nums">£267.00</dd>
    </div>
  </dl>
  <button type="button" class="mt-5 w-full rounded-xl bg-primary px-4 py-3 text-sm font-semibold text-primary-foreground transition-colors hover:bg-primary/90">Checkout</button>
  <p class="mt-3 text-center text-xs text-muted-foreground">Taxes and delivery calculated at checkout for your region.</p>
</aside>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

8 more blocks in Cart & Checkout

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Cart & Checkout

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Cart & Checkout blocks

View category
Open the full page for this block

Slide-Over Cart Drawer

A basket panel with the dialog mechanics usually missing: focus trap, focus return, Escape to close and a background scroll lock.

Cart & Checkout256 lines1 dep
Open the full page for this block

Editable Cart Lines

Quantity steppers and remove-with-undo, with every total derived rather than stored so the basket can never disagree with itself.

Cart & Checkout199 lines1 dep
Open the full page for this block

Checkout Address & Payment

The full autocomplete token set that lets a browser fill eight fields in one tap, plus address labels that follow the selected country.

Cart & Checkout259 lines1 dep
Open the full page for this block

Express Payment Row

The wallet buttons above the form, and what they do to it: the address a wallet returns is shown and stays editable, and the row disappears entirely when no wallet is actually available.

Cart & Checkout258 lines1 dep
Open the full page for this block

Gift Options Form

The gifting step, placed in the cart where it is a choice rather than at checkout where it is friction.

Cart & Checkout177 linesNo deps
Open the full page for this block

Gift Card Purchase

The only checkout where the buyer is not the recipient - live preview, a send date with a stated timezone, and the confirm-the-address field that prevents the expensive typo.

Cart & Checkout361 lines1 dep
Open the full page for this block

Guest Checkout

Guest as the default and the whole form, with a real autocomplete token on every field and the account offer moved to the end, where it costs one checkbox.

Cart & Checkout396 lines1 dep
Open the full page for this block

Discount Offer Modal

The offer popup with four rules applied: triggered by intent, a decline button of equal weight, a dismissal that is remembered, and the terms on its face.

Cart & Checkout214 lines1 dep