StealThis .dev

Shopping Cart

Slide-out shopping cart drawer with item list, quantity controls, remove items, coupon code input, order summary, and checkout CTA. No dependencies.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

Shopping Cart

A slide-out cart drawer with product item list, +/− quantity controls, item removal with undo toast, coupon code input with validation, live order summary (subtotal, discount, shipping, total), and a checkout CTA button.

Features

  • Slide-in drawer from the right with backdrop overlay
  • Product items with thumbnail, name, variant, unit price, and quantity stepper
  • +/− quantity controls with min 1 enforcement; cart badge updates live
  • Remove item with animated slide-out and “Undo” toast (3 s)
  • Coupon code input: SAVE10 → 10% off, FREE → free shipping
  • Live order summary: subtotal, discount line, shipping, grand total
  • Empty cart state with browse button
  • Proceed to Checkout button with simulated loading

How it works

  1. Cart state is a JS array of { id, name, price, qty, image } objects
  2. renderCart() rebuilds the item list from state on every change
  3. recalcTotals() sums items, applies coupon discount, calculates shipping, and updates DOM
  4. Remove uses element.style.maxHeight animation then splice() on state array