@lime-bundles/react 1.0.0 → 2.1.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 +54 -60
- package/dist/index.cjs +134 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +133 -8
- package/dist/index.js.map +1 -1
- package/docs/README.md +81 -0
- package/docs/css-variables.md +158 -0
- package/docs/hydrogen.md +185 -0
- package/docs/react-nextjs.md +379 -0
- package/docs/web-component.md +282 -0
- package/package.json +5 -4
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# Web component
|
|
2
|
+
|
|
3
|
+
`<lime-bundle>` is a standards-compliant custom element that renders Lime Bundles wherever you can drop an HTML tag into a product page template. **One tag, done.** It's the same widget your merchants see in the Lime Bundles admin preview, with every setting and colour choice honoured.
|
|
4
|
+
|
|
5
|
+
Two delivery paths, same widget:
|
|
6
|
+
|
|
7
|
+
- **HTML path**: paste a `<script>` tag and an HTML element. Works on any storefront that can include a `<script type="module">`. Zero build step.
|
|
8
|
+
- **React path**: install via npm, import in your client entry, use `<lime-bundle>` like any JSX element. Recommended for Hydrogen / Next.js / Vite because it avoids Content Security Policy issues with third-party script origins.
|
|
9
|
+
|
|
10
|
+
## <a id="html-storefronts"></a>HTML storefronts
|
|
11
|
+
|
|
12
|
+
Zero build step, zero npm install. Paste two lines into your product page template:
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<!-- Paste once in your product page template -->
|
|
16
|
+
<script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
|
|
17
|
+
<lime-bundle
|
|
18
|
+
shop-domain="my-shop.myshopify.com"
|
|
19
|
+
storefront-token="<YOUR_LIME_BUNDLES_TOKEN>"
|
|
20
|
+
></lime-bundle>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Generate your token by visiting `/app/settings/headless` in your Lime Bundles admin and clicking **Generate token**. The token is a read-only public Storefront Access Token, safe to ship in HTML. If it leaks, click **Regenerate** on the same page.
|
|
24
|
+
|
|
25
|
+
The widget auto-detects the current product from the URL (`/products/<handle>`) and renders every active bundle configured for it. On **Add bundle**, the widget calls Shopify's tokenless Storefront Cart API and redirects to checkout with the discount applied. No cart code needed.
|
|
26
|
+
|
|
27
|
+
## <a id="react-storefronts"></a>React storefronts (Hydrogen, Next.js, Vite)
|
|
28
|
+
|
|
29
|
+
Same `<lime-bundle>` element, but installed via npm so it ships through your bundler instead of a CDN. Recommended for React storefronts because:
|
|
30
|
+
|
|
31
|
+
1. Hydrogen's default Content Security Policy blocks third-party script origins. Importing the package through your own bundle avoids the CSP exception.
|
|
32
|
+
2. You get a pinned version in `package.json` instead of the CDN's "latest."
|
|
33
|
+
3. Tree-shaking and nonce handling are automatic.
|
|
34
|
+
|
|
35
|
+
**1. Install:**
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @lime-bundles/widget
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**2. Import once in your client entry.** This registers `<lime-bundle>` as a global custom element:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// Hydrogen → app/entry.client.tsx
|
|
45
|
+
// Next.js App Router → app/layout.tsx (client component)
|
|
46
|
+
// Vite → src/main.tsx
|
|
47
|
+
import "@lime-bundles/widget";
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**3. Use anywhere in JSX** (product page template is the typical placement):
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
export default function ProductBundles({ token }: { token: string }) {
|
|
54
|
+
return (
|
|
55
|
+
<lime-bundle
|
|
56
|
+
shop-domain="my-shop.myshopify.com"
|
|
57
|
+
storefront-token={token}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Pull the token from your framework's environment variables:
|
|
64
|
+
|
|
65
|
+
- **Hydrogen**: `context.env.PUBLIC_LIME_BUNDLES_TOKEN` inside your loader, pass it as a prop.
|
|
66
|
+
- **Next.js**: `process.env.NEXT_PUBLIC_LIME_BUNDLES_TOKEN`.
|
|
67
|
+
- **Vite**: `import.meta.env.VITE_LIME_BUNDLES_TOKEN`.
|
|
68
|
+
|
|
69
|
+
### TypeScript
|
|
70
|
+
|
|
71
|
+
TypeScript doesn't know about `<lime-bundle>` by default. Add a small ambient declaration to silence the JSX error:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// app/types/lime-bundle.d.ts
|
|
75
|
+
declare namespace JSX {
|
|
76
|
+
interface IntrinsicElements {
|
|
77
|
+
"lime-bundle": React.DetailedHTMLProps<
|
|
78
|
+
React.HTMLAttributes<HTMLElement> & {
|
|
79
|
+
"shop-domain": string;
|
|
80
|
+
"storefront-token": string;
|
|
81
|
+
"bundle-gid"?: string;
|
|
82
|
+
"product-handle"?: string;
|
|
83
|
+
},
|
|
84
|
+
HTMLElement
|
|
85
|
+
>;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Providing the product handle explicitly
|
|
91
|
+
|
|
92
|
+
If your storefront's product URL doesn't follow `/products/<handle>` (for example, some storefronts use `/shop/<handle>` or put the handle in a query param), set `product-handle` explicitly:
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<lime-bundle
|
|
96
|
+
shop-domain="my-shop.myshopify.com"
|
|
97
|
+
storefront-token="<TOKEN>"
|
|
98
|
+
product-handle="cool-tshirt"
|
|
99
|
+
></lime-bundle>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Taking over the cart (BYO)
|
|
103
|
+
|
|
104
|
+
If you have your own cart (Hydrogen `useCart`, custom cart drawer, etc.), listen for `lime-bundle:add-to-cart` and call `event.preventDefault()` to suppress the default redirect:
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<script>
|
|
108
|
+
document.querySelector("lime-bundle").addEventListener(
|
|
109
|
+
"lime-bundle:add-to-cart",
|
|
110
|
+
async (event) => {
|
|
111
|
+
event.preventDefault(); // skip the default "redirect to Shopify checkout" flow
|
|
112
|
+
await myCart.linesAdd(event.detail.lines);
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
</script>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The event is always dispatched; only the default action is conditional.
|
|
119
|
+
|
|
120
|
+
## Attributes
|
|
121
|
+
|
|
122
|
+
| Attribute | Required | Purpose |
|
|
123
|
+
|---|:-:|---|
|
|
124
|
+
| `shop-domain` | ✓ | Your shop domain, e.g. `my-shop.myshopify.com`. |
|
|
125
|
+
| `storefront-token` | ✓ | Generated in `/app/settings/headless`. Read-only Storefront Access Token (not the admin API key). |
|
|
126
|
+
| `bundle-gid` | | Pin one specific bundle. When set, overrides auto-detect. |
|
|
127
|
+
| `product-handle` | | Render bundles for a specific product handle. Overrides URL detection. |
|
|
128
|
+
| `app-url` | | Lime Bundles app URL (sends impression / add-to-cart analytics). Omit to disable analytics. |
|
|
129
|
+
| `analytics` | | Set to `"false"` to suppress analytics even if `app-url` is set. |
|
|
130
|
+
| `locale` | | BCP-47 tag for the buyer's locale. Forwarded to Storefront API. |
|
|
131
|
+
|
|
132
|
+
**Product resolution cascade** (when `bundle-gid` is absent): explicit `product-handle` → `<meta name="shopify:product-handle">` → `/products/<handle>` URL segment → error.
|
|
133
|
+
|
|
134
|
+
Changing any attribute at runtime re-fetches and re-renders. Safe to drive from a framework's reactivity.
|
|
135
|
+
|
|
136
|
+
## Events
|
|
137
|
+
|
|
138
|
+
All events bubble and cross shadow-DOM boundaries (`composed: true`), so you can listen on any ancestor.
|
|
139
|
+
|
|
140
|
+
### `lime-bundle:add-to-cart`
|
|
141
|
+
|
|
142
|
+
Fired when the customer clicks the CTA. The `detail` object carries the cart payload:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
type AddToCartDetail = {
|
|
146
|
+
lines: CartLineInput[];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type CartLineInput = {
|
|
150
|
+
merchandiseId: string; // variant GID
|
|
151
|
+
quantity: number;
|
|
152
|
+
attributes: Array<{ key: string; value: string }>;
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Every `CartLineInput.attributes` array includes `{ key: "_lime_bundle_gid", value: <bundle GID> }`. Preserve it on the way to Shopify cart mutation or purchase attribution breaks.
|
|
157
|
+
|
|
158
|
+
### `lime-bundle:loaded`
|
|
159
|
+
|
|
160
|
+
Fired once bundle data has been fetched and parsed successfully. Useful for hiding a placeholder or triggering analytics in non-SDK systems. The event fires even when zero bundles apply to the current product (product has no bundles attached); check `bundleCount` to tell the difference.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
type LoadedDetail = {
|
|
164
|
+
bundleCount: number;
|
|
165
|
+
bundleTypes: Array<"fixed" | "volume" | "mix_match">;
|
|
166
|
+
// Legacy single-bundle fields; undefined when bundleCount === 0.
|
|
167
|
+
bundleType?: "fixed" | "volume" | "mix_match";
|
|
168
|
+
title?: string;
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Migrating from v1.** Earlier versions emitted only `bundleType` and `title`, scoped to the first bundle rendered. v2 adds `bundleCount` and `bundleTypes` so listeners can see every bundle on the page. The legacy fields are still populated when at least one bundle renders but are `undefined` when `bundleCount === 0`. Guard accordingly, or migrate to the new fields:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
el.addEventListener("lime-bundle:loaded", (e) => {
|
|
176
|
+
const d = e.detail as LoadedDetail;
|
|
177
|
+
if (d.bundleCount === 0) return;
|
|
178
|
+
// d.bundleType / d.title are safe to read here.
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `lime-bundle:error`
|
|
183
|
+
|
|
184
|
+
Fired if bundle fetch or parse fails. The widget renders its own inline fallback, but listen for this event if you want to hide the widget entirely or report to your own telemetry:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
type ErrorDetail = {
|
|
188
|
+
message: string;
|
|
189
|
+
code: string; // e.g. "LOAD_ERROR"
|
|
190
|
+
};
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Other framework integrations
|
|
194
|
+
|
|
195
|
+
Non-React stacks that follow the same npm-install-plus-import pattern.
|
|
196
|
+
|
|
197
|
+
### Astro
|
|
198
|
+
|
|
199
|
+
```astro
|
|
200
|
+
---
|
|
201
|
+
// any component file
|
|
202
|
+
---
|
|
203
|
+
<lime-bundle
|
|
204
|
+
shop-domain="my-shop.myshopify.com"
|
|
205
|
+
storefront-token={import.meta.env.PUBLIC_LIME_BUNDLES_TOKEN}
|
|
206
|
+
bundle-gid="gid://shopify/Metaobject/42"
|
|
207
|
+
></lime-bundle>
|
|
208
|
+
<script>
|
|
209
|
+
import "@lime-bundles/widget";
|
|
210
|
+
document.querySelector("lime-bundle")!.addEventListener("lime-bundle:add-to-cart", async (e: any) => {
|
|
211
|
+
await fetch("/api/cart-add", { method: "POST", body: JSON.stringify(e.detail.lines) });
|
|
212
|
+
});
|
|
213
|
+
</script>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Vue 3
|
|
217
|
+
|
|
218
|
+
```vue
|
|
219
|
+
<template>
|
|
220
|
+
<lime-bundle
|
|
221
|
+
shop-domain="my-shop.myshopify.com"
|
|
222
|
+
:storefront-token="token"
|
|
223
|
+
bundle-gid="gid://shopify/Metaobject/42"
|
|
224
|
+
@lime-bundle:add-to-cart="handleAdd"
|
|
225
|
+
/>
|
|
226
|
+
</template>
|
|
227
|
+
|
|
228
|
+
<script setup lang="ts">
|
|
229
|
+
import "@lime-bundles/widget";
|
|
230
|
+
const token = import.meta.env.VITE_LIME_BUNDLES_TOKEN;
|
|
231
|
+
async function handleAdd(e: CustomEvent) {
|
|
232
|
+
await fetch("/cart/add", { method: "POST", body: JSON.stringify(e.detail.lines) });
|
|
233
|
+
}
|
|
234
|
+
</script>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Vue's custom-element handling needs `app.config.compilerOptions.isCustomElement = (tag) => tag === "lime-bundle"` if you hit warnings.
|
|
238
|
+
|
|
239
|
+
### Svelte
|
|
240
|
+
|
|
241
|
+
```svelte
|
|
242
|
+
<script>
|
|
243
|
+
import "@lime-bundles/widget";
|
|
244
|
+
function handle(e) {
|
|
245
|
+
fetch("/cart/add", { method: "POST", body: JSON.stringify(e.detail.lines) });
|
|
246
|
+
}
|
|
247
|
+
</script>
|
|
248
|
+
|
|
249
|
+
<lime-bundle
|
|
250
|
+
shop-domain="my-shop.myshopify.com"
|
|
251
|
+
storefront-token={import.meta.env.VITE_LIME_BUNDLES_TOKEN}
|
|
252
|
+
bundle-gid="gid://shopify/Metaobject/42"
|
|
253
|
+
on:lime-bundle:add-to-cart={handle}
|
|
254
|
+
></lime-bundle>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Styling
|
|
258
|
+
|
|
259
|
+
`<lime-bundle>` renders inside a closed Shadow DOM. Merchant custom CSS set in `/app/settings/custom-css` is auto-fetched and injected into the shadow root on `connectedCallback`. To override the built-in look, set CSS custom properties on the host:
|
|
260
|
+
|
|
261
|
+
```html
|
|
262
|
+
<lime-bundle
|
|
263
|
+
shop-domain="..."
|
|
264
|
+
style="--lb-primary-color: #e91e63; --lb-radius: 16px;"
|
|
265
|
+
></lime-bundle>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Full variable list: [css-variables.md](./css-variables.md).
|
|
269
|
+
|
|
270
|
+
## What's automatic
|
|
271
|
+
|
|
272
|
+
Every part of the widget a merchant configures in the admin is wired up for you:
|
|
273
|
+
|
|
274
|
+
- **Widget styling.** Every `--lb-*` CSS variable the merchant set in the admin editor (header colours, save badge, savings bar, product list styling, popular tier badge, mix-match picker styling, etc.) is applied inside the shadow root on render. Same widget, same look.
|
|
275
|
+
- **Shop custom CSS.** The sanitized CSS at `shop.metafields["$app"].custom_css` is injected into the shadow root alongside the built-in stylesheets so rules like `.lb-bundle-widget { ... }` hit the widget.
|
|
276
|
+
- **Countdown timer.** When a bundle has `endsAt`, the widget ticks a live countdown every second and hides the bar once the offer expires.
|
|
277
|
+
- **Variant dropdowns on fixed bundles.** Products with multiple eligible variants (filtered by the merchant's `selectedVariantIds`) render a `<select>`; switching variants live-updates the row price and the bundle total.
|
|
278
|
+
- **Mix-match picker modal.** Click any empty slot to open the modal; search, quantity stepper, progress bar, and pricing update as selections change. Keyboard: Escape closes, Tab traps inside the modal.
|
|
279
|
+
- **Out-of-stock behaviour.** Honours `widgetConfig.outOfStockBehavior` (`"hide"` removes OOS products from the list; `"show_greyed_out"` renders them disabled). Fixed bundles hide the whole widget when required products are OOS; mix-match hides when the available count can't satisfy `minQuantity`.
|
|
280
|
+
- **A/B test assignment.** The widget bucketises the visitor via `getABTestAssignment` (cookie-persisted, consent-gated) and merges Variant B overrides (title, description, discount, volume tiers) when the visitor lands in B. Honours Shopify's `customerPrivacy` framework or the SDK's `setConsent(true)` helper.
|
|
281
|
+
- **Impression + add-to-cart analytics.** Fire on visibility + CTA click regardless of whether the merchant takes over the cart via `preventDefault`. Disable by setting `analytics="false"` or omitting `app-url`.
|
|
282
|
+
- **Purchase attribution.** The `orders/create` webhook ingests `bundle_purchased` events server-side from the `_lime_bundle_gid` cart attribute the widget adds automatically. No `checkout_completed` handler needed.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lime-bundles/react",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "React components and hooks for Lime Bundles
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "React components and hooks for the Lime Bundles Shopify app. Use on Hydrogen, Next.js, Vite, or any React-based headless storefront.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"docs"
|
|
20
21
|
],
|
|
21
22
|
"publishConfig": {
|
|
22
23
|
"access": "public"
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"react-dom": ">=18.0.0"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@lime-bundles/core": "^1.0
|
|
55
|
+
"@lime-bundles/core": "^2.1.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@shopify/hydrogen-react": "^2026.4.1",
|