@lime-bundles/widget 0.2.0 → 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 ADDED
@@ -0,0 +1,159 @@
1
+ # @lime-bundles/widget
2
+
3
+ Drop-in `<lime-bundle>` web component for the **Lime Bundles Shopify app**. Embed merchant-configured bundles on any JavaScript-enabled headless storefront (Hydrogen, Astro, Vue, Svelte, plain HTML). If you're not a merchant using Lime Bundles, this package probably isn't what you're looking for.
4
+
5
+ Ships the full widget your merchants see in the admin preview: header, save badge, product list with count bubbles, savings bar, pricing footer, themed CTA.
6
+
7
+ ## Install
8
+
9
+ Via npm:
10
+
11
+ ```bash
12
+ npm install @lime-bundles/widget
13
+ ```
14
+
15
+ ```ts
16
+ import "@lime-bundles/widget"; // registers <lime-bundle> globally
17
+ ```
18
+
19
+ Or via CDN, zero build step:
20
+
21
+ ```html
22
+ <script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
23
+ ```
24
+
25
+ ## Paste-and-go
26
+
27
+ One snippet in your product page template. The widget resolves the current product from the URL (`/products/<handle>`) and renders every active bundle configured for it. Clicking **Add bundle** calls Shopify's tokenless Storefront Cart API and redirects to checkout with the discount applied.
28
+
29
+ ```html
30
+ <script type="module" src="https://unpkg.com/@lime-bundles/widget"></script>
31
+ <lime-bundle
32
+ shop-domain="my-shop.myshopify.com"
33
+ storefront-token="<YOUR_LIME_BUNDLES_TOKEN>"
34
+ ></lime-bundle>
35
+ ```
36
+
37
+ Generate the token at `/app/settings/headless` in your Lime Bundles admin. It's a read-only Storefront Access Token (bundle metaobjects + product listings only), safe to ship in HTML.
38
+
39
+ ## BYO cart
40
+
41
+ Listen for `lime-bundle:add-to-cart` and call `event.preventDefault()` to suppress the default redirect:
42
+
43
+ ```js
44
+ document.querySelector("lime-bundle").addEventListener(
45
+ "lime-bundle:add-to-cart",
46
+ async (event) => {
47
+ event.preventDefault();
48
+ await myCart.linesAdd(event.detail.lines);
49
+ },
50
+ );
51
+ ```
52
+
53
+ ## Attributes
54
+
55
+ | Attribute | Required | Purpose |
56
+ |---|:-:|---|
57
+ | `shop-domain` | ✓ | `*.myshopify.com` domain. |
58
+ | `storefront-token` | ✓ | Storefront Access Token from `/app/settings/headless`. |
59
+ | `bundle-gid` | | Render one specific bundle. Overrides auto-detect. |
60
+ | `product-handle` | | Render bundles for this handle. Overrides URL detection. |
61
+ | `app-url` | | Enables impression + add-to-cart analytics when set. |
62
+ | `analytics` | | `"false"` suppresses analytics even when `app-url` is set. |
63
+ | `locale` | | BCP-47 tag forwarded to the Storefront API. |
64
+
65
+ **Product resolution** (when `bundle-gid` is absent): explicit `product-handle` → `<meta name="shopify:product-handle">` → `/products/<handle>` URL segment.
66
+
67
+ Changing any attribute at runtime re-fetches and re-renders.
68
+
69
+ ## Events
70
+
71
+ All events bubble and pierce shadow-DOM boundaries (`composed: true`), so you can listen on any ancestor.
72
+
73
+ ### `lime-bundle:add-to-cart`
74
+
75
+ Fired on CTA click. Cancelable: `event.preventDefault()` suppresses the default checkout redirect.
76
+
77
+ ```ts
78
+ event.detail: {
79
+ lines: CartLineInput[]; // merchandiseId + quantity + attributes
80
+ }
81
+ ```
82
+
83
+ Every line's `attributes[]` array includes `{ key: "_lime_bundle_gid", value: bundleId }`. Preserve it on the way to Shopify cart mutation or purchase attribution breaks.
84
+
85
+ ### `lime-bundle:loaded`
86
+
87
+ Fired once the bundle(s) have been fetched and parsed.
88
+
89
+ ```ts
90
+ event.detail: {
91
+ bundleCount: number;
92
+ bundleTypes: Array<"fixed" | "volume" | "mix_match">;
93
+ }
94
+ ```
95
+
96
+ ### `lime-bundle:error`
97
+
98
+ Fired if fetch or parse fails.
99
+
100
+ ```ts
101
+ event.detail: { message: string; code: string } // e.g. "LOAD_ERROR"
102
+ ```
103
+
104
+ The widget renders its own inline fallback; listen for this event if you want to hide the parent or report to your own telemetry.
105
+
106
+ ## What the widget handles for you
107
+
108
+ - **Merchant styling.** Every `--lb-*` CSS variable the merchant configured in the admin is applied inside the shadow root on render.
109
+ - **Custom CSS.** `shop.metafields["$app"].custom_css` is auto-fetched, sanitized, and injected.
110
+ - **Countdown timer.** When a bundle has `endsAt`, the widget ticks live and hides on expiry.
111
+ - **Variant dropdowns.** Products with multiple eligible variants render a `<select>`; switching live-updates the row price and bundle total.
112
+ - **Mix-match picker modal.** Full modal with search, quantity stepper, progress bar, focus trap, and keyboard navigation.
113
+ - **Out-of-stock handling.** Honours `widgetConfig.outOfStockBehavior` (`hide` vs `show_greyed_out`); hides the widget when the bundle is unfulfillable.
114
+ - **A/B testing.** Reads the merchant's A/B config, buckets the visitor via a first-party cookie, applies Variant B overrides.
115
+ - **Analytics.** Impression and add-to-cart events fire regardless of whether you override the cart.
116
+
117
+ ## Styling
118
+
119
+ Override any CSS custom property on the host element:
120
+
121
+ ```html
122
+ <lime-bundle
123
+ shop-domain="..."
124
+ style="--lb-primary-color: #e91e63; --lb-radius: 16px;"
125
+ ></lime-bundle>
126
+ ```
127
+
128
+ Full variable reference: [css-variables.md](./docs/css-variables.md).
129
+
130
+ ## Non-React framework snippets
131
+
132
+ **Astro:**
133
+
134
+ ```astro
135
+ <lime-bundle shop-domain="..." storefront-token={import.meta.env.PUBLIC_LIME_BUNDLES_TOKEN} />
136
+ <script>
137
+ import "@lime-bundles/widget";
138
+ </script>
139
+ ```
140
+
141
+ **Vue 3.** Configure `app.config.compilerOptions.isCustomElement = (tag) => tag === "lime-bundle"` to silence the unknown-element warning.
142
+
143
+ **Svelte.** No configuration needed; use `on:lime-bundle:add-to-cart={handler}`.
144
+
145
+ ## Bundle size
146
+
147
+ IIFE build, gzipped: <30 KB. No runtime framework dependency.
148
+
149
+ ## Version policy
150
+
151
+ All three packages (`core`, `react`, `widget`) bump majors together. The v2.0.0 release closes full rendering parity with the admin preview.
152
+
153
+ ## License
154
+
155
+ MIT.
156
+
157
+ ## Support
158
+
159
+ Merchant support and bug reports: email via the Lime Bundles listing on the Shopify App Store.