@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.
- package/dist/index.d.ts +1114 -90
- package/dist/index.js +8077 -3352
- package/package.json +10 -11
- package/src/cart/cart-charge-line.tsx +58 -0
- package/src/cart/cart-columns-form.tsx +98 -0
- package/src/cart/cart-columns.tsx +49 -18
- package/src/cart/cart-foot.tsx +7 -2
- package/src/cart/cart-line-strip.tsx +59 -0
- package/src/cart/cart-line.tsx +20 -8
- package/src/cart/cart-note-row.tsx +30 -0
- package/src/cart/cart-panel.tsx +9 -1
- package/src/cart/cart-row-motion.tsx +125 -0
- package/src/cart/cart-total.tsx +44 -15
- package/src/cart/index.ts +2 -1
- package/src/checkout/cash-tendered.tsx +8 -7
- package/src/checkout/change-display.tsx +2 -1
- package/src/checkout/index.ts +1 -1
- package/src/checkout/payment-selector.tsx +6 -2
- package/src/checkout/payment-types.test-d.ts +28 -0
- package/src/customer/address-editor.tsx +87 -0
- package/src/customer/address-fields.tsx +120 -0
- package/src/customer/customer-dropdown.tsx +200 -0
- package/src/customer/customer-editor.tsx +99 -0
- package/src/customer/customer-form.tsx +39 -5
- package/src/customer/customer-picker.tsx +38 -14
- package/src/customer/customers-list.tsx +83 -0
- package/src/customer/index.ts +5 -0
- package/src/filter/filter-pills.tsx +63 -0
- package/src/i18n/locales/en/components.json +85 -0
- package/src/index.ts +40 -2
- package/src/input/decimal-entry.ts +21 -0
- package/src/layout/checkout-layout.tsx +1 -1
- package/src/layout/live-tab-screen.tsx +1 -1
- package/src/layout/pos-layout.tsx +80 -4
- package/src/layout/settings-layout.tsx +1 -1
- package/src/layout/store-settings-choice-screen.tsx +1 -1
- package/src/lib/current-row.ts +13 -0
- package/src/lib/money-input.ts +16 -0
- package/src/lib/motion.ts +22 -0
- package/src/lib/use-reduced-motion.ts +20 -0
- package/src/order/index.ts +1 -1
- package/src/order/order-detail.tsx +123 -5
- package/src/order/order-filter-bar.tsx +7 -57
- package/src/order/order-status-badge.tsx +42 -19
- package/src/order/refund-form.tsx +7 -5
- package/src/product/camera-scan-button.tsx +2 -0
- package/src/product/category-nav.tsx +8 -0
- package/src/product/category-tile.tsx +65 -15
- package/src/product/in-cart-badge.tsx +55 -6
- package/src/product/index.ts +1 -0
- package/src/product/press-veil.tsx +7 -0
- package/src/product/product-card.tsx +5 -1
- package/src/product/product-grid.tsx +5 -0
- package/src/product/product-price.tsx +6 -3
- package/src/product/product-stock-badge.tsx +3 -2
- package/src/product/product-table.tsx +96 -8
- package/src/product/products-screen-columns.tsx +74 -0
- package/src/product/variant-tile.tsx +68 -0
- package/src/product/variation-picker.tsx +3 -3
- package/src/product/view-toggle.tsx +33 -4
- package/src/register/cashier-sheet.tsx +195 -0
- package/src/register/closure-sheet.tsx +54 -3
- package/src/register/handover-slip.tsx +2 -1
- package/src/register/index.ts +2 -1
- package/src/register/movement-sheet.tsx +66 -7
- package/src/register/open-register-card.tsx +11 -11
- package/src/register/register-bar.helpers.ts +17 -4
- package/src/register/register-bar.tsx +26 -5
- package/src/register/register-count.tsx +158 -24
- package/src/register/register-panel.tsx +16 -5
- package/src/register/register-side-sheet.tsx +32 -8
- package/src/register/switch-confirm.tsx +2 -2
- package/src/reports/card-panel.tsx +131 -0
- package/src/reports/cards.tsx +53 -36
- package/src/reports/hero.tsx +2 -1
- package/src/reports/index.ts +1 -0
- package/src/reports/sales-room.tsx +4 -2
- package/src/sale/breadcrumb.tsx +48 -0
- package/src/sale/cart-bar.tsx +2 -1
- package/src/sale/cart.tsx +127 -38
- package/src/sale/catalogue-settings-form.tsx +92 -0
- package/src/sale/catalogue.tsx +304 -42
- package/src/sale/category-browse.tsx +27 -0
- package/src/sale/charge-form.tsx +85 -21
- package/src/sale/customer-display-screen.tsx +22 -6
- package/src/sale/discount-form.tsx +132 -28
- package/src/sale/index.ts +6 -3
- package/src/sale/line-popover.tsx +72 -36
- package/src/sale/offered-methods.ts +16 -0
- package/src/sale/open-sale-tabs.tsx +58 -10
- package/src/sale/order-note-sheet.tsx +37 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +76 -37
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +7 -5
- package/src/sale/product-filter-bar.tsx +38 -5
- package/src/sale/receipt-sheet.tsx +243 -0
- package/src/sale/receipt.tsx +19 -9
- package/src/sale/sync-status.tsx +10 -0
- package/src/sale/tender-ledger.tsx +92 -0
- package/src/sale/tender-pane.tsx +159 -73
- package/src/sale/tender.tsx +10 -7
- package/src/sale/use-tender.ts +63 -0
- package/src/scale/min-target.tsx +36 -0
- package/src/settings/barcode-scanning-settings.tsx +164 -0
- package/src/settings/connector-status.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +12 -25
- package/src/settings/index.ts +5 -0
- package/src/settings/printer-form.tsx +161 -0
- package/src/settings/printing-settings.tsx +268 -0
- package/src/settings/settings-group.tsx +2 -1
- package/src/settings/tax-calculation-settings.tsx +1 -1
- package/src/shell/added-to-cart-toast.tsx +61 -0
- package/src/shell/app-shell.tsx +5 -1
- package/src/shell/connectivity-toast.tsx +70 -0
- package/src/shell/index.ts +2 -0
- package/src/shell/nav-drawer.tsx +5 -2
- package/src/shell/nav-item.tsx +7 -4
- package/src/shell/nav-rail.tsx +9 -2
- package/src/ui/accordion/index.tsx +86 -8
- package/src/ui/alert-dialog/index.tsx +19 -5
- package/src/ui/combobox/index.tsx +21 -2
- package/src/ui/confirm-dialog/index.tsx +53 -0
- package/src/ui/dialog/index.tsx +68 -14
- package/src/ui/dialog/motion.ts +54 -0
- package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
- package/src/ui/icon/alert-circle-icon.tsx +5 -0
- package/src/ui/icon/alert-triangle-icon.tsx +7 -0
- package/src/ui/icon/banknote-icon.tsx +11 -0
- package/src/ui/icon/cash-register-icon.tsx +10 -0
- package/src/ui/icon/category-icon.tsx +7 -0
- package/src/ui/icon/chart-line-icon.tsx +5 -0
- package/src/ui/icon/check-icon.tsx +5 -0
- package/src/ui/icon/chevron-left-icon.tsx +4 -0
- package/src/ui/icon/chevron-right-icon.tsx +4 -0
- package/src/ui/icon/credit-card-icon.tsx +10 -0
- package/src/ui/icon/discount-icon.tsx +11 -0
- package/src/ui/icon/gift-icon.tsx +10 -0
- package/src/ui/icon/info-circle-icon.tsx +10 -0
- package/src/ui/icon/map-pin-icon.tsx +10 -0
- package/src/ui/icon/message-question-icon.tsx +7 -0
- package/src/ui/icon/pencil-icon.tsx +10 -0
- package/src/ui/icon/plus-icon.tsx +9 -0
- package/src/ui/icon/printer-icon.tsx +10 -0
- package/src/ui/icon/receipt-icon.tsx +7 -0
- package/src/ui/icon/settings-icon.tsx +10 -0
- package/src/ui/icon/sticky-note-icon.tsx +10 -0
- package/src/ui/icon/user-icon.tsx +4 -0
- package/src/ui/icon/users-icon.tsx +7 -0
- package/src/ui/icon/view-grid-icon.tsx +7 -0
- package/src/ui/icon/view-list-icon.tsx +7 -0
- package/src/ui/index.ts +24 -1
- package/src/ui/list-row/index.tsx +93 -0
- package/src/ui/notice/index.tsx +65 -0
- package/src/ui/select/index.tsx +2 -0
- package/src/ui/skeleton/index.tsx +37 -0
- package/src/ui/status-badge/index.tsx +43 -0
- package/src/ui/switch/index.tsx +1 -1
- package/src/ui/tabs/index.tsx +11 -2
- package/src/ui/toggle-group/index.tsx +3 -1
- package/src/ui/tone-disc/index.tsx +41 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useState, type ReactNode } from 'react';
|
|
2
2
|
import { ScrollView, Text, View, type ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { cn } from '@tallyui/theme';
|
|
5
5
|
|
|
6
|
+
import { Button } from '../ui/button';
|
|
7
|
+
import { ConfirmDialog } from '../ui/confirm-dialog';
|
|
8
|
+
import { Text as UIText } from '../ui/text';
|
|
6
9
|
import { OrderStatusBadge, type OrderStatus } from './order-status-badge';
|
|
7
10
|
|
|
8
11
|
export interface OrderDetailLineItem {
|
|
@@ -11,6 +14,12 @@ export interface OrderDetailLineItem {
|
|
|
11
14
|
total: string;
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
/** One tax rate's share, drawn indented under the Tax row (v2: "US 10% $9.20"). */
|
|
18
|
+
export interface OrderDetailTaxLine {
|
|
19
|
+
label: string;
|
|
20
|
+
amount: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
export interface OrderDetailProps extends Omit<ViewProps, 'children'> {
|
|
15
24
|
orderNumber: string;
|
|
16
25
|
status: OrderStatus;
|
|
@@ -18,9 +27,35 @@ export interface OrderDetailProps extends Omit<ViewProps, 'children'> {
|
|
|
18
27
|
subtotal: string;
|
|
19
28
|
tax: string;
|
|
20
29
|
total: string;
|
|
30
|
+
/** The line under the header, v2's "when · store · cashier"; empty parts are dropped. */
|
|
31
|
+
meta?: string[];
|
|
32
|
+
/** Formatted discount, shown as given (pass the negative, e.g. "-$2.00"). Omit to hide the row. */
|
|
33
|
+
discount?: string;
|
|
34
|
+
/** Coupon codes, already joined (v2 joins with ", "), in a chip beside "Discount". */
|
|
35
|
+
couponCodes?: string;
|
|
36
|
+
/** Formatted shipping total. Omit to hide the row. */
|
|
37
|
+
shipping?: string;
|
|
38
|
+
/** Shipping method title, shown beside "Shipping" as "· <title>". */
|
|
39
|
+
shippingMethod?: string;
|
|
40
|
+
/** Formatted fees total. Omit to hide the row. */
|
|
41
|
+
fees?: string;
|
|
42
|
+
/** Per-rate tax breakdown, indented under the Tax row. */
|
|
43
|
+
taxLines?: OrderDetailTaxLine[];
|
|
21
44
|
customerSlot?: ReactNode;
|
|
22
45
|
paymentSlot?: ReactNode;
|
|
23
46
|
footerSlot?: ReactNode;
|
|
47
|
+
/** Re-open the order; draws the Re-open button in the pinned actions row. */
|
|
48
|
+
onReopen?: () => void;
|
|
49
|
+
/** Sync the order with the server; draws the Sync button. */
|
|
50
|
+
onSync?: () => void;
|
|
51
|
+
/** Show the order's receipt; draws the Receipt button. */
|
|
52
|
+
onReceipt?: () => void;
|
|
53
|
+
/** Refund the order; draws Refund in the actions row's destructive group. */
|
|
54
|
+
onRefund?: () => void;
|
|
55
|
+
/** Delete the order; draws Delete, which asks for confirmation and calls this only on confirm. */
|
|
56
|
+
onDelete?: () => void;
|
|
57
|
+
/** Disables Re-open, e.g. while it runs or while storage is degraded. Default `false`. */
|
|
58
|
+
reopenDisabled?: boolean;
|
|
24
59
|
className?: string;
|
|
25
60
|
}
|
|
26
61
|
|
|
@@ -31,19 +66,39 @@ export function OrderDetail({
|
|
|
31
66
|
subtotal,
|
|
32
67
|
tax,
|
|
33
68
|
total,
|
|
69
|
+
meta,
|
|
70
|
+
discount,
|
|
71
|
+
couponCodes,
|
|
72
|
+
shipping,
|
|
73
|
+
shippingMethod,
|
|
74
|
+
fees,
|
|
75
|
+
taxLines,
|
|
34
76
|
customerSlot,
|
|
35
77
|
paymentSlot,
|
|
36
78
|
footerSlot,
|
|
79
|
+
onReopen,
|
|
80
|
+
onSync,
|
|
81
|
+
onReceipt,
|
|
82
|
+
onRefund,
|
|
83
|
+
onDelete,
|
|
84
|
+
reopenDisabled = false,
|
|
37
85
|
className,
|
|
38
86
|
...viewProps
|
|
39
87
|
}: OrderDetailProps) {
|
|
40
|
-
|
|
88
|
+
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
89
|
+
const metaLine = meta?.filter(Boolean).join(' · ');
|
|
90
|
+
const scroll = (
|
|
41
91
|
<ScrollView className={cn('flex-1', className)} {...viewProps}>
|
|
42
92
|
<View className="gap-4 p-4">
|
|
43
93
|
<View className="flex-row items-center justify-between">
|
|
44
94
|
<Text className="text-lg font-bold text-foreground">{orderNumber}</Text>
|
|
45
95
|
<OrderStatusBadge status={status} />
|
|
46
96
|
</View>
|
|
97
|
+
{metaLine ? (
|
|
98
|
+
<Text testID="order-detail-meta" className="text-xs text-muted-foreground">
|
|
99
|
+
{metaLine}
|
|
100
|
+
</Text>
|
|
101
|
+
) : null}
|
|
47
102
|
|
|
48
103
|
{customerSlot && <View className="border-b border-border pb-3">{customerSlot}</View>}
|
|
49
104
|
|
|
@@ -60,15 +115,49 @@ export function OrderDetail({
|
|
|
60
115
|
</View>
|
|
61
116
|
|
|
62
117
|
<View className="gap-1 border-t border-border pt-3">
|
|
63
|
-
<View className="flex-row justify-between">
|
|
118
|
+
<View className="flex-row items-center justify-between">
|
|
64
119
|
<Text className="text-sm text-muted-foreground">Subtotal</Text>
|
|
65
120
|
<Text className="text-sm text-foreground">{subtotal}</Text>
|
|
66
121
|
</View>
|
|
67
|
-
|
|
122
|
+
{discount ? (
|
|
123
|
+
<View testID="order-detail-discount" className="flex-row items-center justify-between">
|
|
124
|
+
<View className="flex-row items-center gap-2">
|
|
125
|
+
<Text className="text-sm text-muted-foreground">Discount</Text>
|
|
126
|
+
{couponCodes ? (
|
|
127
|
+
<View className="rounded bg-primary/10 px-1.5 py-0.5">
|
|
128
|
+
<Text className="text-xs font-medium text-primary">{couponCodes}</Text>
|
|
129
|
+
</View>
|
|
130
|
+
) : null}
|
|
131
|
+
</View>
|
|
132
|
+
<Text className="text-sm text-foreground">{discount}</Text>
|
|
133
|
+
</View>
|
|
134
|
+
) : null}
|
|
135
|
+
{shipping ? (
|
|
136
|
+
<View testID="order-detail-shipping" className="flex-row items-center justify-between">
|
|
137
|
+
<View className="flex-row items-center gap-2">
|
|
138
|
+
<Text className="text-sm text-muted-foreground">Shipping</Text>
|
|
139
|
+
{shippingMethod ? <Text className="text-xs text-muted-foreground">· {shippingMethod}</Text> : null}
|
|
140
|
+
</View>
|
|
141
|
+
<Text className="text-sm text-foreground">{shipping}</Text>
|
|
142
|
+
</View>
|
|
143
|
+
) : null}
|
|
144
|
+
{fees ? (
|
|
145
|
+
<View testID="order-detail-fees" className="flex-row items-center justify-between">
|
|
146
|
+
<Text className="text-sm text-muted-foreground">Fees</Text>
|
|
147
|
+
<Text className="text-sm text-foreground">{fees}</Text>
|
|
148
|
+
</View>
|
|
149
|
+
) : null}
|
|
150
|
+
<View className="flex-row items-center justify-between">
|
|
68
151
|
<Text className="text-sm text-muted-foreground">Tax</Text>
|
|
69
152
|
<Text className="text-sm text-foreground">{tax}</Text>
|
|
70
153
|
</View>
|
|
71
|
-
|
|
154
|
+
{taxLines?.map((line, i) => (
|
|
155
|
+
<View key={i} testID={`order-detail-tax-line-${i}`} className="flex-row items-center justify-between pl-3">
|
|
156
|
+
<Text className="text-xs text-muted-foreground">{line.label}</Text>
|
|
157
|
+
<Text className="text-xs text-muted-foreground">{line.amount}</Text>
|
|
158
|
+
</View>
|
|
159
|
+
))}
|
|
160
|
+
<View className="flex-row items-center justify-between border-t border-border pt-2 mt-1">
|
|
72
161
|
<Text className="text-sm font-bold text-foreground">Total</Text>
|
|
73
162
|
<Text className="text-sm font-bold text-foreground">{total}</Text>
|
|
74
163
|
</View>
|
|
@@ -79,4 +168,33 @@ export function OrderDetail({
|
|
|
79
168
|
</View>
|
|
80
169
|
</ScrollView>
|
|
81
170
|
);
|
|
171
|
+
if (!onReopen && !onSync && !onReceipt && !onRefund && !onDelete) return scroll;
|
|
172
|
+
return (
|
|
173
|
+
<View className="flex-1">
|
|
174
|
+
{scroll}
|
|
175
|
+
{/* v2's pinned order footer (orders/edit/view.tsx): Delete, Refund and Sync on the left, Receipt and Re-open on the right. */}
|
|
176
|
+
<View testID="order-detail-actions" className="flex-row flex-wrap items-center justify-between gap-2 border-t border-border p-4">
|
|
177
|
+
<View className="min-w-0 shrink flex-row flex-wrap gap-2">
|
|
178
|
+
{onDelete && <Button variant="outline" className="border-destructive" testID="order-detail-delete" onPress={() => setDeleteOpen(true)}>
|
|
179
|
+
<UIText className="text-destructive">Delete</UIText></Button>}
|
|
180
|
+
{onRefund && <Button variant="outline" className="border-destructive" testID="order-detail-refund" onPress={onRefund}>
|
|
181
|
+
<UIText className="text-destructive">Refund</UIText></Button>}
|
|
182
|
+
{onSync && <Button variant="outline" testID="order-detail-sync" onPress={onSync}><UIText>Sync</UIText></Button>}
|
|
183
|
+
</View>
|
|
184
|
+
<View className="ml-auto flex-row flex-wrap gap-2">
|
|
185
|
+
{onReceipt && <Button variant="outline" testID="order-detail-receipt" onPress={onReceipt}><UIText>Receipt</UIText></Button>}
|
|
186
|
+
{onReopen && <Button testID="order-detail-reopen" onPress={onReopen} disabled={reopenDisabled}
|
|
187
|
+
accessibilityState={{ disabled: reopenDisabled }}><UIText>Re-open</UIText></Button>}
|
|
188
|
+
</View>
|
|
189
|
+
</View>
|
|
190
|
+
{onDelete && <ConfirmDialog
|
|
191
|
+
testID="order-detail-delete-dialog"
|
|
192
|
+
title={`Delete order ${orderNumber}`}
|
|
193
|
+
description="Are you sure you want to delete this order?"
|
|
194
|
+
confirmLabel="Delete"
|
|
195
|
+
open={deleteOpen} onOpenChange={setDeleteOpen}
|
|
196
|
+
onConfirm={onDelete}
|
|
197
|
+
/>}
|
|
198
|
+
</View>
|
|
199
|
+
);
|
|
82
200
|
}
|
|
@@ -6,20 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Fragment, useState, type JSX, type ReactNode } from 'react';
|
|
8
8
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
9
|
-
import type { OrderFilterField } from '@tallyui/core';
|
|
9
|
+
import type { OrderFilterField, PaymentKind } from '@tallyui/core';
|
|
10
10
|
import { presetRange, type DayRange, type OrderFilterValue } from '@tallyui/pos';
|
|
11
|
-
import {
|
|
11
|
+
import { Chip, ComboboxPill, labelOf, TRIGGER_RESET, type FilterOption } from '../filter/filter-pills';
|
|
12
12
|
import { rangeLabel } from '../reports/date-range-menu';
|
|
13
13
|
import { Button } from '../ui/button';
|
|
14
14
|
import { Calendar } from '../ui/calendar';
|
|
15
|
-
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxTrigger } from '../ui/combobox';
|
|
16
|
-
import { XIcon } from '../ui/icon/x-icon';
|
|
17
15
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
|
18
16
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger } from '../ui/select';
|
|
19
17
|
import { Text as UIText } from '../ui/text';
|
|
20
18
|
|
|
21
|
-
export
|
|
22
|
-
|
|
19
|
+
export type OrderFilterOption = FilterOption;
|
|
20
|
+
/** @deprecated Use `PaymentKind` from `@tallyui/core`; in core, `PaymentMethodKind` is the order's wire method. */
|
|
21
|
+
export type PaymentMethodKind = PaymentKind;
|
|
23
22
|
export interface OrderFilterBarProps {
|
|
24
23
|
value: OrderFilterValue;
|
|
25
24
|
onChange(next: OrderFilterValue): void;
|
|
@@ -30,7 +29,7 @@ export interface OrderFilterBarProps {
|
|
|
30
29
|
options?: {
|
|
31
30
|
status?: OrderFilterOption[];
|
|
32
31
|
/** Grouped by kind in this order, with a separator between groups: cash, card, stored_value, bank_transfer, other. */
|
|
33
|
-
paymentMethod?: (OrderFilterOption & { kind?:
|
|
32
|
+
paymentMethod?: (OrderFilterOption & { kind?: PaymentKind })[];
|
|
34
33
|
customer?: OrderFilterOption[];
|
|
35
34
|
cashier?: OrderFilterOption[];
|
|
36
35
|
register?: OrderFilterOption[];
|
|
@@ -46,12 +45,7 @@ export interface OrderFilterBarProps {
|
|
|
46
45
|
testID?: string;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
const KINDS: readonly
|
|
50
|
-
// The chip look is ProductFilterBar's; the trigger inside it drops the form-field look of SelectTrigger/ComboboxTrigger.
|
|
51
|
-
const chipClass = (on: boolean) => cn('min-h-11 flex-row items-center gap-1.5 rounded-full border px-3',
|
|
52
|
-
on ? 'border-primary/30 bg-primary/10' : 'border-border bg-card');
|
|
53
|
-
const TRIGGER_RESET = 'h-auto min-h-11 w-auto justify-start rounded-none border-0 bg-transparent px-0 py-0';
|
|
54
|
-
const labelOf = (options: OrderFilterOption[] | undefined, value: string) => options?.find((o) => o.value === value)?.label ?? value;
|
|
48
|
+
const KINDS: readonly PaymentKind[] = ['cash', 'card', 'stored_value', 'bank_transfer', 'other'];
|
|
55
49
|
const sameRange = (a?: DayRange, b?: DayRange) => a?.from === b?.from && a?.to === b?.to;
|
|
56
50
|
// Clear all counts pills, as v2 counts its filters: the store pill's two fields are one.
|
|
57
51
|
const SIMPLE = ['status', 'paymentMethod', 'customerId', 'cashierId', 'registerId'] as const;
|
|
@@ -60,22 +54,6 @@ const changedCount = (value: OrderFilterValue, initial: OrderFilterValue) =>
|
|
|
60
54
|
+ (value.storeId !== initial.storeId || value.createdVia !== initial.createdVia ? 1 : 0)
|
|
61
55
|
+ (sameRange(value.dateRange, initial.dateRange) ? 0 : 1);
|
|
62
56
|
|
|
63
|
-
function Chip({ id, on, label, onClear, trigger }: {
|
|
64
|
-
id: string; on: boolean; label: string; onClear: () => void; trigger: (children: ReactNode) => ReactNode;
|
|
65
|
-
}) {
|
|
66
|
-
return (
|
|
67
|
-
<View className={chipClass(on)}>
|
|
68
|
-
{trigger(<Text className={cn('text-sm', on ? 'text-primary' : 'text-foreground')}>{label}</Text>)}
|
|
69
|
-
{on ? (
|
|
70
|
-
<Pressable testID={`${id}-remove`} role="button" accessibilityLabel="Remove" onPress={onClear}
|
|
71
|
-
hitSlop={8} className="min-h-11 min-w-8 items-center justify-center text-primary">
|
|
72
|
-
<XIcon size={14} />
|
|
73
|
-
</Pressable>
|
|
74
|
-
) : null}
|
|
75
|
-
</View>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
57
|
function SelectPill({ id, offLabel, selected, onClear, children }: {
|
|
80
58
|
id: string; offLabel: string; selected?: OrderFilterOption; onClear: () => void; children: ReactNode;
|
|
81
59
|
}) {
|
|
@@ -96,34 +74,6 @@ function Item({ id, option, onPress }: { id: string; option: OrderFilterOption;
|
|
|
96
74
|
);
|
|
97
75
|
}
|
|
98
76
|
|
|
99
|
-
function ComboboxPill({ id, offLabel, placeholder, value, options, onSearch, onPick, onClear }: {
|
|
100
|
-
id: string; offLabel: string; placeholder: string; value?: string; options: OrderFilterOption[];
|
|
101
|
-
onSearch?: (text: string) => void; onPick: (value: string) => void; onClear: () => void;
|
|
102
|
-
}) {
|
|
103
|
-
const [search, setSearch] = useState('');
|
|
104
|
-
const selected = value === undefined ? undefined : { value, label: labelOf(options, value) };
|
|
105
|
-
const needle = search.trim().toLowerCase();
|
|
106
|
-
const shown = onSearch || !needle ? options : options.filter((o) => o.label.toLowerCase().includes(needle));
|
|
107
|
-
return (
|
|
108
|
-
<Combobox value={selected} onValueChange={(next) => { if (next) onPick(next.value); }} searchValue={search}
|
|
109
|
-
onSearchValueChange={(text) => { setSearch(text); onSearch?.(text); }}>
|
|
110
|
-
<Chip id={id} on={!!selected} label={selected?.label ?? offLabel} onClear={onClear}
|
|
111
|
-
trigger={(label) => <ComboboxTrigger testID={id} className={TRIGGER_RESET}>{label}</ComboboxTrigger>} />
|
|
112
|
-
<ComboboxContent testID={`${id}-menu`}>
|
|
113
|
-
<View className="border-b border-border px-2 py-1.5">
|
|
114
|
-
<ComboboxInput testID={`${id}-search`} placeholder={placeholder} />
|
|
115
|
-
</View>
|
|
116
|
-
{shown.map((option) => (
|
|
117
|
-
<ComboboxItem key={option.value} testID={`${id}-${option.value}`} value={option.value} label={option.label}>
|
|
118
|
-
<Text className="text-sm text-popover-foreground">{option.label}</Text>
|
|
119
|
-
</ComboboxItem>
|
|
120
|
-
))}
|
|
121
|
-
{shown.length === 0 ? <ComboboxEmpty /> : null}
|
|
122
|
-
</ComboboxContent>
|
|
123
|
-
</Combobox>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
77
|
function DatePill({ value, onPick, onClear, timezone, now }: {
|
|
128
78
|
value?: DayRange; onPick: (range: DayRange) => void; onClear: () => void; timezone: string; now?: () => Date;
|
|
129
79
|
}) {
|
|
@@ -1,32 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
2
|
|
|
3
3
|
import { cn } from '@tallyui/theme';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { StatusBadge, type StatusBadgeProps } from '../ui/status-badge';
|
|
6
|
+
|
|
7
|
+
// 'canceled' is Medusa's spelling of 'cancelled'; both show as "Cancelled" (WCPOS v2's label).
|
|
8
|
+
// 'pos-open' and 'pos-partial' are WCPOS's own statuses (v2 labels: POS open, POS partial).
|
|
9
|
+
// 'trash' is WordPress's post status and 'checkout-draft' WooCommerce's (labels: Trash, Draft).
|
|
10
|
+
export type OrderStatus =
|
|
11
|
+
| 'pending'
|
|
12
|
+
| 'processing'
|
|
13
|
+
| 'completed'
|
|
14
|
+
| 'refunded'
|
|
15
|
+
| 'cancelled'
|
|
16
|
+
| 'canceled'
|
|
17
|
+
| 'on-hold'
|
|
18
|
+
| 'failed'
|
|
19
|
+
| 'pos-open'
|
|
20
|
+
| 'pos-partial'
|
|
21
|
+
| 'trash'
|
|
22
|
+
| 'checkout-draft';
|
|
6
23
|
|
|
7
24
|
export interface OrderStatusBadgeProps extends Omit<ViewProps, 'children'> {
|
|
8
25
|
status: OrderStatus;
|
|
9
26
|
className?: string;
|
|
10
27
|
}
|
|
11
28
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
type Tone = NonNullable<StatusBadgeProps['variant']>;
|
|
30
|
+
|
|
31
|
+
const STATUS_CONFIG: Record<OrderStatus, { label: string; tone: Tone }> = {
|
|
32
|
+
pending: { label: 'Pending', tone: 'warning' },
|
|
33
|
+
processing: { label: 'Processing', tone: 'info' },
|
|
34
|
+
completed: { label: 'Completed', tone: 'ok' },
|
|
35
|
+
refunded: { label: 'Refunded', tone: 'muted' },
|
|
36
|
+
cancelled: { label: 'Cancelled', tone: 'muted' },
|
|
37
|
+
canceled: { label: 'Cancelled', tone: 'muted' },
|
|
38
|
+
'on-hold': { label: 'On hold', tone: 'warning' },
|
|
39
|
+
failed: { label: 'Failed', tone: 'bad' },
|
|
40
|
+
'pos-open': { label: 'POS open', tone: 'info' },
|
|
41
|
+
'pos-partial': { label: 'POS partial', tone: 'warning' },
|
|
42
|
+
trash: { label: 'Trash', tone: 'muted' },
|
|
43
|
+
'checkout-draft': { label: 'Draft', tone: 'default' },
|
|
18
44
|
};
|
|
19
45
|
|
|
20
46
|
export function OrderStatusBadge({ status, className, ...viewProps }: OrderStatusBadgeProps) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<Text className={cn('text-xs font-semibold', config.text)}>{config.label}</Text>
|
|
30
|
-
</View>
|
|
31
|
-
);
|
|
47
|
+
// As in WCPOS v2, a status not in the table shows its raw string in the default tone.
|
|
48
|
+
const config: { label: string; tone: Tone } = Object.prototype.hasOwnProperty.call(STATUS_CONFIG, status)
|
|
49
|
+
? STATUS_CONFIG[status]
|
|
50
|
+
: { label: status, tone: 'default' };
|
|
51
|
+
|
|
52
|
+
// As in WCPOS v2, a dot and a word with no tinted pill (removal R3); a caller's className still
|
|
53
|
+
// lands on the row, so an app can add its own background.
|
|
54
|
+
return <StatusBadge label={config.label} variant={config.tone} className={cn('self-start', className)} {...viewProps} />;
|
|
32
55
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useState, type JSX } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useFormatMoney, useMoneyFormat, type MoneyFormat, type OrderRefundPayload } from '@tallyui/core';
|
|
4
4
|
import { priceRefund, refundableLines, type EarlierRefund, type RefundableOrderLine } from '@tallyui/pos';
|
|
5
5
|
import { QuantityStepper } from '../input/quantity-stepper';
|
|
6
6
|
import { errorText } from '../lib/error-text';
|
|
@@ -42,11 +42,11 @@ export interface RefundFormProps {
|
|
|
42
42
|
onCancel: () => void;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function parseAmount(text: string, currency: string, signed = false): number | string {
|
|
45
|
+
function parseAmount(text: string, currency: string, signed = false, format?: MoneyFormat): number | string {
|
|
46
46
|
const trimmed = text.trim();
|
|
47
47
|
if (!trimmed) return 0;
|
|
48
48
|
const negative = signed && trimmed.startsWith('-');
|
|
49
|
-
const parsed = parsePrice(negative ? trimmed.slice(1) : trimmed, currency);
|
|
49
|
+
const parsed = parsePrice(negative ? trimmed.slice(1) : trimmed, currency, format);
|
|
50
50
|
return negative && typeof parsed === 'number' && parsed !== 0 ? -parsed : parsed;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -56,6 +56,8 @@ export function RefundForm({
|
|
|
56
56
|
refundableShippingMinor = 0, originalMethod, defaultRestock = true, online = true,
|
|
57
57
|
error, onConfirm, onCancel,
|
|
58
58
|
}: RefundFormProps): JSX.Element {
|
|
59
|
+
const formatMoney = useFormatMoney();
|
|
60
|
+
const format = useMoneyFormat();
|
|
59
61
|
const [quantities, setQuantities] = useState<Record<string, number>>({});
|
|
60
62
|
const [restock, setRestock] = useState<Record<string, boolean>>({});
|
|
61
63
|
const [shippingText, setShippingText] = useState('');
|
|
@@ -74,8 +76,8 @@ export function RefundForm({
|
|
|
74
76
|
restock: restock[orderLineId] ?? defaultRestock,
|
|
75
77
|
})).filter(({ quantity }) => quantity > 0);
|
|
76
78
|
const priced = priceRefund(lines, refunds, request);
|
|
77
|
-
const shippingMinor = refundableShippingMinor > 0 ? parseAmount(shippingText, currency) : 0;
|
|
78
|
-
const adjustmentMinor = parseAmount(adjustmentText, currency, true);
|
|
79
|
+
const shippingMinor = refundableShippingMinor > 0 ? parseAmount(shippingText, currency, false, format) : 0;
|
|
80
|
+
const adjustmentMinor = parseAmount(adjustmentText, currency, true, format);
|
|
79
81
|
const totalMinor = typeof shippingMinor === 'number' && typeof adjustmentMinor === 'number'
|
|
80
82
|
? priced.totalMinor + shippingMinor + adjustmentMinor : undefined;
|
|
81
83
|
const destination = originalMethod?.available ? (picked ?? 'original_method') : 'cash';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { View } from 'react-native';
|
|
2
|
+
import { MinTargetBand } from '../scale/min-target';
|
|
2
3
|
import { IconButton } from '../ui/icon-button';
|
|
3
4
|
import { ScanIcon } from '../ui/icon/scan-icon';
|
|
4
5
|
import { Text } from '../ui/text';
|
|
@@ -20,6 +21,7 @@ export function CameraScanButton({ open, onPress, testID = 'camera-scan-button'
|
|
|
20
21
|
<IconButton variant={open ? 'secondary' : 'ghost'} testID={testID} accessibilityLabel={label}
|
|
21
22
|
accessibilityState={{ expanded: open }} onPress={onPress}>
|
|
22
23
|
<View className={open ? 'text-secondary-foreground' : 'text-foreground'}><ScanIcon size={20} /></View>
|
|
24
|
+
<MinTargetBand square />
|
|
23
25
|
</IconButton>
|
|
24
26
|
</TooltipTrigger>
|
|
25
27
|
<TooltipContent><Text>{label}</Text></TooltipContent>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Pressable, ScrollView, Text, View, type ViewProps } from 'react-native';
|
|
2
2
|
|
|
3
3
|
import { cn } from '@tallyui/theme';
|
|
4
|
+
import { MinTargetBand, useMinTarget } from '../scale/min-target';
|
|
5
|
+
import { usePointer } from '../scale/use-pointer';
|
|
4
6
|
|
|
5
7
|
export interface CategoryItem {
|
|
6
8
|
id: string;
|
|
@@ -24,6 +26,9 @@ export function CategoryNav({
|
|
|
24
26
|
...viewProps
|
|
25
27
|
}: CategoryNavProps) {
|
|
26
28
|
const isHorizontal = orientation === 'horizontal';
|
|
29
|
+
// A horizontal ScrollView clips its content: under a coarse pointer the row is the band's height, so no band is cut.
|
|
30
|
+
const band = useMinTarget();
|
|
31
|
+
const coarse = usePointer() === 'coarse';
|
|
27
32
|
|
|
28
33
|
const content = categories.map((cat) => {
|
|
29
34
|
const active = cat.id === selectedId;
|
|
@@ -47,6 +52,8 @@ export function CategoryNav({
|
|
|
47
52
|
>
|
|
48
53
|
{cat.name}
|
|
49
54
|
</Text>
|
|
55
|
+
{/* Stacked chips would take each other's touches, so only the horizontal row gets a band. */}
|
|
56
|
+
{isHorizontal && <MinTargetBand />}
|
|
50
57
|
</Pressable>
|
|
51
58
|
);
|
|
52
59
|
});
|
|
@@ -57,6 +64,7 @@ export function CategoryNav({
|
|
|
57
64
|
horizontal
|
|
58
65
|
showsHorizontalScrollIndicator={false}
|
|
59
66
|
contentContainerClassName="flex-row gap-2 px-3 py-2"
|
|
67
|
+
contentContainerStyle={coarse ? { alignItems: 'center', minHeight: band } : undefined}
|
|
60
68
|
className={className}
|
|
61
69
|
role="radiogroup"
|
|
62
70
|
accessibilityLabel="Categories"
|
|
@@ -1,13 +1,44 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
1
2
|
import { Pressable, Text, View } from 'react-native';
|
|
2
3
|
import { Image } from '@tallyui/primitives';
|
|
3
4
|
import { cn } from '@tallyui/theme';
|
|
5
|
+
import { Icon } from '../ui/icon';
|
|
6
|
+
import { CategoryIcon } from '../ui/icon/category-icon';
|
|
7
|
+
import { ChevronLeftIcon } from '../ui/icon/chevron-left-icon';
|
|
8
|
+
import { ViewGridIcon } from '../ui/icon/view-grid-icon';
|
|
9
|
+
|
|
10
|
+
// v2 poster-tile/style.ts CARD, FAR and NEAR: the two cards drawn behind a stacked tile.
|
|
11
|
+
const CARD = 'absolute rounded-lg border border-border bg-card';
|
|
12
|
+
const FAR = { top: 6, left: 6, right: -6, bottom: -6, opacity: 0.6 };
|
|
13
|
+
const NEAR = { top: 3, left: 3, right: -3, bottom: -3 };
|
|
14
|
+
|
|
15
|
+
/** The two cards behind a stacked tile; drawn first inside the tile's Pressable. */
|
|
16
|
+
export function TileStack({ id }: { id: string }) {
|
|
17
|
+
return (
|
|
18
|
+
<View testID={`${id}-stack`} pointerEvents="none" className="absolute inset-0">
|
|
19
|
+
<View testID={`${id}-stack-far`} className={CARD} style={FAR} />
|
|
20
|
+
<View testID={`${id}-stack-near`} className={CARD} style={NEAR} />
|
|
21
|
+
</View>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
4
24
|
|
|
5
25
|
export interface CategoryTileProps {
|
|
6
26
|
name: string;
|
|
7
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The category's photo; without one, or when it fails to load, the tile shows the name's initial on a tint.
|
|
29
|
+
* A new URL gets its own chance to load.
|
|
30
|
+
*/
|
|
8
31
|
imageUrl?: string;
|
|
9
32
|
/** Products in the category, shown under the name when above 0. */
|
|
10
33
|
count?: number;
|
|
34
|
+
/** Draws two cards behind the tile, as v2's poster tile does (default false). */
|
|
35
|
+
stacked?: boolean;
|
|
36
|
+
/** The corner mark: `folder` for a category, `all` (a grid) for the All products tile. Decoration only. */
|
|
37
|
+
mark?: 'folder' | 'all';
|
|
38
|
+
/** Draws v2's back badge, a left chevron top-right in the mark's circle, as on a level's first tile. Decoration only (default false). */
|
|
39
|
+
back?: boolean;
|
|
40
|
+
/** The tile's accessible label (default `name`). */
|
|
41
|
+
accessibilityLabel?: string;
|
|
11
42
|
onPress?: () => void;
|
|
12
43
|
testID?: string;
|
|
13
44
|
className?: string;
|
|
@@ -19,24 +50,43 @@ export interface CategoryTileProps {
|
|
|
19
50
|
*
|
|
20
51
|
* Ported from WCPOS v2 `TermTile`, packages/core/src/screens/main/pos/products/browse/term-tile.tsx
|
|
21
52
|
* (MIT, WCPOS): the picture fills the square (`contentFit="cover"`), else a tint; the name bold over two
|
|
22
|
-
* lines with the count under it.
|
|
53
|
+
* lines with the count under it. The stack and the mark follow v2's `PosterTile` (poster-tile/index.tsx).
|
|
23
54
|
*/
|
|
24
|
-
export function CategoryTile({ name, imageUrl, count, onPress, testID, className }: CategoryTileProps) {
|
|
55
|
+
export function CategoryTile({ name, imageUrl, count, stacked = false, mark, back = false, accessibilityLabel, onPress, testID, className }: CategoryTileProps) {
|
|
25
56
|
const id = testID ?? 'category-tile';
|
|
57
|
+
// Keyed by the URL, as v2's useTermPicture: a failed photo falls back to the initial, a new URL is tried.
|
|
58
|
+
const [failed, setFailed] = useState<string | null>(null);
|
|
59
|
+
const photo = imageUrl && imageUrl !== failed ? imageUrl : undefined;
|
|
26
60
|
return (
|
|
27
|
-
<Pressable testID={testID} role="button" accessibilityLabel={name} onPress={onPress}
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
61
|
+
<Pressable testID={testID} role="button" accessibilityLabel={accessibilityLabel ?? name} onPress={onPress} className={className}>
|
|
62
|
+
{stacked ? <TileStack id={id} /> : null}
|
|
63
|
+
<View className={cn('aspect-square overflow-hidden rounded-lg border border-border', photo ? 'bg-card' : 'bg-primary/10')}>
|
|
64
|
+
{photo ? (
|
|
65
|
+
<Image.Root key={photo} testID={`${id}-image`} source={{ uri: photo }} alt="" contentFit="cover"
|
|
66
|
+
onError={() => setFailed(photo)} className="absolute inset-0" style={{ width: '100%', height: '100%' }} />
|
|
67
|
+
) : (
|
|
68
|
+
<View testID={`${id}-fallback`} className="absolute inset-0 items-center justify-center">
|
|
69
|
+
<Text className="text-3xl font-semibold text-primary">{name.trim().charAt(0).toUpperCase() || '?'}</Text>
|
|
70
|
+
</View>
|
|
71
|
+
)}
|
|
72
|
+
<View className={cn('absolute inset-x-0 bottom-0 px-2.5 py-2', photo && 'bg-card/80')}>
|
|
73
|
+
<Text className="font-bold text-foreground" numberOfLines={2}>{name}</Text>
|
|
74
|
+
{count !== undefined && count > 0 ? <Text className="text-xs text-muted-foreground">{count === 1 ? '1 product' : `${count} products`}</Text> : null}
|
|
35
75
|
</View>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
{mark ? (
|
|
77
|
+
<View testID={`${id}-mark`} aria-hidden accessibilityElementsHidden importantForAccessibility="no-hide-descendants"
|
|
78
|
+
className="absolute top-2 left-2 size-6 items-center justify-center rounded-full border border-border bg-card">
|
|
79
|
+
<Icon size="sm" className="text-muted-foreground">
|
|
80
|
+
{mark === 'all' ? <ViewGridIcon size={16} /> : <CategoryIcon size={16} />}
|
|
81
|
+
</Icon>
|
|
82
|
+
</View>
|
|
83
|
+
) : null}
|
|
84
|
+
{back ? (
|
|
85
|
+
<View testID={`${id}-back`} aria-hidden accessibilityElementsHidden importantForAccessibility="no-hide-descendants"
|
|
86
|
+
className="absolute top-2 right-2 size-6 items-center justify-center rounded-full border border-border bg-card">
|
|
87
|
+
<Icon size="sm" className="text-muted-foreground"><ChevronLeftIcon size={16} /></Icon>
|
|
88
|
+
</View>
|
|
89
|
+
) : null}
|
|
40
90
|
</View>
|
|
41
91
|
</Pressable>
|
|
42
92
|
);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Animated, Easing, Platform, Text } from 'react-native';
|
|
2
3
|
import { cn } from '@tallyui/theme';
|
|
4
|
+
import { COUNT_FADE, COUNT_SWELL, EASE } from '../lib/motion';
|
|
5
|
+
import { useReducedMotion } from '../lib/use-reduced-motion';
|
|
3
6
|
|
|
4
7
|
export interface InCartBadgeProps {
|
|
5
8
|
/** How many of the product the cart holds (e.g. from `cartQuantities`); nothing renders at 0. */
|
|
@@ -7,20 +10,66 @@ export interface InCartBadgeProps {
|
|
|
7
10
|
/** Placement, e.g. `absolute right-2 top-2` for a tile's top-right corner. */
|
|
8
11
|
className?: string;
|
|
9
12
|
testID?: string;
|
|
13
|
+
identity?: string;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* How many of a product are in the cart: a primary circle with the count, hidden while there are none.
|
|
14
18
|
*
|
|
15
19
|
* Ported from WCPOS v2 `InCartCount`, packages/core/src/screens/main/pos/products/rows/in-cart-count.tsx
|
|
16
|
-
* (MIT, WCPOS),
|
|
20
|
+
* (MIT, WCPOS), with v2's count beat from packages/components/src/badge/count-beat.tsx.
|
|
17
21
|
*/
|
|
18
|
-
export function InCartBadge({ count, className, testID }: InCartBadgeProps) {
|
|
22
|
+
export function InCartBadge({ count, className, testID, identity = '' }: InCartBadgeProps) {
|
|
23
|
+
const text = count > 0 ? String(count) : null;
|
|
24
|
+
const [seen, setSeen] = useState({ identity, text, value: count, wasText: text, added: false, beat: 0 });
|
|
25
|
+
if (seen.identity !== identity) {
|
|
26
|
+
setSeen({ identity, text, value: count, wasText: text, added: false, beat: 0 });
|
|
27
|
+
} else if (seen.text !== text) {
|
|
28
|
+
setSeen({ identity, text, value: count, wasText: seen.text, added: count > seen.value, beat: seen.beat + 1 });
|
|
29
|
+
} else if (seen.value !== count) {
|
|
30
|
+
setSeen({ ...seen, value: count });
|
|
31
|
+
}
|
|
32
|
+
const pop = useRef(new Animated.Value(1)).current;
|
|
33
|
+
const change = useRef(new Animated.Value(1)).current;
|
|
34
|
+
const reduced = useReducedMotion();
|
|
35
|
+
const { beat, added, wasText, identity: shownIdentity } = seen;
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
if (beat === 0) {
|
|
38
|
+
pop.setValue(1);
|
|
39
|
+
change.setValue(1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (text === null) return;
|
|
43
|
+
if (reduced !== false) {
|
|
44
|
+
pop.setValue(1);
|
|
45
|
+
change.setValue(1);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const useNativeDriver = Platform.OS !== 'web';
|
|
49
|
+
change.setValue(0);
|
|
50
|
+
Animated.timing(change, { toValue: 1, duration: COUNT_FADE, easing: Easing.linear, useNativeDriver }).start();
|
|
51
|
+
if (added) {
|
|
52
|
+
Animated.sequence([
|
|
53
|
+
Animated.timing(pop, { toValue: 1.3, duration: COUNT_SWELL, easing: EASE, useNativeDriver }),
|
|
54
|
+
Animated.spring(pop, { toValue: 1, stiffness: 380, damping: 11, mass: 0.6, useNativeDriver }),
|
|
55
|
+
]).start();
|
|
56
|
+
}
|
|
57
|
+
}, [beat, shownIdentity, text, added, reduced, pop, change]);
|
|
58
|
+
const scaleX = pop.interpolate({ inputRange: [1, 2], outputRange: [1, 1.55], extrapolate: 'extend' });
|
|
19
59
|
if (count <= 0) return null;
|
|
20
60
|
return (
|
|
21
|
-
<View testID={testID} accessibilityLabel={`${count} in cart`}
|
|
61
|
+
<Animated.View testID={testID} accessibilityLabel={`${count} in cart`} style={{ transform: [{ scaleX }, { scaleY: pop }] }}
|
|
22
62
|
className={cn('h-6 min-w-6 items-center justify-center rounded-full bg-primary px-1.5', className)}>
|
|
23
|
-
|
|
24
|
-
|
|
63
|
+
{reduced === false && wasText !== null && wasText !== text ? (
|
|
64
|
+
<Animated.View testID={testID ? `${testID}-was` : undefined} aria-hidden className="absolute inset-0 items-center justify-center"
|
|
65
|
+
style={{ opacity: change.interpolate({ inputRange: [0, 0.45], outputRange: [1, 0], extrapolate: 'clamp' }) }}>
|
|
66
|
+
<Text className="text-xs font-semibold tabular-nums text-primary-foreground">{wasText}</Text>
|
|
67
|
+
</Animated.View>
|
|
68
|
+
) : null}
|
|
69
|
+
<Animated.View style={{ opacity: change.interpolate({ inputRange: [0.3, 0.8], outputRange: [0, 1], extrapolate: 'clamp' }),
|
|
70
|
+
transform: [{ scale: pop.interpolate({ inputRange: [1, 2], outputRange: [1, 2.2], extrapolate: 'extend' }) }] }}>
|
|
71
|
+
<Text className="text-xs font-semibold tabular-nums text-primary-foreground">{text}</Text>
|
|
72
|
+
</Animated.View>
|
|
73
|
+
</Animated.View>
|
|
25
74
|
);
|
|
26
75
|
}
|