@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
@@ -7,6 +7,7 @@ export { ProductCard, type ProductCardProps } from './product-card';
7
7
  export { ProductGrid, type ProductGridProps } from './product-grid';
8
8
  export { ViewToggle, type ViewToggleProps } from './view-toggle';
9
9
  export { ProductTable, defaultProductColumns, useDefaultProductColumns, type ProductTableProps, type ProductTableColumn } from './product-table';
10
+ export { productsScreenColumns, useProductsScreenColumns } from './products-screen-columns';
10
11
  export { ProductList, type ProductListProps } from './product-list';
11
12
  export { CategoryNav, type CategoryNavProps, type CategoryItem } from './category-nav';
12
13
  export { ProductVariantPicker, type ProductVariantPickerProps, type VariantOption } from './product-variant-picker';
@@ -0,0 +1,7 @@
1
+ import { View } from 'react-native';
2
+ import { cn } from '@tallyui/theme';
3
+
4
+ export function PressVeil({ pressed, className, testID }: { pressed: boolean; className?: string; testID?: string }) {
5
+ if (!pressed) return null;
6
+ return <View pointerEvents="none" aria-hidden testID={testID} className={cn('absolute inset-0 bg-foreground/10', className)} />;
7
+ }
@@ -5,6 +5,7 @@ import { VStack, Text, type VStackProps } from '../ui';
5
5
  import { ProductImage } from './product-image';
6
6
  import { ProductTitle } from './product-title';
7
7
  import { ProductPrice } from './product-price';
8
+ import { PressVeil } from './press-veil';
8
9
 
