vlite3 1.5.12 → 1.5.14

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.
Files changed (124) hide show
  1. package/README.md +20 -8
  2. package/components/Accordion/AccordionContent.vue.js +2 -2
  3. package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
  4. package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
  5. package/components/Form/AccordionView2.vue.js +1 -1
  6. package/components/Form/Form.vue.js +2 -2
  7. package/components/NavbarCommandPalette.vue.js +1 -1
  8. package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
  9. package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
  10. package/components/Tabes/Tabes.vue.js +2 -2
  11. package/docs/README.md +16 -0
  12. package/docs/component-index.md +313 -0
  13. package/docs/components/accordion.md +52 -0
  14. package/docs/components/alert.md +34 -0
  15. package/docs/components/app-shell.md +371 -0
  16. package/docs/components/async-select.md +264 -0
  17. package/docs/components/attachments-list.md +231 -0
  18. package/docs/components/avatar-group.md +74 -0
  19. package/docs/components/avatar-uploader.md +61 -0
  20. package/docs/components/avatar.md +28 -0
  21. package/docs/components/badge.md +81 -0
  22. package/docs/components/barcode.md +42 -0
  23. package/docs/components/beacon.md +29 -0
  24. package/docs/components/breadcrumb.md +317 -0
  25. package/docs/components/button-group.md +35 -0
  26. package/docs/components/button.md +86 -0
  27. package/docs/components/calendar.md +95 -0
  28. package/docs/components/carousel.md +122 -0
  29. package/docs/components/cart.md +533 -0
  30. package/docs/components/category-manager.md +269 -0
  31. package/docs/components/category-menu.md +251 -0
  32. package/docs/components/charts.md +1456 -0
  33. package/docs/components/chat.md +330 -0
  34. package/docs/components/checkbox.md +31 -0
  35. package/docs/components/chip.md +137 -0
  36. package/docs/components/choice-box.md +40 -0
  37. package/docs/components/clipboard.md +105 -0
  38. package/docs/components/clock.md +70 -0
  39. package/docs/components/color-picker.md +82 -0
  40. package/docs/components/command-palette.md +214 -0
  41. package/docs/components/comment-thread.md +171 -0
  42. package/docs/components/confirmation-modal.md +50 -0
  43. package/docs/components/custom-fields-display.md +94 -0
  44. package/docs/components/custom-fields.md +97 -0
  45. package/docs/components/data-list.md +93 -0
  46. package/docs/components/data-table.md +922 -0
  47. package/docs/components/date-picker.md +58 -0
  48. package/docs/components/date-range-picker.md +24 -0
  49. package/docs/components/date-time.md +104 -0
  50. package/docs/components/dropdown.md +740 -0
  51. package/docs/components/empty.md +100 -0
  52. package/docs/components/export-data.md +320 -0
  53. package/docs/components/file-picker.md +83 -0
  54. package/docs/components/file-preview.md +42 -0
  55. package/docs/components/file-tree.md +144 -0
  56. package/docs/components/footer.md +251 -0
  57. package/docs/components/forms.md +776 -0
  58. package/docs/components/gantt-chart.md +767 -0
  59. package/docs/components/google-login.md +67 -0
  60. package/docs/components/google-map.md +128 -0
  61. package/docs/components/heatmap.md +80 -0
  62. package/docs/components/icon-picker.md +58 -0
  63. package/docs/components/icon.md +176 -0
  64. package/docs/components/image-comparison.md +51 -0
  65. package/docs/components/image-magnifier.md +26 -0
  66. package/docs/components/import-data.md +521 -0
  67. package/docs/components/input.md +58 -0
  68. package/docs/components/invoice.md +339 -0
  69. package/docs/components/kanban.md +302 -0
  70. package/docs/components/label.md +25 -0
  71. package/docs/components/list.md +419 -0
  72. package/docs/components/masonry.md +55 -0
  73. package/docs/components/modal.md +133 -0
  74. package/docs/components/multi-select.md +54 -0
  75. package/docs/components/navbar.md +403 -0
  76. package/docs/components/number-input.md +41 -0
  77. package/docs/components/otp-input.md +68 -0
  78. package/docs/components/pagination.md +83 -0
  79. package/docs/components/pan-zoom-viewport.md +245 -0
  80. package/docs/components/permission-editor.md +322 -0
  81. package/docs/components/persona.md +56 -0
  82. package/docs/components/price.md +106 -0
  83. package/docs/components/pricing-plan.md +68 -0
  84. package/docs/components/progress-bar.md +53 -0
  85. package/docs/components/qr-code.md +59 -0
  86. package/docs/components/rating.md +59 -0
  87. package/docs/components/rich-text-editor.md +210 -0
  88. package/docs/components/scale-generator.md +101 -0
  89. package/docs/components/screen.md +208 -0
  90. package/docs/components/seo-provider.md +189 -0
  91. package/docs/components/side-panel.md +94 -0
  92. package/docs/components/sidebar-menu.md +422 -0
  93. package/docs/components/skeleton.md +115 -0
  94. package/docs/components/slider.md +48 -0
  95. package/docs/components/spinner.md +27 -0
  96. package/docs/components/splitter.md +97 -0
  97. package/docs/components/stats.md +234 -0
  98. package/docs/components/status-chip.md +232 -0
  99. package/docs/components/switch.md +23 -0
  100. package/docs/components/tabs.md +335 -0
  101. package/docs/components/tag-input.md +55 -0
  102. package/docs/components/textarea.md +31 -0
  103. package/docs/components/theme-provider.md +130 -0
  104. package/docs/components/theme-toggle.md +36 -0
  105. package/docs/components/thumbnail-selector.md +186 -0
  106. package/docs/components/timeline.md +225 -0
  107. package/docs/components/toast-notification.md +89 -0
  108. package/docs/components/tooltip.md +31 -0
  109. package/docs/components/workbook.md +102 -0
  110. package/docs/composables/use-theme.md +59 -0
  111. package/docs/getting-started/setup.md +176 -0
  112. package/docs/guides/draggable.md +211 -0
  113. package/docs/guides/internationalization.md +281 -0
  114. package/docs/guides/performance.md +118 -0
  115. package/docs/guides/testing-forms.md +154 -0
  116. package/docs/guides/testing-overlays.md +131 -0
  117. package/docs/guides/theming.md +124 -0
  118. package/docs/utilities/search.md +580 -0
  119. package/docs/utilities/utilities.md +371 -0
  120. package/docs-manifest.json +336 -0
  121. package/package.json +5 -13
  122. package/scripts/generate-docs-manifest.js +207 -0
  123. package/scripts/sync-docs.js +754 -0
  124. package/style.css +1 -1
