Skip to content

CountdownTimer

final class Phui\Components\CountdownTimer

A prefix, a falling time and a postfix. Starts from seconds when it mounts and decrements once a second, clearing its interval when it unmounts. Takes no focus and emits nothing, so drive the end of the countdown from your own timer and unmount the component when it is done.

A countdown reading "Session expires in 1m 34s"

php
use Phui\Components\CountdownTimer;
use Phui\Nodes\Node;

Node::when(
    $this->expiring,
    CountdownTimer::mount()->props(seconds: 90, prefix: 'Expires in'),
);

Props

PropTypeDefaultDescription
secondsint60Where the countdown starts, read once on mount.
prefixstring|StyledString'Remaining:'Text before the time.
postfixstring|StyledString'...'Text appended to the time.

The time is formatted 1h 2m 3s, dropping the hours below an hour and the minutes below a minute.

Colours

Phui\Components\Colours\CountdownTimerColours

ColourPalette defaultUsed for
timeaccentThe remaining time. The prefix is left unstyled.

Released under the MIT License.