Skip to content
Brok UI

Loading…

No results

Shopping Cart

Open source

Cart pages — a list of editable line items with quantity steppers beside a sticky order-summary card with a promo field and totals that recompute live.

Preview

resources/views/blocks/shopping-cart-drawer.blade.php Blade
@props([
    'items'     => null,
    'currency'  => '$',
    'subtotal'  => null,
    'shipping'  => null,
    'note'      => false,
    'noteValue' => null,
])

@php
    $items ??= [
        ['name' => 'Aerolight Running Shoes', 'variant' => 'Slate / US 10', 'price' => 128.00, 'qty' => 1],
        ['name' => 'Merino Crew Socks (3-pack)', 'variant' => 'Charcoal / One Size', 'price' => 27.00, 'qty' => 2],
        ['name' => 'Everyday Tech Backpack', 'variant' => 'Olive / 22 L', 'price' => 149.00, 'qty' => 1],
    ];

    $computedSubtotal = $subtotal ?? array_reduce($items, fn ($c, $i) => $c + ($i['price'] * $i['qty']), 0.0);
    $computedItemCount = array_reduce($items, fn ($c, $i) => $c + $i['qty'], 0);
    $shippingLabel = $shipping ?? __('Free');
    $money = fn (float $a) => $currency.number_format($a, 2);
    $thumbTones = ['bg-muted', 'bg-accent', 'bg-secondary', 'bg-primary/10'];
@endphp

<div data-slot="cart-drawer" role="dialog" aria-modal="true" aria-label="{{ __('Shopping cart') }}" {{ $attributes->merge(['class' => 'fixed inset-0 z-50']) }}>
    <div class="absolute inset-0 bg-scrim/40" aria-hidden="true"></div>

    <aside class="absolute inset-y-0 end-0 flex w-full max-w-md flex-col bg-background shadow-xl" aria-labelledby="cart-drawer-title">
        <div class="flex items-center justify-between border-b border-border p-4">
            <div class="flex items-center gap-2">
                <h2 id="cart-drawer-title" class="text-base font-semibold tracking-tight text-foreground">{{ __('Your cart') }}</h2>
                <x-ui.badge variant="secondary">{{ $computedItemCount }}</x-ui.badge>
            </div>
            <x-ui.button type="button" variant="ghost" size="icon" aria-label="{{ __('Close') }}">
                <svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
            </x-ui.button>
        </div>

        <ul role="list" class="flex-1 divide-y divide-border overflow-y-auto">
            @foreach ($items as $index => $item)
                <li class="flex items-start gap-4 p-4">
                    <div class="size-16 shrink-0 rounded-md {{ $thumbTones[$index % count($thumbTones)] }}" aria-hidden="true"></div>
                    <div class="flex min-w-0 flex-1 flex-col gap-2">
                        <div class="flex items-start justify-between gap-4">
                            <div class="min-w-0">
                                <p class="truncate text-sm font-medium text-foreground">{{ __($item['name']) }}</p>
                                <p class="mt-0.5 truncate text-xs text-muted-foreground">{{ __($item['variant']) }}</p>
                                <p class="mt-0.5 text-xs text-muted-foreground">{{ $money($item['price']) }} {{ __('each') }}</p>
                            </div>
                            <span class="shrink-0 text-sm font-semibold text-foreground">{{ $money($item['price'] * $item['qty']) }}</span>
                        </div>
                        <div class="flex items-center justify-between gap-4">
                            <x-ui.number-field
                                variant="stepper"
                                size="sm"
                                :value="$item['qty']"
                                :min="1"
                                :max="10"
                                :label="__('Quantity for :name', ['name' => __($item['name'])])"
                            />
                            <x-ui.button type="button" variant="ghost" size="icon" class="size-7 text-muted-foreground hover:text-destructive" aria-label="{{ __('Remove') }} {{ __($item['name']) }}">
                                <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /><path d="M10 11v6M14 11v6" /></svg>
                            </x-ui.button>
                        </div>
                    </div>
                </li>
            @endforeach
        </ul>

        @if ($note)
            <div class="border-t border-border p-4">
                <x-ui.label for="cart-note" class="mb-2">{{ __('Order note') }}</x-ui.label>
                <x-ui.textarea id="cart-note" name="note" :rows="2" class="resize-none" placeholder="{{ __('Add a note to your order…') }}">{{ $noteValue }}</x-ui.textarea>
            </div>
        @endif

        <div class="border-t border-border p-4">
            <dl class="space-y-2 text-sm">
                <div class="flex items-center justify-between">
                    <dt class="text-muted-foreground">{{ __('Subtotal') }}</dt>
                    <dd class="font-medium text-foreground">{{ $money($computedSubtotal) }}</dd>
                </div>
                <div class="flex items-center justify-between">
                    <dt class="text-muted-foreground">{{ __('Shipping') }}</dt>
                    <dd class="font-medium text-foreground">{{ $shippingLabel }}</dd>
                </div>
            </dl>
            <x-ui.separator class="my-4" />
            <p class="mb-4 text-xs text-muted-foreground">{{ __('Free shipping on orders over $75') }}</p>
            <div class="space-y-2">
                <x-ui.button type="button" class="w-full">{{ __('Checkout') }}</x-ui.button>
                <x-ui.button type="button" variant="ghost" class="w-full">{{ __('View cart') }}</x-ui.button>
            </div>
        </div>
    </aside>