@@ -0,0 +1,533 @@
1
+ ---
2
+ title: Cart
3
+ description: A reusable, fully-typed cart component with 4 visual variants — built to work for both e-commerce sites and POS systems from a single API. The cart does the math for you.
4
+ ---
5
+
6
+ # Cart
7
+
8
+ A flexible, fully-typed cart component for the vlite3 library. The same `<Cart />` component
9
+ renders an e-commerce slide-over drawer, a POS register list, a full-page cart with a sticky
10
+ summary, or a header mini-cart — driven entirely by the `variant` prop and a `features` toggle
11
+ object.
12
+
13
+ **The big idea:** the cart owns all the business math. Subtotal, discount, tax, shipping and
14
+ grand-total are computed inside the component from `items + tax + shipping + coupon`. You pass
15
+ in the data, the cart does the rest. If you already have server-side totals, you can still pass
16
+ `data.totals` and the cart will use them verbatim.
17
+
18
+ ## Highlights
19
+
20
+ - **Self-driving math** — pass `items + tax + shipping + coupon` and the cart computes
21
+ subtotal, discount, tax, shipping, and grand-total internally. Re-runs on every item change.
22
+ - **Plug-and-play tax** — rate, flat, exempt, or VAT-inclusive.
23
+ - **Plug-and-play shipping** — flat, free, free-over-threshold, tiered, pickup, or a custom
24
+ function. Free-shipping progress with a formatted remaining amount is rendered automatically.
25
+ - **Cart-wide currency** — set `data.currency` once and every internal `Price` in line items,
26
+ summaries, coupon discounts, and progress messages uses that currency. Server-provided totals
27
+ can also carry `totals.currency`.
28
+ - **Two coupon modes** — sync (`data.coupons[]`, validated in-browser) or async
29
+ (`validateCoupon` prop, validated by your API). Fixed or percentage. The cart drives the
30
+ `applying` / `applied` / `invalid` / `expired` / `error` UX for you.
31
+ - **4 visual variants** out of the box: Drawer, POS, Full Page, Mini.
32
+ - **Per-feature toggles** — turn on/off subtotal, discount, estimated tax, shipping, coupon,
33
+ total savings, thumbnails, qty editing, item removal, "clear cart" — independently.
34
+ - **Coupon UX modeled as states** — `idle`, `applying`, `applied`, `invalid`, `expired`, `error`
35
+ with proper border / icon / helper text for each.
36
+ - **Read-only mode** — disables qty editing, item removal and coupon mutation. Use it for order
37
+ detail pages.
38
+ - **Compact mode** — same convention as `Invoice`. Reduces padding / typography for dense
39
+ contexts.
40
+ - **Built on the library's own primitives** — `Input`, `Button`, `Label`, `Price`, `Icon`.
41
+ No custom inputs, no duplicated design tokens.
42
+ - **Trust signals** — pass a `trustSignals` array to render preformatted shipping thresholds,
43
+ return windows, secure-checkout notes, etc., dynamically via the API instead of static text.
44
+ - **`v-model` for the applied coupon** — `(cart) => cart.coupon` and the cart auto-applies
45
+ internally.
46
+
47
+ ## Quick start — self-driving
48
+
49
+ This is the **recommended** path. You pass your line items, the tax rate, the shipping rule,
50
+ and a list of valid coupons. The cart computes everything else, including the discount amount
51
+ when the user applies a coupon.
52
+
53
+ ```vue
54
+ <script setup lang="ts">
55
+ import { ref } from 'vue'
56
+ import { Cart } from 'vlite3'
57
+ import type { CartData, CartCouponDefinition, CartCoupon } from 'vlite3'
58
+
59
+ // Your product/service line items — the only thing you have to maintain
60
+ const cart = ref<CartData>({
61
+ title: 'Your Cart',
62
+ currency: 'USD', // ISO 4217 code used by all cart price displays
63
+ items: [
64
+ {
65
+ id: 1,
66
+ name: 'Wireless Noise-Cancelling Headphones',
67
+ sku: 'AUD-NC-2024',
68
+ variant: 'Midnight Black',
69
+ thumbnail: 'https://…/headphones.jpg',
70
+ price: 299,
71
+ quantity: 1,
72
+ taxable: true,
73
+ },
74
+ {
75
+ id: 2,
76
+ name: 'Mechanical Keyboard',
77
+ variant: 'Cream',
78
+ price: 159,
79
+ quantity: 2,
80
+ taxable: true,
81
+ },
82
+ ],
83
+
84
+ // ── Tax config — the cart applies this to taxable items ──
85
+ tax: {
86
+ mode: 'rate', // 'rate' | 'flat' | 'exempt' | 'inclusive'
87
+ rate: 8.75, // 8.75% US sales tax
88
+ label: 'Sales Tax',
89
+ applyTo: 'afterDiscount',
90
+ },
91
+
92
+ // ── Shipping config ──
93
+ shipping: {
94
+ mode: 'freeOver', // 'flat' | 'free' | 'freeOver' | 'tiered' | 'function' | 'pickup'
95
+ cost: 9.99, // standard shipping rate
96
+ freeOver: 50, // free when subtotal ≥ 50
97
+ label: 'Standard shipping',
98
+ },
99
+
100
+ // ── Coupon catalog — the cart validates user input against this list ──
101
+ coupons: [
102
+ {
103
+ code: 'WELCOME10',
104
+ type: 'percentage', // 'percentage' or 'fixed'
105
+ value: 10, // 10% off
106
+ description: '10% off your first order',
107
+ minSubtotal: 100,
108
+ maxDiscount: 50,
109
+ expiresAt: '2026-12-31',
110
+ },
111
+ {
112
+ code: 'SAVE25',
113
+ type: 'fixed',
114
+ value: 25, // 25 off in the cart currency
115
+ description: '25 off your order',
116
+ },
117
+ {
118
+ code: 'VIP20',
119
+ type: 'percentage',
120
+ value: 20,
121
+ description: '20% off — VIP only',
122
+ minSubtotal: 200,
123
+ maxDiscount: 100,
124
+ },
125
+ ] as CartCouponDefinition[],
126
+
127
+ // ── Trust Signals (Optional) ──
128
+ trustSignals: [
129
+ { icon: 'lucide:truck', text: 'Free shipping over 50' },
130
+ { icon: 'lucide:rotate-ccw', text: '30-day easy returns' },
131
+ { icon: 'lucide:shield-check', text: 'Secure checkout' },
132
+ ],
133
+ })
134
+ </script>
135
+
136
+ <template>
137
+ <Cart :data="cart" variant="Variant1" @continue="$router.push('/checkout')" />
138
+ </template>
139
+ ```
140
+
141
+ That's it. No math in your component, no API call to validate the coupon, no discount
142
+ recomputation when the user changes quantity. The cart does it all.
143
+
144
+ ## Quick start — with `useCart`
145
+
146
+ Use `useCart` when your page needs to add products from elsewhere, read quantities for badges,
147
+ or wire the cart events without writing the same item-management code in every app.
148
+
149
+ ```vue
150
+ <script setup lang="ts">
151
+ import { Cart, useCart } from 'vlite3'
152
+ import type { CartItem } from 'vlite3'
153
+
154
+ const cart = useCart({
155
+ title: 'Your Cart',
156
+ currency: 'USD', // preserved in cart.data and computed totals
157
+ tax: { mode: 'rate', rate: 8.75 },
158
+ shipping: { mode: 'freeOver', cost: 9.99, freeOver: 50 },
159
+ items: [],
160
+ })
161
+
162
+ const product: CartItem = {
163
+ id: 'keyboard-cream',
164
+ name: 'Mechanical Keyboard',
165
+ variant: 'Cream',
166
+ price: 159,
167
+ quantity: 1,
168
+ taxable: true,
169
+ }
170
+
171
+ function addProduct() {
172
+ cart.addToCart(product)
173
+ }
174
+
175
+ function quantityInCart(productId: string) {
176
+ return cart.getQuantity(productId)
177
+ }
178
+ </script>
179
+
180
+ <template>
181
+ <button @click="addProduct">
182
+ Add to cart ({{ quantityInCart('keyboard-cream') }})
183
+ </button>
184
+
185
+ <Cart
186
+ :data="cart.data"
187
+ variant="Variant1"
188
+ @update:quantity="cart.updateQuantity"
189
+ @remove="cart.removeFromCart"
190
+ @clear="cart.clearCart"
191
+ @update:coupon="cart.setCoupon"
192
+ />
193
+ </template>
194
+ ```
195
+
196
+ ### `useCart` return API
197
+
198
+ | Name | Type | Description |
199
+ | --- | --- | --- |
200
+ | `items` | `Ref<CartItem[]>` | Reactive cart line items. Use this when you need to render or watch the live cart contents. |
201
+ | `coupon` | `Ref<CartCoupon \| null>` | Reactive applied coupon. Updated by `setCoupon` and suitable for syncing with `<Cart @update:coupon>`. |
202
+ | `totals` | `ComputedRef<CartTotals>` | Computed totals from the same cart calculator used by `<Cart />`: subtotal, discount, tax, shipping, grand total, item count, and savings. |
203
+ | `data` | `ComputedRef<CartData>` | A ready-to-pass object for `<Cart :data="cart.data" />`. It includes current `items`, `coupon`, `totals`, and any options passed to `useCart`. |
204
+ | `itemCount` | `ComputedRef<number>` | Total quantity across all cart lines. Useful for header badges and mini-cart counts. |
205
+ | `isEmpty` | `ComputedRef<boolean>` | `true` when the cart has no line items. Useful for disabling checkout actions. |
206
+ | `addToCart(item, quantity?)` | `(item: CartItem, quantity?: number) => void` | Adds a new line item or merges with an existing line that has the same `id`. Quantity defaults to `item.quantity` or `1`, and respects `maxQuantity`. |
207
+ | `removeFromCart(itemId, quantity?)` | `(itemId: string \| number, quantity?: number) => void` | Removes a line completely when `quantity` is omitted. When `quantity` is provided, subtracts that amount and removes the line at zero. |
208
+ | `updateQuantity(itemId, quantity)` | `(itemId: string \| number, quantity: number) => void` | Sets an exact line quantity. Values less than or equal to `0` remove the item. |
209
+ | `incrementQuantity(itemId, amount?)` | `(itemId: string \| number, amount?: number) => void` | Increases a line quantity. `amount` defaults to `1`. |
210
+ | `decrementQuantity(itemId, amount?)` | `(itemId: string \| number, amount?: number) => void` | Decreases a line quantity. `amount` defaults to `1`, and the line is removed at zero. |
211
+ | `setItems(nextItems)` | `(nextItems: CartItem[]) => void` | Replaces the whole cart item list. Use after loading a saved cart or syncing from an API. |
212
+ | `clearCart()` | `() => void` | Removes every item from the cart. Useful for `<Cart @clear="cart.clearCart" />`. |
213
+ | `setCoupon(nextCoupon)` | `(nextCoupon: CartCoupon \| null) => void` | Sets or clears the applied coupon. Wire this to `<Cart @update:coupon="cart.setCoupon" />`. |
214
+ | `getQuantity(itemId)` | `(itemId: string \| number) => number` | Returns the current quantity for a line item, or `0` when the item is not in the cart. |
215
+ | `getCartItems()` | `() => CartItem[]` | Returns a shallow-copied snapshot of the current cart items for API calls, persistence, or analytics. |
216
+
217
+ ## Quick start — async coupon (call your API)
218
+
219
+ If your coupons live in a database (rate-limited, single-use, fraud-checked), swap the static
220
+ `data.coupons` list for a `validateCoupon` prop. The cart will await your promise and drive
221
+ the `applying` → `applied` / `invalid` / `expired` / `error` UX around it.
222
+
223
+ ```vue
224
+ <script setup lang="ts">
225
+ import { ref } from 'vue'
226
+ import { Cart } from 'vlite3'
227
+ import type { CartData, CartCouponDefinition } from 'vlite3'
228
+
229
+ const cart = ref<CartData>({
230
+ currency: 'USD', // passed into validateCoupon as the currency context
231
+ items: [/* … */],
232
+ tax: { mode: 'rate', rate: 8.75 },
233
+ shipping: { mode: 'flat', cost: 9.99 },
234
+ })
235
+
236
+ async function validateCoupon(code, { subtotal, currency, items }) {
237
+ const res = await fetch(`/api/coupons/${code}`, {
238
+ method: 'POST',
239
+ body: JSON.stringify({ subtotal, currency, items }),
240
+ })
241
+ if (res.status === 404) {
242
+ return { code, state: 'invalid', message: 'That coupon code is not valid.' }
243
+ }
244
+ if (res.status === 410) {
245
+ return { code, state: 'expired', message: 'This coupon has expired.' }
246
+ }
247
+ if (!res.ok) {
248
+ return { code, state: 'error', message: 'We could not apply that coupon right now.' }
249
+ }
250
+ // 200 — return the definition, the cart applies the discount itself
251
+ return (await res.json()) as CartCouponDefinition
252
+ }
253
+ </script>
254
+
255
+ <template>
256
+ <Cart
257
+ :data="cart"
258
+ :validate-coupon="validateCoupon"
259
+ variant="Variant3"
260
+ @update:coupon="(c) => cart.coupon = c"
261
+ @update:totals="(t) => cart.totals = t" />
262
+ </template>
263
+ ```
264
+
265
+ Resolve with a `CartCouponDefinition` to apply, or `{ code, state, message }` to reject.
266
+
267
+ ## Quick start — server-side totals (advanced)
268
+
269
+ Already have totals from your API? Skip the built-in calculator and pass `data.totals` directly.
270
+
271
+ ```vue
272
+ <script setup lang="ts">
273
+ import { ref, watch } from 'vue'
274
+ import { Cart } from 'vlite3'
275
+ import type { CartData, CartTotals } from 'vlite3'
276
+
277
+ const cart = ref<CartData>({
278
+ title: 'Your Cart',
279
+ currency: 'EUR',
280
+ items: [/* … */],
281
+ // `totals` is OPTIONAL — if you pass it, the cart uses it verbatim and skips its own math.
282
+ // If you don't, the cart computes it from items + tax + shipping + coupon.
283
+ })
284
+ const totals = ref<CartTotals>(/* fetched from your API */)
285
+
286
+ watch([() => cart.value.items, () => cart.value.coupon], async () => {
287
+ const res = await fetch('/api/cart/quote', { method: 'POST', body: JSON.stringify(cart.value) })
288
+ totals.value = await res.json()
289
+ }, { deep: true })
290
+ </script>
291
+
292
+ <template>
293
+ <Cart :data="{ ...cart, totals: totals }" variant="Variant1" />
294
+ </template>
295
+ ```
296
+
297
+ The cart will render your server-side totals as-is. For display, it uses `data.currency` first
298
+ and falls back to `data.totals.currency` when `data.currency` is missing. If coupon rules or
299
+ your async validator depend on currency, still pass `data.currency`; that is the currency sent
300
+ to coupon validation.
301
+
302
+ ## Currency display
303
+
304
+ Use ISO 4217 currency codes such as `USD`, `EUR`, `PKR`, or `AED`.
305
+
306
+ The cart passes one active currency into every internal `Price` component used by:
307
+
308
+ - line item unit prices, original prices, and line totals
309
+ - subtotal, discount, shipping, estimated tax, grand total, and total savings rows
310
+ - applied coupon discount pills
311
+ - free-shipping progress and coupon min-spend messages
312
+ - the `Variant4` header total
313
+
314
+ Currency precedence for display is:
315
+
316
+ 1. `data.currency`
317
+ 2. `data.totals.currency`
318
+ 3. the global `Price` config from `createVLite`
319
+
320
+ When the cart computes totals internally, it writes `totals.currency` from `data.currency`,
321
+ `tax.currency`, or `shipping.currency`. Currency-specific coupons and `validateCoupon` receive
322
+ `data.currency`, so set `data.currency` when coupon validity depends on the order currency.
323
+
324
+ ## Quick start — manual control (legacy / maximal control)
325
+
326
+ If you want full control — drive every state transition yourself — skip the new APIs and use
327
+ the original `apply-coupon` / `remove-coupon` events. The cart still renders everything
328
+ (applied pill, discount row, free-shipping hint) based on whatever you set `data.coupon` to.
329
+
330
+ ```vue
331
+ <script setup lang="ts">
332
+ import { ref } from 'vue'
333
+ import { Cart } from 'vlite3'
334
+ import type { CartData, CartCoupon } from 'vlite3'
335
+
336
+ const cart = ref<CartData>({ /* items + tax + shipping, no coupons list, no validateCoupon */ })
337
+ const coupon = ref<CartCoupon>({ code: '', state: 'idle' })
338
+
339
+ async function onApplyCoupon(code: string) {
340
+ coupon.value = { code, state: 'applying' }
341
+ const def = await fetch(`/api/coupons/${code}`).then((r) => r.json())
342
+ if (!def) {
343
+ coupon.value = { code, state: 'invalid', message: 'Invalid coupon code.' }
344
+ } else {
345
+ coupon.value = {
346
+ code,
347
+ state: 'applied',
348
+ discountAmount: def.amount, // you pass the computed amount; cart renders it
349
+ description: def.description,
350
+ }
351
+ }
352
+ cart.value.coupon = coupon.value
353
+ }
354
+ </script>
355
+
356
+ <template>
357
+ <Cart
358
+ :data="cart"
359
+ @apply-coupon="onApplyCoupon"
360
+ @remove-coupon="coupon = { code: '', state: 'idle' }; cart.coupon = undefined" />
361
+ </template>
362
+ ```
363
+
364
+ ## Variants
365
+
366
+ | Variant | Use case | Layout |
367
+ | ------------- | ---------------------------------------------- | ---------------------------------------------------------------------- |
368
+ | `Variant1` | E-commerce slide-over drawer | Full line items, sticky bottom summary + actions |
369
+ | `Variant2` | POS / register / fast checkout | Dense list, no thumbnails, dashed dividers, inline coupon |
370
+ | `Variant3` | Full-page cart (`/cart` route) | 2-column with sticky summary card on lg+; stacks on mobile |
371
+ | `Variant4` | Header dropdown / mini cart | Single column, summary-first, tiny line items |
372
+
373
+ ## Coupon States
374
+
375
+ The `CartCoupon.state` field drives the entire UX of the coupon input. The cart sets this
376
+ state automatically when you use `data.coupons` or `validateCoupon`. If you drive it
377
+ manually, set it from your validation logic.
378
+
379
+ | State | UI |
380
+ | ----------- | -------------------------------------------------------------------------------------- |
381
+ | `idle` | Empty input, no validation feedback. |
382
+ | `applying` | Spinner replaces the Apply button label, input + button disabled. |
383
+ | `applied` | Green check pill showing the code, description, and discount amount. Remove replaces Apply. |
384
+ | `invalid` | Red border on the input, red helper text, error icon. |
385
+ | `expired` | Amber border, amber helper text, clock icon. |
386
+ | `error` | Red border, red helper text, alert icon — message comes from `coupon.message`. |
387
+
388
+ ## Tax config (`CartTaxConfig`)
389
+
390
+ | Mode | What it does | Required fields |
391
+ | ------------- | ----------------------------------------------------- | --------------------------- |
392
+ | `rate` | `%` tax on post-discount subtotal (default base) | `rate` (e.g. `8.75`) |
393
+ | `flat` | Fixed tax amount regardless of cart value | `amount` |
394
+ | `exempt` | No tax at all (digital goods, B2B resale) | — |
395
+ | `inclusive` | Tax already baked into the displayed price (EU VAT) | `rate` |
396
+
397
+ Use `applyTo: 'afterDiscount'` (default) to tax the discounted subtotal, or
398
+ `applyTo: 'subtotal'` to tax the full price (some jurisdictions require this).
399
+
400
+ ## Shipping config (`CartShippingConfig`)
401
+
402
+ | Mode | What it does |
403
+ | ------------ | --------------------------------------------------------------------------------------------- |
404
+ | `flat` | Always `cost` |
405
+ | `free` | Always free |
406
+ | `pickup` | In-store pickup — always free, label says "In-store pickup" |
407
+ | `freeOver` | `cost` normally, free when subtotal ≥ `freeOver`. UI shows a formatted "Add more for free shipping" amount. |
408
+ | `tiered` | Lookup table; first row with `minSubtotal ≤ subtotal` wins. |
409
+ | `function` | `(subtotal, items) => { cost, isFree?, label? }` — fully custom. |
410
+
411
+ ## Coupon definition (`CartCouponDefinition`)
412
+
413
+ | Field | Type | Notes |
414
+ | ------------- | ------------------- | -------------------------------------------------------------------------------------- |
415
+ | `code` | `string` | Required. Matched case-insensitively. |
416
+ | `type` | `'percentage' \| 'fixed'` | Required. Determines how `value` is interpreted. |
417
+ | `value` | `number` | Required. Percent (0-100) for `percentage`, currency amount for `fixed`. |
418
+ | `description` | `string?` | Shown in the applied pill. |
419
+ | `minSubtotal` | `number?` | Min cart subtotal required to apply. UI shows a formatted "Add more to use CODE" amount. |
420
+ | `maxDiscount` | `number?` | Cap on the discount — typically used with `type: 'percentage'`. |
421
+ | `expiresAt` | `string \| Date?` | Expiry. After this, the cart auto-rejects with `expired` state. |
422
+ | `currency` | `string?` | Coupon only applies if cart currency matches. |
423
+ | `minItems` | `number?` | Min number of items in cart. |
424
+ | `usageLimit` | `number?` | Reserved for future client-side tracking; server-side enforcement recommended. |
425
+
426
+ ## Features (toggles)
427
+
428
+ Every optional block can be turned on or off via the `features` prop. Defaults match a standard
429
+ e-commerce cart; POS scenarios typically disable `thumbnails` and `description`.
430
+
431
+ ```ts
432
+ features: {
433
+ editableQuantity: true,
434
+ removable: true,
435
+ clearable: true,
436
+ coupon: true,
437
+ subtotal: true,
438
+ discount: true,
439
+ estimatedTax: true,
440
+ shipping: true,
441
+ totalSavings: true,
442
+ continue: true,
443
+ continueShopping: true,
444
+ thumbnails: true,
445
+ description: true,
446
+ sku: true,
447
+ itemVariant: true,
448
+ emptyState: true,
449
+ trustSignals: true,
450
+ }
451
+ ```
452
+
453
+ For a POS scenario:
454
+
455
+ ```ts
456
+ features: {
457
+ thumbnails: false,
458
+ description: false,
459
+ sku: false,
460
+ totalSavings: false,
461
+ continueShopping: true, // shown as "Add more"
462
+ trustSignals: false,
463
+ }
464
+ ```
465
+
466
+ ## Read-only mode
467
+
468
+ Set `data.readonly = true` (or pass `readonly` globally) to disable every editing affordance —
469
+ quantity stepper, remove buttons, "clear cart", and the coupon field. The cart becomes a static
470
+ summary. Use this for **order detail pages** and **past-order receipts**.
471
+
472
+ ## Compact mode
473
+
474
+ Pass `data.compact = true` to reduce padding, spacing, and font sizes — same convention as the
475
+ `Invoice` component.
476
+
477
+ ## Global configuration
478
+
479
+ The Cart component can be globally configured via `createVLite`:
480
+
481
+ ```ts
482
+ import { createApp } from 'vue'
483
+ import { createVLite } from 'vlite3'
484
+
485
+ const app = createApp(App)
486
+ app.use(createVLite, {
487
+ components: {
488
+ cart: {
489
+ variant: 'Variant3', // default for the whole app
490
+ compact: true,
491
+ actions: {
492
+ continueLabel: 'Proceed to checkout',
493
+ },
494
+ },
495
+ },
496
+ })
497
+ ```
498
+
499
+ ## Events
500
+
501
+ | Event | Payload | When |
502
+ | ----------------- | -------------------------------------------------------- | --------------------------------------------------- |
503
+ | `update:quantity` | `(itemId, newQuantity)` | User clicks +/- on a stepper or types a new qty. |
504
+ | `remove` | `(itemId)` | User clicks the trash / × button on a line. |
505
+ | `clear` | `()` | User clicks "Clear cart". |
506
+ | `apply-coupon` | `(code: string)` | User submits a coupon code. Always emitted. |
507
+ | `remove-coupon` | `()` | User removes an applied coupon. |
508
+ | `coupon-change` | `(code: string)` | User types in the coupon field. |
509
+ | `update:coupon` | `(coupon: CartCoupon \| null)` | Cart wants to change the applied coupon (apply / reject / remove). Use with `v-model:coupon`. |
510
+ | `update:totals` | `(totals: CartTotals)` | Cart's currently-used totals. Fires whenever the totals change — whether the cart computed them or you supplied them. **Observe only.** Use to sync to your server, but never write this back into `data.totals` (it'll freeze the cart on the first emitted value). |
511
+ | `continue` | `()` | User clicks the primary action. |
512
+ | `continue-shopping` | `()` | User clicks the secondary action. |
513
+
514
+ ## API
515
+
516
+ See the [Cart Demo](/components/cart) for a full interactive reference. The key types are:
517
+
518
+ - `CartData` — root data object (includes `tax`, `shipping`, `coupons`, `currency`)
519
+ - `CartItem` — one line item
520
+ - `CartTotals` — subtotal / discount / tax / grand total / currency (auto-computed if not provided)
521
+ - `CartTaxConfig` — `rate | flat | exempt | inclusive` tax configuration
522
+ - `CartShippingConfig` — `flat | free | freeOver | tiered | function | pickup` shipping rule
523
+ - `CartCouponDefinition` — coupon business rules (type, value, min/max, expiry, etc.)
524
+ - `CartCoupon` — applied coupon with state + (optional) definition
525
+ - `CartFeatures` — per-feature on/off toggles
526
+ - `CartActions` — action button configuration
527
+ - `CartLabels` — text label overrides for i18n / rebranding
528
+ - `CartTrustSignal` — array of icon + text objects for rendering trust signals
529
+ - `CartVariant` — `'Variant1' | 'Variant2' | 'Variant3' | 'Variant4'`
530
+ - `CartCouponState` — `'idle' | 'applying' | 'applied' | 'invalid' | 'expired' | 'error'`
531
+ - `CartProps` — component props (adds `validateCoupon` for async validation)
532
+ - `useCart` — cart state composable for adding/removing items and passing data into `<Cart />`
533
+ - `UseCartOptions` / `UseCartReturn` — composable options and return contracts