Skip to content
Brok UI

Loading…

No results

Clock Widget

Open source

Live clocks — an analog dial with arabic/roman/no numerals and a multi-city world clock.

Preview

resources/views/blocks/clock-widget-world.blade.php Blade
@props([
    'cities' => null,
])

@php
    // Each city carries a name and a UTC offset in hours. The local time for
    // every row is derived from one Date() instance in inline Alpine so the
    // whole list stays in lockstep on each tick.
    $cities ??= [
        ['name' => 'New York', 'offset' => -4],
        ['name' => 'London', 'offset' => 1],
        ['name' => 'Dubai', 'offset' => 4],
        ['name' => 'Tokyo', 'offset' => 9],
    ];

    $rows = [];
    foreach ($cities as $city) {
        $offset = (float) ($city['offset'] ?? 0);
        $sign = $offset >= 0 ? '+' : '−';
        $rows[] = [
            'name' => __($city['name'] ?? ''),
            'offset' => $offset,
            'label' => 'UTC' . $sign . rtrim(rtrim(number_format(abs($offset), 1, '.', ''), '0'), '.'),
        ];
    }
@endphp

<x-ui.card class="w-full max-w-[16rem] flex flex-col">
    <div
        x-data="{
            now: null,
            timer: null,
            init() {
                this.tick();
                this.timer = setInterval(() => this.tick(), 1000);
            },
            destroy() {
                clearInterval(this.timer);
            },
            tick() {
                this.now = new Date();
            },
            localFor(offset) {
                if (!this.now) return { hour: 0, minute: 0 };
                const utcMs = this.now.getTime() + this.now.getTimezoneOffset() * 60000;
                const local = new Date(utcMs + offset * 3600000);
                return { hour: local.getHours(), minute: local.getMinutes() };
            },
            timeLabel(offset) {
                const t = this.localFor(offset);
                return String(t.hour).padStart(2, '0') + ':' + String(t.minute).padStart(2, '0');
            },
            isDay(offset) {
                const h = this.localFor(offset).hour;
                return h >= 6 && h < 18;
            },
        }"
        role="img"
        aria-label="{{ __('World clock') }}"
        class="flex flex-col divide-y divide-border"
    >
        @foreach ($rows as $row)
            <div class="flex items-center justify-between gap-4 px-4 py-4">
                <div class="flex flex-col">
                    <span class="text-sm font-medium text-foreground">{{ $row['name'] }}</span>
                    <span class="text-xs text-muted-foreground">{{ $row['label'] }}</span>
                </div>

                <div class="flex items-center gap-2">
                    <span class="text-base font-semibold tabular-nums text-foreground" x-text="timeLabel({{ $row['offset'] }})">00:00</span>

                    {{-- Sun (daytime) --}}
                    <svg
                        x-show="isDay({{ $row['offset'] }})"
                        class="size-4 text-foreground"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="1.75"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        aria-hidden="true"
                    >
                        <circle cx="12" cy="12" r="4" />
                        <path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
                    </svg>

                    {{-- Moon (nighttime) --}}
                    <svg
                        x-show="!isDay({{ $row['offset'] }})"
                        class="size-4 text-muted-foreground"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="1.75"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        aria-hidden="true"
                    >
                        <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z" />
                    </svg>
                </div>
            </div>
        @endforeach
    </div>
</x-ui.card>

Installation

terminal
php artisan ui:add blocks/clock-widget-world

Installs these dependencies automatically:

Registry contract

Install confidence

php artisan ui:add blocks/clock-widget-world 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/clock-widget-world.blade.php

Registry dependencies

card

Package dependencies

composer: jml/brok:^0.2

npm: alpinejs

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.

clock-widget-world.md
# Brok UI block: Clock Widget World (`clock-widget-world`)

