Modern TypeScript Progress Bar Library – BProgress
It generates a slim, animated progress bar at the top of the viewport, showing your users that something is happening in the background, like a page transition or a data fetch.
This can help manage user expectations during asynchronous operations and make the application feel more responsive.
1. Install BProgress using your preferred package manager:
# Yarn $ yarn add @bprogress/core # NPM $ npm install @bprogress/core # PNPM $ pnpm install @bprogress/core # BUN $ bun add @bprogress/core
2. Import the library and CSS styles in your JavaScript application:
import '@bprogress/core/css';
import { BProgress } from '@bprogress/core'; 3. If you prefer not to use a package manager, you can link to the library directly from a CDN in your HTML.
<link rel="stylesheet" type="text/css" href="https://unpkg.com/@bprogress/core/dist/index.css" />
<script type="module">
import { BProgress } from 'https://unpkg.com/@bprogress/core/dist/index.js';
// Your code here
</script> 4. Start & complete the progress bar.
// Start the progress bar BProgress.start(); // Complete the progress bar BProgress.done();
5. Available options to customize the progress bar.
'ltr' or 'rtl').BProgress.configure({
minimum: 0.08,
maximum: 1,
template: `<div class="bar"><div class="peg"></div></div>
<div class="spinner"><div class="spinner-icon"></div></div>
<div class="indeterminate"><div class="inc"></div><div class="dec"></div></div>`,
easing: 'linear',
positionUsing: 'width',
speed: 200,
trickle: true,
trickleSpeed: 200,
showSpinner: true,
indeterminate: false,
indeterminateSelector: '.indeterminate',
barSelector: '.bar',
spinnerSelector: '.spinner',
parent: 'body',
direction: 'ltr',
}); 6. Full API Methods
7. Here’s a common usage pattern for a fetch request:
function fetchData() {
BProgress.start();
fetch('/api/data')
.then(response => response.json())
.then(data => {
// process data
})
.catch(error => {
console.error('Error fetching data:', error);
})
.finally(() => {
BProgress.done();
});
} 8. BProgress uses CSS custom properties for easy theming without JavaScript configuration:
:root {
--bprogress-color: #ff6b35; /* Progress bar color */ --bprogress-height: 3px; /* Bar thickness */ --bprogress-spinner-size: 20px; /* Spinner dimensions */ --bprogress-spinner-animation-duration: 500ms; /* Spinner speed */ --bprogress-spinner-border-size: 3px; /* Spinner border width */ --bprogress-box-shadow: 0 0 15px var(--bprogress-color); /* Glow effect */ --bprogress-z-index: 99999; /* Stacking context */ --bprogress-spinner-top: 20px; /* Spinner position */ --bprogress-spinner-right: 20px;
} Q: How do I prevent the progress bar from completing too quickly on fast connections?
A: Use the minimum configuration option to ensure the progress bar displays for a minimum duration, and consider implementing artificial delays with setTimeout before calling done(). We typically set a minimum 300ms display time for better user perception.
Q: Is it possible to have multiple progress bars on the same page?
A: BProgress follows a singleton pattern by design, but you can create multiple instances by using different parent containers and custom selectors. Configure each instance with unique barSelector, spinnerSelector, and parent options.
Q: How do I handle progress bars for file uploads with actual progress data?
A: Use the set() method with progress values from upload events. Monitor the XMLHttpRequest.upload.onprogress event and call BProgress.set(loaded / total) to reflect actual upload progress rather than using the automatic trickle functionality.
The post Modern TypeScript Progress Bar Library – BProgress appeared first on CSS Script.
Spoilers of course follow for The Boys Season 5, Episode 7.With Prime Video's The Boys…
FORT WAYNE, Ind. (WOWO) — After President Trump signaled support for suspending the 18-cent federal…
INDIANAPOLIS, Ind. (WOWO) — Katherine Legge will become the first woman to try and complete…
The U.S. Capitol is pictured on March 3, 2026. (Photo by Jennifer Shutt/States Newsroom)WASHINGTON —…
The U.S. Capitol is pictured on March 3, 2026. (Photo by Jennifer Shutt/States Newsroom)WASHINGTON —…
The U.S. Capitol is pictured on March 3, 2026. (Photo by Jennifer Shutt/States Newsroom)WASHINGTON —…
This website uses cookies.