@tallyui/components 3.20.0 → 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
package/src/sale/tender-pane.tsx
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The tender pane, laid out as WCPOS v2's (monorepo main, packages/core/src/screens/main/pos/checkout/tender/):
|
|
3
|
-
* BalanceHeadline
|
|
3
|
+
* BalanceHeadline from ledger-pane.tsx, LedgerLegs (now tender-ledger.tsx's TenderLedger), then the method tiles, entry, quick-cash chips,
|
|
4
4
|
* keypad and commit from tender-pane.tsx's TenderKeypad. Copy is read with useT, under v2's catalogue keys. Every figure
|
|
5
5
|
* comes from pos (useSale's captured-only totals, tenderRounding, quickTenderedAmounts, planLegs).
|
|
6
|
+
* The caption row and the hero figure follow tender-pane.tsx's caption row and AmountFigure (v2 :390-459).
|
|
6
7
|
*/
|
|
7
8
|
import { useEffect, useState, type JSX } from 'react';
|
|
8
|
-
import { Pressable, Text, TextInput, View } from 'react-native';
|
|
9
|
-
import {
|
|
9
|
+
import { Pressable, ScrollView, Text, TextInput, View } from 'react-native';
|
|
10
|
+
import { useFormatMoney, minorUnitDigits, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
|
|
10
11
|
import {
|
|
11
|
-
activePlan,
|
|
12
|
-
type
|
|
12
|
+
activePlan, changeMinor, countsTowardPaid, evenSplitShareMinor, inMotionMinor, isInMotion, legStatus, lockedRefundDueMinor, planLegs, quickTenderedAmounts, tenderRounding, tillLegsTheStoreRefuses,
|
|
13
|
+
type TenderAction, type TenderKey, type TenderPlan, type TenderState, type useSale,
|
|
13
14
|
} from '@tallyui/pos';
|
|
14
15
|
import { cn } from '@tallyui/theme';
|
|
15
16
|
import { QUICK_CASH_STEPS } from '../checkout/cash-tendered';
|
|
16
17
|
import { useT } from '../i18n';
|
|
17
18
|
import { DIGIT_ROWS, Keypad } from '../input/keypad';
|
|
19
|
+
import { offeredMethods, tenderOf } from './offered-methods';
|
|
20
|
+
import { TenderLedger } from './tender-ledger';
|
|
21
|
+
import { pickFigure } from './use-tender';
|
|
22
|
+
import { BanknoteIcon } from '../ui/icon/banknote-icon';
|
|
23
|
+
import { CreditCardIcon } from '../ui/icon/credit-card-icon';
|
|
18
24
|
|
|
19
25
|
type Sale = ReturnType<typeof useSale>;
|
|
20
26
|
type Leg = Sale['order']['payments'][number];
|
|
@@ -24,31 +30,36 @@ export interface TenderPaneProps {
|
|
|
24
30
|
/** The tender reducer's state (`tenderReducer` in @tallyui/pos); the host owns the reducer. */
|
|
25
31
|
state: TenderState;
|
|
26
32
|
dispatch: (action: TenderAction) => void;
|
|
27
|
-
/** Defaults to `defaultPaymentMethods()
|
|
33
|
+
/** Defaults to `defaultPaymentMethods()`. Each manual-capture method is offered, recorded as its wire method (`wireMethodOf`) plus its own id. */
|
|
28
34
|
methods?: PaymentMethodDescriptor[];
|
|
35
|
+
/** Draws the payments ledger in the pane. Pass `false` when the host shows it in the cart column, as v2 does (Cart's `tenderLedger`). Default `true`. */
|
|
36
|
+
ledger?: boolean;
|
|
37
|
+
/** Draws the Back button (`sale.cancelTender`). Pass `false` when the host leaves the tender stage itself, as v2's phone checkout does. Default `true`. */ back?: boolean;
|
|
38
|
+
/** Passed to the ledger: v2's "Cancel this payment?" before a leg is voided. Default `false`: Cancel payment voids at once. */
|
|
39
|
+
confirmVoid?: boolean;
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
/** order.create's bound on `payments[].reference`, in UTF-16 units. */
|
|
32
43
|
const REFERENCE_MAX = 255;
|
|
33
|
-
/** v2
|
|
34
|
-
const
|
|
35
|
-
pending: 'pos_checkout.status_pending', authorized: 'pos_checkout.status_authorized', captured: 'pos_checkout.status_captured',
|
|
36
|
-
failed: 'pos_checkout.status_failed', voided: 'pos_checkout.status_voided',
|
|
37
|
-
};
|
|
38
|
-
/** v2 labels.ts statusVariant: coloured by what the cashier has to do about the leg. */
|
|
39
|
-
const STATUS_TONE: Record<PaymentLegStatus, string> = {
|
|
40
|
-
pending: 'text-muted-foreground', authorized: 'text-success', captured: 'text-success', failed: 'text-destructive', voided: 'text-muted-foreground',
|
|
41
|
-
};
|
|
44
|
+
/** v2 tender-pane.tsx: five method tiles a row on a wide pane (TileGrid columns). */
|
|
45
|
+
const TILE_COLUMNS = 5;
|
|
42
46
|
/** v2 tender-pane.tsx keypadRows: 123 / 456 / 789, then C, 0, backspace. No decimal key: digits shift in from the right. */
|
|
43
47
|
const keypadRows = (t: ReturnType<typeof useT>) => [...DIGIT_ROWS,
|
|
44
48
|
[{ name: 'clear', label: t('pos_checkout.clear_amount'), text: 'C' }, { name: '0', label: '0' }, { name: 'backspace', label: t('common.backspace'), text: '⌫' }]];
|
|
45
49
|
const button = 'min-h-11 justify-center rounded-md border border-border bg-card px-4 py-2';
|
|
50
|
+
/** v2 tender-pane.tsx "Split the rest" strip: 2 to 6 equal ways. */
|
|
51
|
+
const SPLIT_WAYS = [2, 3, 4, 5, 6];
|
|
46
52
|
|
|
47
|
-
/** The captured legs
|
|
48
|
-
const rowsSince = (payments: readonly Leg[],
|
|
49
|
-
payments.filter(countsTowardPaid)
|
|
53
|
+
/** The captured legs in ledger order excluding `plan.before`, or sliced from `plan.from` when `before` is absent. */
|
|
54
|
+
const rowsSince = (payments: readonly Leg[], plan: TenderPlan | null) => {
|
|
55
|
+
const captured = payments.filter(countsTowardPaid);
|
|
56
|
+
const before = plan?.before;
|
|
57
|
+
return (before ? captured.filter((leg) => !before.includes(leg.id)) : captured.slice(plan?.from ?? 0))
|
|
58
|
+
.map((leg) => ({ title: leg.method, amountMinor: leg.amountMinor }));
|
|
59
|
+
};
|
|
50
60
|
|
|
51
|
-
export function TenderPane({ sale, state, dispatch, methods }: TenderPaneProps): JSX.Element | null {
|
|
61
|
+
export function TenderPane({ sale, state, dispatch, methods, ledger = true, back = true, confirmVoid }: TenderPaneProps): JSX.Element | null {
|
|
62
|
+
const formatMoney = useFormatMoney();
|
|
52
63
|
const { order, stage } = sale;
|
|
53
64
|
const t = useT();
|
|
54
65
|
const [reference, setReference] = useState('');
|
|
@@ -56,99 +67,168 @@ export function TenderPane({ sale, state, dispatch, methods }: TenderPaneProps):
|
|
|
56
67
|
const balance = order.balanceDueMinor;
|
|
57
68
|
// The ledger changed (a leg taken or voided) and the entry is untouched: pre-type the next leg or plan share.
|
|
58
69
|
useEffect(() => {
|
|
59
|
-
if (!state.entryDirty) dispatch({ type: 'tender-recorded', rowsSinceFrom: rowsSince(order.payments, state.plan
|
|
70
|
+
if (!state.entryDirty) dispatch({ type: 'tender-recorded', rowsSinceFrom: rowsSince(order.payments, state.plan), balanceMinor: balance });
|
|
60
71
|
}, [order.payments, balance, state.entryDirty, state.plan, dispatch]);
|
|
61
72
|
if (stage.kind !== 'tender') return null;
|
|
62
73
|
|
|
63
|
-
const offered = (methods
|
|
74
|
+
const offered = offeredMethods(methods);
|
|
64
75
|
const descriptorOf = (id: string) => offered.find((method) => method.id === id);
|
|
65
76
|
const money = (minor: number) => formatMoney({ amount: minor, currency: order.currency }) ?? '';
|
|
66
77
|
const method = state.methodId ? descriptorOf(state.methodId) ?? null : null;
|
|
67
|
-
|
|
68
|
-
const
|
|
78
|
+
// ADR-072: change comes only from cash, so a non-cash method's `change: true` gives none (take() records no change for it).
|
|
79
|
+
const givesChange = method !== null && wireMethodOf(method) === 'cash' && method.capabilities.change === true;
|
|
80
|
+
const pick = state.plan || Object.keys(state.pickedUnits).length === 0 ? null : pickFigure(order, state.pickedUnits);
|
|
81
|
+
const target = pick ? Math.min(pick.minor, balance - inMotionMinor(order.payments)) : balance;
|
|
82
|
+
const partPick = pick !== null && target < balance;
|
|
83
|
+
const entry = state.entryDirty ? state.entryMinor : target;
|
|
84
|
+
const figures = partPick ? tenderRounding({ entryMinor: entry, entryDirty: state.entryDirty }, target, null) : tenderRounding(state, balance, method);
|
|
85
|
+
const pickRefused = (partPick && entry > 0 && (givesChange ? entry < target : entry !== target))
|
|
86
|
+
|| (pick !== null && !partPick && figures.appliedMinor > 0 && figures.appliedMinor < figures.roundedDueMinor);
|
|
69
87
|
const entryChange = changeMinor(figures.entryMinor, figures.appliedMinor, givesChange);
|
|
70
88
|
const left = balance + figures.roundingMinor - figures.appliedMinor;
|
|
71
|
-
const noChange = method !== null && !givesChange && figures.entryMinor > balance;
|
|
72
|
-
const
|
|
89
|
+
const noChange = !partPick && method !== null && !givesChange && figures.entryMinor > balance;
|
|
90
|
+
const changeLeads = !noChange && entryChange > 0;
|
|
91
|
+
// v2 tender-pane.tsx:405-410: the caption names the balance only when it differs from the figure shown.
|
|
92
|
+
const balanceInCaption = balance === 0 || figures.entryMinor !== balance;
|
|
93
|
+
const rows = rowsSince(order.payments, state.plan).map(({ title, amountMinor }) => ({ title, minor: amountMinor }));
|
|
73
94
|
const plan = activePlan(state.plan, rows.length, balance);
|
|
74
95
|
const planned = plan ? planLegs(plan, rows, balance) : null;
|
|
75
|
-
const
|
|
96
|
+
const counted = order.payments.filter(countsTowardPaid).length;
|
|
97
|
+
const splitOn = state.splitView || plan !== null;
|
|
98
|
+
// v2 tender-figures.ts: a typed part payment comes first, and the ways divide what is left after it.
|
|
99
|
+
const typed = state.entryDirty && figures.appliedMinor > 0 && figures.appliedMinor < balance;
|
|
100
|
+
const restMinor = balance - (typed ? figures.appliedMinor : 0);
|
|
101
|
+
const thisPaymentMinor = planned ? planned.thisPaymentMinor : balance;
|
|
102
|
+
const dueMinor = partPick ? target : planned && planned.thisPaymentMinor < balance ? planned.thisPaymentMinor : figures.roundedDueMinor;
|
|
76
103
|
const chips = givesChange ? quickTenderedAmounts(dueMinor, QUICK_CASH_STEPS.map((step) => step * 10 ** minorUnitDigits(order.currency))) : [];
|
|
77
|
-
|
|
78
|
-
const
|
|
104
|
+
// v2 tender-pane.tsx:942-954: a method that gives no change gets one chip setting the entry to the due figure; hidden in percent entry, as v2 does.
|
|
105
|
+
const balanceChip = method !== null && !givesChange && state.entryMode !== 'percent' ? dueMinor : null;
|
|
79
106
|
const [onlyLeg] = order.payments;
|
|
80
107
|
// startTender('external') records the card leg for the total: its reference is edited in place, as before.
|
|
81
108
|
const cardReference = order.payments.length === 1 && onlyLeg.method === 'external' && legStatus(onlyLeg) === 'captured' && balance === 0;
|
|
82
|
-
const hint =
|
|
109
|
+
const hint = partPick ? (pickRefused || entry === target ? t('pos_checkout.pick_amount_due', { amount: money(target) })
|
|
110
|
+
: givesChange && entry > target ? t('pos_checkout.change_due', { amount: money(entry - target) }) : '')
|
|
111
|
+
: pickRefused ? t('pos_checkout.pick_amount_due', { amount: money(figures.roundedDueMinor) })
|
|
112
|
+
: noChange ? t('pos_checkout.no_change_for_method', { amount: money(balance), method: method?.title })
|
|
83
113
|
: entryChange > 0 ? t('pos_checkout.change_due', { amount: money(entryChange) })
|
|
84
114
|
: figures.appliedMinor < balance && figures.entryMinor > 0 ? t('pos_checkout.part_payment_left', { left: money(left) }) : '';
|
|
85
|
-
|
|
86
|
-
const
|
|
115
|
+
// ADR-090 gate 36c: once the store's legs cover the total, finalize refuses every till leg; name them and offer their removal.
|
|
116
|
+
const refused = tillLegsTheStoreRefuses(order);
|
|
117
|
+
const refusedMinor = order.payments.filter((leg) => refused.includes(leg.id)).reduce((total, leg) => total + leg.amountMinor, 0);
|
|
118
|
+
const canComplete = balance === 0 && !order.payments.some(isInMotion) && refused.length === 0;
|
|
119
|
+
// ADR-090 gate 36 (desk Q4): changeDueMinor counts locked legs; what they hold beyond the total is the store's refund due, never till change.
|
|
120
|
+
const refundDue = Math.min(order.changeDueMinor, lockedRefundDueMinor(order));
|
|
121
|
+
const tillChange = order.changeDueMinor - refundDue + order.payments.reduce((sum, leg) => sum + (!leg.locked && countsTowardPaid(leg) ? leg.changeMinor ?? 0 : 0), 0);
|
|
122
|
+
const cannotTake = figures.appliedMinor <= 0 || noChange || pickRefused;
|
|
87
123
|
|
|
88
124
|
function take() {
|
|
89
|
-
if (!method) return;
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
125
|
+
if (!method || pickRefused) return;
|
|
126
|
+
const tender = tenderOf(method);
|
|
127
|
+
// No pick stands (a plan is set, or nothing is picked): the leg carries no units. Otherwise it carries the picks that stand (pickFigure), never the raw ones.
|
|
128
|
+
const units = pick === null ? {} : { units: pick.picks };
|
|
129
|
+
const id = tender.method === 'cash'
|
|
130
|
+
? sale.addTender({ ...tender, ...units, amountMinor: partPick ? target : figures.entryMinor, ...(partPick ? { tenderedMinor: entry } : {}) })
|
|
131
|
+
: sale.addTender({ ...tender, ...units, amountMinor: partPick ? target : figures.appliedMinor, ...(reference ? { reference } : {}) });
|
|
93
132
|
if (id === null) { setRefusal(true); return; }
|
|
94
133
|
setRefusal(false);
|
|
95
134
|
setReference('');
|
|
96
|
-
dispatch({ type: 'tender-started' });
|
|
135
|
+
dispatch({ type: 'tender-started', paymentId: id, units: pick === null ? {} : pick.picks });
|
|
97
136
|
}
|
|
98
137
|
|
|
99
138
|
return <View dataSet={{ print: 'hide' }} testID="tender-pane" className="gap-4 p-4">
|
|
100
|
-
<View testID="tender-headline" className="gap-1">
|
|
101
|
-
<
|
|
102
|
-
|
|
139
|
+
<View testID="tender-headline" className="items-center gap-1">
|
|
140
|
+
<View className="flex-row flex-wrap items-center justify-center gap-2">
|
|
141
|
+
<Text testID="tender-caption" className="text-xs uppercase tracking-wide text-muted-foreground">
|
|
142
|
+
{order.paidMinor > 0 ? t('pos_checkout.remaining') : t('pos_checkout.to_pay')}
|
|
143
|
+
{balanceInCaption ? <>{' '}<Text testID="tender-balance">{money(balance)}</Text></> : null}
|
|
144
|
+
</Text>
|
|
145
|
+
{balance > 0 ? <Pressable testID="tender-split-chip" accessibilityRole="button" aria-pressed={splitOn} className={cn(button, splitOn && 'border-primary bg-muted')}
|
|
146
|
+
onPress={() => {
|
|
147
|
+
if (splitOn) {
|
|
148
|
+
dispatch({ type: 'clear-plan', balanceMinor: balance });
|
|
149
|
+
for (const lineId of Object.keys(state.pickedUnits)) dispatch({ type: 'set-split-units', lineId, units: 0, unpaidUnits: 0 });
|
|
150
|
+
} else dispatch({ type: 'open-split' });
|
|
151
|
+
}}>
|
|
152
|
+
<Text className="font-semibold text-foreground">{t('pos_checkout.split')}</Text>
|
|
153
|
+
</Pressable> : null}
|
|
154
|
+
</View>
|
|
103
155
|
{order.paidMinor > 0 ? <Text testID="tender-paid" className="text-sm text-muted-foreground">{t('pos_checkout.paid_of_total', { paid: money(order.paidMinor), total: money(order.totalMinor) })}</Text> : null}
|
|
104
|
-
{
|
|
156
|
+
{tillChange > 0 ? <Text testID="tender-change" className="text-lg font-semibold text-success">{t('pos_checkout.change_due', { amount: money(tillChange) })}</Text> : null}
|
|
157
|
+
{refundDue > 0 ? <Text testID="tender-refund-due" className="text-lg font-semibold text-foreground">{t('pos_checkout.refund_due', { amount: money(refundDue) })}</Text> : null}
|
|
105
158
|
</View>
|
|
106
159
|
|
|
107
|
-
<View testID="tender-
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{descriptor && canVoidLeg(leg, descriptor) ? <Pressable testID={`tender-leg-${leg.id}-void`} accessibilityRole="button" accessibilityLabel={t('pos_checkout.cancel_payment')}
|
|
121
|
-
onPress={() => sale.voidTender(leg.id)} className="self-start min-h-11 justify-center px-2">
|
|
122
|
-
<Text className="text-destructive">{t('pos_checkout.cancel_payment')}</Text>
|
|
123
|
-
</Pressable> : null}
|
|
124
|
-
</View>;
|
|
125
|
-
})}
|
|
126
|
-
{balance === 0 && settled ? <Text className="text-sm text-success">{t('pos_checkout.paid_in_full')}</Text> : null}
|
|
127
|
-
</View>
|
|
160
|
+
{balance > 0 ? <View testID="tender-figure" className="items-center gap-1">
|
|
161
|
+
{changeLeads ? <>
|
|
162
|
+
<Text testID="tender-entry-hint" className="text-4xl font-bold text-success">{hint}</Text>
|
|
163
|
+
<Text testID="tender-tendered-line" className="min-h-6 text-sm text-muted-foreground">{t('pos_checkout.tendered')} <Text testID="tender-entry-amount" className="font-semibold text-foreground">{money(figures.entryMinor)}</Text>{order.totalMinor !== balance ? ` · ${t('common.total')} ${money(order.totalMinor)}` : ''}</Text>
|
|
164
|
+
{figures.roundingMinor !== 0 ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(balance) })}</Text> : null}
|
|
165
|
+
</> : <>
|
|
166
|
+
<Text testID="tender-entry-amount" className={cn('text-4xl font-bold text-foreground', !state.entryDirty && 'opacity-70')}>{money(figures.entryMinor)}</Text>
|
|
167
|
+
{figures.roundingMinor !== 0 ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(balance) })}</Text> : null}
|
|
168
|
+
<Text testID="tender-entry-hint" className={cn('min-h-6 text-center text-sm', noChange || pickRefused ? 'text-warning-text' : entryChange > 0 ? 'text-success' : 'text-muted-foreground')}>{hint}</Text>
|
|
169
|
+
</>}
|
|
170
|
+
</View> : null}
|
|
171
|
+
|
|
172
|
+
{ledger ? <TenderLedger sale={sale} methods={methods} confirmVoid={confirmVoid} /> : null}
|
|
128
173
|
|
|
174
|
+
{/* cardReference holds only for an external leg; the edit keeps that leg's method and its own methodId. */}
|
|
129
175
|
{cardReference ? <TextInput accessibilityLabel={t('tender.terminal_reference')} placeholder={t('tender.terminal_reference')} maxLength={REFERENCE_MAX}
|
|
130
|
-
value={onlyLeg.reference ?? ''} onChangeText={(text) => sale.setTender({ method: 'external', amountMinor: onlyLeg.amountMinor, reference: text })}
|
|
176
|
+
value={onlyLeg.reference ?? ''} onChangeText={(text) => sale.setTender({ method: 'external', ...(onlyLeg.methodId !== undefined ? { methodId: onlyLeg.methodId } : {}), amountMinor: onlyLeg.amountMinor, reference: text })}
|
|
131
177
|
className="rounded-md border border-border px-3 py-2 text-foreground" /> : null}
|
|
132
178
|
|
|
133
179
|
{balance > 0 ? <View testID="tender-entry" className="gap-3">
|
|
134
|
-
<View
|
|
135
|
-
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
180
|
+
<View testID="tender-methods" className="w-full gap-2">
|
|
181
|
+
{Array.from({ length: Math.ceil(offered.length / TILE_COLUMNS) }, (_, row) => (
|
|
182
|
+
<View key={row} className="flex-row gap-2">
|
|
183
|
+
{Array.from({ length: TILE_COLUMNS }, (_, column) => {
|
|
184
|
+
const tile = offered[row * TILE_COLUMNS + column];
|
|
185
|
+
if (!tile) return <View key={column} className="min-w-0 flex-1" />;
|
|
186
|
+
const selected = tile.id === state.methodId;
|
|
187
|
+
const Icon = tile.kind === 'cash' ? BanknoteIcon : CreditCardIcon;
|
|
188
|
+
return <View key={tile.id} className="min-w-0 flex-1">
|
|
189
|
+
<Pressable key={tile.id} testID={`tender-method-${tile.id}`} accessibilityRole="button" accessibilityState={{ selected: tile.id === state.methodId }}
|
|
190
|
+
// react-native-web does not render accessibilityState.selected.
|
|
191
|
+
aria-selected={tile.id === state.methodId}
|
|
192
|
+
onPress={() => dispatch({ type: 'pick-method', methodId: tile.id, prefillMinor: state.view === 'amount' ? state.entryMinor : thisPaymentMinor, readerId: null })}
|
|
193
|
+
className={cn('min-h-16 items-center justify-center gap-1 rounded-md border bg-card px-2 py-2', selected ? 'border-primary bg-muted' : 'border-border')}>
|
|
194
|
+
<Icon size={20} testID={`tender-method-${tile.id}-icon`} />
|
|
195
|
+
<Text numberOfLines={2} className="text-center font-semibold text-foreground">{tile.title}</Text>
|
|
196
|
+
</Pressable>
|
|
197
|
+
</View>;
|
|
198
|
+
})}
|
|
199
|
+
</View>
|
|
200
|
+
))}
|
|
140
201
|
</View>
|
|
141
202
|
{planned ? <Text testID="tender-plan" className="text-sm text-muted-foreground">{t('pos_checkout.n_of_ways', { n: planned.label.n, ways: planned.label.ways })}</Text> : null}
|
|
142
|
-
<Text testID="tender-entry-amount" className={cn('text-3xl font-bold text-foreground', !state.entryDirty && 'opacity-70')}>{money(figures.entryMinor)}</Text>
|
|
143
|
-
{figures.roundingMinor !== 0 ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(balance) })}</Text> : null}
|
|
144
|
-
<Text testID="tender-entry-hint" className={cn('min-h-6 text-sm', noChange ? 'text-warning' : entryChange > 0 ? 'text-success' : 'text-muted-foreground')}>{hint}</Text>
|
|
145
203
|
{method?.id === 'external' ? <TextInput accessibilityLabel={t('tender.terminal_reference')} placeholder={t('tender.terminal_reference')} maxLength={REFERENCE_MAX}
|
|
146
204
|
value={reference} onChangeText={setReference} className="rounded-md border border-border px-3 py-2 text-foreground" /> : null}
|
|
147
|
-
{
|
|
205
|
+
{state.splitView && !plan ? <>
|
|
206
|
+
<Text testID="tender-split-heading" className="text-center text-sm text-muted-foreground">
|
|
207
|
+
{typed ? t('pos_checkout.after_this_payment', { amount: money(restMinor) }) : t('pos_checkout.split_the_rest')}
|
|
208
|
+
</Text>
|
|
209
|
+
<ScrollView horizontal testID="tender-split-ways" showsHorizontalScrollIndicator={false} keyboardShouldPersistTaps="handled" contentContainerClassName="grow gap-2">
|
|
210
|
+
{SPLIT_WAYS.map((count) => <View key={count} className="min-w-28 flex-1">
|
|
211
|
+
<Pressable testID={`tender-split-even-${count}`} accessibilityRole="button"
|
|
212
|
+
onPress={() => dispatch({ type: 'set-plan', balanceMinor: balance, plan: typed
|
|
213
|
+
? { kind: 'fixed', firstMinor: figures.appliedMinor, title: null, thenWays: count, from: counted, before: order.payments.map((leg) => leg.id) }
|
|
214
|
+
: { kind: 'even', ways: count, from: counted, before: order.payments.map((leg) => leg.id) } })}
|
|
215
|
+
className="min-h-16 items-center justify-center gap-1 rounded-md border border-border bg-card px-2 py-2">
|
|
216
|
+
<Text className="font-semibold text-foreground">{t('pos_checkout.n_ways', { ways: count })}</Text>
|
|
217
|
+
<Text className="text-sm text-muted-foreground">{t('pos_checkout.amount_each', { amount: money(evenSplitShareMinor(restMinor, count)) })}</Text>
|
|
218
|
+
</Pressable>
|
|
219
|
+
</View>)}
|
|
220
|
+
</ScrollView>
|
|
221
|
+
</> : null}
|
|
222
|
+
{chips.length || balanceChip !== null ? <View testID="tender-quick" className="flex-row flex-wrap justify-center gap-2">
|
|
148
223
|
{chips.map((minor, index) => <Pressable key={minor} testID={index === 0 ? 'tender-quick-exact' : `tender-quick-${minor}`} accessibilityRole="button"
|
|
149
224
|
onPress={() => dispatch({ type: 'set-entry', minor })} className={cn(button, state.entryDirty && figures.entryMinor === minor && 'border-primary')}>
|
|
150
225
|
<Text className="font-semibold text-foreground">{index === 0 ? t('pos_checkout.exact_amount', { amount: money(minor) }) : money(minor)}</Text>
|
|
151
226
|
</Pressable>)}
|
|
227
|
+
{balanceChip !== null ? <Pressable testID="tender-quick-balance" accessibilityRole="button"
|
|
228
|
+
onPress={() => dispatch({ type: 'set-entry', minor: balanceChip })} className={cn(button, state.entryDirty && figures.entryMinor === balanceChip && 'border-primary')}>
|
|
229
|
+
<Text className="font-semibold text-foreground">{plan ? t('pos_checkout.exact_amount', { amount: money(balanceChip) })
|
|
230
|
+
: figures.entryMinor === balanceChip ? t('pos_checkout.full_balance_label') : t('pos_checkout.full_balance', { amount: money(balanceChip) })}</Text>
|
|
231
|
+
</Pressable> : null}
|
|
152
232
|
</View> : null}
|
|
153
233
|
<Keypad testID="tender-keypad" rows={keypadRows(t)} onPress={(name) => dispatch({ type: 'key', key: name as TenderKey })} />
|
|
154
234
|
{refusal ? <Text accessibilityRole="alert" className="text-destructive">{t('tender.not_taken')}</Text> : null}
|
|
@@ -158,6 +238,12 @@ export function TenderPane({ sale, state, dispatch, methods }: TenderPaneProps):
|
|
|
158
238
|
</Pressable> : null}
|
|
159
239
|
</View> : null}
|
|
160
240
|
|
|
241
|
+
{refused.length > 0 ? <>
|
|
242
|
+
<Text testID="tender-store-holds" className="text-foreground">{t('pos_checkout.store_holds_payment', { amount: money(refusedMinor) })}</Text>
|
|
243
|
+
{refused.map((id) => <Pressable key={id} testID={`tender-leg-${id}-remove`} accessibilityRole="button" onPress={() => sale.removeTender(id)} className={button}>
|
|
244
|
+
<Text className="text-center text-foreground">{t('pos_checkout.remove_payment')}</Text>
|
|
245
|
+
</Pressable>)}
|
|
246
|
+
</> : null}
|
|
161
247
|
<Pressable testID="tender-complete" accessibilityRole="button" disabled={!canComplete} onPress={sale.complete}
|
|
162
248
|
className={cn('rounded-md bg-primary px-4 py-3', !canComplete && 'opacity-50')}>
|
|
163
249
|
<Text className="text-center font-semibold text-primary-foreground">{t('tender.complete_sale')}</Text>
|
|
@@ -169,6 +255,6 @@ export function TenderPane({ sale, state, dispatch, methods }: TenderPaneProps):
|
|
|
169
255
|
<Text className="text-center font-semibold text-primary-foreground">{t('tender.continue')}</Text>
|
|
170
256
|
</Pressable>
|
|
171
257
|
</> : null}
|
|
172
|
-
<Pressable accessibilityRole="button" onPress={sale.cancelTender} className={button}><Text className="text-center text-foreground">{t('common.back')}</Text></Pressable>
|
|
258
|
+
{back ? <Pressable accessibilityRole="button" onPress={sale.cancelTender} className={button}><Text className="text-center text-foreground">{t('common.back')}</Text></Pressable> : null}
|
|
173
259
|
</View>;
|
|
174
260
|
}
|
package/src/sale/tender.tsx
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { useReducer, type JSX } from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type PaymentMethodDescriptor } from '@tallyui/core';
|
|
3
3
|
import { initTenderState, tenderReducer, type useSale } from '@tallyui/pos';
|
|
4
|
+
import { openingMethodId, type useTender } from './use-tender';
|
|
4
5
|
import { TenderPane } from './tender-pane';
|
|
5
6
|
|
|
6
7
|
type Sale = ReturnType<typeof useSale>;
|
|
7
8
|
|
|
8
|
-
function HostedPane({ sale, method, methods }:
|
|
9
|
-
const [state, dispatch] = useReducer(tenderReducer, { methodId: method, balanceMinor: sale.order.balanceDueMinor }, initTenderState);
|
|
10
|
-
return <TenderPane sale={sale} state={state} dispatch={dispatch} methods={methods} />;
|
|
9
|
+
function HostedPane({ sale, method, methods, ledger, back, confirmVoid, tender }: TenderProps & { method: string }) {
|
|
10
|
+
const [state, dispatch] = useReducer(tenderReducer, { methodId: openingMethodId(method, methods), balanceMinor: sale.order.balanceDueMinor, payments: sale.order.payments }, initTenderState);
|
|
11
|
+
return <TenderPane sale={sale} state={tender ? tender.state : state} dispatch={tender ? tender.dispatch : dispatch} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} />;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
type TenderProps = { sale: Sale; methods?: PaymentMethodDescriptor[]
|
|
14
|
+
type TenderProps = { sale: Sale; methods?: PaymentMethodDescriptor[]; /** Passed to TenderPane: `false` leaves the ledger to Cart's `tenderLedger`. Default `true`. */ ledger?: boolean; /** Passed to TenderPane: `false` hides Back (v2's phone checkout). Default `true`. */ back?: boolean;
|
|
15
|
+
/** Passed to TenderPane's ledger: v2's "Cancel this payment?" before a leg is voided. Default `false`. */ confirmVoid?: boolean;
|
|
16
|
+
/** One reducer shared with Cart's `picker` (useTender). Without it, Tender keeps its own reducer, as before. */ tender?: ReturnType<typeof useTender> };
|
|
14
17
|
|
|
15
18
|
/** The tender pane with its own reducer, opened on the method `startTender` chose. Renders nothing outside the tender stage. */
|
|
16
|
-
export function Tender({ sale, methods }: TenderProps): JSX.Element | null {
|
|
17
|
-
return sale.stage.kind === 'tender' ? <HostedPane sale={sale} method={sale.stage.method} methods={methods} /> : null;
|
|
19
|
+
export function Tender({ sale, methods, ledger, back, confirmVoid, tender }: TenderProps): JSX.Element | null {
|
|
20
|
+
return sale.stage.kind === 'tender' ? <HostedPane sale={sale} method={sale.stage.method} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} tender={tender} /> : null;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/** @deprecated Use Tender: the pane now handles split payments. */
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useEffect, useReducer, useRef } from 'react';
|
|
2
|
+
import { wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
|
|
3
|
+
import { heldUnitsByLine, initialTenderState, initTenderState, pickedUnitsMinor, splitUnitLines, tenderReducer, unpaidUnitsByLine, type TenderAction, type TenderState, type useSale } from '@tallyui/pos';
|
|
4
|
+
import { offeredMethods } from './offered-methods';
|
|
5
|
+
|
|
6
|
+
type Sale = ReturnType<typeof useSale>;
|
|
7
|
+
export type TenderPicker = { picked: Readonly<Record<string, number>>; paid: Readonly<Record<string, number>>;
|
|
8
|
+
unitMinor: (lineId: string, units: number) => number; onPick: (lineId: string, units: number) => void };
|
|
9
|
+
|
|
10
|
+
/** The offered method `startTender`'s wire method opens on: that id when offered, else the first offered method recording it, else the method itself. */
|
|
11
|
+
export function openingMethodId(method: string, methods?: PaymentMethodDescriptor[]): string {
|
|
12
|
+
const offered = offeredMethods(methods);
|
|
13
|
+
if (offered.some(({ id }) => id === method)) return method;
|
|
14
|
+
return offered.find((descriptor) => wireMethodOf(descriptor) === method)?.id ?? method;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The picks that still stand on the order (unknown lines dropped, each clamped to unpaid) and their money; `null` when none. Never throws. */
|
|
18
|
+
export function pickFigure(order: Sale['order'], picked: Readonly<Record<string, number>>): { picks: Record<string, number>; minor: number } | null {
|
|
19
|
+
const lines = splitUnitLines(order), paid = heldUnitsByLine(order.payments);
|
|
20
|
+
const unpaid = unpaidUnitsByLine(lines, paid);
|
|
21
|
+
const picks: Record<string, number> = {};
|
|
22
|
+
for (const [id, n] of Object.entries(picked)) {
|
|
23
|
+
if (!Object.hasOwn(unpaid, id)) continue;
|
|
24
|
+
const units = Math.min(Math.floor(n), unpaid[id]);
|
|
25
|
+
if (units >= 1) picks[id] = units;
|
|
26
|
+
}
|
|
27
|
+
return Object.keys(picks).length ? { picks, minor: pickedUnitsMinor(lines, picks, paid) } : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One tender reducer above both columns, so Cart's `picker` and Tender share this payment's picks. */
|
|
31
|
+
export function useTender(sale: Sale, methods?: PaymentMethodDescriptor[]): { state: TenderState; dispatch: (action: TenderAction) => void; picker: TenderPicker | undefined } {
|
|
32
|
+
const { order, stage } = sale;
|
|
33
|
+
const [state, dispatch] = useReducer((state: TenderState, action: TenderAction | { type: 'init'; state: TenderState }) =>
|
|
34
|
+
action.type === 'init' ? action.state : tenderReducer(state, action), undefined, () => stage.kind === 'tender'
|
|
35
|
+
? initTenderState({ methodId: openingMethodId(stage.method, methods), balanceMinor: order.balanceDueMinor, payments: order.payments }) : initialTenderState);
|
|
36
|
+
const previousStage = useRef(stage.kind);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (previousStage.current === stage.kind) return;
|
|
39
|
+
previousStage.current = stage.kind;
|
|
40
|
+
dispatch({ type: 'init', state: stage.kind === 'tender'
|
|
41
|
+
? initTenderState({ methodId: openingMethodId(stage.method, methods), balanceMinor: order.balanceDueMinor, payments: order.payments }) : initialTenderState });
|
|
42
|
+
}, [stage, methods, order.balanceDueMinor, order.payments]);
|
|
43
|
+
const lines = splitUnitLines(order), paid = heldUnitsByLine(order.payments);
|
|
44
|
+
const unpaid = unpaidUnitsByLine(lines, paid);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (Object.keys(state.pickedUnits).length === 0) return;
|
|
47
|
+
const picks = state.plan ? undefined : pickFigure(order, state.pickedUnits)?.picks;
|
|
48
|
+
for (const [lineId, n] of Object.entries(state.pickedUnits)) {
|
|
49
|
+
const units = picks?.[lineId] ?? 0;
|
|
50
|
+
if (n !== units) dispatch({ type: 'set-split-units', lineId, units, unpaidUnits: unpaid[lineId] ?? 0 });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const picker: TenderPicker | undefined = stage.kind === 'tender' && state.plan === null && (state.splitView || Object.keys(state.pickedUnits).length > 0) ? {
|
|
54
|
+
picked: state.pickedUnits, paid,
|
|
55
|
+
unitMinor: (id, n) => {
|
|
56
|
+
if (!Object.hasOwn(unpaid, id)) return 0;
|
|
57
|
+
const units = Math.min(Math.floor(n), unpaid[id]);
|
|
58
|
+
return units >= 1 ? pickedUnitsMinor(lines, { [id]: units }, paid) : 0;
|
|
59
|
+
},
|
|
60
|
+
onPick: (lineId, units) => dispatch({ type: 'set-split-units', lineId, units, unpaidUnits: unpaid[lineId] ?? 0 }),
|
|
61
|
+
} : undefined;
|
|
62
|
+
return { state, dispatch, picker };
|
|
63
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of WCPOS v2 `packages/components/src/lib/min-target.tsx`: a transparent band the control token tall,
|
|
3
|
+
* centred over a control drawn under it and overflowing it, out of layout, so the finger still gets the full
|
|
4
|
+
* target while the control keeps its drawn size. Render it as the LAST child of the press target, so a touch on
|
|
5
|
+
* it is the control's own.
|
|
6
|
+
*
|
|
7
|
+
* From v2: not `hitSlop`, because iOS (Fabric) hit-tests nothing outside a parent that no child overflows, and
|
|
8
|
+
* React Native Web ignores `hitSlop` altogether; a real overflowing child is hit-tested on iOS and Android and is
|
|
9
|
+
* part of the control's DOM on the web.
|
|
10
|
+
* Also from v2: tall only by default, because sideways growth would take a neighbour's touches in a dense
|
|
11
|
+
* strip; `square` grows it to the full target both ways, for a lone icon control with no neighbour within reach.
|
|
12
|
+
*
|
|
13
|
+
* TallyUI differences: it renders nothing unless the pointer is coarse, and its size is a style number (the
|
|
14
|
+
* `--spacing-ctl` token, floored at the coarse pointer floor) rather than the `min-h-ctl` class, because
|
|
15
|
+
* `scale.css` is opt-in.
|
|
16
|
+
*/
|
|
17
|
+
import { View } from 'react-native';
|
|
18
|
+
import { POINTER_FLOORS } from '@tallyui/theme';
|
|
19
|
+
import { usePointer } from './use-pointer';
|
|
20
|
+
import { useScale } from './scale-provider';
|
|
21
|
+
|
|
22
|
+
/** The band's size under a coarse pointer: 44 at Compact and Regular, 52 at Spacious. */
|
|
23
|
+
export function useMinTarget(): number {
|
|
24
|
+
return Math.max(useScale().variables['--spacing-ctl'], POINTER_FLOORS.coarse);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function MinTargetBand({ square = false }: { square?: boolean }) {
|
|
28
|
+
const pointer = usePointer();
|
|
29
|
+
const size = useMinTarget();
|
|
30
|
+
if (pointer !== 'coarse') return null;
|
|
31
|
+
return (
|
|
32
|
+
<View testID="min-target-band" style={{ pointerEvents: 'box-none' }} className="absolute inset-0 items-center justify-center">
|
|
33
|
+
<View className={square ? undefined : 'w-full'} style={square ? { minHeight: size, minWidth: size } : { minHeight: size }} />
|
|
34
|
+
</View>
|
|
35
|
+
);
|
|
36
|
+
}
|