Skip to content
Bladewell

<x-widget.clock>

Clock Blade component for Laravel and Livewire

Live clocks: digital and analog, world clocks across timezones, countdowns to a date, and a stopwatch or timer. First paint from the server, then they tick in the browser. Works inside Livewire components: they keep ticking, and a running stopwatch keeps running, through renders.

php artisan bladewell:add clock
Also adds
Button, Icon
Works with
Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+

Usage

In scripts

window.clock is available once the clock script has loaded. It runs stopwatches and timers. <x-widget.clock.stopwatch id="lap" />

JavaScript
clock.start('lap');
clock.pause('lap');
clock.reset('lap');

// A timer says when it's done.
document.addEventListener('clock:finished', (event) => console.log('Done:', event.target.id));

Livewire

Inside a Livewire component the clocks keep ticking through every render, and world clocks keep their offsets from the visitor. A countdown follows its :to, so moving the deadline in PHP moves it. A stopwatch or timer is the browser's alone and keeps running through renders; its props are read once, when it first appears, so give it a wire:key that changes to start a new one. Listen for clock:finished to call the component when a countdown or timer reaches zero.

Blade
<div x-on:clock:finished="$wire.timeUp()" class="space-y-6">
    <x-widget.clock :timezone="$user->timezone" seconds date />

    <x-widget.clock.countdown :to="$auction->ends_at" label="Bidding closes in" />

    <x-widget.clock.stopwatch mode="timer" :duration="$round->seconds" wire:key="round-{{ $round->id }}" />
</div>

Examples

Digital

timezone is required, so the time the server paints is the time the browser ticks on. For a user's own time, store their timezone and pass it, e.g. :timezone="$user->timezone". hour12, seconds and date add the rest.

Mumbai
New York Friday, November 20
London office
Show code
Blade
<div class="flex flex-wrap items-end gap-10">
    <x-widget.clock timezone="Asia/Kolkata" label="Mumbai" />
    <x-widget.clock timezone="America/New_York" label="New York" hour12 seconds date />
    <x-widget.clock timezone="Europe/London" label="London office" size="sm" />
</div>

Analog

A face with hands. numbers adds 12, 3, 6 and 9; seconds can be turned off for a calmer face. Screen readers get the time in words.

London
Tokyo
New York
Show code
Blade
<div class="flex flex-wrap items-end gap-10">
    <x-widget.clock.analog timezone="Europe/London" label="London" />
    <x-widget.clock.analog timezone="Asia/Tokyo" label="Tokyo" numbers />
    <x-widget.clock.analog timezone="America/New_York" label="New York" :seconds="false" size="sm" />
</div>

World

Several cities at once, each with how far ahead or behind the visitor it is, "Tomorrow" when the date has rolled over, and day or night.

  • London Same time
  • New York −5h
  • Mumbai +5h 30m
  • Tokyo +9h
Show code
Blade
<x-widget.clock.world class="w-full" :zones="[
    'London' => 'Europe/London',
    'New York' => 'America/New_York',
    'Mumbai' => 'Asia/Kolkata',
    'Tokyo' => 'Asia/Tokyo',
]" />

Countdown

Counts down to a date: launches, sale ends. The server's clock is the reference, so a wrong device clock doesn't matter. At zero it shows the done message, announces it, and fires clock:finished.

Launch in
2 days, 4 hours left

Show code
Blade
<x-widget.clock.countdown label="Launch in" :to="now()->addDays(2)->addHours(4)" done="We're live!" />

Countdown inline

variant="inline" sits in running text. Short ones suit one-time codes and sessions; this one ends in 15 seconds.

Sale ends in 5 hours, 12 minutes left

Your code expires in 15 seconds left

Show code
Blade
<div class="flex flex-col gap-3 text-sm">
    <p>Sale ends in <x-widget.clock.countdown variant="inline" :to="now()->addHours(5)->addMinutes(12)" label="Sale ends in" /></p>
    <p>Your code expires in <x-widget.clock.countdown variant="inline" :to="now()->addSeconds(15)" label="Code expires in" done="Code expired. Request a new one." /></p>
</div>

Stopwatch

mode="stopwatch" counts up; mode="timer" counts down from duration (in seconds), announces the end and fires clock:finished. Pause keeps the time; Reset starts over.

Lap time
0:00.0

Plank
1:30

Show code
Blade
<div class="flex flex-wrap items-start gap-12">
    <x-widget.clock.stopwatch label="Lap time" />
    <x-widget.clock.stopwatch mode="timer" :duration="90" label="Plank" done="Done. Take a break." />
</div>

Props

Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.

<x-widget.clock>

Prop Default Description
timezone Required Required: an IANA timezone like "Europe/London".
hour12 false 12-hour time with AM or PM, instead of 24-hour.
seconds false Shows the seconds as well.
date false A line under the time: "Friday, 27 September".
label null Small text above the time, e.g. the city.
size 'md' How big the time is: sm, md or lg.

<x-widget.clock.analog>

Prop Default Description
timezone Required Required: an IANA timezone like "Europe/London".
seconds true Draws a seconds hand.
numbers false Puts 12, 3, 6 and 9 on the face.
label null A caption under the face, e.g. the city.
size 'md' How big the face is: sm, md or lg.

<x-widget.clock.countdown>

Prop Default Description
to Required When it ends: a date string ("2026-12-31 23:59") in the app's timezone, or a Carbon/DateTime instance.
label 'Time left' Small text above the boxes (not shown inline), and the countdown's name for screen readers.
done "Time's up" Shown in place of the numbers, and announced, once it reaches zero.
variant 'boxes' boxes: a card per unit. inline: "2d 04h 12m 09s" in running text.
size 'md' How big the numbers are: sm, md or lg.

<x-widget.clock.stopwatch>

Prop Default Description
mode 'stopwatch' stopwatch counts up from zero; timer counts down from duration.
duration 60 Timer length in seconds, e.g. 1500 for 25 minutes.
label null Small text above the time, and its name for screen readers.
done "Time's up" Announced, and shown, when a timer reaches zero.
size 'md' How big the time is: sm, md or lg.

<x-widget.clock.world>

Prop Default Description
zones [] ['London' => 'Europe/London', 'Tokyo' => 'Asia/Tokyo'], or a list of ['label' => …, 'timezone' => …].
hour12 false 12-hour time with AM or PM, instead of 24-hour.
label 'World clocks' The list's name for screen readers.

Accessibility

All 6 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.

Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.

Source

What bladewell:add clock writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from the components it also adds , and the theme and base CSS.

resources/views/components/widget/clock/analog.blade.php Show
analog.blade.php
resources/views/components/widget/clock/countdown.blade.php Show
countdown.blade.php
resources/views/components/widget/clock/index.blade.php Show
index.blade.php
resources/views/components/widget/clock/stopwatch.blade.php Show
stopwatch.blade.php
resources/views/components/widget/clock/world.blade.php Show
world.blade.php
resources/js/widget/clock/index.js Show
index.js