Skip to main content

Crate dioxus_nox_timer

Crate dioxus_nox_timer 

Source
Expand description

§dioxus-nox-timer

⚠️ Disclaimer: This crate was entirely generated by AI (Claude) as part of a personal learning project. It has not been battle-tested in production and may contain bugs or unsound abstractions. Use at your own risk and exercise extreme caution before depending on it in anything that matters.

Headless timer primitives for Dioxus applications: countdown and stopwatch hooks.

§Features

  • Wall-clock based — survives browser tab backgrounding (no setInterval drift)
  • Cross-platform — works on web (wasm32), desktop, iOS, and Android
  • Headless — no rendered components, just hooks and state machines

§Quick start

use dioxus::prelude::*;
use dioxus_nox_timer::*;

#[component]
fn RestTimer() -> Element {
    let (remaining, state, controls) = use_countdown(None);

    rsx! {
        div {
            // Recommended ARIA attributes for consumers:
            role: "timer",
            aria_live: "polite",
            "data-timer-state": match *state.read() {
                TimerState::Idle => "idle",
                TimerState::Running => "running",
                TimerState::Paused => "paused",
                TimerState::Complete => "complete",
            },
            p { "{format_duration(*remaining.read())}" }
            button { onclick: move |_| controls.start.call(90), "Start 90s" }
            button { onclick: move |_| controls.pause.call(()), "Pause" }
            button { onclick: move |_| controls.resume.call(()), "Resume" }
        }
    }
}

Structs§

CountdownControls
Controls returned by use_countdown.

Enums§

TimerState
Timer state machine.

Functions§

format_duration
Format seconds as M:SS or H:MM:SS.
use_countdown
Countdown timer hook.
use_stopwatch
Stopwatch hook — counts up from a start time.