Skip to content
Hazine

Floating Cart Pill

Pro

Fixed pill in a corner of the viewport with the item count and subtotal. Pressing it grows the pill in place into a compact panel with editable lines, a totals ledger and checkout.

How it differs. Trigger and panel are one surface that grows from pill to panel, with no overlay, backdrop or focus trap. It leaves the page while the cart is empty and takes an edge offset to clear page controls.

Install

pnpm dlx shadcn@latest add @hazine/mini-cart-floating-pill

Adds 2 files, 2 shadcn primitives (badge, button), 2 Hazine items (@hazine/heading, @hazine/use-controllable-state), 1 package (lucide-react), and the success token.

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": {
      "url": "https://api.hazine.dev/r/{name}.json",
      "headers": { "Authorization": "Bearer ${HAZINE_TOKEN}" }
    }
  }
}

Set HAZINE_TOKEN in your environment. The token comes with a Pro licence.

Props16

title
string = "Your cart"
headingLevel
HeadingLevel = 2
open
boolean
defaultOpen
boolean = false
onOpenChange
(open: boolean) => void
lines
CartLine[]
defaultLines
CartLine[] = DEFAULT_LINES
onLinesChange
(lines: CartLine[]) => void
freeShippingFrom
number = DEFAULT_FREE_SHIPPING_FROM
Subtotal from which shipping is free. Pass 0 for no threshold.
shippingCost
number = DEFAULT_SHIPPING_COST
Flat shipping rate charged below the threshold.
loading
boolean = false
Replaces lines and figures with skeletons and holds the checkout action.
placement
"bottom-end" | "bottom-start" = "bottom-end"
Corner of the viewport. Logical, so it mirrors in right-to-left layouts.
offset
{ block?: number; inline?: number }
Distance from the viewport edges in px. Raise block to clear a bottom bar or a chat button.
currency
string = "EUR"
locale
string = "en-US"
checkoutHref
string = "/checkout"

Also accepts every prop of Omit<React.ComponentProps<"div">, "title">.

Accessibility

Keyboard
Keyboard support for Floating Cart Pill
KeyEffect
Enter or Space on the pillExpands or collapses the panel. Focus stays on the button. Collapsing an empty cart removes the pill and returns focus to the element that had it before
Tab, Shift+TabMoves through the pill, then product link, decrease, increase and remove for each line, then checkout, and on into the page. With an empty cart the only stop after the pill is Keep shopping, which collapses the panel. Focus is not trapped
Enter or Space on Decrease or IncreaseChanges the quantity by 1. At a bound the button stays focusable and does nothing
Enter or Space on RemoveRemoves the line and moves focus to the line that takes its place, or to the empty state heading
Escape inside the panelCollapses the panel and moves focus to the pill. With an empty cart the pill leaves the page and focus returns to the element that had it before
Screen reader

Labelled section whose heading wraps a button with aria-expanded and aria-controls. The collapsed panel is inert. Lines are a list, quantity is a named group of two labelled buttons, the total sits in a status region, removal is announced, and a cart changed from the page while the pill is closed is announced with its count and subtotal.

  • Announces: {name} removed from cart.
  • Announces: Total {total}
  • Announces: {title}: {count} items, subtotal {subtotal}.
Reduced motion
The panel opens and closes at once, the chevron turns without a transition, and the spinner and skeletons stay still. Colour transitions remain.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies5

  • badge
  • button
  • @hazine/heading
  • @hazine/use-controllable-state
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped2

  • --success
  • --success-foreground

Added to your stylesheet in light and dark, unless you already define them.

Other takes on this3

The same question answered with a different structure.

  • mini carts

    Bottom sheet with two snap heights and the summary above the lines, so checkout is reachable at half height. Each drag (expand, collapse, dismiss) has a button equivalent.

    shadcn add @hazine/mini-cart-bottom-sheet

    Depends on button, drawer, @hazine/heading, @hazine/use-controllable-state, lucide-react

  • mini carts

    Non-modal popover on its trigger with no editing: only the newest lines are listed, older ones fold into one summed row that links to the cart, and the page behind stays usable.

    shadcn add @hazine/mini-cart-header-popover

    Depends on badge, button, popover, @hazine/heading, lucide-react

  • mini carts

    Modal side sheet with three fixed zones: header with count and shipping meter, scrolling lines, pinned subtotal footer. Focus is trapped while open and returns to the cart button.

    shadcn add @hazine/mini-cart-side-drawer

    Depends on button, sheet, @hazine/heading, @hazine/use-controllable-state, lucide-react

More in Carts and Checkout