Time Tracker
<wa-time-tracker>
Tracks elapsed time as a stopwatch or remaining time as a countdown.
Examples
Countdown
Use mode="timer" and provide a duration in seconds.
Auto start
auto-start begins tracking when the component connects. A supplied value alone does not start it.
Control with JavaScript
stop() preserves the current value so tracking can resume. Use reset() to restore zero for a stopwatch or duration for a countdown.
Custom control
Replace the default control with the control slot. Listen for lifecycle events or inspect running to synchronize it.
Completion
wa-complete fires when a timer reaches zero or a limited stopwatch reaches its duration.
tracker.addEventListener('wa-complete', () => { console.log('Tracking complete', tracker.value); });
Notes
duration="0"leaves a stopwatch unlimited. A countdown requires a positivedurationorvalue.- Use
intervalto change how often the display refreshes; it does not change elapsed time. - Provide
start-label,stop-label, andtime-labelwhen localized accessible labels are required. - The component exposes
:state(running)for state-dependent styling.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://cdn.yoummday.com/packages/@yoummday/webawesome/0.5.1/dist/components/time-tracker/time-tracker.js';
After installing Web Awesome via npm, import this component:
import '@yoummday/webawesome/dist/components/time-tracker/time-tracker.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/time-tracker/time-tracker.js';
To import this component for React 18 or below, use the following code:
import WaTimeTracker from '@yoummday/webawesome/dist/react/time-tracker/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
control
|
Replaces the default start and stop control. |
label
|
An optional label shown before the time. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
autoStartauto-start |
Starts tracking when the component connects.
Type
boolean
Default
false
|
|
disableddisabled |
Prevents the default control and
start() method from starting the tracker.
Type
boolean
Default
false
|
|
durationduration |
The countdown length or optional stopwatch limit, in seconds. A value of zero leaves a stopwatch unlimited.
Type
number
Default
0
|
|
intervalinterval |
How often the displayed value is refreshed, in milliseconds. Elapsed time remains based on the system clock.
Type
number
Default
1000
|
|
modemode |
Whether the tracker counts elapsed time up or remaining time down.
Type
TimeTrackerMode
Default
'stopwatch'
|
|
running |
Whether the tracker is currently running.
|
|
startLabelstart-label |
Accessible label for the default start control.
Type
string
Default
'Start'
|
|
stopLabelstop-label |
Accessible label for the default stop control.
Type
string
Default
'Stop'
|
|
timeLabeltime-label |
Accessible label for the time display. Defaults to a label based on
mode.
Type
string
Default
''
|
|
valuevalue |
The current elapsed or remaining time, in seconds.
Type
number | undefined
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
reset() |
Stops tracking and restores zero for a stopwatch or duration for a countdown. |
|
start() |
Starts or resumes tracking from the current value. | |
stop() |
Stops tracking and preserves the current value. |
Events
Learn more about events.
| Name | Description |
|---|---|
wa-complete |
Emitted when a countdown reaches zero or a stopwatch reaches its duration. |
wa-start |
Emitted when tracking starts. |
wa-stop |
Emitted when tracking stops, including when the configured duration completes. |
Custom States
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
running |
Applied while the tracker is running. |
:state(running)
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
control-button |
The default start and stop button. |
::part(control-button)
|
controls |
The control container. |
::part(controls)
|
label |
The label container. |
::part(label)
|
time |
The formatted time display. |
::part(time)
|
time-tracker |
The component's outer wrapper. |
::part(time-tracker)
|
base |
An alias for the component's outer wrapper. |
::part(base)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.