@tallyui/components 3.20.1 → 4.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.
Files changed (161) hide show
  1. package/dist/index.d.ts +1114 -90
  2. package/dist/index.js +8077 -3352
  3. package/package.json +10 -11
  4. package/src/cart/cart-charge-line.tsx +58 -0
  5. package/src/cart/cart-columns-form.tsx +98 -0
  6. package/src/cart/cart-columns.tsx +49 -18
  7. package/src/cart/cart-foot.tsx +7 -2
  8. package/src/cart/cart-line-strip.tsx +59 -0
  9. package/src/cart/cart-line.tsx +20 -8
  10. package/src/cart/cart-note-row.tsx +30 -0
  11. package/src/cart/cart-panel.tsx +9 -1
  12. package/src/cart/cart-row-motion.tsx +125 -0
  13. package/src/cart/cart-total.tsx +44 -15
  14. package/src/cart/index.ts +2 -1
  15. package/src/checkout/cash-tendered.tsx +8 -7
  16. package/src/checkout/change-display.tsx +2 -1
  17. package/src/checkout/index.ts +1 -1
  18. package/src/checkout/payment-selector.tsx +6 -2
  19. package/src/checkout/payment-types.test-d.ts +28 -0
  20. package/src/customer/address-editor.tsx +87 -0
  21. package/src/customer/address-fields.tsx +120 -0
  22. package/src/customer/customer-dropdown.tsx +200 -0
  23. package/src/customer/customer-editor.tsx +99 -0
  24. package/src/customer/customer-form.tsx +39 -5
  25. package/src/customer/customer-picker.tsx +38 -14
  26. package/src/customer/customers-list.tsx +83 -0
  27. package/src/customer/index.ts +5 -0
  28. package/src/filter/filter-pills.tsx +63 -0
  29. package/src/i18n/locales/en/components.json +85 -0
  30. package/src/index.ts +40 -2
  31. package/src/input/decimal-entry.ts +21 -0
  32. package/src/layout/checkout-layout.tsx +1 -1
  33. package/src/layout/live-tab-screen.tsx +1 -1
  34. package/src/layout/pos-layout.tsx +80 -4
  35. package/src/layout/settings-layout.tsx +1 -1
  36. package/src/layout/store-settings-choice-screen.tsx +1 -1
  37. package/src/lib/current-row.ts +13 -0
  38. package/src/lib/money-input.ts +16 -0
  39. package/src/lib/motion.ts +22 -0
  40. package/src/lib/use-reduced-motion.ts +20 -0
  41. package/src/order/index.ts +1 -1
  42. package/src/order/order-detail.tsx +123 -5
  43. package/src/order/order-filter-bar.tsx +7 -57
  44. package/src/order/order-status-badge.tsx +42 -19
  45. package/src/order/refund-form.tsx +7 -5
  46. package/src/product/camera-scan-button.tsx +2 -0
  47. package/src/product/category-nav.tsx +8 -0
  48. package/src/product/category-tile.tsx +65 -15
  49. package/src/product/in-cart-badge.tsx +55 -6
  50. package/src/product/index.ts +1 -0
  51. package/src/product/press-veil.tsx +7 -0
  52. package/src/product/product-card.tsx +5 -1
  53. package/src/product/product-grid.tsx +5 -0
  54. package/src/product/product-price.tsx +6 -3
  55. package/src/product/product-stock-badge.tsx +3 -2
  56. package/src/product/product-table.tsx +96 -8
  57. package/src/product/products-screen-columns.tsx +74 -0
  58. package/src/product/variant-tile.tsx +68 -0
  59. package/src/product/variation-picker.tsx +3 -3
  60. package/src/product/view-toggle.tsx +33 -4
  61. package/src/register/cashier-sheet.tsx +195 -0
  62. package/src/register/closure-sheet.tsx +54 -3
  63. package/src/register/handover-slip.tsx +2 -1
  64. package/src/register/index.ts +2 -1
  65. package/src/register/movement-sheet.tsx +66 -7
  66. package/src/register/open-register-card.tsx +11 -11
  67. package/src/register/register-bar.helpers.ts +17 -4
  68. package/src/register/register-bar.tsx +26 -5
  69. package/src/register/register-count.tsx +158 -24
  70. package/src/register/register-panel.tsx +16 -5
  71. package/src/register/register-side-sheet.tsx +32 -8
  72. package/src/register/switch-confirm.tsx +2 -2
  73. package/src/reports/card-panel.tsx +131 -0
  74. package/src/reports/cards.tsx +53 -36
  75. package/src/reports/hero.tsx +2 -1
  76. package/src/reports/index.ts +1 -0
  77. package/src/reports/sales-room.tsx +4 -2
  78. package/src/sale/breadcrumb.tsx +48 -0
  79. package/src/sale/cart-bar.tsx +2 -1
  80. package/src/sale/cart.tsx +127 -38
  81. package/src/sale/catalogue-settings-form.tsx +92 -0
  82. package/src/sale/catalogue.tsx +304 -42
  83. package/src/sale/category-browse.tsx +27 -0
  84. package/src/sale/charge-form.tsx +85 -21
  85. package/src/sale/customer-display-screen.tsx +22 -6
  86. package/src/sale/discount-form.tsx +132 -28
  87. package/src/sale/index.ts +6 -3
  88. package/src/sale/line-popover.tsx +72 -36
  89. package/src/sale/offered-methods.ts +16 -0
  90. package/src/sale/open-sale-tabs.tsx +58 -10
  91. package/src/sale/order-note-sheet.tsx +37 -0
  92. package/src/sale/order-reference.ts +3 -0
  93. package/src/sale/orders-list.tsx +76 -37
  94. package/src/sale/parked-sales.tsx +2 -1
  95. package/src/sale/price-form.tsx +7 -5
  96. package/src/sale/product-filter-bar.tsx +38 -5
  97. package/src/sale/receipt-sheet.tsx +243 -0
  98. package/src/sale/receipt.tsx +19 -9
  99. package/src/sale/sync-status.tsx +10 -0
  100. package/src/sale/tender-ledger.tsx +92 -0
  101. package/src/sale/tender-pane.tsx +159 -73
  102. package/src/sale/tender.tsx +10 -7
  103. package/src/sale/use-tender.ts +63 -0
  104. package/src/scale/min-target.tsx +36 -0
  105. package/src/settings/barcode-scanning-settings.tsx +164 -0
  106. package/src/settings/connector-status.tsx +1 -1
  107. package/src/settings/customer-display-settings.tsx +12 -25
  108. package/src/settings/index.ts +5 -0
  109. package/src/settings/printer-form.tsx +161 -0
  110. package/src/settings/printing-settings.tsx +268 -0
  111. package/src/settings/settings-group.tsx +2 -1
  112. package/src/settings/tax-calculation-settings.tsx +1 -1
  113. package/src/shell/added-to-cart-toast.tsx +61 -0
  114. package/src/shell/app-shell.tsx +5 -1
  115. package/src/shell/connectivity-toast.tsx +70 -0
  116. package/src/shell/index.ts +2 -0
  117. package/src/shell/nav-drawer.tsx +5 -2
  118. package/src/shell/nav-item.tsx +7 -4
  119. package/src/shell/nav-rail.tsx +9 -2
  120. package/src/ui/accordion/index.tsx +86 -8
  121. package/src/ui/alert-dialog/index.tsx +19 -5
  122. package/src/ui/combobox/index.tsx +21 -2
  123. package/src/ui/confirm-dialog/index.tsx +53 -0
  124. package/src/ui/dialog/index.tsx +68 -14
  125. package/src/ui/dialog/motion.ts +54 -0
  126. package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
  127. package/src/ui/icon/alert-circle-icon.tsx +5 -0
  128. package/src/ui/icon/alert-triangle-icon.tsx +7 -0
  129. package/src/ui/icon/banknote-icon.tsx +11 -0
  130. package/src/ui/icon/cash-register-icon.tsx +10 -0
  131. package/src/ui/icon/category-icon.tsx +7 -0
  132. package/src/ui/icon/chart-line-icon.tsx +5 -0
  133. package/src/ui/icon/check-icon.tsx +5 -0
  134. package/src/ui/icon/chevron-left-icon.tsx +4 -0
  135. package/src/ui/icon/chevron-right-icon.tsx +4 -0
  136. package/src/ui/icon/credit-card-icon.tsx +10 -0
  137. package/src/ui/icon/discount-icon.tsx +11 -0
  138. package/src/ui/icon/gift-icon.tsx +10 -0
  139. package/src/ui/icon/info-circle-icon.tsx +10 -0
  140. package/src/ui/icon/map-pin-icon.tsx +10 -0
  141. package/src/ui/icon/message-question-icon.tsx +7 -0
  142. package/src/ui/icon/pencil-icon.tsx +10 -0
  143. package/src/ui/icon/plus-icon.tsx +9 -0
  144. package/src/ui/icon/printer-icon.tsx +10 -0
  145. package/src/ui/icon/receipt-icon.tsx +7 -0
  146. package/src/ui/icon/settings-icon.tsx +10 -0
  147. package/src/ui/icon/sticky-note-icon.tsx +10 -0
  148. package/src/ui/icon/user-icon.tsx +4 -0
  149. package/src/ui/icon/users-icon.tsx +7 -0
  150. package/src/ui/icon/view-grid-icon.tsx +7 -0
  151. package/src/ui/icon/view-list-icon.tsx +7 -0
  152. package/src/ui/index.ts +24 -1
  153. package/src/ui/list-row/index.tsx +93 -0
  154. package/src/ui/notice/index.tsx +65 -0
  155. package/src/ui/select/index.tsx +2 -0
  156. package/src/ui/skeleton/index.tsx +37 -0
  157. package/src/ui/status-badge/index.tsx +43 -0
  158. package/src/ui/switch/index.tsx +1 -1
  159. package/src/ui/tabs/index.tsx +11 -2
  160. package/src/ui/toggle-group/index.tsx +3 -1
  161. package/src/ui/tone-disc/index.tsx +41 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/components",
