Time Tracker
<sl-time-tracker> | SlTimeTracker
A flexible stopwatch and timer component with start/stop controls, supporting stopwatch and timer modes, and optional auto-start behavior.
Time Tracker
A time tracker with stopwatch and countdown timer with start/stop controls.
Use mode="stopwatch" to count up or mode="timer" to count down.
Default Stopwatch
Timer Mode
Auto Start
Start from Initial Time (Auto Start)
Custom Control
<h3>Default Stopwatch</h3> <sl-time-tracker> <span slot="label">Duration</span> </sl-time-tracker> <h3>Timer Mode</h3> <sl-time-tracker mode="timer" targetDuration="10"> <span slot="label">Countdown (10s)</span> </sl-time-tracker> <h3>Auto Start</h3> <sl-time-tracker mode="stopwatch" autoStart> <span slot="label">Auto Start Stopwatch</span> </sl-time-tracker> <h3>Start from Initial Time (Auto Start)</h3> <sl-time-tracker mode="stopwatch" initialTime="60"> <span slot="label">Starts from 60 seconds and runs automatically</span> </sl-time-tracker> <h3>Custom Control</h3> <sl-time-tracker id="myTracker" mode="stopwatch"> <span slot="label">Working time</span> <sl-button id="myTrackerBtn" slot="control" size="small" variant="success"> <sl-icon id="myTrackerIcon" name="mdi:play-circle-outline"></sl-icon> <span id="myTrackerText">Start</span> </sl-button> </sl-time-tracker> <script> const tracker = document.querySelector('#myTracker'); const btn = document.querySelector('#myTrackerBtn'); const icon = document.querySelector('#myTrackerIcon'); const text = document.querySelector('#myTrackerText'); let running = false; function update() { btn.variant = running ? 'danger' : 'success'; icon.name = running ? 'mdi:stop-circle-outline' : 'mdi:play-circle-outline'; text.textContent = running ? 'Stop' : 'Start'; } btn.addEventListener('click', () => { running ? tracker.stop() : tracker.start(); }); tracker.addEventListener('sl-start-time', () => { running = true; update(); }); tracker.addEventListener('sl-stop-time', () => { running = false; update(); }); </script>
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://v2-54-0.yoummday-theme.pages.dev/components/time-tracker/time-tracker.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://v2-54-0.yoummday-theme.pages.dev/components/time-tracker/time-tracker.js';
To import this component using a bundler:
import '@yoummday/ymmd-shoelace/dist/components/time-tracker/time-tracker.js';
To import this component as a React component:
import SlTimeTracker from '@yoummday/ymmd-shoelace/dist/react/time-tracker';
Slots
| Name | Description |
|---|---|
label
|
Optional slot for displaying a label above the time display (e.g. “Duration” or “Countdown”). |
control
|
Custom slot for the entire control (button area). Defaults to a start/stop icon button. |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
mode
|
Defines whether the component counts up (“stopwatch”) or down (“timer”). |
"stopwatch" | "timer"
|
- | |
targetDuration
|
The maximum duration in seconds for the timer (used for countdown or auto-stop). |
number
|
- | |
initialTime
|
Optional initial time in seconds to start the timer from (default: 0 for stopwatch, targetDuration for timer). When set, the timer will automatically start running. |
number
|
- | |
refreshInterval
|
The update interval in milliseconds (default: 1000). |
number
|
1000
|
|
autoStart
|
Automatically starts the timer when connected. |
boolean
|
false
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
sl-start-time |
onSlStartTime |
Emitted when the timer starts, providing the current time in seconds. |
CustomEvent
|
sl-stop-time |
onSlStopTime |
Emitted when the timer stops, providing the current time in seconds. |
CustomEvent
|
Learn more about events.