FlexWait Documentation
A FlexWait can be created declaratively by adding the flexwait class to a <div>. Declarative FlexWaits are initialized in a hidden state and are controlled through their instance.
This overlay example uses the documented defaults except for mode, text, backdrop, and pointer blocking.
<section id="productResults">
<div id="productWait"
class="flexwait"
data-mode="overlay"
data-text="Loading products..."
data-backdrop="true"
data-block-interaction="true"></div>
<!-- Product content -->
</section>
const productWait = FlexWait.get("#productWait");
productWait.show();
try {
await loadProducts();
}
finally {
productWait.hide();
}
A FlexWait can also be created programmatically. Pass an Element, id, or selector as target. If no target is supplied, the component is appended to the document body.
const wait = FlexWait.create({
target: document.getElementById("productResults"),
mode: "overlay",
variant: "dots",
size: "large",
text: "Loading products...",
backdrop: true
});
wait.show();
Use an operation token when multiple asynchronous operations share one loader. Calling end() more than once on the same token is safe.
const productsOperation = wait.begin(); const filtersOperation = wait.begin(); loadProducts().finally(() => productsOperation.end()); loadFilters().finally(() => filtersOperation.end());
Use FlexWait.configure(<options object>) before initialization to change the defaults for FlexWaits created afterwards.
FlexWait.configure({
mode: "inline",
variant: "ring",
size: "medium",
thickness: "3px",
text: "",
textPosition: "below",
ariaLabel: "Loading",
animationDuration: 800,
showDelay: 150,
minimumVisibleDuration: 300,
timeout: 0,
backdrop: false,
blockInteraction: false,
styles: {
color: "currentColor",
trackColor: "rgba(0, 0, 0, 0.12)",
backdropColor: "rgba(255, 255, 255, 0.72)",
borderRadius: "8px",
zIndex: 1000,
cssClass: ""
}
});
Data-attributes configure an individual declarative FlexWait and override the corresponding default configuration.
| Attribute | Values | Description |
|---|---|---|
| class | flexwait |
|
| data-target-id | Element id |
|
| data-mode | inline, overlay, fullscreen |
|
| data-variant | ring, dots, bars, pulse, orbit |
|
| data-size | small, medium, large, or CSS length |
|
| data-thickness | CSS length |
|
| data-text | Text |
|
| data-text-position | below, right |
|
| data-aria-label | Text |
|
| data-animation-duration | Milliseconds, zero or greater |
|
| data-show-delay | Milliseconds, zero or greater |
|
| data-minimum-visible-duration | Milliseconds, zero or greater |
|
| data-timeout | Milliseconds, zero or greater |
|
| data-backdrop | true, false |
|
| data-block-interaction | true, false |
|
| styles | Visual options for an individual FlexWait. | |
| data-styles-color | CSS color |
|
| data-styles-track-color | CSS color |
|
| data-styles-backdrop-color | CSS color |
|
| data-styles-border-radius | CSS length |
|
| data-styles-z-index | Integer |
|
| data-styles-css-class | One or more CSS class names |
|
Designs
| Variant | Best suited for |
|---|---|
| ring | General-purpose loading. This is the default. |
| dots | Compact or conversational interfaces. |
| bars | Data processing or activity-oriented states. |
| pulse | Subtle inline and overlay feedback. |
| orbit | Prominent overlays and fullscreen waiting. |
Modes
| Mode | Behaviour |
|---|---|
| inline | Participates in the normal document flow and inherits the surrounding text color by default. |
| overlay | Covers its target. FlexWait temporarily gives a statically positioned target position: relative and restores the original inline value on destruction. |
| fullscreen | Covers the viewport and is appended to the document body. |
FlexWait respects prefers-reduced-motion by slowing animations and removing the opacity transition.
Events bubble from the FlexWait root. Every event exposes the instance as event.detail.instance.
| Event | Description |
|---|---|
| flexwait:show | Emitted when the visual loader is shown after any configured delay. |
| flexwait:hide | Emitted when the visual loader is hidden after its minimum visible duration. |
| flexwait:timeout | Emitted when the configured timeout expires, immediately before FlexWait requests hiding. |
| Method | Parameters and return value | Description |
|---|---|---|
| FlexWait.configure(options) |
|
Deep-merges options into the defaults used by FlexWaits created afterwards. |
| FlexWait.initialize() | Returns the array of registered instances. | Initializes every uninitialized element with the flexwait class. It is called on DOMContentLoaded. |
| FlexWait.create(options) |
|
Creates a hidden programmatic FlexWait and appends it to its target. |
| FlexWait.get(elementOrSelector) |
|
Retrieves an initialized declarative or programmatic instance. |
| myFlexWait.show() | Returns the same instance for chaining. | Marks the target busy immediately, then displays the loader after showDelay. |
| myFlexWait.hide() | Returns the same instance for chaining. | Cancels a pending show or hides a visible loader after minimumVisibleDuration. Direct hiding also clears active operation tokens. |
| myFlexWait.begin() | Returns an operation token with an idempotent end() method. | Shows the loader and increments its active-operation count. The loader hides after the last operation token ends. |
| myFlexWait.setText(text) | Returns the same instance for chaining. | Updates only the status text without rebuilding the loader or its host content. |
| myFlexWait.destroy() | Returns nothing. | Clears timers and busy state, restores target positioning when applicable, unregisters the instance, and removes its element. |