A world-clock widget card listing four cities, each row showing the city name and its UTC-offset label alongside the live local time and a sun or moon icon reflecting day or night, all computed from one local time instance in 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/clock-widget-world
```

## Render it

```blade
<x-blocks.clock-widget-world />
```

## Props

- `cities` (mixed|null, default `null`)

## Use when

- Listing several cities with their live local time, computed from one local time instance and each city's UTC offset.
- Showing a sun or moon icon per row to indicate day or night at that city's current time.

## Avoid when

- Use clock-widget-analog for a single analog dial instead of a multi-city list.

## Rules

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

  • Listing several cities with their live local time, computed from one local time instance and each city's UTC offset.
  • Showing a sun or moon icon per row to indicate day or night at that city's current time.

Avoid when

  • Use clock-widget-analog for a single analog dial instead of a multi-city list.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.

Usage

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

resources/views/welcome.blade.php Blade
<x-blocks.clock-widget-world />

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/clock-widget-world.blade.php Blade
@props([
    'cities' => null,
])

@php
    // Each city carries a name and a UTC offset in hours. The local time for
    // every row is derived from one Date() instance in inline Alpine so the
    // whole list stays in lockstep on each tick.
    $cities ??= [
        ['name' => 'New York', 'offset' => -4],
        ['name' => 'London', 'offset' => 1],
        ['name' => 'Dubai', 'offset' => 4],
        ['name' => 'Tokyo', 'offset' => 9],
    ];

    $rows = [];
    foreach ($cities as $city) {
        $offset = (float) ($city['offset'] ?? 0);
        $sign = $offset >= 0 ? '+' : '−';
        $rows[] = [
            'name' => __($city['name'] ?? ''),
            'offset' => $offset,
            'label' => 'UTC' . $sign . rtrim(rtrim(number_format(abs($offset), 1, '.', ''), '0'), '.'),
        ];
    }
@endphp

<x-ui.card class="w-full max-w-[16rem] flex flex-col">
    <div
        x-data="{
            now: null,
            timer: null,
            init() {
                this.tick();
                this.timer = setInterval(() => this.tick(), 1000);
            },
            destroy() {
                clearInterval(this.timer);
            },
            tick() {
                this.now = new Date();
            },
            localFor(offset) {
                if (!this.now) return { hour: 0, minute: 0 };
                const utcMs = this.now.getTime() + this.now.getTimezoneOffset() * 60000;
                const local = new Date(utcMs + offset * 3600000);
                return { hour: local.getHours(), minute: local.getMinutes() };
            },
            timeLabel(offset) {
                const t = this.localFor(offset);
                return String(t.hour).padStart(2, '0') + ':' + String(t.minute).padStart(2, '0');
            },
            isDay(offset) {
                const h = this.localFor(offset).hour;
                return h >= 6 && h < 18;
            },
        }"
        role="img"
        aria-label="{{ __('World clock') }}"
        class="flex flex-col divide-y divide-border"
    >
        @foreach ($rows as $row)
            <div class="flex items-center justify-between gap-4 px-4 py-4">
                <div class="flex flex-col">
                    <span class="text-sm font-medium text-foreground">{{ $row['name'] }}</span>
                    <span class="text-xs text-muted-foreground">{{ $row['label'] }}</span>
                </div>

                <div class="flex items-center gap-2">
                    <span class="text-base font-semibold tabular-nums text-foreground" x-text="timeLabel({{ $row['offset'] }})">00:00</span>

                    {{-- Sun (daytime) --}}
                    <svg
                        x-show="isDay({{ $row['offset'] }})"
                        class="size-4 text-foreground"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="1.75"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        aria-hidden="true"
                    >
                        <circle cx="12" cy="12" r="4" />
                        <path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
                    </svg>

                    {{-- Moon (nighttime) --}}
                    <svg
                        x-show="!isDay({{ $row['offset'] }})"
                        class="size-4 text-muted-foreground"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="1.75"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        aria-hidden="true"
                    >
                        <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z" />
                    </svg>
                </div>
            </div>
        @endforeach
    </div>
</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