<label for="file">File progress:</label>
<progress id="file" max="100" value="70">70%</progress>
Progress Bar
Whakerexa provides both a native HTML <progress> element,
styled by wexa.css, and a JavaScript ProgressBar class
for managing dynamic progress updates in application workflows.
HTML element
A <progress> element renders a full-width bar.
Set max and value to indicate completion.
Always associate a <label> for accessibility.
Variables
Track and fill colors are controlled by theme variables:
| Variable | Role |
|---|---|
--progress-bg-color |
Track background (empty portion) |
--progress-fg-color |
Fill color (completed portion) |
ProgressBar JS class
The ProgressBar class manages a visual progress bar and supports
two operating modes: Managed mode, driven by application callbacks,
and Autonomous mode, using a RequestManager to poll
a target URL automatically.
Parameters
| Parameter | Type | Description |
|---|---|---|
updateCallback |
Function | Optional. Called periodically to fetch progress data (managed mode). |
completeCallback |
Function | Optional. Called when progress reaches 100%. |
requestManager |
Object | Optional. Instance of RequestManager for autonomous mode. |
targetUrl |
string | Optional. URL polled by POST in autonomous mode. |
domIds |
Object | IDs of the DOM elements to update: percent, text, header. |
intervalMs |
number | Optional. Refresh interval in milliseconds. Default: 1500. |
Behavior
- Calls
updateCallbackorRequestManager.send_post_request()every interval. - Updates DOM elements referenced by
domIds.percent,domIds.text,domIds.header. - Stops automatically when
percent >= 100, then callscompleteCallback.
Requirements
- A
<progress>element with the ID given indomIds.percent. - A
RequestManagerinstance (autonomous mode) or anupdateCallback(managed mode).
Minimal example
const bar = new ProgressBar({
updateCallback: async () => ({ percent: 50, text: 'Halfway', header: 'Demo' }),
domIds: { percent: 'my-bar', text: 'my-text', header: 'my-header' },
completeCallback: () => console.log('Done!')
});
bar.start();
Demo — Managed mode
The application provides an updateCallback that returns
{ percent, text, header }. The bar polls this callback
every intervalMs milliseconds until percent reaches 100.
Managed header
Managed text...
const bar = new ProgressBar({
updateCallback: async () => {
const p = parseInt(el.value, 10) + 10;
return { percent: p, text: `Processing... ${p}%`, header: 'In progress' };
},
domIds: {
percent: 'percent_progress-managed',
text: 'progress_text-managed',
header: 'progress_header-managed'
},
completeCallback: () => { msg.textContent = 'Done!'; },
intervalMs: 1000
});
bar.start();
Demo — Autonomous mode
The bar drives itself by sending POST requests to targetUrl
via a RequestManager and reading { percent, text, header }
from each response.
Autonomous header
Autonomous text...
const bar = new ProgressBar({
requestManager: new RequestManager(),
targetUrl: '/api/progress',
domIds: {
percent: 'percent-autonomous',
text: 'progress_text-autonomous',
header: 'progress_header-autonomous'
},
completeCallback: () => { msg.textContent = 'Done!'; },
intervalMs: 1000
});
bar.start();
The ProgressBar class is reusable across Whakerexa applications.
The same class operates in either mode depending on the constructor parameters supplied.