@magic-spells/cart-progress-bar 0.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -32
- package/dist/cart-progress-bar.css +15 -36
- package/dist/cart-progress-bar.esm.js +197 -273
- package/dist/cart-progress-bar.min.css +2 -1
- package/dist/cart-progress-bar.min.js +1 -1
- package/package.json +19 -26
- package/dist/cart-progress-bar.cjs.js +0 -333
- package/dist/cart-progress-bar.cjs.js.map +0 -1
- package/dist/cart-progress-bar.esm.js.map +0 -1
- package/dist/cart-progress-bar.js +0 -339
- package/dist/cart-progress-bar.js.map +0 -1
- package/dist/cart-progress-bar.scss +0 -124
- package/src/cart-progress-bar.js +0 -332
- package/src/cart-progress-bar.scss +0 -124
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
A beautiful, accessible cart progress bar web component for free shipping thresholds and e-commerce sites.
|
|
4
4
|
|
|
5
|
-
[**Live Demo**](https://magic-spells.github.io/cart
|
|
5
|
+
[**Live Demo**](https://magic-spells.github.io/cart/)
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- 🎯 **Smart Messaging** - Template-based messages with
|
|
10
|
-
- 🎨 **Simplified Theming** - Just
|
|
9
|
+
- 🎯 **Smart Messaging** - Template-based messages with an `[amount]` placeholder
|
|
10
|
+
- 🎨 **Simplified Theming** - Just 6 CSS variables to control all colors and appearance
|
|
11
11
|
- 📱 **Responsive** - Mobile-optimized with responsive breakpoints
|
|
12
12
|
- ⚡ **Smooth Animations** - Buttery smooth transitions and completion effects
|
|
13
13
|
- 🔧 **Easy Integration** - Drop-in web component that works with any framework
|
|
@@ -18,6 +18,32 @@ A beautiful, accessible cart progress bar web component for free shipping thresh
|
|
|
18
18
|
npm install @magic-spells/cart-progress-bar
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
The package is **ESM only** — there is no CommonJS build and `exports` declares no
|
|
22
|
+
`require` condition. Import it once, anywhere in your module graph; it registers
|
|
23
|
+
`<cart-progress-bar>` and `<progress-bar>` as a side effect.
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import '@magic-spells/cart-progress-bar';
|
|
27
|
+
// or, if you need the classes:
|
|
28
|
+
import { CartProgressBar, ProgressBar } from '@magic-spells/cart-progress-bar';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The stylesheet is extracted into its own file rather than injected by the JS, so
|
|
32
|
+
load it yourself:
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
@import '@magic-spells/cart-progress-bar/css'; /* unminified */
|
|
36
|
+
@import '@magic-spells/cart-progress-bar/css/min'; /* minified */
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For a plain `<script>` tag with no build step, use the minified UMD bundle, which
|
|
40
|
+
exposes the global `CartProgressBar`:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<link rel="stylesheet" href="node_modules/@magic-spells/cart-progress-bar/dist/cart-progress-bar.min.css" />
|
|
44
|
+
<script src="node_modules/@magic-spells/cart-progress-bar/dist/cart-progress-bar.min.js"></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
21
47
|
## Basic Usage
|
|
22
48
|
|
|
23
49
|
```html
|
|
@@ -25,16 +51,12 @@ npm install @magic-spells/cart-progress-bar
|
|
|
25
51
|
threshold="75.00"
|
|
26
52
|
current="25.50"
|
|
27
53
|
message-above="🎉 Congratulations! You've qualified for FREE shipping!"
|
|
28
|
-
message-below="Add $
|
|
29
|
-
<p data-content-cart-progress-message>Add $
|
|
54
|
+
message-below="Add $[amount] more for FREE shipping!">
|
|
55
|
+
<p data-content-cart-progress-message>Add $[amount] more for FREE shipping!</p>
|
|
30
56
|
<progress-bar></progress-bar>
|
|
31
57
|
</cart-progress-bar>
|
|
32
58
|
```
|
|
33
59
|
|
|
34
|
-
```css
|
|
35
|
-
@import '@magic-spells/cart-progress-bar/css/min';
|
|
36
|
-
```
|
|
37
|
-
|
|
38
60
|
## JavaScript API
|
|
39
61
|
|
|
40
62
|
```javascript
|
|
@@ -54,21 +76,21 @@ const info = progressBar.getProgress();
|
|
|
54
76
|
console.log(info.percent, info.isComplete, info.thresholdAmount);
|
|
55
77
|
|
|
56
78
|
// Update message templates
|
|
57
|
-
progressBar.setMessages('Almost there!', 'Only $
|
|
79
|
+
progressBar.setMessages('Almost there!', 'Only $[amount] more to go!');
|
|
58
80
|
```
|
|
59
81
|
|
|
60
82
|
## Cart Integration
|
|
61
83
|
|
|
62
|
-
The component automatically listens for cart data changes when placed inside a `<cart-
|
|
84
|
+
The component automatically listens for cart data changes when placed inside a `<cart-panel>` component from the `@magic-spells/cart-panel` package:
|
|
63
85
|
|
|
64
86
|
```html
|
|
65
|
-
<cart-
|
|
66
|
-
<cart-progress-bar threshold="75.00" message-below="Add $
|
|
87
|
+
<cart-panel>
|
|
88
|
+
<cart-progress-bar threshold="75.00" message-below="Add $[amount] more for FREE shipping!">
|
|
67
89
|
</cart-progress-bar>
|
|
68
|
-
</cart-
|
|
90
|
+
</cart-panel>
|
|
69
91
|
```
|
|
70
92
|
|
|
71
|
-
When the cart-
|
|
93
|
+
When the cart-panel emits a `cart-panel:data-changed` event (typically from Shopify cart API updates), the progress bar will automatically update with the calculated cart subtotal. Point it at a different ancestor with `listen-selector` and `listen-event`.
|
|
72
94
|
|
|
73
95
|
### Smart Pricing Logic
|
|
74
96
|
|
|
@@ -86,7 +108,10 @@ The progress bar uses intelligent pricing calculation:
|
|
|
86
108
|
| `threshold` | Threshold amount for free shipping | `"75.00"` |
|
|
87
109
|
| `current` | Current cart amount | `"25.50"` |
|
|
88
110
|
| `message-above` | Success message when threshold is reached | `"🎉 FREE shipping unlocked!"` |
|
|
89
|
-
| `message-below` | Message template shown below the bar | `"Add $
|
|
111
|
+
| `message-below` | Message template shown below the bar | `"Add $[amount] more!"` |
|
|
112
|
+
| `money-format` | Shopify money format string; uses `{{amount}}` placeholders and formats the amount that fills `[amount]` in the messages | `"${{amount}}"` |
|
|
113
|
+
| `listen-selector` | `closest()` selector for the element to listen on | `"cart-panel"` (default) |
|
|
114
|
+
| `listen-event` | Event name to listen for on that element | `"cart-panel:data-changed"` (default) |
|
|
90
115
|
|
|
91
116
|
## Customization
|
|
92
117
|
|
|
@@ -95,8 +120,6 @@ Use CSS custom properties to customize the appearance:
|
|
|
95
120
|
```css
|
|
96
121
|
cart-progress-bar {
|
|
97
122
|
/* Core color customization */
|
|
98
|
-
--cart-progress-section-bg: #f8f9fa;
|
|
99
|
-
--cart-progress-section-color: #333;
|
|
100
123
|
--cart-progress-bar-bg: #e9ecef;
|
|
101
124
|
--cart-progress-bar-fill-before: #ff6b6b;
|
|
102
125
|
--cart-progress-bar-fill-after: #28a745;
|
|
@@ -104,6 +127,7 @@ cart-progress-bar {
|
|
|
104
127
|
/* Structure (optional) */
|
|
105
128
|
--cart-progress-bar-height: 16px;
|
|
106
129
|
--cart-progress-bar-border-radius: 8px;
|
|
130
|
+
--cart-progress-bar-transition-duration: 0.3s;
|
|
107
131
|
}
|
|
108
132
|
```
|
|
109
133
|
|
|
@@ -113,8 +137,6 @@ cart-progress-bar {
|
|
|
113
137
|
|
|
114
138
|
| Property | Description | Default |
|
|
115
139
|
| --------------------------------- | ------------------------------------ | ------------- |
|
|
116
|
-
| `--cart-progress-section-bg` | Background color of entire component | `transparent` |
|
|
117
|
-
| `--cart-progress-section-color` | Text/foreground color | `#495057` |
|
|
118
140
|
| `--cart-progress-bar-bg` | Background of progress bar track | `#e9ecef` |
|
|
119
141
|
| `--cart-progress-bar-fill-before` | Fill color before reaching threshold | `#28a745` |
|
|
120
142
|
| `--cart-progress-bar-fill-after` | Fill color after reaching threshold | `#007bff` |
|
|
@@ -125,38 +147,43 @@ cart-progress-bar {
|
|
|
125
147
|
| --------------------------------------- | --------------------------------- | ------- |
|
|
126
148
|
| `--cart-progress-bar-height` | Height of the progress bar | `12px` |
|
|
127
149
|
| `--cart-progress-bar-border-radius` | Border radius | `6px` |
|
|
128
|
-
| `--cart-progress-bar-shadow` | Box shadow for progress bar | `inset 0 1px 2px rgba(0, 0, 0, 0.1)` |
|
|
129
150
|
| `--cart-progress-bar-transition-duration` | Animation transition duration | `0.3s` |
|
|
130
151
|
|
|
152
|
+
Two more are set for you and are not meant to be overridden:
|
|
153
|
+
`--cart-progress-percent` (the fill width, written by JavaScript) and
|
|
154
|
+
`--cart-progress-bar-fill-current` (switched between the before/after colors by the
|
|
155
|
+
`complete` attribute).
|
|
156
|
+
|
|
131
157
|
## Message Templates
|
|
132
158
|
|
|
133
|
-
Use placeholder
|
|
159
|
+
Use the `[amount]` placeholder in your message templates and include the currency symbol:
|
|
134
160
|
|
|
135
161
|
```html
|
|
136
162
|
<cart-progress-bar
|
|
137
163
|
message-above="🎉 FREE shipping unlocked!"
|
|
138
|
-
message-below="You need $
|
|
139
|
-
<p data-content-cart-progress-message>You need $
|
|
164
|
+
message-below="You need $[amount] more for free shipping!">
|
|
165
|
+
<p data-content-cart-progress-message>You need $[amount] more for free shipping!</p>
|
|
140
166
|
</cart-progress-bar>
|
|
141
167
|
```
|
|
142
168
|
|
|
143
|
-
### Supported Placeholder
|
|
169
|
+
### Supported Placeholder Format
|
|
144
170
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
171
|
+
`[amount]` — square brackets, with or without spaces inside (`[amount]`, `[ amount ]`). Square
|
|
172
|
+
brackets avoid clashing with Liquid's `{{ }}` and JavaScript template literals, so curly-brace
|
|
173
|
+
forms are **not** substituted in messages. (`money-format` is the one place `{{amount}}` is used,
|
|
174
|
+
and it formats the number that fills `[amount]`.)
|
|
148
175
|
|
|
149
176
|
### Examples
|
|
150
177
|
|
|
151
178
|
```html
|
|
152
179
|
<!-- Dollar amounts -->
|
|
153
|
-
<cart-progress-bar message-below="Add $
|
|
180
|
+
<cart-progress-bar message-below="Add $[amount] more for free shipping!">
|
|
154
181
|
|
|
155
182
|
<!-- Euro amounts -->
|
|
156
|
-
<cart-progress-bar message-below="Only €
|
|
183
|
+
<cart-progress-bar message-below="Only €[amount] left to unlock free delivery!">
|
|
157
184
|
|
|
158
|
-
<!--
|
|
159
|
-
<cart-progress-bar message-below="Just £[amount] more to go!">
|
|
185
|
+
<!-- Spaces inside the brackets work too -->
|
|
186
|
+
<cart-progress-bar message-below="Just £[ amount ] more to go!">
|
|
160
187
|
```
|
|
161
188
|
|
|
162
189
|
The component automatically:
|
|
@@ -183,6 +210,36 @@ These attributes are used internally to switch between the "before" and "after"
|
|
|
183
210
|
- Safari 14+
|
|
184
211
|
- All modern browsers with Custom Elements support
|
|
185
212
|
|
|
213
|
+
## Development
|
|
214
|
+
|
|
215
|
+
- `npm run build` — production build to `dist/` via `scripts/build.mjs` (Vite +
|
|
216
|
+
Rolldown, Lightning CSS, Terser). Emits exactly four files: the unminified ESM
|
|
217
|
+
bundle, the minified UMD bundle, and the plain and minified stylesheets.
|
|
218
|
+
- `npm run dev` — watch build into `demo/dist/`, plus a Vite dev server for
|
|
219
|
+
`demo/` at [http://localhost:3001](http://localhost:3001) with live reload.
|
|
220
|
+
`host: true`, so the demo also answers on the LAN address Vite prints.
|
|
221
|
+
- `npm run lint` / `npm run format` — ESLint / Prettier.
|
|
222
|
+
|
|
223
|
+
`scripts/build.mjs` is the whole build configuration (`configFile: false`) —
|
|
224
|
+
there is no `vite.config.js`. Sourcemaps are emitted for the demo only; the
|
|
225
|
+
published `dist/` carries none, because Rolldown inlines `sourcesContent` and
|
|
226
|
+
would ship `src/` a second time inside them.
|
|
227
|
+
|
|
228
|
+
### Build output
|
|
229
|
+
|
|
230
|
+
| File | Format |
|
|
231
|
+
| ----------------------------- | ----------------------------------------- |
|
|
232
|
+
| `cart-progress-bar.esm.js` | Unminified ESM |
|
|
233
|
+
| `cart-progress-bar.min.js` | Minified UMD, global `CartProgressBar` |
|
|
234
|
+
| `cart-progress-bar.css` | Plain stylesheet |
|
|
235
|
+
| `cart-progress-bar.min.css` | Minified stylesheet |
|
|
236
|
+
|
|
186
237
|
## License
|
|
187
238
|
|
|
188
239
|
MIT License - see LICENSE file for details.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
<p align="center">
|
|
244
|
+
Made by <a href="https://github.com/coryschulz">Cory Schulz</a>
|
|
245
|
+
</p>
|
|
@@ -1,69 +1,48 @@
|
|
|
1
1
|
cart-progress-bar {
|
|
2
2
|
--cart-progress-bar-height: 12px;
|
|
3
3
|
--cart-progress-bar-border-radius: 6px;
|
|
4
|
-
--cart-progress-bar-
|
|
5
|
-
--cart-progress-bar-transition-duration: 0.3s;
|
|
6
|
-
--cart-progress-section-bg: transparent;
|
|
7
|
-
--cart-progress-section-color: #495057;
|
|
4
|
+
--cart-progress-bar-transition-duration: .3s;
|
|
8
5
|
--cart-progress-bar-bg: #e9ecef;
|
|
9
6
|
--cart-progress-bar-fill-before: #28a745;
|
|
10
7
|
--cart-progress-bar-fill-after: #007bff;
|
|
11
8
|
--cart-progress-percent: 0%;
|
|
12
9
|
--cart-progress-bar-fill-current: var(--cart-progress-bar-fill-before);
|
|
13
|
-
display: block;
|
|
14
10
|
width: 100%;
|
|
15
|
-
|
|
16
|
-
background-color: var(--cart-progress-section-bg);
|
|
17
|
-
color: var(--cart-progress-section-color);
|
|
11
|
+
display: block;
|
|
18
12
|
}
|
|
13
|
+
|
|
19
14
|
cart-progress-bar p[data-content-cart-progress-message] {
|
|
20
|
-
color: inherit;
|
|
21
15
|
transition: opacity var(--cart-progress-bar-transition-duration) ease;
|
|
22
16
|
}
|
|
23
|
-
|
|
17
|
+
|
|
18
|
+
cart-progress-bar[complete="true"] p[data-content-cart-progress-message] {
|
|
24
19
|
font-weight: 600;
|
|
25
20
|
}
|
|
26
|
-
|
|
21
|
+
|
|
22
|
+
cart-progress-bar[complete="false"] {
|
|
27
23
|
--cart-progress-bar-fill-current: var(--cart-progress-bar-fill-before);
|
|
28
24
|
}
|
|
29
|
-
|
|
25
|
+
|
|
26
|
+
cart-progress-bar[complete="true"] {
|
|
30
27
|
--cart-progress-bar-fill-current: var(--cart-progress-bar-fill-after);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
progress-bar {
|
|
34
|
-
display: block;
|
|
35
31
|
width: 100%;
|
|
36
32
|
height: var(--cart-progress-bar-height);
|
|
37
33
|
background-color: var(--cart-progress-bar-bg);
|
|
38
34
|
border-radius: var(--cart-progress-bar-border-radius);
|
|
39
|
-
|
|
40
|
-
overflow: hidden;
|
|
35
|
+
display: block;
|
|
41
36
|
position: relative;
|
|
37
|
+
overflow: hidden;
|
|
42
38
|
}
|
|
39
|
+
|
|
43
40
|
progress-bar .progress-bar-fill {
|
|
44
41
|
height: 100%;
|
|
45
42
|
width: var(--cart-progress-percent);
|
|
46
43
|
background-color: var(--cart-progress-bar-fill-current);
|
|
47
44
|
border-radius: var(--cart-progress-bar-border-radius);
|
|
48
|
-
transition: width var(--cart-progress-bar-transition-duration) ease,
|
|
49
|
-
|
|
50
|
-
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.1) 75%, transparent 75%, transparent);
|
|
51
|
-
background-size: 12px 12px;
|
|
52
|
-
}
|
|
53
|
-
progress-bar .progress-bar-fill::after {
|
|
54
|
-
content: "";
|
|
55
|
-
position: absolute;
|
|
56
|
-
top: 0;
|
|
57
|
-
left: -100%;
|
|
58
|
-
width: 100%;
|
|
59
|
-
height: 100%;
|
|
60
|
-
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
|
|
61
|
-
transition: left 0.5s ease;
|
|
62
|
-
}
|
|
63
|
-
cart-progress-bar[complete=true] progress-bar .progress-bar-fill::after {
|
|
64
|
-
left: 100%;
|
|
45
|
+
transition: width var(--cart-progress-bar-transition-duration) ease,
|
|
46
|
+
background-color var(--cart-progress-bar-transition-duration) ease;
|
|
65
47
|
}
|
|
66
|
-
|
|
67
|
-
outline: 2px solid #007bff;
|
|
68
|
-
outline-offset: 2px;
|
|
69
|
-
}
|
|
48
|
+
/*$vite$:1*/
|