A timer that ticks in the browser: a ring with the time in the middle (a shift, a countdown, any stretch of time) and a small pill of it for a top bar.
<.timer id="shift" elapsed={@shift_seconds} running={@running} kicker="Register open"
kicker_paused="Paused" label="Register 01" on_toggle="shift_toggled">
<:actions>
<button phx-click={LedgerUI.Timer.toggle("shift")}>Pause</button>
<button phx-click={LedgerUI.Timer.add("shift", 900)}>+15 min</button>
</:actions>
</.timer>
<.timer id="break" direction="down" total={900} elapsed={0} color="warning" on_finish="break_over" />
<.timer id="mini" variant="mini" elapsed={@seconds} running={@running} label="Shift time" />The server owns the time (elapsed, running, total, direction); the LedgerUI.Timer
hook counts from there on a monotonic clock with no round trip, and a new value from the server
replaces what the browser counted. format is hms (03:12:45), hm (3h12) or hh:mm.
The timer is role="timer" named by label; the ticking text is not a live region. color
is the ring while it runs (nothing is added by default); paused is always warning.
Events (on_toggle, on_tick, on_finish) take an event name or a %JS{} and go to target.
Browser commands live in LedgerUI.Timer (pause/1, resume/1, toggle/1, add/2, and the
socket versions to push them from the server).
Summary
Functions
Attributes
id(:string) (required)elapsed(:integer) - Defaults to0.total(:integer) - Defaults to28800.seconds(:integer) - The same astotal(seconds={600}withdirection="down"is a ten minute countdown). Defaults tonil.running(:boolean) - Defaults totrue.direction(:string) - Defaults to"up". Must be one of"up", or"down".variant(:string) - Defaults to"ring". Must be one of"ring", or"mini".size(:string) - Defaults to"md". Must be one of"sm","md", or"lg".color(:string) - Defaults tonil.Must be one ofnil,"neutral","primary","secondary","info","success","warning", or"error".format(:string) - Defaults to"auto". Must be one of"auto","hms","hm", or"hh:mm".kicker(:string) - Defaults tonil.kicker_paused(:string) - Defaults tonil.label(:string) - Defaults tonil.stop_at_total(:boolean) - Defaults tofalse.on_toggle(:any) - Defaults tonil.on_tick(:any) - Defaults tonil.on_finish(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
actions- The controls under the ring (ringonly).caption- Replaces thelabelline under the time (ringonly).