9
10
  export interface ProductCardProps extends Omit<VStackProps, 'children'> {
10
11
  doc: any;
@@ -50,7 +51,10 @@ export function ProductCard({ doc, onPress, imageSize = 80, currencySymbol, notS
50
51
  return <Pressable disabled aria-disabled onPress={undefined}>{content}</Pressable>;
51
52
  }
52
53
  if (onPress) {
53
- return <Pressable onPress={onPress}>{content}</Pressable>;
54
+ return <Pressable onPress={onPress}>{({ pressed }) => <>
55
+ {content}
56
+ <PressVeil pressed={pressed} className="rounded-lg" testID="product-card-pressed" />
57
+ </>}</Pressable>;
54
58
  }
55
59
  return content;
56
60
  }
@@ -30,6 +30,8 @@ export interface ProductGridProps extends Omit<VStackProps, 'children'> {
30
30
  * unless `showUnsellable`.
31
31
  */
32
32
  showUnsellable?: boolean;
33
+ /** Rendered after the last tile, inside the list (for example a paging spinner); not shown with `emptyState`. */
34
+ footerSlot?: ReactNode;
33
35
  className?: string;
34
36
  }
35
37
 
@@ -55,6 +57,7 @@ export function ProductGrid({
55
57
  filterSlot,
56
58
  emptyState,
57
59
  showUnsellable = false,
60
+ footerSlot,
58
61
  className,
59
62
  ...viewProps
60
63
  }: ProductGridProps) {
@@ -78,6 +81,7 @@ export function ProductGrid({
78
81
  {hasItems ? (
79
82
  <FlatList
80
83
  key={numColumns}
84
+ testID="product-grid-list"
81
85
  data={visibleItems}
82
86
  numColumns={numColumns}
83
87
  keyExtractor={(item, index) => String(item.id ?? index)}
@@ -90,6 +94,7 @@ export function ProductGrid({
90
94
  {renderItem(item, index)}
91
95
  </View>
92
96
  )}
97
+ ListFooterComponent={footerSlot == null ? null : <>{footerSlot}</>}
93
98
  />
94
99
  ) : (
95
100
  emptyState ?? null
@@ -1,4 +1,4 @@
1
- import { formatMoney, minorUnitDigits, moneyToMajor, resolvePrice, resolvePriceRange, useProductTraits, useTraitContext } from '@tallyui/core';
1
+ import { useFormatMoney, minorUnitDigits, moneyToMajor, resolvePrice, resolvePriceRange, useProductTraits, useTraitContext } from '@tallyui/core';
2
2
  import type { Money } from '@tallyui/core';
3
3
  import { cn } from '@tallyui/theme';
4
4
  import { Text, type TextProps } from '../ui';
@@ -32,6 +32,8 @@ export interface ProductPriceProps extends Omit<TextProps, 'children'> {
32
32
  * `` (price) => `from ${price}` ``. Wins over `fromLabel` when both are given.
33
33
  */
34
34
  formatFrom?: (price: string) => string;
35
+ /** Show the price a sale replaces, struck through. Default true. False renders an on-sale price like a regular one. */
36
+ showWas?: boolean;
35
37
  className?: string;
36
38
  }
37
39
 
@@ -46,7 +48,8 @@ export interface ProductPriceProps extends Omit<TextProps, 'children'> {
46
48
  * <ProductPrice doc={productDocument} currency="EUR" />
47
49
  * ```
48
50
  */
49
- export function ProductPrice({ doc, currency, locale, currencySymbol = '$', className, showFromPrice = true, fromLabel, formatFrom, ...textProps }: ProductPriceProps) {
51
+ export function ProductPrice({ doc, currency, locale, currencySymbol = '$', className, showFromPrice = true, fromLabel, formatFrom, showWas = true, ...textProps }: ProductPriceProps) {
52
+ const formatMoney = useFormatMoney();
50
53
  const { getPrices, getVariants } = useProductTraits();
51
54
  const traitContext = useTraitContext();
52
55
  const effectiveCurrency = currency ?? traitContext.currency;
@@ -83,7 +86,7 @@ export function ProductPrice({ doc, currency, locale, currencySymbol = '$', clas
83
86
  );
84
87
  }
85
88
 
86
- if (resolved.was) {
89
+ if (resolved.was && showWas) {
87
90
  return (
88
91
  <Text
89
92
  className={cn('text-sm font-semibold text-sale', className)}
@@ -15,7 +15,8 @@ export interface ProductStockBadgeProps extends Omit<HStackProps, 'children'> {
15
15
  className?: string;
16
16
  }
17
17
 
18
- const statusLabels: Record<StockStatus, string> = {
18
+ /** The stock-status words every stock display uses (catalogue rows, the badge, the variations popover). */
19
+ export const STOCK_STATUS_LABELS: Record<StockStatus, string> = {
19
20
  in_stock: 'In Stock',
20
21
  out_of_stock: 'Out of Stock',
21
22
  backorder: 'On Backorder',
@@ -66,7 +67,7 @@ function formatAsOf(iso: string): string {
66
67
  */
67
68
  export function ProductStockBadge({ doc, showQuantity = false, showAsOf = true, className, ...props }: ProductStockBadgeProps) {
68
69
  const { status, quantity, asOf } = useProductStock(doc);
69
- const label = statusLabels[status] ?? statusLabels.unknown;
70
+ const label = STOCK_STATUS_LABELS[status] ?? STOCK_STATUS_LABELS.unknown;
70
71
  const styles = STATUS_STYLES[status] ?? STATUS_STYLES.unknown;
71
72
 
72
73
  return (
@@ -3,11 +3,16 @@ import { FlatList, Pressable, View, type ViewProps } from 'react-native';
3
3
  import { useProductTraits, useTraitContext, useStockOverlaid, type ProductTraits, type TraitContext } from '@tallyui/core';
4
4
  import { productSortValue, sortProducts, type ProductSort, type ProductSortValue } from '@tallyui/pos';
5
5
  import { cn } from '@tallyui/theme';
6
- import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell, Text, VStack } from '../ui';
6
+ import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell, Text, VStack, IconButton, PlusIcon, ChevronRightIcon,
7
+ Skeleton, skeletonCount } from '../ui';
8
+ import { MinTargetBand } from '../scale/min-target';
9
+ import { usePointer } from '../scale/use-pointer';
10
+ import { ProductImage } from './product-image';
7
11
  import { ProductTitle } from './product-title';
8
12
  import { ProductSku } from './product-sku';
9
13
  import { ProductPrice } from './product-price';
10
14
  import { ProductStockBadge } from './product-stock-badge';
15
+ import { InCartBadge } from './in-cart-badge';
11
16
 
12
17
  // Limit initial mounts for a 2,000-product catalogue to eight rows.
13
18
  const INITIAL_ROWS = 8;
@@ -16,6 +21,18 @@ const BATCH_ROWS = 8;
16
21
  // Keep nearby rows mounted without rendering the whole 2,000-product catalogue.
17
22
  const WINDOW_SIZE = 5;
18
23
 
24
+ // v2 PosterThumb sizes: sm (size-10) under a fine pointer, md (size-14) under a coarse one.
25
+ const THUMB_FINE = 40;
26
+ const THUMB_COARSE = 56;
27
+ // The thumbnail column adds the cells' px-3 (12 px each side) to the image.
28
+ const CELL_PAD_X = 24;
29
+ // The add column: a 40 px md IconButton centred with 8 px either side.
30
+ const ACTION_WIDTH = 56;
31
+ // The table has no row height constant, so skeleton rows are drawn and counted at v2's DataTableSkeleton figure (48), or taller with the thumbnail.
32
+ const SKELETON_ROW_HEIGHT = 48;
33
+ // A skeleton row with the thumbnail: the image plus the cell's py-1.5 (12 px) and the row's 1 px border.
34
+ const SKELETON_THUMB_PAD = 13;
35
+
19
36
  // Place column content horizontally inside column-direction Views.
20
37
  const ALIGN = { left: 'items-start', center: 'items-center', right: 'items-end' } as const;
21
38
 
@@ -35,6 +52,8 @@ export interface ProductTableColumn<Doc = any> {
35
52
  flex?: number;
36
53
  }
37
54
 
55
+ /** A row's doc: an item of `items` (the table is not generic, so this is that item's type). */
56
+ type ProductTableRowDoc = ProductTableProps['items'][number];
38
57
  export interface ProductTableProps extends Omit<ViewProps, 'children'> {
39
58
  items: any[];
40
59
  /** Default: trait columns with a ConnectorProvider, else none. */
@@ -53,6 +72,26 @@ export interface ProductTableProps extends Omit<ViewProps, 'children'> {
53
72
  showUnsellable?: boolean;
54
73
  /** Passed to the default price column's ProductPrice. */
55
74
  currencySymbol?: string;
75
+ /** Lead each row with the product's thumbnail, as v2's image column: 40 px, 56 px under a coarse pointer, an
76
+ * initial tile when there is no image. Needs a ConnectorProvider. Default false. */
77
+ showThumbnail?: boolean;
78
+ /** End each row with v2's add control, which calls onSelect(item) exactly as a row press does: a + labelled
79
+ * "Add to cart", or a > labelled "Variations" for a product with more than one variant. Needs onSelect. Default false. */
80
+ showAddButton?: boolean;
81
+ /** v2's in-cart count: how many of the product the cart holds (e.g. from cartQuantities). In the add column
82
+ * (showAddButton), a count above 0 shows in place of the +, labelled "In cart: N", and pressing it calls onSelect
83
+ * as the + does; a product with variants keeps its >. Default: no count. */
84
+ cartQuantity?: (doc: any) => number;
85
+ /** v2's expanding variable row: whether the row's expanded block shows. Used only with onToggleExpand and
86
+ * renderExpanded. Pass a new function when the expanded set changes (an inline arrow does). */
87
+ isExpanded?: (doc: ProductTableRowDoc) => boolean;
88
+ /** With renderExpanded and showThumbnail, a product with more than one variant has its thumbnail toggle its
89
+ * expanded block: a button labelled "Show variations" with aria-expanded. A press calls this, never onSelect. */
90
+ onToggleExpand?: (doc: ProductTableRowDoc) => void;
91
+ /** The block drawn under an expanded row (e.g. its variant rows), indented by the thumbnail column. */
92
+ renderExpanded?: (doc: ProductTableRowDoc) => ReactNode;
93
+ /** With no items, draw the header and skeleton rows instead of emptyState, as WCPOS v2's DataTableSkeleton. */
94
+ loading?: boolean;
56
95
  className?: string;
57
96
  }
58
97
 
@@ -81,7 +120,8 @@ export function useDefaultProductColumns(options?: { currencySymbol?: string }):
81
120
 
82
121
  export function ProductTable({
83
122
  items, columns, sort, defaultSort = null, onSortChange, sortItems = true, onSelect,
84
- searchSlot, filterSlot, emptyState, showUnsellable = false, currencySymbol, className, ...viewProps
123
+ searchSlot, filterSlot, emptyState, showUnsellable = false, currencySymbol, showThumbnail = false,
124
+ showAddButton = false, cartQuantity, isExpanded, onToggleExpand, renderExpanded, loading = false, className, ...viewProps
85
125
  }: ProductTableProps): JSX.Element {
86
126
  // Without a ConnectorProvider, custom columns can render without traits.
87
127
  let traits: ReturnType<typeof useProductTraits> | undefined;
@@ -91,9 +131,14 @@ export function ProductTable({
91
131
  traits = undefined;
92
132
  }
93
133
  const context = useTraitContext();
134
+ const thumb = usePointer() === 'coarse' ? THUMB_COARSE : THUMB_FINE;
135
+ const thumbnail = showThumbnail && traits !== undefined;
136
+ const skeletonRow = Math.max(SKELETON_ROW_HEIGHT, thumbnail ? thumb + SKELETON_THUMB_PAD : 0);
137
+ const addButton = showAddButton && onSelect !== undefined;
94
138
  const resolvedColumns = useMemo(() => columns ?? (traits
95
139
  ? defaultProductColumns(traits, context, { currencySymbol }) : []), [columns, traits, context, currencySymbol]);
96
140
  const [internalSort, setInternalSort] = useState(defaultSort);
141
+ const [skeletonHeight, setSkeletonHeight] = useState(0);
97
142
  const activeSort = sort === undefined ? internalSort : sort;
98
143
  const visibleItems = showUnsellable || !traits ? items : items.filter((item) => traits!.isSellable(item));
99
144
  const overlaidItems = useStockOverlaid(visibleItems);
@@ -111,10 +156,11 @@ export function ProductTable({
111
156
  <VStack space="none" className={cn('flex-1', className)} {...viewProps}>
112
157
  {searchSlot && <View className="px-3 py-2">{searchSlot}</View>}
113
158
  {filterSlot && <View className="px-3 pb-2">{filterSlot}</View>}
114
- {rows.length ? (
159
+ {rows.length || (loading && items.length === 0) ? (
115
160
  <Table className="flex-1">
116
161
  <TableHeader>
117
162
  <TableRow>
163
+ {thumbnail ? <TableHead aria-label="Image" style={{ width: thumb + CELL_PAD_X }} className="h-9 flex-none px-3 py-0" /> : null}
118
164
  {resolvedColumns.map((column) => (
119
165
  <TableHead key={column.id} style={{ flex: column.flex ?? 1 }}
120
166
  className={cn('h-9 justify-center px-3 py-0', column.align && ALIGN[column.align])}
@@ -129,33 +175,75 @@ export function ProductTable({
129
175
  ) : <Text numberOfLines={1}>{column.hideHeader ? '' : column.header}</Text>}
130
176
  </TableHead>
131
177
  ))}
178
+ {addButton ? <TableHead aria-label="Actions" style={{ width: ACTION_WIDTH }} className="h-9 flex-none px-3 py-0" /> : null}
132
179
  </TableRow>
133
180
  </TableHeader>
134
- <TableBody className="flex-1">
181
+ {rows.length ? <TableBody className="flex-1">
135
182
  <FlatList
136
183
  data={rows}
184
+ extraData={isExpanded}
137
185
  keyExtractor={(item, index) => String(item.id ?? index)}
138
186
  initialNumToRender={INITIAL_ROWS}
139
187
  maxToRenderPerBatch={BATCH_ROWS}
140
188
  windowSize={WINDOW_SIZE}
141
189
  renderItem={({ item, index }) => {
142
190
  const key = String(item.id ?? index);
191
+ const variations = addButton && traits !== undefined && traits.getVariantCount(item) > 1;
192
+ const count = addButton && !variations ? cartQuantity?.(item) ?? 0 : 0;
193
+ const expandable = thumbnail && onToggleExpand !== undefined && renderExpanded !== undefined && traits!.getVariantCount(item) > 1;
194
+ const expanded = expandable && (isExpanded?.(item) ?? false);
143
195
  const row = (
144
196
  <TableRow testID={onSelect ? undefined : 'product-row-' + key}>
197
+ {thumbnail ? <TableCell style={{ width: thumb + CELL_PAD_X }} className="flex-none px-3 py-1.5">
198
+ {expandable ? <Pressable accessibilityRole="button" accessibilityLabel="Show variations" aria-expanded={expanded}
199
+ testID={'product-row-expand-' + key} onPress={(event) => { event.stopPropagation?.(); onToggleExpand!(item); }}>
200
+ <ProductImage doc={item} size={thumb} showPlaceholder className="rounded-md" /></Pressable> :
201
+ <ProductImage doc={item} size={thumb} showPlaceholder className="rounded-md" />}</TableCell> : null}
145
202
  {resolvedColumns.map((column) => (
146
203
  <TableCell key={column.id} style={{ flex: column.flex ?? 1 }}
147
204
  className={cn('px-3 py-1.5', column.align && ALIGN[column.align])}>{column.render(item)}</TableCell>
148
205
  ))}
206
+ {addButton ? (
207
+ <TableCell style={{ width: ACTION_WIDTH }} className="flex-none items-center justify-center px-0 py-1.5">
208
+ <IconButton testID={'product-row-add-' + key}
209
+ accessibilityLabel={variations ? 'Variations' : count > 0 ? `In cart: ${count}` : 'Add to cart'}
210
+ onPress={(event) => { event.stopPropagation?.(); onSelect!(item); }}>
211
+ {variations || count <= 0 ? <View className="text-muted-foreground">
212
+ {variations ? <ChevronRightIcon size={18} /> : <PlusIcon size={18} />}</View> : null}
213
+ {!variations && cartQuantity ? <InCartBadge count={count} identity={key} testID={'product-row-in-cart-' + key} /> : null}
214
+ <MinTargetBand square />
215
+ </IconButton>
216
+ </TableCell>
217
+ ) : null}
149
218
  </TableRow>
150
219
  );
151
- return onSelect ? (
152
- <Pressable accessibilityRole="button" testID={'product-row-' + key} onPress={() => onSelect(item)}>
220
+ return <>{onSelect ? (
221
+ <Pressable accessibilityRole={addButton ? undefined : 'button'} testID={'product-row-' + key} onPress={() => onSelect(item)}>
153
222
  {row}
154
223
  </Pressable>
155
- ) : row;
224
+ ) : row}
225
+ {expanded ? <View testID={'product-row-expanded-' + key} style={{ paddingLeft: thumb + CELL_PAD_X }}
226
+ className="border-b border-border">{renderExpanded!(item)}</View> : null}
227
+ </>;
156
228
  }}
157
229
  />
158
- </TableBody>
230
+ </TableBody> : (
231
+ // v2's DataTableSkeleton: one placeholder per cell, in the real cells' widths, so the rows that replace them line up.
232
+ <TableBody className="flex-1 overflow-hidden" accessibilityLabel="Loading" aria-busy
233
+ onLayout={(event) => setSkeletonHeight(event.nativeEvent.layout.height)}>
234
+ {Array.from({ length: skeletonCount(skeletonHeight, skeletonRow) }, (_, row) => (
235
+ <TableRow key={row} testID="product-table-skeleton-row" className="border-b border-border" style={{ minHeight: skeletonRow }}>
236
+ {thumbnail ? <TableCell style={{ width: thumb + CELL_PAD_X }} className="flex-none px-3 py-1.5">
237
+ <Skeleton style={{ width: thumb, height: thumb }} className="flex-none rounded-md" /></TableCell> : null}
238
+ {resolvedColumns.map((column) => (
239
+ <TableCell key={column.id} style={{ flex: column.flex ?? 1 }}
240
+ className={cn('px-3 py-1.5', column.align && ALIGN[column.align])}><Skeleton shape="line" className="w-3/4" /></TableCell>
241
+ ))}
242
+ {addButton ? <TableCell style={{ width: ACTION_WIDTH }} className="flex-none px-0 py-1.5" /> : null}
243
+ </TableRow>
244
+ ))}
245
+ </TableBody>
246
+ )}
159
247
  </Table>
160
248
  ) : emptyState ?? null}
161
249
  </VStack>
@@ -0,0 +1,74 @@
1
+ import { useMemo } from 'react';
2
+ import { useProductTraits, useTraitContext, type ProductTraits, type TraitContext } from '@tallyui/core';
3
+ import { productSortValue } from '@tallyui/pos';
4
+ import { View } from 'react-native';
5
+ import { HStack, Switch, Text, VStack } from '../ui';
6
+ import { ProductImage } from './product-image';
7
+ import { ProductTitle } from './product-title';
8
+ import { ProductPrice } from './product-price';
9
+ import { ProductStockBadge } from './product-stock-badge';
10
+ import type { ProductTableColumn } from './product-table';
11
+
12
+ // v2's Products screen thumbnail, about 48 px.
13
+ const IMAGE_SIZE = 48;
14
+ // The ids productSortValue knows (PRODUCT_SORT_FIELDS); image and stockStatus stay unsortable.
15
+ const SORTABLE = new Set(['name', 'stock', 'category', 'price']);
16
+
17
+ /**
18
+ * WCPOS v2's Products screen read columns: image, product (with its variation count), stock with the Manage switch,
19
+ * stock status, categories and price. Pass them to `ProductTable columns={...}`.
20
+ */
21
+ export function productsScreenColumns(
22
+ traits: ProductTraits, context?: TraitContext, options?: { currencySymbol?: string },
23
+ ): ProductTableColumn[] {
24
+ const columns: ProductTableColumn[] = [
25
+ { id: 'image', header: 'Image', hideHeader: true, flex: 0.6,
26
+ render: (doc) => <ProductImage doc={doc} size={IMAGE_SIZE} showPlaceholder className="rounded-md" /> },
27
+ { id: 'name', header: 'Product', flex: 3, render: (doc) => {
28
+ const count = traits.getVariantCount(doc);
29
+ return (
30
+ <VStack space="none">
31
+ <ProductTitle doc={doc} numberOfLines={2} />
32
+ {traits.hasVariants(doc) ? (
33
+ <Text testID="product-variation-count" className="text-xs text-muted-foreground">
34
+ {count === 1 ? `${count} variation` : `${count} variations`}
35
+ </Text>
36
+ ) : null}
37
+ </VStack>
38
+ );
39
+ } },
40
+ { id: 'stock', header: 'Stock', flex: 1.5, render: (doc) => {
41
+ // "Manages stock" from the core contract, not a new trait: getStock's quantity is "the total on hand when every
42
+ // variant is tracked, else undefined" (packages/core/src/types/traits/product.ts, getStock).
43
+ const quantity = traits.getStock(doc).quantity;
44
+ return (
45
+ <VStack space="none" className="gap-1">
46
+ <Text testID="product-stock-quantity">{quantity === undefined ? '—' : String(quantity)}</Text>
47
+ {/* Read-only, unlike v2's editable field and switch: edits go through each platform's own API (a later row). */}
48
+ <HStack space="none" className="items-center gap-1.5">
49
+ <Switch size="sm" disabled checked={quantity !== undefined} testID="product-manage-stock" accessibilityLabel="Manage" />
50
+ <Text className="text-xs text-muted-foreground">Manage</Text>
51
+ </HStack>
52
+ </VStack>
53
+ );
54
+ } },
55
+ { id: 'stockStatus', header: 'Stock Status', flex: 1.5, render: (doc) => (
56
+ <View testID="product-stock-status"><ProductStockBadge doc={doc} showAsOf={false} /></View>
57
+ ) },
58
+ { id: 'category', header: 'Categories', flex: 2, render: (doc) => <Text>{traits.getCategoryNames(doc).join(', ') || '—'}</Text> },
59
+ // One Price column: ProductPrice draws a sale price with the price it replaces, from getPrices. v2's separate
60
+ // Regular and Sale price columns would need the deprecated getRegularPrice / getSalePrice, so they are left out.
61
+ { id: 'price', header: 'Price', flex: 1.5, align: 'right',
62
+ render: (doc) => <ProductPrice doc={doc} currencySymbol={options?.currencySymbol} /> },
63
+ ];
64
+ return columns.map((column) => SORTABLE.has(column.id)
65
+ ? { ...column, sortValue: (doc) => productSortValue(doc, column.id, traits, context) } : column);
66
+ }
67
+
68
+ /** `productsScreenColumns` from the ConnectorProvider's traits, memoised; requires a ConnectorProvider. */
69
+ export function useProductsScreenColumns(options?: { currencySymbol?: string }): ProductTableColumn[] {
70
+ const traits = useProductTraits();
71
+ const context = useTraitContext();
72
+ const currencySymbol = options?.currencySymbol;
73
+ return useMemo(() => productsScreenColumns(traits, context, { currencySymbol }), [traits, context, currencySymbol]);
74
+ }
@@ -0,0 +1,68 @@
1
+ import { Pressable, Text, View } from 'react-native';
2
+ import type { StockStatus } from '@tallyui/core';
3
+ import { DEFAULT_TILE_FIELDS, type TileFields } from '@tallyui/pos';
4
+ import { VStack } from '../ui';
5
+ import { InCartBadge } from './in-cart-badge';
6
+ import { PressVeil } from './press-veil';
7
+ import { ProductImage } from './product-image';
8
+ import { ProductTitle } from './product-title';
9
+ import { STOCK_STATUS_LABELS } from './product-stock-badge';
10
+
11
+ // v2's variation tile (P/tiles/variation-tile.tsx:129-213): the product name small above one chip per option value
12
+ // (P/option-chips.tsx:7-23), then price and stock. The chips are labels; a tap on the tile adds the variant.
13
+ // Its words follow the grid's Tile Fields as v2's gridFields (variation-tile.tsx:136,180): name off keeps name and
14
+ // chips as the label, SKU then barcode after the price, and out of stock still shows while the price does.
15
+ export function VariantTile({ name, chips, price, stockStatus, onPress, testID, fields: tileFields, sku, barcode, inCart }: {
16
+ name: string; chips: string[]; price?: string; stockStatus: StockStatus; onPress: () => void; testID: string;
17
+ fields?: Partial<TileFields>; sku?: string; barcode?: string;
18
+ /** How many of this variant the cart holds, top-right as v2's per-variation InCartCount (variation-tile.tsx:176-177). */
19
+ inCart?: number;
20
+ }) {
21
+ const fields: TileFields = { ...DEFAULT_TILE_FIELDS, ...tileFields };
22
+ const facts = [fields.sku && sku ? `SKU ${sku}` : '', fields.barcode ? barcode ?? '' : ''].filter(Boolean);
23
+ const showStock = fields.stock || (stockStatus === 'out_of_stock' && fields.price);
24
+ return (
25
+ <Pressable accessibilityRole="button" testID={testID} onPress={onPress}
26
+ {...(fields.name ? {} : { accessibilityLabel: [name, ...chips].join(', ') })}>
27
+ {({ pressed }) => <>
28
+ <VStack space="sm" className="rounded-lg border border-border bg-card p-3">
29
+ {fields.name ? <>
30
+ <Text className="text-xs text-muted-foreground" numberOfLines={1}>{name}</Text>
31
+ <View testID={`${testID}-chips`} className="flex-row flex-wrap gap-1">
32
+ {chips.map((chip, index) => (
33
+ <Text key={index} className="rounded bg-foreground/12 px-1.5 text-xs font-bold text-foreground">{chip}</Text>
34
+ ))}
35
+ </View>
36
+ </> : null}
37
+ {price && fields.price ? <Text className="text-sm font-semibold text-foreground">{price}</Text> : null}
38
+ {facts.map((fact, index) => <Text key={index} className="text-xs text-muted-foreground" numberOfLines={1}>{fact}</Text>)}
39
+ {showStock
40
+ ? <Text className="text-xs text-muted-foreground">{STOCK_STATUS_LABELS[stockStatus] ?? STOCK_STATUS_LABELS.unknown}</Text>
41
+ : null}
42
+ </VStack>
43
+ <PressVeil pressed={pressed} className="rounded-lg" />
44
+ <InCartBadge count={inCart ?? 0} className="absolute right-2 top-2" testID={`${testID}-in-cart`} />
45
+ </>}
46
+ </Pressable>
47
+ );
48
+ }
49
+
50
+ // v2's parent tile in slot 0 (P/tiles/variation-tile.tsx:223-255): the product's own tile acts as Back, with a
51
+ // chevron-left badge in a circle top-right.
52
+ export function VariantParentTile({ doc, onPress }: { doc: unknown; onPress: () => void }) {
53
+ return (
54
+ <Pressable accessibilityRole="button" accessibilityLabel="Back" testID="variations-parent-tile" onPress={onPress}>
55
+ {({ pressed }) => <>
56
+ <VStack space="sm" className="items-center rounded-lg border border-border bg-card p-3">
57
+ <ProductImage doc={doc} size={80} className="rounded-md" />
58
+ <ProductTitle doc={doc} className="text-sm" numberOfLines={2} />
59
+ </VStack>
60
+ <PressVeil pressed={pressed} className="rounded-lg" />
61
+ <View aria-hidden pointerEvents="none"
62
+ className="absolute right-2 top-2 h-6 w-6 items-center justify-center rounded-full bg-foreground/12">
63
+ <Text className="text-base leading-none text-foreground">‹</Text>
64
+ </View>
65
+ </>}
66
+ </Pressable>
67
+ );
68
+ }
@@ -8,6 +8,7 @@ import { cn } from '@tallyui/theme';
8
8
  import { Button } from '../ui/button';
9
9
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
10
10
  import { Text } from '../ui/text';
11
+ import { STOCK_STATUS_LABELS } from './product-stock-badge';
11
12
 
12
13
  export interface VariationPickerProps {
13
14
  /** The product name. */
@@ -27,9 +28,8 @@ const CHIP_CHARACTERS = 15;
27
28
 
28
29
  // ProductStockBadge's label vocabulary; v2 shows nothing for stock it does not track.
29
30
  function stockLabel({ status, quantity }: StockLevel): string | null {
30
- if (status === 'out_of_stock') return 'Out of Stock';
31
- if (status === 'backorder') return 'On Backorder';
32
- if (status === 'in_stock' && quantity != null) return `In Stock (${quantity})`;
31
+ if (status === 'out_of_stock' || status === 'backorder') return STOCK_STATUS_LABELS[status];
32
+ if (status === 'in_stock' && quantity != null) return `${STOCK_STATUS_LABELS.in_stock} (${quantity})`;
33
33
  return null;
34
34
  }
35
35
 
@@ -2,27 +2,56 @@ import type { JSX } from 'react';
2
2
  import { Pressable, Text, View, type ViewProps } from 'react-native';
3
3
  import { cn } from '@tallyui/theme';
4
4
  import type { CatalogueView } from '@tallyui/pos';
5
+ import { MinTargetBand } from '../scale/min-target';
6
+ import { IconButton } from '../ui/icon-button';
7
+ import { ViewGridIcon } from '../ui/icon/view-grid-icon';
8
+ import { ViewListIcon } from '../ui/icon/view-list-icon';
9
+ import { Text as UiText } from '../ui/text';
10
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
5
11
 
6
12
  export interface ViewToggleProps extends Omit<ViewProps, 'children'> {
7
13
  value: CatalogueView;
8
14
  onChange: (view: CatalogueView) => void;
9
- /** Default { grid: 'Grid', table: 'Table' }. */
15
+ /** Default { grid: 'Grid', table: 'Table' }. In the icon form the label names the view a press switches to,
16
+ * default "Switch to grid view" / "Switch to table view". */
10
17
  labels?: { grid?: string; table?: string };
11
18
  className?: string;
19
+ /** 'segments' (default): the Grid/Table radio pair. 'icon': v2's single view-mode button
20
+ * (pos/products/view-mode-toggle.tsx), one press switches to the other view. */
21
+ variant?: 'segments' | 'icon';
12
22
  }
13
23
 
14
- export function ViewToggle({ value, onChange, labels, className, ...viewProps }: ViewToggleProps): JSX.Element {
24
+ export function ViewToggle({ value, onChange, labels, className, variant, ...viewProps }: ViewToggleProps): JSX.Element {
25
+ if (variant === 'icon') {
26
+ const next = value === 'table' ? 'grid' : 'table';
27
+ const label = labels?.[next] ?? (next === 'grid' ? 'Switch to grid view' : 'Switch to table view');
28
+ return (
29
+ <View {...viewProps} testID="view-toggle" className={cn('self-start', className)}>
30
+ <Tooltip>
31
+ <TooltipTrigger asChild>
32
+ <IconButton variant="ghost" testID={`view-toggle-${next}`} accessibilityLabel={label} onPress={() => onChange(next)}>
33
+ <View className="text-foreground">{value === 'table' ? <ViewGridIcon size={20} /> : <ViewListIcon size={20} />}</View>
34
+ <MinTargetBand square />
35
+ </IconButton>
36
+ </TooltipTrigger>
37
+ <TooltipContent><UiText>{label}</UiText></TooltipContent>
38
+ </Tooltip>
39
+ </View>
40
+ );
41
+ }
42
+ // No overflow-hidden, which would clip each segment's band: the end segments round their own outer corners.
15
43
  return (
16
44
  <View {...viewProps} role="radiogroup" accessibilityLabel="View" testID="view-toggle"
17
- className={cn('flex-row self-start overflow-hidden rounded-md border border-border', className)}>
45
+ className={cn('flex-row self-start rounded-md border border-border', className)}>
18
46
  {(['grid', 'table'] as const).map((view) => {
19
47
  const selected = value === view;
20
48
  const label = labels?.[view] ?? (view === 'grid' ? 'Grid' : 'Table');
21
49
  return (
22
50
  <Pressable key={view} role="radio" aria-checked={selected} testID={`view-toggle-${view}`}
23
51
  accessibilityLabel={label} onPress={() => { if (!selected) onChange(view); }}
24
- className={cn('px-3 py-2', selected ? 'bg-primary' : 'bg-card')}>
52
+ className={cn('px-3 py-2', view === 'grid' ? 'rounded-l-md' : 'rounded-r-md', selected ? 'bg-primary' : 'bg-card')}>
25
53
  <Text className={cn('text-sm font-medium', selected ? 'text-primary-foreground' : 'text-foreground')}>{label}</Text>
54
+ <MinTargetBand />
26
55
  </Pressable>
27
56
  );
28
57
  })}