Skip to content
Brok UI

Loading…

No results

Metrics

Open source

Dashboard analytics cards — a traffic trend card with a range control, a KPI performance row with sparklines, a sales-by-channel distribution, a weekly-traffic heatmap and a spending breakdown with a segmented bar and table.

Preview

1 of 5

resources/views/blocks/metrics-traffic.blade.php Blade
@props([
    'heading' => 'API Traffic',
    'subheading' => 'Last 30 days performance',
    'range' => 'Last 90 days',
    'value' => '128.4k',
    'unit' => 'requests',
    'trend' => '+12.4%',
    'series' => null,
    'categories' => null,
    'height' => 300,
])

@php
    $series ??= [
        [
            'name' => __('Requests'),
            'data' => [62, 71, 68, 80, 76, 91, 88, 102, 97, 110, 121, 128],
        ],
    ];

    $categories ??= [
        __('Wk 1'), __('Wk 2'), __('Wk 3'), __('Wk 4'),
        __('Wk 5'), __('Wk 6'), __('Wk 7'), __('Wk 8'),
        __('Wk 9'), __('Wk 10'), __('Wk 11'), __('Wk 12'),
    ];

    $trendVariant = str_starts_with(trim((string) $trend), '-') ? 'destructive' : 'success';

    // Only chart-type-specific options here; palette, grid, axis, legend and
    // tooltip are themed from design tokens by the <x-ui.chart> wrapper.
    $options = [
        'stroke' => ['curve' => 'smooth', 'width' => 2],
        'fill' => [
            'type' => 'gradient',
            'gradient' => ['opacityFrom' => 0.4, 'opacityTo' => 0.05, 'stops' => [0, 90, 100]],
        ],
        'markers' => ['size' => 0, 'hover' => ['size' => 5]],
        'dataLabels' => ['enabled' => false],
        'legend' => ['show' => count($series) > 1, 'position' => 'bottom'],
        'xaxis' => ['categories' => $categories],
    ];
@endphp

<x-ui.card {{ $attributes->merge(['class' => 'w-full']) }}>
    <x-ui.card.header>
        <div class="flex flex-wrap items-start justify-between gap-4">
            <div class="space-y-2">
                <x-ui.card.title>{{ __($heading) }}</x-ui.card.title>
                <x-ui.card.description>{{ __($subheading) }}</x-ui.card.description>
            </div>

            <x-ui.button variant="outline" size="sm">
                {{ __($range) }}
                <svg
                    aria-hidden="true"
                    class="size-4 ms-2"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="2"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                >
                    <path d="m6 9 6 6 6-6" />
                </svg>
            </x-ui.button>
        </div>
    </x-ui.card.header>

    <x-ui.card.content>
        <div class="mb-6 flex flex-wrap items-baseline gap-x-4 gap-y-2">
            <span class="text-3xl font-semibold tracking-tight tabular-nums text-foreground">{{ $value }}</span>
            <span class="text-sm text-muted-foreground">{{ __($unit) }}</span>
            @if ($trend)
                <x-ui.badge :variant="$trendVariant" class="ms-2">{{ $trend }}</x-ui.badge>
            @endif
        </div>

        <x-ui.chart
            type="area"
            :series="$series"
            :options="$options"
            :height="$height"
            :label="__($heading)"
        />
    </x-ui.card.content>
</x-ui.card>

Installation

terminal
php artisan ui:add blocks/metrics-traffic

Installs these dependencies automatically:

Registry contract

Install confidence

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

Registry dependencies

card button badge chart

Package dependencies

composer: jml/brok:^0.2

npm: apexcharts

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.

metrics-traffic.md
# Brok UI block: Metric Traffic (`metrics-traffic`)