</div>

Installation

terminal
php artisan ui:add blocks/shopping-cart-drawer

Installs these dependencies automatically:

Registry contract

Install confidence

php artisan ui:add blocks/shopping-cart-drawer writes only the generated targets below. The CLI validates each file hash before writing and prompts before replacing local changes unless --force is used.

Version
1.2.2
License
open
Stability
stable
Contract
v1
Foundation
≥ 1.0.0
Type Generated target
blade resources/views/blocks/shopping-cart-drawer.blade.php

Registry dependencies

button badge separator number-field label textarea

Package dependencies

composer: jml/brok:^0.2

Use with AI

A brief for your coding agent: what the block is, the install command, how to render it, its props and the rules. Copy it, or open a prompt about this block in an assistant.

shopping-cart-drawer.md
# Brok UI block: Cart Drawer (`shopping-cart-drawer`)

A slide-over mini-cart drawer with a backdrop, scrollable line items with quantity steppers, an optional order-note field, and a totals footer with checkout actions.

Brok UI is a Laravel Blade registry. `ui:add` copies this block into the app as plain Blade the app owns; it composes installed `<brok:*>` primitives and semantic design tokens.

## Install

```bash
php artisan ui:add blocks/shopping-cart-drawer
```

## Render it

```blade
<x-blocks.shopping-cart-drawer />
```

## Props

- `items` (mixed|null, default `null`) — Cart line items with name, variant, price and quantity; null falls back to sample data.
- `currency` (string, default `$`) — Currency symbol or code used to format prices.
- `subtotal` (mixed|null, default `null`) — Precomputed subtotal; null computes it from the items.
- `shipping` (mixed|null, default `null`) — Shipping line label; null falls back to "Free".
- `note` (bool, default `false`) — Shows an optional order-note textarea.
- `note-value` (mixed|null, default `null`) — Initial value of the order-note textarea.

## Use when

- Showing a slide-over mini-cart drawer with quantity steppers and a totals footer, triggered from anywhere in the app.
- Wanting the cart to overlay the current page instead of navigating to a dedicated page.

## Avoid when

- Building a dedicated cart page; use shopping-cart-two-column, shopping-cart-table or shopping-cart-editorial instead.

## Rules

- Render the installed block with `<x-blocks.shopping-cart-drawer />` and pass data through its props; edit the copied file only for structural changes.
- Keep the semantic design tokens (`bg-background`, `text-muted-foreground`); never swap in raw colour utilities.
- Keep the `data-slot` attributes and the logical (start/end) spacing so the markup still mirrors under `dir="rtl"`.

## Links

- Docs: https://brokui.dev/blocks/shopping-cart-drawer
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/shopping-cart-drawer.json

Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.

Guidance

Use when

  • Showing a slide-over mini-cart drawer with quantity steppers and a totals footer, triggered from anywhere in the app.
  • Wanting the cart to overlay the current page instead of navigating to a dedicated page.

Avoid when

  • Building a dedicated cart page; use shopping-cart-two-column, shopping-cart-table or shopping-cart-editorial instead.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.
Anatomy
root cart-drawer

Usage

Render the block as a component, passing data where useful:

resources/views/welcome.blade.php Blade
<x-blocks.shopping-cart-drawer />

Built from primitives

Composes <brok:*> Semantic tokens Re-themeable RTL-ready

This block composes installed <brok:*> primitives and semantic design tokens only — it does not reimplement any primitive. Re-theme it (light, dark, admin, customer) by editing CSS variables; flip the preview to RTL to confirm it mirrors.

Source

The exact, editable file ui:add writes into your app. The preview above renders this same source — there are no preview-only blocks.

resources/views/blocks/shopping-cart-drawer.blade.php Blade
@props([
    'items'     => null,
    'currency'  => '$',
    'subtotal'  => null,
    'shipping'  => null,
    'note'      => false,
    'noteValue' => null,
])

