Skip to content
Brok UI

Loading…

No results

Frequently Bought

Open source

Cross-sell upsells — frequently-bought-together bundles with a toggleable, live-totalling checklist.

Preview

resources/views/blocks/frequently-bought-together.blade.php Blade
@props([
    'heading' => 'Frequently bought together',
    'items' => null,
])

@php
    $items ??= [
        ['name' => 'Aero running shoes', 'price' => 128.0, 'checked' => true],
        ['name' => 'Performance ankle socks (3-pack)', 'price' => 18.0, 'checked' => true],
        ['name' => 'Quick-dry shoe spray', 'price' => 12.0, 'checked' => true],
    ];

    // Pre-encode the seed for Alpine so prices/labels are server-rendered and
    // the running total works before hydration. currency formatting happens in JS.
    $itemsJson = \Illuminate\Support\Js::from(
        collect($items)->map(fn ($item) => [
            'name' => __($item['name']),
            'price' => (float) $item['price'],
            'checked' => (bool) ($item['checked'] ?? true),
        ])->values()
    );
@endphp

<x-ui.section
    data-slot="frequently-bought-01"
    space="lg" {{ $attributes }}
>
    <div
        class="mx-auto max-w-3xl px-4"
        x-data="{
            items: {{ $itemsJson }},
            get count() {
                return this.items.filter((item) => item.checked).length;
            },
            get total() {
                return this.items
                    .filter((item) => item.checked)
                    .reduce((sum, item) => sum + item.price, 0);
            },
            money(value) {
                return new Intl.NumberFormat(undefined, {
                    style: 'currency',
                    currency: 'USD',
                }).format(value);
            },
        }"
    >
        <x-ui.card class="p-6 sm:p-8">
            <h2 class="text-lg font-semibold tracking-tight text-foreground">
                {{ __($heading) }}
            </h2>

            {{-- Top row: thumbnails joined by + … = total + add-all CTA --}}
            <div class="mt-6 flex flex-col gap-6 lg:flex-row lg:items-center lg:justify-between">
                <ul role="list" class="flex flex-wrap items-center gap-4">
                    @foreach ($items as $index => $item)
                        @if (! $loop->first)
                            <li aria-hidden="true" class="text-2xl font-normal text-muted-foreground">+</li>
                        @endif
                        <li>
                            <span
                                class="block size-20 rounded-lg bg-muted ring-1 ring-border transition-opacity"
                                x-bind:class="items[{{ $index }}].checked ? 'opacity-100' : 'opacity-30'"
                                role="img"
                                aria-label="{{ __($item['name']) }}"
                            ></span>
                        </li>
                    @endforeach

                    <li aria-hidden="true" class="text-2xl font-normal text-muted-foreground">=</li>

                    <li class="flex flex-col">
                        <span class="text-sm font-medium uppercase tracking-wide text-muted-foreground">{{ __('Total') }}</span>
                        <span class="text-lg font-semibold tracking-tight text-foreground" x-text="money(total)">{{ '$158.00' }}</span>
                    </li>
                </ul>

                <x-ui.button
                    type="button"
                    size="lg"
                    class="w-full shrink-0 lg:w-auto"
                    x-bind:disabled="count === 0"
                >
                    <span x-text="count === 1
                        ? '{{ __('Add 1 item to cart') }}'
                        : '{{ __('Add :count items to cart') }}'.replace(':count', count)"
                    >{{ __('Add :count items to cart', ['count' => count($items)]) }}</span>
                </x-ui.button>
            </div>

            {{-- Checklist: toggle each item; total/count update live --}}
            <ul role="list" class="mt-8 flex flex-col gap-4 border-t border-border pt-6">
                @foreach ($items as $index => $item)
                    <li class="flex items-center gap-4">
                        <label
                            class="flex min-w-0 flex-1 cursor-pointer items-center gap-4"
                            for="frequently-bought-01-item-{{ $index }}"
                        >
                            <x-ui.checkbox
                                id="frequently-bought-01-item-{{ $index }}"
                                x-model="items[{{ $index }}].checked"
                                :checked="$item['checked'] ?? true"
                                aria-label="{{ $loop->first ? __('This item: :name', ['name' => __($item['name'])]) : __('Add :name', ['name' => __($item['name'])]) }}"
                            />

                            <span class="block size-12 shrink-0 rounded-md bg-muted ring-1 ring-border" aria-hidden="true"></span>

                            <span class="min-w-0 flex-1">
                                <span class="block truncate text-sm font-medium text-foreground">
                                    @if ($loop->first)
                                        {{ __('This item: :name', ['name' => __($item['name'])]) }}
                                    @else
                                        {{ __('+ :name', ['name' => __($item['name'])]) }}
                                    @endif
                                </span>
                            </span>
                        </label>

                        @if ($loop->first)
                            <x-ui.badge variant="secondary" class="shrink-0">{{ __('Save :amount', ['amount' => '$14']) }}</x-ui.badge>
                        @endif

                        <span class="shrink-0 text-sm font-semibold tabular-nums text-foreground" x-text="money(items[{{ $index }}].price)">
                            {{ '$'.number_format((float) $item['price'], 2) }}
                        </span>
                    </li>
                @endforeach
            </ul>
        </x-ui.card>
    </div>
