npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@magic-spells/cart-progress-bar

v0.2.1

Published

Cart progress bar web component for free shipping thresholds.

Readme

Cart Progress Bar

A beautiful, accessible cart progress bar web component for free shipping thresholds and e-commerce sites.

Live Demo

Features

  • 🎯 Smart Messaging - Template-based messages with flexible placeholder formats
  • 🎨 Simplified Theming - Just 5 CSS variables to control all colors and appearance
  • 📱 Responsive - Mobile-optimized with responsive breakpoints
  • Smooth Animations - Buttery smooth transitions and completion effects
  • 🔧 Easy Integration - Drop-in web component that works with any framework

Installation

npm install @magic-spells/cart-progress-bar

Basic Usage

<cart-progress-bar
	threshold="75.00"
	current="25.50"
	message-above="🎉 Congratulations! You've qualified for FREE shipping!"
	message-below="Add ${ amount } more for FREE shipping!">
	<p data-content-cart-progress-message>Add ${ amount } more for FREE shipping!</p>
	<progress-bar></progress-bar>
</cart-progress-bar>
@import '@magic-spells/cart-progress-bar/css/min';

JavaScript API

const progressBar = document.querySelector('cart-progress-bar');

// Set progress percentage directly
progressBar.setPercent(67);

// Update cart amount
progressBar.setCurrentAmount(45.5);

// Change threshold
progressBar.setThresholdAmount(100.0);

// Get current progress info
const info = progressBar.getProgress();
console.log(info.percent, info.isComplete, info.thresholdAmount);

// Update message templates
progressBar.setMessages('Almost there!', 'Only ${ amount } more to go!');

Cart Integration

The component automatically listens for cart data changes when placed inside a <cart-dialog> component from the @magic-spells/cart-panel package:

<cart-dialog>
	<cart-progress-bar threshold="75.00" message-below="Add ${ amount } more for FREE shipping!">
	</cart-progress-bar>
</cart-dialog>

When the cart-dialog emits a cart-dialog:data-changed event (typically from Shopify cart API updates), the progress bar will automatically update with the calculated cart subtotal.

Smart Pricing Logic

The progress bar uses intelligent pricing calculation:

  • Preferred: Uses calculated_subtotal from cart-panel (respects _ignore_price_in_subtotal property)
  • Fallback: Uses total_price for backwards compatibility
  • Includes: Bundle items that are hidden in cart but should count toward shipping threshold
  • Excludes: Gift items or promotions marked with _ignore_price_in_subtotal property

Attributes

| Attribute | Description | Example | | --------------- | ----------------------------------------- | ------------------------------ | | threshold | Threshold amount for free shipping | "75.00" | | current | Current cart amount | "25.50" | | message-above | Success message when threshold is reached | "🎉 FREE shipping unlocked!" | | message-below | Message template shown below the bar | "Add ${ amount } more!" |

Customization

Use CSS custom properties to customize the appearance:

cart-progress-bar {
	/* Core color customization */
	--cart-progress-section-bg: #f8f9fa;
	--cart-progress-section-color: #333;
	--cart-progress-bar-bg: #e9ecef;
	--cart-progress-bar-fill-before: #ff6b6b;
	--cart-progress-bar-fill-after: #28a745;

	/* Structure (optional) */
	--cart-progress-bar-height: 16px;
	--cart-progress-bar-border-radius: 8px;
}

Available CSS Custom Properties

Core Color Variables

| Property | Description | Default | | --------------------------------- | ------------------------------------ | ------------- | | --cart-progress-section-bg | Background color of entire component | transparent | | --cart-progress-section-color | Text/foreground color | #495057 | | --cart-progress-bar-bg | Background of progress bar track | #e9ecef | | --cart-progress-bar-fill-before | Fill color before reaching threshold | #28a745 | | --cart-progress-bar-fill-after | Fill color after reaching threshold | #007bff |

Structure Variables (Optional)

| Property | Description | Default | | --------------------------------------- | --------------------------------- | ------- | | --cart-progress-bar-height | Height of the progress bar | 12px | | --cart-progress-bar-border-radius | Border radius | 6px | | --cart-progress-bar-shadow | Box shadow for progress bar | inset 0 1px 2px rgba(0, 0, 0, 0.1) | | --cart-progress-bar-transition-duration | Animation transition duration | 0.3s |

Message Templates

Use placeholder formats in your message templates and include the currency symbol:

<cart-progress-bar
	message-above="🎉 FREE shipping unlocked!"
	message-below="You need ${ amount } more for free shipping!">
	<p data-content-cart-progress-message>You need ${ amount } more for free shipping!</p>
</cart-progress-bar>

Supported Placeholder Formats

  • { amount } - spaces around amount
  • {amount} - no spaces
  • [amount] - square brackets (with or without spaces)

Examples

<!-- Dollar amounts -->
<cart-progress-bar message-below="Add ${ amount } more for free shipping!">

<!-- Euro amounts -->
<cart-progress-bar message-below="Only €{amount} left to unlock free delivery!">

<!-- With square brackets -->
<cart-progress-bar message-below="Just £[amount] more to go!">

The component automatically:

  • Shows message-below when incomplete (with placeholder replaced with remaining amount)
  • Shows message-above when threshold is reached (success message)
  • Formats amounts as minimal decimal numbers (removes .00 for whole amounts)
  • Updates messages when amounts change
  • Switches between before/after progress bar colors based on completion status

States and Attributes

The component automatically sets attributes based on completion status:

  • complete="true" - When threshold is reached
  • complete="false" - When threshold is not reached

These attributes are used internally to switch between the "before" and "after" progress bar colors.

Browser Support

  • Chrome/Edge 88+
  • Firefox 85+
  • Safari 14+
  • All modern browsers with Custom Elements support

License

MIT License - see LICENSE file for details.