3
- "version": "3.20.1",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "description": "Universal POS UI components for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -28,9 +28,9 @@
28
28
  "directory": "packages/components"
29
29
  },
30
30
  "peerDependencies": {
31
- "@tallyui/core": "^3.20.1",
32
- "@tallyui/primitives": "^3.20.1",
33
- "@tallyui/theme": "^3.20.1",
31
+ "@tallyui/core": "^4.0.0",
32
+ "@tallyui/primitives": "^4.0.0",
33
+ "@tallyui/theme": "^4.0.0",
34
34
  "react": ">=18",
35
35
  "react-native": ">=0.74",
36
36
  "react-native-svg": ">=15"
@@ -39,13 +39,13 @@
39
39
  "class-variance-authority": "^0.7.1",
40
40
  "i18next": "^26.7.1",
41
41
  "react-i18next": "^17.1.12",
42
- "@tallyui/pos": "3.20.1"
42
+ "@tallyui/pos": "4.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@tallyui/connector-medusa": "3.20.1",
46
- "@tallyui/connector-vendure": "3.20.1",
47
- "@tallyui/connector-woocommerce": "3.20.1",
48
- "@tallyui/mock-api": "3.20.1",
45
+ "@tallyui/connector-medusa": "4.0.0",
46
+ "@tallyui/connector-vendure": "4.0.0",
47
+ "@tallyui/connector-woocommerce": "4.0.0",
48
+ "@tallyui/mock-api": "4.0.0",
49
49
  "@types/react": ">=18",
50
50
  "react": "^19.2.4",
51
51
  "react-native-svg": "15.12.1",
@@ -54,7 +54,6 @@
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsup",
57
- "typecheck": "tsc --noEmit",
58
- "test": "echo \"no tests yet\""
57
+ "typecheck": "tsc --noEmit"
59
58
  }
60
59
  }