</x-ui.section>

Installation

terminal
php artisan ui:add blocks/frequently-bought-together

Installs these dependencies automatically:

Registry contract

Install confidence

php artisan ui:add blocks/frequently-bought-together 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.0.5
License
open
Stability
stable
Contract
v1
Foundation
≥ 1.0.0
Type Generated target
blade resources/views/blocks/frequently-bought-together.blade.php

Registry dependencies

badge button card checkbox section

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.

frequently-bought-together.md
# Brok UI block: Frequently Bought (`frequently-bought-together`)

A 'Frequently bought together' cross-sell panel inside a card: a top row of product thumbnails joined by plus signs that equal a running total beside a primary 'Add all to cart' button, over a checklist where each item has a checkbox (checked by default), a thumbnail, its name ('This item:' for the first, '+' for the rest), and price. A 'Save' badge highlights the bundle discount; unchecking an item dims its plus thumbnail and live-updates the total and the cart button count via inline Alpine.

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/frequently-bought-together
```

## Render it

```blade
<x-blocks.frequently-bought-together />
```

## Props

- `heading` (string, default `Frequently bought together`)
- `items` (mixed|null, default `null`)

## Use when

- Cross-selling related products as a 'Frequently bought together' panel with thumbnails joined by plus signs and a running total.
- Letting a shopper uncheck an item to remove it from the bundle, live-updating the total and Add all to cart button.

## Avoid when

- Use bundle-builder-box for a configurable build-your-own bundle instead of a fixed cross-sell set.

## Rules

- Render the installed block with `<x-blocks.frequently-bought-together />` 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/frequently-bought-together
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/frequently-bought-together.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

  • Cross-selling related products as a 'Frequently bought together' panel with thumbnails joined by plus signs and a running total.
  • Letting a shopper uncheck an item to remove it from the bundle, live-updating the total and Add all to cart button.

Avoid when

  • Use bundle-builder-box for a configurable build-your-own bundle instead of a fixed cross-sell set.

Anti-patterns

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

Usage

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

resources/views/welcome.blade.php Blade
<x-blocks.frequently-bought-together />

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/frequently-bought-together.blade.php Blade
@props([
    'heading' => 'Frequently bought together',
    'items' => null,
])

@php
    $items ??= [
        ['name' => 'Aero running shoes', 'price' => 128.0, 'checked' => true],
        ['name' => 'Performance ankle socks (3-pack)', 'price' => 18.0, 'checked' => true],
        ['name' => 'Quick-dry shoe spray', 'price' => 12.0, 'checked' => true],
    ];

    // Pre-encode the seed for Alpine so prices/labels are server-rendered and
    // the running total works before hydration. currency formatting happens in JS.
    $itemsJson = \Illuminate\Support\Js::from(
        collect($items)->map(fn ($item) => [
            'name' => __($item['name']),
            'price' => (float) $item['price'],
            'checked' => (bool) ($item['checked'] ?? true),
        ])->values()
    );
@endphp

<x-ui.section
    data-slot="frequently-bought-01"
    space="lg" {{ $attributes }}
>
    <div
        class="mx-auto max-w-3xl px-4"
        x-data="{
            items: {{ $itemsJson }},
            get count() {
                return this.items.filter((item) => item.checked).length;
            },
            get total() {
                return this.items
                    .filter((item) => item.checked)
                    .reduce((sum, item) => sum + item.price, 0);
            },
            money(value) {
                return new Intl.NumberFormat(undefined, {
                    style: 'currency',
                    currency: 'USD',
                }).format(value);
            },
        }"
    >
        <x-ui.card class="p-6 sm:p-8">
            <h2 class="text-lg font-semibold tracking-tight text-foreground">
                {{ __($heading) }}
            </h2>

            {{-- Top row: thumbnails joined by + … = total + add-all CTA --}}
            <div class="mt-6 flex flex-col gap-6 lg:flex-row lg:items-center lg:justify-between">
                <ul role="list" class="flex flex-wrap items-center gap-4">
                    @foreach ($items as $index => $item)
                        @if (! $loop->first)
                            <li aria-hidden="true" class="text-2xl font-normal text-muted-foreground">+</li>
                        @endif
                        <li>
                            <span
                                class="block size-20 rounded-lg bg-muted ring-1 ring-border transition-opacity"
                                x-bind:class="items[{{ $index }}].checked ? 'opacity-100' : 'opacity-30'"
                                role="img"
                                aria-label="{{ __($item['name']) }}"
                            ></span>
                        </li>
                    @endforeach

                    <li aria-hidden="true" class="text-2xl font-normal text-muted-foreground">=</li>

                    <li class="flex flex-col">
                        <span class="text-sm font-medium uppercase tracking-wide text-muted-foreground">{{ __('Total') }}</span>
                        <span class="text-lg font-semibold tracking-tight text-foreground" x-text="money(total)">{{ '$158.00' }}</span>
                    </li>
                </ul>

                <x-ui.button
                    type="button"
                    size="lg"
                    class="w-full shrink-0 lg:w-auto"
                    x-bind:disabled="count === 0"
                >
                    <span x-text="count === 1
                        ? '{{ __('Add 1 item to cart') }}'
                        : '{{ __('Add :count items to cart') }}'.replace(':count', count)"
                    >{{ __('Add :count items to cart', ['count' => count($items)]) }}</span>
                </x-ui.button>
            </div>

            {{-- Checklist: toggle each item; total/count update live --}}
            <ul role="list" class="mt-8 flex flex-col gap-4 border-t border-border pt-6">
                @foreach ($items as $index => $item)
                    <li class="flex items-center gap-4">
                        <label
                            class="flex min-w-0 flex-1 cursor-pointer items-center gap-4"
                            for="frequently-bought-01-item-{{ $index }}"
                        >
                            <x-ui.checkbox
                                id="frequently-bought-01-item-{{ $index }}"
                                x-model="items[{{ $index }}].checked"
                                :checked="$item['checked'] ?? true"
                                aria-label="{{ $loop->first ? __('This item: :name', ['name' => __($item['name'])]) : __('Add :name', ['name' => __($item['name'])]) }}"
                            />

                            <span class="block size-12 shrink-0 rounded-md bg-muted ring-1 ring-border" aria-hidden="true"></span>

                            <span class="min-w-0 flex-1">
                                <span class="block truncate text-sm font-medium text-foreground">
                                    @if ($loop->first)
                                        {{ __('This item: :name', ['name' => __($item['name'])]) }}
                                    @else
                                        {{ __('+ :name', ['name' => __($item['name'])]) }}
                                    @endif
                                </span>
                            </span>
                        </label>

                        @if ($loop->first)
                            <x-ui.badge variant="secondary" class="shrink-0">{{ __('Save :amount', ['amount' => '$14']) }}</x-ui.badge>
                        @endif

                        <span class="shrink-0 text-sm font-semibold tabular-nums text-foreground" x-text="money(items[{{ $index }}].price)">
                            {{ '$'.number_format((float) $item['price'], 2) }}
                        </span>
                    </li>
                @endforeach
            </ul>
        </x-ui.card>
    </div>
</x-ui.section>

Ownership & lifecycle

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