@php
    $items ??= [
        ['name' => 'Aerolight Running Shoes', 'variant' => 'Slate / US 10', 'price' => 128.00, 'qty' => 1],
        ['name' => 'Merino Crew Socks (3-pack)', 'variant' => 'Charcoal / One Size', 'price' => 27.00, 'qty' => 2],
        ['name' => 'Everyday Tech Backpack', 'variant' => 'Olive / 22 L', 'price' => 149.00, 'qty' => 1],
    ];

    $computedSubtotal = $subtotal ?? array_reduce($items, fn ($c, $i) => $c + ($i['price'] * $i['qty']), 0.0);
    $computedItemCount = array_reduce($items, fn ($c, $i) => $c + $i['qty'], 0);
    $shippingLabel = $shipping ?? __('Free');
    $money = fn (float $a) => $currency.number_format($a, 2);
    $thumbTones = ['bg-muted', 'bg-accent', 'bg-secondary', 'bg-primary/10'];
@endphp

<div data-slot="cart-drawer" role="dialog" aria-modal="true" aria-label="{{ __('Shopping cart') }}" {{ $attributes->merge(['class' => 'fixed inset-0 z-50']) }}>
    <div class="absolute inset-0 bg-scrim/40" aria-hidden="true"></div>

    <aside class="absolute inset-y-0 end-0 flex w-full max-w-md flex-col bg-background shadow-xl" aria-labelledby="cart-drawer-title">
        <div class="flex items-center justify-between border-b border-border p-4">
            <div class="flex items-center gap-2">
                <h2 id="cart-drawer-title" class="text-base font-semibold tracking-tight text-foreground">{{ __('Your cart') }}</h2>
                <x-ui.badge variant="secondary">{{ $computedItemCount }}</x-ui.badge>
            </div>
            <x-ui.button type="button" variant="ghost" size="icon" aria-label="{{ __('Close') }}">
                <svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
            </x-ui.button>
        </div>

        <ul role="list" class="flex-1 divide-y divide-border overflow-y-auto">
            @foreach ($items as $index => $item)
                <li class="flex items-start gap-4 p-4">
                    <div class="size-16 shrink-0 rounded-md {{ $thumbTones[$index % count($thumbTones)] }}" aria-hidden="true"></div>
                    <div class="flex min-w-0 flex-1 flex-col gap-2">
                        <div class="flex items-start justify-between gap-4">
                            <div class="min-w-0">
                                <p class="truncate text-sm font-medium text-foreground">{{ __($item['name']) }}</p>
                                <p class="mt-0.5 truncate text-xs text-muted-foreground">{{ __($item['variant']) }}</p>
                                <p class="mt-0.5 text-xs text-muted-foreground">{{ $money($item['price']) }} {{ __('each') }}</p>
                            </div>
                            <span class="shrink-0 text-sm font-semibold text-foreground">{{ $money($item['price'] * $item['qty']) }}</span>
                        </div>
                        <div class="flex items-center justify-between gap-4">
                            <x-ui.number-field
                                variant="stepper"
                                size="sm"
                                :value="$item['qty']"
                                :min="1"
                                :max="10"
                                :label="__('Quantity for :name', ['name' => __($item['name'])])"
                            />
                            <x-ui.button type="button" variant="ghost" size="icon" class="size-7 text-muted-foreground hover:text-destructive" aria-label="{{ __('Remove') }} {{ __($item['name']) }}">
                                <svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /><path d="M10 11v6M14 11v6" /></svg>
                            </x-ui.button>
                        </div>
                    </div>
                </li>
            @endforeach
        </ul>

        @if ($note)
            <div class="border-t border-border p-4">
                <x-ui.label for="cart-note" class="mb-2">{{ __('Order note') }}</x-ui.label>
                <x-ui.textarea id="cart-note" name="note" :rows="2" class="resize-none" placeholder="{{ __('Add a note to your order…') }}">{{ $noteValue }}</x-ui.textarea>
            </div>
        @endif

        <div class="border-t border-border p-4">
            <dl class="space-y-2 text-sm">
                <div class="flex items-center justify-between">
                    <dt class="text-muted-foreground">{{ __('Subtotal') }}</dt>
                    <dd class="font-medium text-foreground">{{ $money($computedSubtotal) }}</dd>
                </div>
                <div class="flex items-center justify-between">
                    <dt class="text-muted-foreground">{{ __('Shipping') }}</dt>
                    <dd class="font-medium text-foreground">{{ $shippingLabel }}</dd>
                </div>
            </dl>
            <x-ui.separator class="my-4" />
            <p class="mb-4 text-xs text-muted-foreground">{{ __('Free shipping on orders over $75') }}</p>
            <div class="space-y-2">
                <x-ui.button type="button" class="w-full">{{ __('Checkout') }}</x-ui.button>
                <x-ui.button type="button" variant="ghost" class="w-full">{{ __('View cart') }}</x-ui.button>
            </div>
        </div>
    </aside>
</div>

Ownership & lifecycle

Owner, release state, review evidence and adoption for this item.
Owner
Platform UI (@JoshJML)
Current version
1.2.2
Status
Stable
License
open
Deprecation
Not deprecated
Contract
v1
Foundation
≥ 1.0.0