@@ -0,0 +1,58 @@
1
+ // Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/table.tsx cells for fee_lines/shipping_lines,
2
+ // cells/fee-name.tsx, cells/fee-price.tsx, cells/shipping-price.tsx and cells/fee-and-shipping-total.tsx; MIT, WCPOS.
3
+ import type { JSX, ReactNode } from 'react';
4
+ import { View } from 'react-native';
5
+ import { useFormatMoney, type Money } from '@tallyui/core';
6
+ import { cn } from '@tallyui/theme';
7
+ import { Text, HStack, type HStackProps } from '../ui';
8
+ import { CART_COLUMNS, CART_PICKING_QUANTITY, cartColumnSlots, type CartColumnSettings } from './cart-columns';
9
+
10
+ export interface CartChargeLineProps extends Omit<HStackProps, 'children'> {
11
+ name: string;
12
+ /** The charge as entered (v2's Price cell). */
13
+ price: Money;
14
+ /** The charge in the display tax mode (v2's Total cell). */
15
+ total: Money;
16
+ /** As CartLine's showPrice. */
17
+ showPrice?: boolean;
18
+ /** As CartLine's columns. */
19
+ columns?: CartColumnSettings;
20
+ locale?: string;
21
+ /** A percent fee: the Price cell shows the percent, as v2's fee-price.tsx. */
22
+ percent?: number;
23
+ /** As CartColumnHeads' `picking`: the quantity column takes its wider picking width (default false). */
24
+ picking?: boolean;
25
+ className?: string;
26
+ /** The line strip's press target (`CartLineStrip`): wraps the Total cell's content, or the last visible cell's when
27
+ * Total is hidden, as v2's table does. */
28
+ wrapTotal?: (content: ReactNode) => ReactNode;
29
+ }
30
+
31
+ export function CartChargeLine({ name, price, total, showPrice = true, columns, locale, percent, picking = false, className, wrapTotal, ...rest }: CartChargeLineProps): JSX.Element {
32
+ const formatMoney = useFormatMoney();
33
+ const slots = cartColumnSlots(columns, { showPrice });
34
+ const target = slots.includes('total') ? 'total' : slots[slots.length - 1];
35
+ const wrap = (id: (typeof slots)[number], content: ReactNode) => wrapTotal && id === target ? wrapTotal(content) : content;
36
+ const cells: Record<(typeof slots)[number], ReactNode> = {
37
+ fill: <View key="fill" className="flex-1">{wrap('fill', null)}</View>,
38
+ quantity: <View key="quantity" className={(picking ? CART_PICKING_QUANTITY : CART_COLUMNS.quantity).cell}>{wrap('quantity', null)}</View>,
39
+ image: <View key="image" className={CART_COLUMNS.image.cell}>{wrap('image', null)}</View>,
40
+ name: <View key="name" className={CART_COLUMNS.name.cell}>
41
+ {wrap('name', <Text className="text-sm" numberOfLines={2}>{name}</Text>)}
42
+ </View>,
43
+ sku: <View key="sku" className={CART_COLUMNS.sku.cell}>{wrap('sku', null)}</View>,
44
+ regularPrice: <View key="regularPrice" className={CART_COLUMNS.regularPrice.cell}>{wrap('regularPrice', null)}</View>,
45
+ price: <View key="price" className={CART_COLUMNS.price.cell}>
46
+ {wrap('price', <Text testID="cart-charge-price" className="text-right text-sm tabular-nums text-muted-foreground">
47
+ {percent !== undefined ? `${new Intl.NumberFormat(locale, { maximumFractionDigits: 4 }).format(percent)}%` : formatMoney(price, locale) ?? '—'}</Text>)}
48
+ </View>,
49
+ total: <View key="total" className={CART_COLUMNS.total.cell}>
50
+ {wrap('total', <Text testID="cart-charge-total" className="text-right text-sm tabular-nums">{formatMoney(total, locale) ?? '—'}</Text>)}
51
+ </View>,
52
+ };
53
+ return (
54
+ <HStack space="none" className={cn('py-2.5', className)} {...rest}>
55
+ {slots.map((id) => cells[id])}
56
+ </HStack>
57
+ );
58
+ }
@@ -0,0 +1,98 @@
1
+ // Ported from WCPOS v2 packages/core/src/screens/main/components/ui-settings/columns-form.tsx (the Columns section,
2
+ // its Show and display switches) and use-ui-label.ts (the labels), MIT, WCPOS. v2's drag handle is replaced by Move up
3
+ // and Move down buttons (desk, 19 Nov).
4
+ import type { JSX } from 'react';
5
+ import { View, type ViewProps } from 'react-native';
6
+ import { cn } from '@tallyui/theme';
7
+ import { useT } from '../i18n';
8
+ import { Button } from '../ui/button';
9
+ import { ChevronDownIcon } from '../ui/icon/chevron-down-icon';
10
+ import { IconButton } from '../ui/icon-button';
11
+ import { Switch } from '../ui/switch';
12
+ import { Text } from '../ui/text';
13
+ import { CART_COLUMN_DEFAULT_SHOWN, cartColumnOrder, type CartColumnId, type CartColumnSettings } from './cart-columns';
14
+
15
+ /** Each column's catalogue key, v2's `use-ui-label.ts`. */
16
+ const LABELS: Record<CartColumnId, string> = {
17
+ quantity: 'pos_cart.qty_abbrev', image: 'common.image', name: 'common.name', sku: 'common.sku',
18
+ price: 'common.price', regularPrice: 'common.regular_price', total: 'common.total',
19
+ };
20
+
21
+ /** The display switch nested under a column, drawn only while the column shows; `on` is its default. */
22
+ const DISPLAY: Partial<Record<CartColumnId, { field: 'split' | 'sku' | 'onSale'; label: string; on: boolean }>> = {
23
+ quantity: { field: 'split', label: 'pos_cart.split_qty', on: false },
24
+ name: { field: 'sku', label: 'common.sku', on: false },
25
+ price: { field: 'onSale', label: 'common.on_sale', on: true },
26
+ };
27
+
28
+ export interface CartColumnsFormProps extends Omit<ViewProps, 'children'> {
29
+ /** The saved columns (default `{}`, today's look). */
30
+ value?: CartColumnSettings;
31
+ /** Called with a fresh value on every change; the form stores nothing. */
32
+ onChange: (next: CartColumnSettings) => void;
33
+ /** Draw a Restore Default Settings button that emits `{}` (default false; v2 keeps it in the dialog footer). */
34
+ showReset?: boolean;
35
+ className?: string;
36
+ }
37
+
38
+ /**
39
+ * v2's Cart Settings › Columns: a Show switch per column, the nested Split, SKU and On Sale switches, and Move up and
40
+ * Move down buttons for the order. It emits a value for `Cart`'s `columns`.
41
+ *
42
+ * ```tsx
43
+ * <CartColumnsForm value={settings['cart.columns']} onChange={(next) => setSetting('cart.columns', next)} />
44
+ * ```
45
+ */
46
+ export function CartColumnsForm({ value = {}, onChange, showReset = false, className, ...viewProps }: CartColumnsFormProps): JSX.Element {
47
+ const t = useT();
48
+ const order = cartColumnOrder(value);
49
+ const patch = (id: CartColumnId, fields: Record<string, boolean>) =>
50
+ onChange({ ...value, [id]: { ...value[id], ...fields } });
51
+ const move = (at: number, by: -1 | 1) => {
52
+ const next = [...order];
53
+ [next[at], next[at + by]] = [next[at + by], next[at]];
54
+ onChange({ ...value, order: next });
55
+ };
56
+ return (
57
+ <View className={cn('gap-1', className)} {...viewProps}>
58
+ <Text role="heading" className="pb-1 text-base font-semibold">{t('common.columns')}</Text>
59
+ {order.map((id, at) => {
60
+ const label = t(LABELS[id]);
61
+ const show = value[id]?.show ?? CART_COLUMN_DEFAULT_SHOWN[id];
62
+ const display = DISPLAY[id];
63
+ const fields = value[id] as Record<string, boolean | undefined> | undefined;
64
+ const first = at === 0;
65
+ const last = at === order.length - 1;
66
+ return (
67
+ <View key={id} testID={`cart-columns-${id}`} className="py-1">
68
+ <View className="flex-row items-center gap-3">
69
+ <Switch testID={`cart-columns-${id}-show`} accessibilityLabel={label} checked={show}
70
+ onCheckedChange={(on) => patch(id, { show: on })} />
71
+ <Text className="flex-1">{label}</Text>
72
+ <IconButton size="sm" testID={`cart-columns-${id}-up`} accessibilityLabel={t('common.move_up_value', { label })}
73
+ disabled={first} aria-disabled={first} onPress={() => move(at, -1)}>
74
+ <View style={{ transform: [{ rotate: '180deg' }] }}><ChevronDownIcon size={18} strokeWidth={1.5} /></View>
75
+ </IconButton>
76
+ <IconButton size="sm" testID={`cart-columns-${id}-down`} accessibilityLabel={t('common.move_down_value', { label })}
77
+ disabled={last} aria-disabled={last} onPress={() => move(at, 1)}>
78
+ <ChevronDownIcon size={18} strokeWidth={1.5} />
79
+ </IconButton>
80
+ </View>
81
+ {display && show ? (
82
+ <View className="flex-row items-center gap-3 pt-2 pl-10">
83
+ <Switch size="sm" testID={`cart-columns-${id}-${display.field}`} accessibilityLabel={t(display.label)}
84
+ checked={fields?.[display.field] ?? display.on} onCheckedChange={(on) => patch(id, { [display.field]: on })} />
85
+ <Text className="flex-1 text-sm">{t(display.label)}</Text>
86
+ </View>
87
+ ) : null}
88
+ </View>
89
+ );
90
+ })}
91
+ {showReset ? (
92
+ <Button variant="outline" testID="cart-columns-reset" className="mt-2 self-start" onPress={() => onChange({})}>
93
+ <Text>{t('common.restore_default_settings')}</Text>
94
+ </Button>
95
+ ) : null}
96
+ </View>
97
+ );
98
+ }
@@ -4,6 +4,7 @@
4
4
  import type { JSX } from 'react';
