Countdown
DCountdown renders daisyUI's CSS-only
To the new year
30
days 7
hours 43
minutes 36
seconds Computed at render time (16:16:23) — press refresh-style below to re-render.
<DCountdown Days="@((_newYear - DateTime.Now).Days)"
Hours="@((_newYear - DateTime.Now).Hours)"
Minutes="@((_newYear - DateTime.Now).Minutes)"
Seconds="@((_newYear - DateTime.Now).Seconds)" />
<button class="btn btn-sm btn-primary mt-2" @onclick="() => { }">Re-render</button>
@code {
private static readonly DateTime _newYear = new(DateTime.Now.Year + 1, 1, 1);
}Custom units— Only pass the units you want; labels can be dropped too
100
days
7
42
59
seconds <DCountdown Days="100" />
<DCountdown Hours="7" Minutes="42" ShowLabels="false" />
<DCountdown Seconds="59" />Live ticking (interactive modes)— Uses a plain System.Threading.Timer + InvokeAsync — no library JS
1
0
<DCountdown Minutes="@(_tick / 60)" Seconds="@(_tick % 60)" ShowLabels="false" />
<button class="btn btn-outline btn-sm" @onclick="StartTick">Start 60 s timer</button>
@code {
private int _tick = 60;
private System.Threading.Timer? _timer;
private void StartTick()
{
_timer?.Dispose();
_tick = 60;
_timer = new System.Threading.Timer(async _ =>
{
await InvokeAsync(() =>
{
_tick = Math.Max(0, _tick - 1);
if (_tick == 0) { _timer?.Dispose(); }
StateHasChanged();
});
}, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
}
public void Dispose() => _timer?.Dispose();
}API
DCountdown
Parameters
| Name | Type | Default | Binding | Description |
|---|---|---|---|---|
| Days | int? | — | — | Days to display (omit to hide the unit). |
| Hours | int? | — | — | Hours to display (omit to hide the unit). |
| Minutes | int? | — | — | Minutes to display (omit to hide the unit). |
| Seconds | int? | — | — | Seconds to display (omit to hide the unit). |
| ShowLabels | bool | True | — | Whether to print "days/hours/minutes/seconds" labels after each unit. |
| Class | string | — | — | Additional CSS classes appended to the component's computed daisyUI classes. |
| Style | string | — | — | Inline styles applied to the root element. |