An analytics dashboard card showing API/request traffic over a range, with a headline value, a trend badge, a range selector and a token-themed area chart.

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/metrics-traffic
```

## Render it

```blade
<x-blocks.metrics-traffic />
```

## Props

- `heading` (string, default `API Traffic`) — Card title.
- `subheading` (string, default `Last 30 days performance`) — Supporting copy under the heading.
- `range` (string, default `Last 90 days`) — Label shown on the range-selector button; display only, not wired to reload data.
- `value` (string, default `128.4k`) — Headline metric value.
- `unit` (string, default `requests`) — Unit label shown next to the headline value.
- `trend` (string, default `+12.4%`) — Delta label vs. the previous period; a leading – renders the destructive badge variant.
- `series` (mixed|null, default `null`) — ApexCharts series data; null falls back to a sample 12-week series.
- `categories` (mixed|null, default `null`) — X-axis category labels; null falls back to sample week labels.
- `height` (int, default `300`) — Chart height in pixels.

## Use when

- Showing a single headline metric, such as API or request traffic, over time as a token-themed area chart with a trend badge.
- Offering a range-selector affordance above the chart alongside the headline value.

## Avoid when

- Needing several metrics with sparklines or share bars side-by-side instead of one time-series chart; use metrics-kpis or metrics-channels.

## Rules

- Render the installed block with `<x-blocks.metrics-traffic />` 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/metrics-traffic
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/metrics-traffic.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 single headline metric, such as API or request traffic, over time as a token-themed area chart with a trend badge.
  • Offering a range-selector affordance above the chart alongside the headline value.

Avoid when

  • Needing several metrics with sparklines or share bars side-by-side instead of one time-series chart; use metrics-kpis or metrics-channels.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.
Anatomy
header with title and range button headline value with unit and trend badge area chart

Usage

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

resources/views/welcome.blade.php Blade
<x-blocks.metrics-traffic />

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/metrics-traffic.blade.php Blade
@props([
    'heading' => 'API Traffic',
    'subheading' => 'Last 30 days performance',
    'range' => 'Last 90 days',
    'value' => '128.4k',
    'unit' => 'requests',
    'trend' => '+12.4%',
    'series' => null,
    'categories' => null,
    'height' => 300,
])

@php
    $series ??= [
        [
            'name' => __('Requests'),
            'data' => [62, 71, 68, 80, 76, 91, 88, 102, 97, 110, 121, 128],
        ],
    ];

    $categories ??= [
        __('Wk 1'), __('Wk 2'), __('Wk 3'), __('Wk 4'),
        __('Wk 5'), __('Wk 6'), __('Wk 7'), __('Wk 8'),
        __('Wk 9'), __('Wk 10'), __('Wk 11'), __('Wk 12'),
    ];

    $trendVariant = str_starts_with(trim((string) $trend), '-') ? 'destructive' : 'success';

    // Only chart-type-specific options here; palette, grid, axis, legend and
    // tooltip are themed from design tokens by the <x-ui.chart> wrapper.
    $options = [
        'stroke' => ['curve' => 'smooth', 'width' => 2],
        'fill' => [
            'type' => 'gradient',
            'gradient' => ['opacityFrom' => 0.4, 'opacityTo' => 0.05, 'stops' => [0, 90, 100]],
        ],
        'markers' => ['size' => 0, 'hover' => ['size' => 5]],
        'dataLabels' => ['enabled' => false],
        'legend' => ['show' => count($series) > 1, 'position' => 'bottom'],
        'xaxis' => ['categories' => $categories],
    ];
@endphp

<x-ui.card {{ $attributes->merge(['class' => 'w-full']) }}>
    <x-ui.card.header>
        <div class="flex flex-wrap items-start justify-between gap-4">
            <div class="space-y-2">
                <x-ui.card.title>{{ __($heading) }}</x-ui.card.title>
                <x-ui.card.description>{{ __($subheading) }}</x-ui.card.description>
            </div>

            <x-ui.button variant="outline" size="sm">
                {{ __($range) }}
                <svg
                    aria-hidden="true"
                    class="size-4 ms-2"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="2"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                >
                    <path d="m6 9 6 6 6-6" />
                </svg>
            </x-ui.button>
        </div>
    </x-ui.card.header>

    <x-ui.card.content>
        <div class="mb-6 flex flex-wrap items-baseline gap-x-4 gap-y-2">
            <span class="text-3xl font-semibold tracking-tight tabular-nums text-foreground">{{ $value }}</span>
            <span class="text-sm text-muted-foreground">{{ __($unit) }}</span>
            @if ($trend)
                <x-ui.badge :variant="$trendVariant" class="ms-2">{{ $trend }}</x-ui.badge>
            @endif
        </div>

        <x-ui.chart
            type="area"
            :series="$series"
            :options="$options"
            :height="$height"
            :label="__($heading)"
        />
    </x-ui.card.content>
</x-ui.card>

Ownership & lifecycle

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