5
5
  import { View, type ViewProps } from 'react-native';
6
6
  import { cn } from '@tallyui/theme';
7
+ import { useT } from '../i18n';
7
8
  import { Text } from '../ui';
8
9
 
9
10
  /**
@@ -11,13 +12,16 @@ import { Text } from '../ui';
11
12
  * left, so a total never wraps. The total cell has a floor, so a long total widens its own cell rather than wrapping.
12
13
  */
13
14
  export const CART_COLUMNS = {
14
- quantity: { head: 'w-12 flex-none items-center pr-2 pl-3', cell: 'w-12 flex-none items-center pr-2 pl-3' },
15
+ quantity: { head: 'w-12 flex-none items-center pr-1 pl-2', cell: 'w-12 flex-none items-center pr-2 pl-3' },
15
16
  image: { head: 'w-14 flex-none items-center justify-center pl-3', cell: 'w-14 flex-none items-center justify-center pl-3' },
16
17
  name: { head: 'min-w-0 flex-1 px-3', cell: 'min-w-0 flex-1 px-3' },
17
18
  sku: { head: 'w-24 flex-none px-2', cell: 'w-24 flex-none px-2' },
18
19
  price: { head: 'w-18 flex-none items-end px-2', cell: 'w-18 flex-none items-end px-2' },
20
+ regularPrice: { head: 'w-18 flex-none items-end px-2', cell: 'w-18 flex-none items-end px-2' },
19
21
  total: { head: 'w-20 flex-none items-end pr-3 pl-2', cell: 'min-w-20 flex-none items-end pr-3 pl-2' },
20
22
  };
23
+ /** The quantity column while Cart's `picker` is on: w-48 (192px) fits v2's `− 99 of 99 +` stepper (two 44px buttons, two gaps and the count, about 175px) and its "This payment" head. */
24
+ export const CART_PICKING_QUANTITY = { head: 'w-48 flex-none items-center px-2', cell: 'w-48 flex-none items-center px-2' };
21
25
 
22
26
  /** Under this cart width the Price column folds away, so the item name keeps room to read. */
23
27
  const PRICE_COLUMN_MIN_WIDTH = 300;
