Countdown

A recipe: the time left to a moment, or a timer, its digits rolling — a Number Ticker for each unit, the time from Temporal. No component of its own.

Usage

Usage

12Days
05Hours
30Minutes
00Seconds
import {  Component,  DestroyRef,  ViewEncapsulation,  afterNextRender,  computed,  inject,  signal,} from '@angular/core';import { ScFrame, ScNumberTicker } from '@semantic-components/ui';

How it is made

The time left is the target less now — Temporal.Now.instant(), read once a second by a timer of yours, in the browser (after the first render), stopped when the page goes. Split into days, hours, minutes and seconds, each is a Number Ticker with effect="roll" and [format]="{ minimumIntegerDigits: 2 }" (07, not 7). The unit names are your words, or the locale's (Intl.DisplayNames, type dateTimeField).

import { ScNumberTicker } from '@semantic-components/ui';
<div role="timer" aria-label="Time left until the launch">  @for (unit of units(); track unit.name) {    <span scNumberTicker effect="roll" [value]="unit.value"          [format]="{ minimumIntegerDigits: 2 }"></span>    <span>{{ unit.name }}</span>  }</div>

Accessibility

  • The digits sit in a role="timer" you name: a live region that is quiet — read when someone goes to it, not every second.
  • Screen readers get each Number Ticker's value, never the digits rolling; with reduced motion, the digits change at once.
  • The end is a status of yours («Time's up»): announced once.

Examples

Timer

0500

import {  Component,  DestroyRef,  ViewEncapsulation,  computed,  inject,  signal,} from '@angular/core';import { ScButton, ScNumberTicker } from '@semantic-components/ui';

RTL

12يوم
05الساعات
30الدقائق
00الثواني
import { Dir } from '@angular/cdk/bidi';import {  Component,  DestroyRef,  LOCALE_ID,  ViewEncapsulation,  afterNextRender,  computed,  inject,  signal,