Components

Timer

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

Previews are drawn in the theme you made.

Edit it
tone
look
progress
size
scheme
direction

Countdown #

Tea
03:00
import { Bundles, Recipes, Timer, TimerSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// The time counted is the Bundle's Model; its ticks are Commands that read
// Effect's clock, so the count stays the clock's however late a tick lands.
// With a `duration` the root carries how much of it is counted, which the
// recipe's `progress: 'bar'` draws.
export default example({
  title: 'Countdown',
  slots: TimerSlots,
  recipe: Recipes.Timer,
  pins: { progress: 'bar' },
  state: Bundles.Timer.with({ id: 'tea', countdown: true, duration: 3 * 60_000 }),
  view: ({ style, model, onMessage, h }) =>
    Timer.view({ model, onMessage, label: 'Tea', units: ['minutes', 'seconds'], style }, h),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Stopwatch #

Lap
00:00:000
import { Bundles, Recipes, Timer, TimerSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// A stopwatch whose Model ticks every 10ms (`interval: 10`), so hundredths
// show; `words` renames the presses.
export default example({
  title: 'Stopwatch',
  slots: TimerSlots,
  recipe: Recipes.Timer,
  state: Bundles.Timer.with({ id: 'lap', interval: 10 }),
  view: ({ style, model, onMessage, h }) =>
    Timer.view(
      {
        model,
        onMessage,
        label: 'Lap',
        units: ['minutes', 'seconds', 'milliseconds'],
        words: { start: 'Go', restart: 'Again' },
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Tiles, without controls #

Launch in
02:00:00
import { Bundles, Recipes, Timer, TimerSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// A countdown in days, hours and minutes, each unit its own tile: the
// recipe's `look: 'tiles'`, over the same markup. With `controls: false` no
// presses are drawn, and the application sends `Pressed` itself.
export default example({
  title: 'Tiles, without controls',
  slots: TimerSlots,
  recipe: Recipes.Timer,
  pins: { look: 'tiles' },
  state: Bundles.Timer.with({ id: 'launch', countdown: true, duration: 2 * 86_400_000 }),
  view: ({ style, model, onMessage, h }) =>
    Timer.view(
      {
        model,
        onMessage,
        label: 'Launch in',
        units: ['days', 'hours', 'minutes'],
        controls: false,
        style,
      },
      h,
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Configure once #

Manche
00:00:000
import { Bundles, Recipes, Timer, TimerSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Tiles = Recipes.Timer.style({ look: 'tiles', tone: 'neutral' })

// What every timer of an application starts from: its look, its units and
// its words, said once. A preset is a named set over it, chosen at a use.
const AppTimer = Timer.configure({
  base: {
    style: Tiles,
    units: ['minutes', 'seconds'],
    words: { start: 'Commencer', pause: 'Pause', resume: 'Reprendre', reset: 'Remise à zéro' },
  },
  presets: { stopwatch: { units: ['minutes', 'seconds', 'milliseconds'] } },
})

export default example({
  title: 'Configure once',
  slots: TimerSlots,
  recipe: Recipes.Timer,
  state: Bundles.Timer.with({ id: 'round', interval: 10 }),
  view: ({ model, onMessage, h }) =>
    AppTimer.view({ model, onMessage, label: 'Manche', preset: 'stopwatch' }, h),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