@@ -32,8 +36,9 @@ export function cartShowsPrice({ cartWidth, windowWidth, windowHeight }:
32
36
  }
33
37
 
34
38
  /**
35
- * v2's Cart Settings › Columns: each column's `show` switch and display options. Every field is optional; the
36
- * defaults are today's look and v2's: Qty, Item, Price and Total show; Image, SKU, `quantity.split` and `name.sku` are off.
39
+ * v2's Cart Settings › Columns: each column's `show` switch, display options and order. Every field is optional; the
40
+ * defaults are today's look and v2's: Qty, Item, Price and Total show, in v2's order (Qty, Image, Item, SKU, Price,
41
+ * Regular Price, Total), with `price.onSale` on; Image, SKU, Regular Price, `quantity.split` and `name.sku` are off.
37
42
  */
38
43
  export interface CartColumnSettings {
39
44
  /** `split`: a Split link under a quantity above 1. */
@@ -43,35 +48,59 @@ export interface CartColumnSettings {
43
48
  /** `sku`: the SKU on a line under the name. */
44
49
  name?: { show?: boolean; sku?: boolean };
45
50
  sku?: { show?: boolean };
46
- /** Still folds on a narrow cart or a phone (`showPrice`). */
47
- price?: { show?: boolean };
51
+ /** Still folds on a narrow cart or a phone (`showPrice`). `onSale` (default true): the regular price struck through
52
+ * above a lower price (v2's `on_sale`). */
53
+ price?: { show?: boolean; onSale?: boolean };
54
+ /** The regular unit price, read-only (v2's Regular Price column); off by default. */
55
+ regularPrice?: { show?: boolean };
48
56
  total?: { show?: boolean };
57
+ /** The column order (v2's drag order). Listed ids come first, in this order; ids not listed follow in the default
58
+ * order; unknown and repeated ids are ignored. */
59
+ order?: readonly CartColumnId[];
49
60
  }
50
61
 
51
- export type CartColumnId = 'quantity' | 'image' | 'name' | 'sku' | 'price' | 'total';
52
- const DEFAULT_SHOWN: Record<CartColumnId, boolean> = { quantity: true, image: false, name: true, sku: false, price: true, total: true };
62
+ export type CartColumnId = 'quantity' | 'image' | 'name' | 'sku' | 'price' | 'regularPrice' | 'total';
63
+ export const CART_COLUMN_DEFAULT_SHOWN: Record<CartColumnId, boolean> = {
64
+ quantity: true, image: false, name: true, sku: false, price: true, regularPrice: false, total: true,
65
+ };
66
+
67
+ /** Every column in `columns.order`, then the default order. */
68
+ export function cartColumnOrder(columns: CartColumnSettings = {}): CartColumnId[] {
69
+ const all = Object.keys(CART_COLUMN_DEFAULT_SHOWN) as CartColumnId[];
70
+ return [...new Set([...(columns.order ?? []).filter((id) => all.includes(id)), ...all])];
71
+ }
53
72
 
54
- /** The visible columns, in their fixed order; the heads and every line use it, so they cannot disagree. */
73
+ const shown = (columns: CartColumnSettings, showPrice: boolean) => (id: CartColumnId) =>
74
+ (columns[id]?.show ?? CART_COLUMN_DEFAULT_SHOWN[id]) && (id !== 'price' || showPrice);
75
+
76
+ /** The visible columns, in order; the heads and every line use it, so they cannot disagree. */
55
77
  export function cartColumnIds(columns: CartColumnSettings = {}, { showPrice = true }: { showPrice?: boolean } = {}): CartColumnId[] {
56
- return (Object.keys(DEFAULT_SHOWN) as CartColumnId[])
57
- .filter((id) => (columns[id]?.show ?? DEFAULT_SHOWN[id]) && (id !== 'price' || showPrice));
78
+ return cartColumnOrder(columns).filter(shown(columns, showPrice));
58
79
  }
59
80
 
60
81
  /** cartColumnIds with a `fill` in Item's place when it is hidden, so the amount columns stay right-aligned. */
61
- export function cartColumnSlots(...args: Parameters<typeof cartColumnIds>): (CartColumnId | 'fill')[] {
62
- const ids = cartColumnIds(...args);
82
+ export function cartColumnSlots(columns: CartColumnSettings = {}, { showPrice = true }: { showPrice?: boolean } = {}): (CartColumnId | 'fill')[] {
83
+ const ordered = cartColumnOrder(columns);
84
+ const ids = ordered.filter(shown(columns, showPrice));
63
85
  if (ids.includes('name')) return ids;
64
- const at = ids.filter((id) => id === 'quantity' || id === 'image').length;
65
- return [...ids.slice(0, at), 'fill', ...ids.slice(at)];
86
+ const after = ordered.slice(ordered.indexOf('name') + 1);
87
+ const at = ids.findIndex((id) => after.includes(id));
88
+ return at < 0 ? [...ids, 'fill'] : [...ids.slice(0, at), 'fill', ...ids.slice(at)];
66
89
  }
67
90
 
68
- const HEADS: Record<CartColumnId, string> = { quantity: 'Qty', image: '', name: 'Item', sku: 'SKU', price: 'Price', total: 'Total' };
91
+ /** Each head's catalogue key, v2's `pos_cart.col_*` and `common.*`; Image has no label. */
92
+ const HEADS: Partial<Record<CartColumnId, string>> = {
93
+ quantity: 'pos_cart.col_qty', name: 'pos_cart.col_item', sku: 'common.sku', price: 'pos_cart.col_price',
94
+ regularPrice: 'common.regular_price', total: 'pos_cart.col_total',
95
+ };
69
96
 
70
97
  export interface CartColumnHeadsProps extends Omit<ViewProps, 'children'> {
71
98
  /** Show the Price head (default true); pass the same value as each CartLine's `showPrice`. */
72
99
  showPrice?: boolean;
73
100
  /** Which columns show (v2's Cart Settings › Columns); pass the same value as each CartLine's `columns`. */
74
101
  columns?: CartColumnSettings;
102
+ /** Cart's `picker` is on: the quantity column heads v2's split-by-item bill, "This payment" (default false). */
103
+ picking?: boolean;
75
104
  className?: string;
76
105
  }
77
106
 
@@ -82,12 +111,14 @@ export interface CartColumnHeadsProps extends Omit<ViewProps, 'children'> {
82
111
  * <CartColumnHeads showPrice={showPrice} />
83
112
  * ```
84
113
  */
85
- export function CartColumnHeads({ showPrice = true, columns, className, ...props }: CartColumnHeadsProps): JSX.Element {
114
+ export function CartColumnHeads({ showPrice = true, columns, picking = false, className, ...props }: CartColumnHeadsProps): JSX.Element {
115
+ const t = useT();
116
+ const label = (id: CartColumnId) => picking && id === 'quantity' ? t('pos_checkout.this_payment') : HEADS[id] && t(HEADS[id]);
86
117
  return (
87
118
  <View role="row" className={cn('flex-row border-b border-border', className)} {...props}>
88
119
  {cartColumnSlots(columns, { showPrice }).map((id) => id === 'fill' ? <View key={id} className="flex-1" /> : (
89
- <View key={id} role="columnheader" className={cn('h-9 justify-center', CART_COLUMNS[id].head)}>
90
- {HEADS[id] ? <Text className="text-xs font-medium uppercase tracking-wide text-muted-foreground" numberOfLines={1}>{HEADS[id]}</Text> : null}
120
+ <View key={id} role="columnheader" className={cn('h-9 justify-center', (picking && id === 'quantity' ? CART_PICKING_QUANTITY : CART_COLUMNS[id]).head)}>
121
+ {label(id) ? <Text className="text-xs font-medium uppercase tracking-wide text-muted-foreground" numberOfLines={1}>{label(id)}</Text> : null}
91
122
  </View>
92
123
  ))}
93
124
  </View>
@@ -2,8 +2,9 @@
2
2
  // (the ⋮ beside a full-width "Checkout {order_total}"), MIT, WCPOS.
3
3
  import * as React from 'react';
4
4
  import { Platform, Pressable, Text, View } from 'react-native';
5
- import { formatMoney, type Money } from '@tallyui/core';
5
+ import { useFormatMoney, type Money } from '@tallyui/core';
6
6
  import { cn } from '@tallyui/theme';
7
+ import { CartNoteRow } from './cart-note-row';
7
8
 
8
9
  export interface CartFootAction {
9
10
  label: string;
@@ -17,6 +18,8 @@ export interface CartFootProps {
17
18
  onCheckout: () => void;
18
19
  /** The ⋮ menu's items; the ⋮ is left out when there are none. */
19
20
  actions?: readonly CartFootAction[];
21
+ /** v2's note row above the buttons: hidden when the text is empty; pressing it calls onPress (the app opens its note editor). */
22
+ note?: { text: string; onPress: () => void };
20
23
  /** Disables Checkout only; the menu stays usable. */
21
24
  disabled?: boolean;
22
25
  locale?: string;
@@ -33,7 +36,8 @@ const MENU_LABEL = 'More actions';
33
36
  * <CartFoot total={total} onCheckout={startCheckout} actions={[{ label: 'Void', onPress: voidSale, destructive: true }]} />
34
37
  * ```
35
38
  */
36
- export function CartFoot({ total, onCheckout, actions = [], disabled = false, locale, className }: CartFootProps) {
39
+ export function CartFoot({ total, onCheckout, actions = [], note, disabled = false, locale, className }: CartFootProps) {
40
+ const formatMoney = useFormatMoney();
37
41
  const [open, setOpen] = React.useState(false);
38
42
  const trigger = React.useRef<View>(null);
39
43
  const menu = React.useRef<View>(null);
@@ -53,6 +57,7 @@ export function CartFoot({ total, onCheckout, actions = [], disabled = false, lo
53
57
 
54
58
  return (
55
59
  <View className={cn('gap-2', className)}>
60
+ {note ? <CartNoteRow text={note.text} onPress={note.onPress} /> : null}
56
61
  {open && actions.length > 0 ? (
57
62
  <View ref={menu} role="menu" aria-label={MENU_LABEL} testID="cart-foot-menu"
58
63
  className="rounded-md border border-border bg-card p-1">
@@ -0,0 +1,59 @@
1
+ // Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/cells/line-strip.tsx (press to open, Remove flies the row off; no swipe or hover yet) and cells/edit-cart-item-button.tsx; MIT, WCPOS.
2
+ import { useRef, useState, type JSX, type ReactNode } from 'react';
3
+ import { Animated, Platform, Pressable, View } from 'react-native';
4
+ import { Button, Text } from '../ui';
5
+ import { ARM, EASE_EXIT, PANEL_SLIDE_OUT } from '../lib/motion';
6
+ import { useReducedMotion } from '../lib/use-reduced-motion';
7
+
8
+ /** A cart row with v2's hidden strip under it: pressing the row's Total slides the row left onto a solid Edit and Remove. */
9
+ export function CartLineStrip({ name, onEdit, onRemove, children }: {
10
+ name: string;
11
+ onEdit: () => void;
12
+ // A returned string is a refusal, and the row comes back.
13
+ onRemove: () => string | null | void;
14
+ children: (wrapTotal: (content: ReactNode) => ReactNode) => ReactNode;
15
+ }): JSX.Element {
16
+ const reduced = useReducedMotion() !== false;
17
+ const offset = useRef(new Animated.Value(0)).current;
18
+ // The row is flying off or its removal is committing: nothing else may move it.
19
+ const leaving = useRef(false);
20
+ const [open, setOpen] = useState(false);
21
+ const [rowWidth, setRowWidth] = useState<number>();
22
+ const [stripWidth, setStripWidth] = useState(0);
23
+ const settle = (next: boolean) => {
24
+ if (leaving.current) return;
25
+ setOpen(next);
26
+ const target = next ? -stripWidth : 0;
27
+ if (reduced) offset.setValue(target);
28
+ else Animated.spring(offset, { toValue: target, overshootClamping: true, useNativeDriver: Platform.OS !== 'web' }).start();
29
+ };
30
+ const commit = () => { if (typeof onRemove() === 'string') { leaving.current = false; settle(false); } };
31
+ const leave = () => {
32
+ if (leaving.current) return;
33
+ leaving.current = true;
34
+ if (reduced || !rowWidth) return commit();
35
+ Animated.timing(offset, { toValue: -rowWidth, duration: PANEL_SLIDE_OUT, delay: ARM, easing: EASE_EXIT,
36
+ useNativeDriver: Platform.OS !== 'web' }).start(({ finished }) => {
37
+ if (finished) return commit();
38
+ leaving.current = false;
39
+ settle(false);
40
+ });
41
+ };
42
+ const wrapTotal = (content: ReactNode) => <Pressable testID="cart-line-total" accessibilityRole="button"
43
+ accessibilityLabel={`Edit total of ${name}`} accessibilityState={{ expanded: open }} className="justify-center"
44
+ onPress={() => settle(!open)}>{content}</Pressable>;
45
+ const block = 'h-auto min-w-16 rounded-none px-5';
46
+ return <View testID="cart-line-row" className="relative overflow-hidden" onLayout={(event) => setRowWidth(event.nativeEvent.layout.width)}>
47
+ <View testID="cart-line-strip" className="absolute inset-y-0 right-0 flex-row items-stretch justify-end bg-destructive"
48
+ style={rowWidth === undefined ? undefined : { width: rowWidth }} pointerEvents={open ? 'auto' : 'none'}
49
+ accessibilityElementsHidden={!open} importantForAccessibility={open ? 'auto' : 'no-hide-descendants'} aria-hidden={!open}>
50
+ <View testID="cart-line-strip-actions" className="flex-row items-stretch" onLayout={(event) => setStripWidth(event.nativeEvent.layout.width)}>
51
+ <Button variant="default" testID="cart-line-edit" accessibilityLabel={`Edit ${name}`} className={block}
52
+ onPress={() => { if (leaving.current) return; settle(false); onEdit(); }}><Text>Edit</Text></Button>
53
+ <Button variant="destructive" testID="cart-line-remove" accessibilityLabel={`Remove ${name}`} className={block}
54
+ onPress={leave}><Text>Remove</Text></Button>
55
+ </View>
56
+ </View>
57
+ <Animated.View className="bg-background" style={{ transform: [{ translateX: offset }] }}>{children(wrapTotal)}</Animated.View>
58
+ </View>;
59
+ }
@@ -1,10 +1,11 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
- import { formatMoney, type Money } from '@tallyui/core';
3
+ import { useFormatMoney, type Money } from '@tallyui/core';
4
4
  import { Image } from '@tallyui/primitives';
5
5
  import { cn } from '@tallyui/theme';
6
+ import { useT } from '../i18n';
6
7
  import { Text, HStack, type HStackProps } from '../ui';
7
- import { CART_COLUMNS, cartColumnSlots, type CartColumnSettings } from './cart-columns';
8
+ import { CART_COLUMNS, CART_PICKING_QUANTITY, cartColumnSlots, type CartColumnSettings } from './cart-columns';
8
9
 
9
10
  export interface CartLineProps extends Omit<HStackProps, 'children'> {
10
11
  name: string;
@@ -12,7 +13,8 @@ export interface CartLineProps extends Omit<HStackProps, 'children'> {
12
13
  attributes?: Record<string, string>;
13
14
  quantity: number;
14
15
  unitPrice: Money;
15
- /** The regular unit price; shown struck through above unitPrice only when it is above unitPrice. */
16
+ /** The regular unit price; shown struck through above unitPrice only when it is above unitPrice (and
17
+ * `columns.price.onSale` is not false), and in the Regular Price column. */
16
18
  regularUnitPrice?: Money;
17
19
  lineTotal: Money;
18
20
  /** Show the Price column (default true); the Cart passes false on a narrow cart or a phone, as CartColumnHeads does. */
@@ -29,6 +31,8 @@ export interface CartLineProps extends Omit<HStackProps, 'children'> {
29
31
  imageUrl?: string;
30
32
  /** With `columns.quantity.split` and a quantity above 1, a Split link under the quantity calls this. */
31
33
  onSplit?: () => void;
34
+ /** As CartColumnHeads' `picking`: the quantity column takes its wider picking width (default false). */
35
+ picking?: boolean;
32
36
  locale?: string;
33
37
  className?: string;
34
38
  }
@@ -44,16 +48,20 @@ export interface CartLineProps extends Omit<HStackProps, 'children'> {
44
48
  * ```
45
49
  */
46
50
  export function CartLine({ name, attributes, quantity, unitPrice, regularUnitPrice, lineTotal, showPrice = true, quantitySlot, priceSlot,
47
- columns, sku, imageUrl, onSplit, locale, className, ...props }: CartLineProps) {
51
+ columns, sku, imageUrl, onSplit, picking = false, locale, className, ...props }: CartLineProps) {
52
+ const formatMoney = useFormatMoney();
53
+ const t = useT();
48
54
  const options = Object.entries(attributes ?? {}).map(([key, value]) => `${key}: ${value}`).join(' · ');
49
- const regular = regularUnitPrice && regularUnitPrice.currency === unitPrice.currency && regularUnitPrice.amount > unitPrice.amount
55
+ const sameCurrency = regularUnitPrice?.currency === unitPrice.currency;
56
+ const regular = (columns?.price?.onSale ?? true) && regularUnitPrice && sameCurrency && regularUnitPrice.amount > unitPrice.amount
50
57
  ? formatMoney(regularUnitPrice, locale) ?? '—' : null;
51
58
  const cells: Record<ReturnType<typeof cartColumnSlots>[number], ReactNode> = {
52
59
  fill: <View key="fill" className="flex-1" />,
53
- quantity: <View key="quantity" className={CART_COLUMNS.quantity.cell}>
60
+ quantity: <View key="quantity" className={(picking ? CART_PICKING_QUANTITY : CART_COLUMNS.quantity).cell}>
54
61
  {quantitySlot ?? <Text className="text-sm tabular-nums">{quantity}</Text>}
55
- {columns?.quantity?.split && quantity > 1 && onSplit ? <Pressable accessibilityRole="button" accessibilityLabel={`Split ${name}`}
56
- testID="cart-line-split" onPress={onSplit} className="min-h-11 justify-center"><Text className="text-xs text-primary">Split</Text></Pressable> : null}
62
+ {columns?.quantity?.split && quantity > 1 && onSplit ? <Pressable accessibilityRole="button" accessibilityLabel={t('pos_cart.split_line', { name })}
63
+ testID="cart-line-split" onPress={onSplit} className="min-h-11 justify-center">
64
+ <Text className="text-xs text-primary">{t('pos_cart.split_qty')}</Text></Pressable> : null}
57
65
  </View>,
58
66
  image: <View key="image" className={CART_COLUMNS.image.cell}>
59
67
  {imageUrl ? <Image.Root testID="cart-line-image" source={{ uri: imageUrl }} alt="" contentFit="cover" className="rounded-md"
@@ -72,6 +80,10 @@ export function CartLine({ name, attributes, quantity, unitPrice, regularUnitPri
72
80
  className="text-right text-sm tabular-nums text-muted-foreground line-through">{regular}</Text> : null}
73
81
  {priceSlot ?? <Text className="text-right text-sm tabular-nums text-muted-foreground">{formatMoney(unitPrice, locale) ?? '—'}</Text>}
74
82
  </View>,
83
+ regularPrice: <View key="regularPrice" className={CART_COLUMNS.regularPrice.cell}>
84
+ <Text testID="cart-line-regular-price" className="text-right text-sm tabular-nums text-muted-foreground">
85
+ {formatMoney(regularUnitPrice && sameCurrency ? regularUnitPrice : unitPrice, locale) ?? '—'}</Text>
86
+ </View>,
75
87
  total: <View key="total" className={CART_COLUMNS.total.cell}>
76
88
  <Text className="text-right text-sm font-semibold tabular-nums">{formatMoney(lineTotal, locale) ?? '—'}</Text>
77
89
  </View>,
@@ -0,0 +1,30 @@
1
+ // Port of WCPOS v2 packages/core/src/screens/main/pos/cart/note-row.tsx (monorepo 7a475d8), MIT, WCPOS.
2
+ import { useState } from 'react';
3
+ import { Pressable, View } from 'react-native';
4
+ import { cn } from '@tallyui/theme';
5
+ import { usePointer } from '../scale';
6
+ import { PencilIcon } from '../ui/icon/pencil-icon';
7
+ import { StickyNoteIcon } from '../ui/icon/sticky-note-icon';
8
+ import { Text } from '../ui/text';
9
+
10
+ export function CartNoteRow({ text, onPress }: { text: string; onPress: () => void }) {
11
+ const [active, setActive] = useState(false);
12
+ const coarse = usePointer() === 'coarse';
13
+ if (text.trim() === '') return null;
14
+
15
+ return (
16
+ <View className="border-t border-border pt-2">
17
+ <Pressable testID="cart-note-row" accessibilityRole="button" accessibilityLabel={`Edit note: ${text}`}
18
+ hitSlop={{ top: 4, bottom: 4 }} onPress={onPress}
19
+ onHoverIn={() => setActive(true)} onHoverOut={() => setActive(false)}
20
+ onFocus={() => setActive(true)} onBlur={() => setActive(false)}
21
+ className={cn('min-h-9 flex-row items-center gap-2 rounded-md px-2', active && 'bg-accent')}>
22
+ <View className={active ? 'text-foreground' : 'text-muted-foreground'}><StickyNoteIcon size={16} /></View>
23
+ <Text numberOfLines={1} className={cn('flex-1 text-sm', active ? 'text-foreground' : 'text-muted-foreground')}>{text}</Text>
24
+ <View testID="cart-note-edit" className={cn('text-foreground web:transition-opacity', active || coarse ? 'opacity-100' : 'opacity-0')}>
25
+ <PencilIcon size={14} />
26
+ </View>
27
+ </Pressable>
28
+ </View>
29
+ );
30
+ }
@@ -2,6 +2,7 @@ import type { JSX, ReactNode } from 'react';
2
2
  import { ScrollView, View } from 'react-native';
3
3
  import { cn } from '@tallyui/theme';
4
4
  import { VStack, type VStackProps } from '../ui';
5
+ import { MotionRows } from './cart-row-motion';
5
6
 
6
7
  export interface CartPanelProps<T> extends Omit<VStackProps, 'children'> {
7
8
  /** Cart line items to render */
@@ -20,6 +21,10 @@ export interface CartPanelProps<T> extends Omit<VStackProps, 'children'> {
20
21
  footerClassName?: string;
21
22
  /** Content shown when items is empty */
22
23
  emptyState?: ReactNode;
24
+ /** A value per row whose change pulses it (e.g. the quantity); with it, rows pulse when added and tint and collapse when removed, as in WCPOS v2. Without it, nothing animates. */
25
+ pulseKey?: (item: T) => string | number;
26
+ /** What the rows belong to (e.g. the order id): a change rebaselines without a pulse. */
27
+ identity?: string;
23
28
  className?: string;
24
29
  }
25
30
 
@@ -55,6 +60,8 @@ export function CartPanel<T>({
55
60
  footer,
56
61
  footerClassName,
57
62
  emptyState,
63
+ pulseKey,
64
+ identity,
58
65
  className,
59
66
  ...props
60
67
  }: CartPanelProps<T>): JSX.Element {
@@ -65,7 +72,8 @@ export function CartPanel<T>({
65
72
  {header && <View className="border-b border-border px-3 py-2">{header}</View>}
66
73
 
67
74
  <ScrollView className="flex-1 min-h-0" contentContainerClassName="flex-grow">
68
- {hasItems
75
+ {pulseKey ? <MotionRows items={items} keyOf={keyExtractor ?? defaultKey} pulseKey={pulseKey} identity={identity}
76
+ renderItem={renderItem} empty={emptyState ?? null} /> : hasItems
69
77
  ? items.map((item, index) => (
70
78
  <View key={keyExtractor ? keyExtractor(item, index) : defaultKey(item, index)}>
71
79
  {renderItem(item, index)}