Components

Timer

A countdown or a stopwatch, started, paused, resumed and reset, each unit its own part.

tone
look
progress
size
scheme
direction

Countdown #

Tea
03:00
export const TimerStyle = forSlots(TimerSlots)(Recipes.Timer({ progress: 'bar' }))

/** The time counted is the timer's Model, folded with `Timer.update`; its ticks are its Commands. */
export const timerCountdown = <Message>(
  style: NamedStyle<typeof TimerSlots>,
  model: Timer.Model,
  onMessage: (message: Timer.Message) => Message,
  h: HtmlBuilder<Message>,
): Html => Timer.view({ model, onMessage, label: 'Tea', units: ['minutes', 'seconds'], style }, h)

Stopwatch #

Lap
00:00:000
/** A stopwatch whose Model ticks every 10ms (`Timer.init({ id, interval: 10 })`), so hundredths show. */
export const timerStopwatch = <Message>(
  style: NamedStyle<typeof TimerSlots>,
  model: Timer.Model,
  onMessage: (message: Timer.Message) => Message,
  h: HtmlBuilder<Message>,
): Html =>
  Timer.view(
    {
      model,
      onMessage,
      label: 'Lap',
      units: ['minutes', 'seconds', 'milliseconds'],
      labels: { start: 'Go', restart: 'Again' },
      style,
    },
    h,
  )

Usage

Each example above names the function that drew it, over the theme module Create a theme writes. The preview passes it the style picked above instead of its default.

The recipe ↗This code ↗