@liquidcommerce/elements-sdk 2.5.7 → 2.5.8

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 CHANGED
@@ -228,7 +228,7 @@ Add a product list to any page with a data attribute:
228
228
 
229
229
  ### Customizing the Cart Button
230
230
 
231
- By default, you get a floating cart button. Here's how to customize it:
231
+ By default, you get a floating cart button with badge. Here's how to customize it:
232
232
 
233
233
  #### Option 1: Cart Button in a Specific Container
234
234
 
@@ -246,7 +246,56 @@ By default, you get a floating cart button. Here's how to customize it:
246
246
  ></script>
247
247
  ```
248
248
 
249
- #### Option 2: No Cart Button (Manual Control)
249
+ **Position Options:**
250
+
251
+ You can control where the cart button is placed relative to a target element:
252
+
253
+ ```html
254
+ <!-- Place inside the target (default) -->
255
+ <script data-cart-badge-button="header-cart" ...></script>
256
+
257
+ <!-- Place above the target -->
258
+ <script data-cart-badge-button="above:.header-logo" ...></script>
259
+
260
+ <!-- Place below the target -->
261
+ <script data-cart-badge-button="below:#main-nav" ...></script>
262
+
263
+ <!-- Replace the target -->
264
+ <script data-cart-badge-button="replace:.old-cart" ...></script>
265
+ ```
266
+
267
+ **ID Auto-Prefixing:**
268
+
269
+ Element IDs are automatically prefixed with `#` if needed:
270
+
271
+ ```html
272
+ <!-- These are equivalent: -->
273
+ <script data-cart-button="header-cart" ...></script>
274
+ <script data-cart-button="#header-cart" ...></script>
275
+ ```
276
+
277
+ #### Option 2: Floating Cart Button (Default)
278
+
279
+ If no cart button attribute is provided, or if the target element is not found, the SDK automatically falls back to a floating cart button (bottom-right corner):
280
+
281
+ ```html
282
+ <!-- Empty attribute = floating cart button without badge -->
283
+ <script data-cart-button="" ...></script>
284
+
285
+ <!-- Empty badge attribute = floating cart button with badge -->
286
+ <script data-cart-badge-button="" ...></script>
287
+
288
+ <!-- Or simply omit the attribute for floating button with badge -->
289
+ <script
290
+ data-liquid-commerce-elements
291
+ data-token="YOUR_API_KEY"
292
+ src="https://assets-elements.liquidcommerce.us/all/elements.js"
293
+ ></script>
294
+ ```
295
+
296
+ #### Option 3: No Cart Button (Manual Control)
297
+
298
+ Hide the cart button completely when you want to manage cart access manually:
250
299
 
251
300
  ```html
252
301
  <script
@@ -258,6 +307,8 @@ By default, you get a floating cart button. Here's how to customize it:
258
307
  ></script>
259
308
  ```
260
309
 
310
+ **Use case:** When you have a custom cart implementation or want to trigger cart display programmatically using `client.actions.cart.openCart()`
311
+
261
312
  ### Advanced Auto-Init Features
262
313
 
263
314
  #### Add Product via URL (Marketing Links)
@@ -357,15 +408,19 @@ Here's every available data attribute:
357
408
  data-env="production|staging|development|local"
358
409
 
359
410
  <!-- Cart Button -->
360
- data-cart-button="container-id"
361
- data-cart-badge-button="container-id"
362
- data-cart-button-hidden
411
+ data-cart-button="container-id" <!-- Simple cart button (no badge) -->
412
+ data-cart-badge-button="container-id" <!-- Cart button with badge -->
413
+ data-cart-button-hidden <!-- Hide cart button completely -->
363
414
 
364
415
  <!-- Cart Button with Position Prefixes -->
365
- data-cart-button="above:.logo"
366
- data-cart-badge-button="below:#header"
367
- data-cart-button="inside:.nav"
368
- data-cart-badge-button="replace:.old-cart"
416
+ data-cart-button="above:.logo" <!-- Place above target -->
417
+ data-cart-badge-button="below:#header" <!-- Place below target -->
418
+ data-cart-button="inside:.nav" <!-- Place inside target (default) -->
419
+ data-cart-badge-button="replace:.old-cart" <!-- Replace target -->
420
+
421
+ <!-- Cart Button Floating (empty values) -->
422
+ data-cart-button="" <!-- Floating button without badge -->
423
+ data-cart-badge-button="" <!-- Floating button with badge -->
369
424
 
370
425
  <!-- Products (Method 1: Direct) -->
371
426
  data-container-1="div-id"
@@ -775,16 +830,32 @@ Bind elements to auto-update with cart data:
775
830
  // Show live subtotal
776
831
  client.ui.cartSubtotal('cart-total-display');
777
832
 
778
- // Show live item count
833
+ // Show live item count (default behavior: hides when count is 0)
779
834
  client.ui.cartItemsCount('cart-badge');
835
+
836
+ // Show live item count (always visible, even when 0)
837
+ client.ui.cartItemsCount('cart-badge', { hideZero: false });
780
838
  ```
781
839
 
840
+ **Parameters for `cartItemsCount`:**
841
+ - `elementId` (string) - ID of the element to update
842
+ - `options` (object, optional) - Configuration options:
843
+ - `hideZero` (boolean, default: `true`) - When `true`, element is hidden when cart count is 0. When `false`, element remains visible showing "0".
844
+
782
845
  **Example:**
783
846
  ```html
784
847
  <nav>
785
848
  <span>Cart: $<span id="cart-total-display">0.00</span></span>
786
849
  <span>(<span id="cart-badge">0</span> items)</span>
787
850
  </nav>
851
+
852
+ <script>
853
+ // Default behavior - badge hidden when cart is empty
854
+ client.ui.cartItemsCount('cart-badge');
855
+
856
+ // Always show count, even when 0
857
+ client.ui.cartItemsCount('cart-badge', { hideZero: false });
858
+ </script>
788
859
  ```
789
860
 
790
861
  ### Builder Methods (Development Mode)