@tallyui/components 3.13.0 → 3.15.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 +357 -27
- package/dist/index.js +2386 -1370
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +57 -0
- package/src/cart/cart-foot.tsx +82 -0
- package/src/cart/cart-line.tsx +37 -17
- package/src/cart/index.ts +2 -0
- package/src/checkout/cash-tendered.tsx +5 -7
- package/src/index.ts +26 -3
- package/src/input/index.ts +1 -0
- package/src/input/keypad.tsx +38 -0
- package/src/lib/error-text.ts +5 -0
- package/src/order/refund-form.tsx +2 -1
- package/src/product/category-tile.tsx +43 -0
- package/src/product/in-cart-badge.tsx +26 -0
- package/src/product/index.ts +2 -0
- package/src/register/closure-sheet.tsx +2 -1
- package/src/register/handover-slip.tsx +46 -0
- package/src/register/index.ts +2 -0
- package/src/register/movement-sheet.tsx +2 -1
- package/src/register/open-register-card.tsx +2 -1
- package/src/register/register-bar.tsx +57 -11
- package/src/register/register-column.tsx +2 -1
- package/src/register/register-count.tsx +30 -11
- package/src/register/register-panel.tsx +45 -4
- package/src/register/switch-confirm.tsx +102 -0
- package/src/sale/cart.tsx +63 -31
- package/src/sale/catalogue.tsx +34 -5
- package/src/sale/customer-display-screen.tsx +92 -0
- package/src/sale/index.ts +5 -2
- package/src/sale/line-popover.tsx +145 -0
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +37 -4
- package/src/sale/product-filter-bar.tsx +58 -0
- package/src/sale/tender-pane.tsx +171 -0
- package/src/sale/tender.tsx +20 -35
- package/src/shell/app-shell.tsx +71 -0
- package/src/shell/index.ts +4 -0
- package/src/shell/nav-drawer.tsx +130 -0
- package/src/shell/nav-item.tsx +70 -0
- package/src/shell/nav-rail.tsx +58 -0
- package/src/shell/shell-context.ts +18 -0
- package/src/ui/icon/menu-icon.tsx +10 -0
- package/src/sale/split-tender.tsx +0 -81
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal POS UI components for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"directory": "packages/components"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tallyui/core": "^3.
|
|
32
|
-
"@tallyui/primitives": "^3.
|
|
33
|
-
"@tallyui/theme": "^3.
|
|
31
|
+
"@tallyui/core": "^3.15.0",
|
|
32
|
+
"@tallyui/primitives": "^3.15.0",
|
|
33
|
+
"@tallyui/theme": "^3.15.0",
|
|
34
34
|
"react": ">=18",
|
|
35
35
|
"react-native": ">=0.74",
|
|
36
36
|
"react-native-svg": ">=15"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"class-variance-authority": "^0.7.1",
|
|
40
|
-
"@tallyui/pos": "3.
|
|
40
|
+
"@tallyui/pos": "3.15.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tallyui/connector-medusa": "3.
|
|
44
|
-
"@tallyui/connector-vendure": "3.
|
|
45
|
-
"@tallyui/connector-woocommerce": "3.
|
|
46
|
-
"@tallyui/mock-api": "3.
|
|
43
|
+
"@tallyui/connector-medusa": "3.15.0",
|
|
44
|
+
"@tallyui/connector-vendure": "3.15.0",
|
|
45
|
+
"@tallyui/connector-woocommerce": "3.15.0",
|
|
46
|
+
"@tallyui/mock-api": "3.15.0",
|
|
47
47
|
"@types/react": ">=18",
|
|
48
48
|
"react": "^19.2.4",
|
|
49
49
|
"react-native-svg": "15.12.1",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/table.tsx (AMOUNT_COLUMNS,
|
|
2
|
+
// PRICE_COLUMN_MIN_WIDTH, the header labels) and packages/components/src/lib/device.ts (the phone
|
|
3
|
+
// boundary), MIT, WCPOS.
|
|
4
|
+
import type { JSX } from 'react';
|
|
5
|
+
import { View, type ViewProps } from 'react-native';
|
|
6
|
+
import { cn } from '@tallyui/theme';
|
|
7
|
+
import { Text } from '../ui';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The cart's columns, head and cell. Item gives way: the amount columns hold a width and the name takes what is
|
|
11
|
+
* left, so a total never wraps. The total cell has a floor, so a long total widens its own cell rather than wrapping.
|
|
12
|
+
*/
|
|
13
|
+
export const CART_COLUMNS = {
|
|
14
|
+
quantity: { head: 'w-12 flex-none items-center pr-2 pl-3', cell: 'w-12 flex-none items-center pr-2 pl-3' },
|
|
15
|
+
name: { head: 'min-w-0 flex-1 px-3', cell: 'min-w-0 flex-1 px-3' },
|
|
16
|
+
price: { head: 'w-18 flex-none items-end px-2', cell: 'w-18 flex-none items-end px-2' },
|
|
17
|
+
total: { head: 'w-20 flex-none items-end pr-3 pl-2', cell: 'min-w-20 flex-none items-end pr-3 pl-2' },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Under this cart width the Price column folds away, so the item name keeps room to read. */
|
|
21
|
+
const PRICE_COLUMN_MIN_WIDTH = 300;
|
|
22
|
+
/** A window narrower or shorter than this is a phone, which has no Price column either. */
|
|
23
|
+
const WIDE_MIN_WIDTH = 768;
|
|
24
|
+
const WIDE_MIN_HEIGHT = 480;
|
|
25
|
+
|
|
26
|
+
/** Whether the Price column shows. An unmeasured cart (`cartWidth` undefined) counts as wide. */
|
|
27
|
+
export function cartShowsPrice({ cartWidth, windowWidth, windowHeight }:
|
|
28
|
+
{ cartWidth?: number; windowWidth: number; windowHeight: number }): boolean {
|
|
29
|
+
return (cartWidth ?? Infinity) >= PRICE_COLUMN_MIN_WIDTH && windowWidth >= WIDE_MIN_WIDTH && windowHeight >= WIDE_MIN_HEIGHT;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const HEADS = [['quantity', 'Qty'], ['name', 'Item'], ['price', 'Price'], ['total', 'Total']] as const;
|
|
33
|
+
|
|
34
|
+
export interface CartColumnHeadsProps extends Omit<ViewProps, 'children'> {
|
|
35
|
+
/** Show the Price head (default true); pass the same value as each CartLine's `showPrice`. */
|
|
36
|
+
showPrice?: boolean;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The cart's header row, Qty, Item, Price and Total, over lines laid out by CartLine in the same columns.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <CartColumnHeads showPrice={showPrice} />
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function CartColumnHeads({ showPrice = true, className, ...props }: CartColumnHeadsProps): JSX.Element {
|
|
48
|
+
return (
|
|
49
|
+
<View role="row" className={cn('flex-row border-b border-border', className)} {...props}>
|
|
50
|
+
{HEADS.filter(([id]) => showPrice || id !== 'price').map(([id, label]) => (
|
|
51
|
+
<View key={id} role="columnheader" className={cn('h-9 justify-center', CART_COLUMNS[id].head)}>
|
|
52
|
+
<Text className="text-xs font-medium uppercase tracking-wide text-muted-foreground" numberOfLines={1}>{label}</Text>
|
|
53
|
+
</View>
|
|
54
|
+
))}
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Port of WCPOS v2 `packages/core/src/screens/main/pos/cart/foot.tsx` and `cart/buttons/pay.tsx`
|
|
2
|
+
// (the ⋮ beside a full-width "Checkout {order_total}"), MIT, WCPOS.
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Platform, Pressable, Text, View } from 'react-native';
|
|
5
|
+
import { formatMoney, type Money } from '@tallyui/core';
|
|
6
|
+
import { cn } from '@tallyui/theme';
|
|
7
|
+
|
|
8
|
+
export interface CartFootAction {
|
|
9
|
+
label: string;
|
|
10
|
+
onPress: () => void;
|
|
11
|
+
/** Shown in the destructive colour, e.g. a Void. */
|
|
12
|
+
destructive?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CartFootProps {
|
|
16
|
+
total: Money;
|
|
17
|
+
onCheckout: () => void;
|
|
18
|
+
/** The ⋮ menu's items; the ⋮ is left out when there are none. */
|
|
19
|
+
actions?: readonly CartFootAction[];
|
|
20
|
+
/** Disables Checkout only; the menu stays usable. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
locale?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const MENU_LABEL = 'More actions';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The cart's foot: a ⋮ menu of the host's actions beside one "Checkout {total}" button, as in WCPOS v2.
|
|
30
|
+
* v2's ⋮ opens its Order details sheet; here the host passes the items, so it can pass one that opens its own sheet.
|
|
31
|
+
*
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <CartFoot total={total} onCheckout={startCheckout} actions={[{ label: 'Void', onPress: voidSale, destructive: true }]} />
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function CartFoot({ total, onCheckout, actions = [], disabled = false, locale, className }: CartFootProps) {
|
|
37
|
+
const [open, setOpen] = React.useState(false);
|
|
38
|
+
const trigger = React.useRef<View>(null);
|
|
39
|
+
const menu = React.useRef<View>(null);
|
|
40
|
+
|
|
41
|
+
// Web keyboard: focus moves to the first item on open; Escape closes and hands focus back to the ⋮.
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!open || Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
44
|
+
(menu.current as unknown as HTMLElement | null)?.querySelector<HTMLElement>('[role="menuitem"]')?.focus();
|
|
45
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
46
|
+
if (event.key !== 'Escape') return;
|
|
47
|
+
setOpen(false);
|
|
48
|
+
(trigger.current as unknown as HTMLElement | null)?.focus?.();
|
|
49
|
+
};
|
|
50
|
+
document.addEventListener('keydown', onKeyDown);
|
|
51
|
+
return () => document.removeEventListener('keydown', onKeyDown);
|
|
52
|
+
}, [open]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View className={cn('gap-2', className)}>
|
|
56
|
+
{open && actions.length > 0 ? (
|
|
57
|
+
<View ref={menu} role="menu" aria-label={MENU_LABEL} testID="cart-foot-menu"
|
|
58
|
+
className="rounded-md border border-border bg-card p-1">
|
|
59
|
+
{actions.map((action, index) => (
|
|
60
|
+
<Pressable key={index} role="menuitem" className="min-h-11 justify-center rounded-sm px-3 py-2"
|
|
61
|
+
onPress={() => { setOpen(false); action.onPress(); }}>
|
|
62
|
+
<Text className={action.destructive ? 'text-destructive' : 'text-foreground'}>{action.label}</Text>
|
|
63
|
+
</Pressable>
|
|
64
|
+
))}
|
|
65
|
+
</View>
|
|
66
|
+
) : null}
|
|
67
|
+
<View className="flex-row gap-3">
|
|
68
|
+
{actions.length > 0 ? (
|
|
69
|
+
<Pressable ref={trigger} accessibilityRole="button" accessibilityLabel={MENU_LABEL} aria-haspopup="menu"
|
|
70
|
+
aria-expanded={open} testID="cart-foot-more" onPress={() => setOpen((value) => !value)}
|
|
71
|
+
className="min-h-12 min-w-12 items-center justify-center rounded-md border border-border bg-card">
|
|
72
|
+
<Text className="text-lg text-foreground">⋮</Text>
|
|
73
|
+
</Pressable>
|
|
74
|
+
) : null}
|
|
75
|
+
<Pressable accessibilityRole="button" testID="cart-checkout" disabled={disabled} onPress={onCheckout}
|
|
76
|
+
className={cn('min-h-12 flex-1 justify-center rounded-md bg-primary px-4 py-3', disabled && 'opacity-50')}>
|
|
77
|
+
<Text className="text-center font-semibold text-primary-foreground">{`Checkout ${formatMoney(total, locale) ?? '—'}`}</Text>
|
|
78
|
+
</Pressable>
|
|
79
|
+
</View>
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
}
|
package/src/cart/cart-line.tsx
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
1
3
|
import { formatMoney, type Money } from '@tallyui/core';
|
|
2
4
|
import { cn } from '@tallyui/theme';
|
|
3
|
-
import { Text, HStack,
|
|
5
|
+
import { Text, HStack, type HStackProps } from '../ui';
|
|
6
|
+
import { CART_COLUMNS } from './cart-columns';
|
|
4
7
|
|
|
5
8
|
export interface CartLineProps extends Omit<HStackProps, 'children'> {
|
|
6
9
|
name: string;
|
|
7
|
-
/** The variant's chosen options, one "Name: Value"
|
|
10
|
+
/** The variant's chosen options, shown as one "Name: Value · Name: Value" line under the name. */
|
|
8
11
|
attributes?: Record<string, string>;
|
|
9
12
|
quantity: number;
|
|
10
13
|
unitPrice: Money;
|
|
14
|
+
/** The regular unit price; shown struck through above unitPrice only when it is above unitPrice. */
|
|
15
|
+
regularUnitPrice?: Money;
|
|
11
16
|
lineTotal: Money;
|
|
17
|
+
/** Show the Price column (default true); the Cart passes false on a narrow cart or a phone, as CartColumnHeads does. */
|
|
18
|
+
showPrice?: boolean;
|
|
19
|
+
/** Replaces the quantity's text, e.g. a LinePopover that edits it (Cart's `lineEditor="popover"`). */
|
|
20
|
+
quantitySlot?: ReactNode;
|
|
21
|
+
/** Replaces the unit price's text (the struck regular price stays above it). */
|
|
22
|
+
priceSlot?: ReactNode;
|
|
12
23
|
locale?: string;
|
|
13
24
|
className?: string;
|
|
14
25
|
}
|
|
15
26
|
|
|
27
|
+
// Name and attributes: WCPOS v2 packages/core/src/screens/main/pos/cart/cells/product-name.tsx; price:
|
|
28
|
+
// cells/price.tsx; total: cells/product-total.tsx; MIT, WCPOS.
|
|
16
29
|
/**
|
|
17
|
-
*
|
|
30
|
+
* A single cart line in the columns of CartColumnHeads: quantity, the name with its attributes, the unit price
|
|
31
|
+
* (with the regular price struck through when it is higher) and the line total.
|
|
18
32
|
*
|
|
19
33
|
* ```tsx
|
|
20
34
|
* <CartLine name="Coffee" quantity={2} unitPrice={unitPrice} lineTotal={lineTotal} />
|
|
21
35
|
* ```
|
|
22
36
|
*/
|
|
23
|
-
export function CartLine({ name, attributes, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps) {
|
|
37
|
+
export function CartLine({ name, attributes, quantity, unitPrice, regularUnitPrice, lineTotal, showPrice = true, quantitySlot, priceSlot, locale, className, ...props }: CartLineProps) {
|
|
38
|
+
const options = Object.entries(attributes ?? {}).map(([key, value]) => `${key}: ${value}`).join(' · ');
|
|
39
|
+
const regular = regularUnitPrice && regularUnitPrice.currency === unitPrice.currency && regularUnitPrice.amount > unitPrice.amount
|
|
40
|
+
? formatMoney(regularUnitPrice, locale) ?? '—' : null;
|
|
24
41
|
return (
|
|
25
|
-
<HStack className={cn('
|
|
26
|
-
<
|
|
27
|
-
<Text className="text-sm
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<Text className="text-xs text-muted-foreground">
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{formatMoney(
|
|
37
|
-
</
|
|
42
|
+
<HStack space="none" className={cn('py-2.5', className)} {...props}>
|
|
43
|
+
<View className={CART_COLUMNS.quantity.cell}>
|
|
44
|
+
{quantitySlot ?? <Text className="text-sm tabular-nums">{quantity}</Text>}
|
|
45
|
+
</View>
|
|
46
|
+
<View className={CART_COLUMNS.name.cell}>
|
|
47
|
+
<Text className="text-sm font-medium" numberOfLines={2}>{name}</Text>
|
|
48
|
+
{options ? <Text className="text-xs text-muted-foreground" numberOfLines={2}>{options}</Text> : null}
|
|
49
|
+
</View>
|
|
50
|
+
{showPrice ? <View className={CART_COLUMNS.price.cell}>
|
|
51
|
+
{regular ? <Text accessibilityLabel={`Regular price ${regular}`} style={{ textDecorationLine: 'line-through' }}
|
|
52
|
+
className="text-right text-sm tabular-nums text-muted-foreground line-through">{regular}</Text> : null}
|
|
53
|
+
{priceSlot ?? <Text className="text-right text-sm tabular-nums text-muted-foreground">{formatMoney(unitPrice, locale) ?? '—'}</Text>}
|
|
54
|
+
</View> : null}
|
|
55
|
+
<View className={CART_COLUMNS.total.cell}>
|
|
56
|
+
<Text className="text-right text-sm font-semibold tabular-nums">{formatMoney(lineTotal, locale) ?? '—'}</Text>
|
|
57
|
+
</View>
|
|
38
58
|
</HStack>
|
|
39
59
|
);
|
|
40
60
|
}
|
package/src/cart/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { CartLine, type CartLineProps } from './cart-line';
|
|
2
|
+
export { CartColumnHeads, type CartColumnHeadsProps } from './cart-columns';
|
|
2
3
|
export { CartTotal, type CartTotalProps } from './cart-total';
|
|
3
4
|
export { CartPanel, type CartPanelProps } from './cart-panel';
|
|
4
5
|
export { DiscountBadge, type DiscountBadgeProps } from './discount-badge';
|
|
5
6
|
export { CartNoteInput, type CartNoteInputProps } from './cart-note-input';
|
|
6
7
|
export { CartLineActions, type CartLineActionsProps, type CartAction } from './cart-line-actions';
|
|
8
|
+
export { CartFoot, type CartFootProps, type CartFootAction } from './cart-foot';
|
|
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { Pressable, Text, TextInput, View, type ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { formatMoney, minorUnitDigits, moneyFromDecimalString, type Money } from '@tallyui/core';
|
|
5
|
+
import { quickTenderedAmounts } from '@tallyui/pos';
|
|
5
6
|
import { cn } from '@tallyui/theme';
|
|
6
7
|
|
|
7
8
|
export interface CashTenderedProps extends Omit<ViewProps, 'children'> {
|
|
@@ -14,15 +15,12 @@ export interface CashTenderedProps extends Omit<ViewProps, 'children'> {
|
|
|
14
15
|
className?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/** Quick-cash round-ups in major units: WCPOS v2 tender-figures.ts:25 QUICK_TENDER_STEPS. */
|
|
19
|
+
export const QUICK_CASH_STEPS = [5, 10, 50] as const;
|
|
20
|
+
|
|
17
21
|
function defaultQuickAmounts(total: Money): Money[] {
|
|
18
22
|
const unit = 10 ** minorUnitDigits(total.currency);
|
|
19
|
-
|
|
20
|
-
total.amount,
|
|
21
|
-
Math.ceil(total.amount / (5 * unit)) * 5 * unit,
|
|
22
|
-
Math.ceil(total.amount / (10 * unit)) * 10 * unit,
|
|
23
|
-
Math.ceil(total.amount / (20 * unit)) * 20 * unit,
|
|
24
|
-
];
|
|
25
|
-
return [...new Set(amounts)].sort((a, b) => a - b).map((amount) => ({ amount, currency: total.currency }));
|
|
23
|
+
return quickTenderedAmounts(total.amount, QUICK_CASH_STEPS.map((step) => step * unit)).map((amount) => ({ amount, currency: total.currency }));
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
export function CashTendered({
|
package/src/index.ts
CHANGED
|
@@ -40,6 +40,10 @@ export {
|
|
|
40
40
|
ProductVariantPicker,
|
|
41
41
|
type ProductVariantPickerProps,
|
|
42
42
|
type VariantOption,
|
|
43
|
+
InCartBadge,
|
|
44
|
+
type InCartBadgeProps,
|
|
45
|
+
CategoryTile,
|
|
46
|
+
type CategoryTileProps,
|
|
43
47
|
} from './product';
|
|
44
48
|
|
|
45
49
|
// Cart components
|
|
@@ -57,6 +61,11 @@ export {
|
|
|
57
61
|
CartLineActions,
|
|
58
62
|
type CartLineActionsProps,
|
|
59
63
|
type CartAction,
|
|
64
|
+
CartColumnHeads,
|
|
65
|
+
type CartColumnHeadsProps,
|
|
66
|
+
CartFoot,
|
|
67
|
+
type CartFootProps,
|
|
68
|
+
type CartFootAction,
|
|
60
69
|
} from './cart';
|
|
61
70
|
|
|
62
71
|
// Input components
|
|
@@ -70,6 +79,10 @@ export {
|
|
|
70
79
|
type ChipItem,
|
|
71
80
|
QuantityStepper,
|
|
72
81
|
type QuantityStepperProps,
|
|
82
|
+
Keypad,
|
|
83
|
+
DIGIT_ROWS,
|
|
84
|
+
type KeypadKey,
|
|
85
|
+
type KeypadProps,
|
|
73
86
|
} from './input';
|
|
74
87
|
|
|
75
88
|
// Customer components
|
|
@@ -157,6 +170,10 @@ export {
|
|
|
157
170
|
type RegisterCountProps,
|
|
158
171
|
ClosureSheet,
|
|
159
172
|
type ClosureSheetProps,
|
|
173
|
+
SwitchConfirm,
|
|
174
|
+
type SwitchConfirmProps,
|
|
175
|
+
HandoverSlip,
|
|
176
|
+
type HandoverSlipProps,
|
|
160
177
|
} from './register';
|
|
161
178
|
|
|
162
179
|
// Settings components
|
|
@@ -174,11 +191,12 @@ export {
|
|
|
174
191
|
|
|
175
192
|
// Sale components
|
|
176
193
|
export {
|
|
177
|
-
Cart, CartBar, Tender, SplitTender, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
178
|
-
PriceForm, parsePrice,
|
|
194
|
+
Cart, CartBar, Tender, SplitTender, TenderPane, type TenderPaneProps, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
195
|
+
PriceForm, parsePrice, LinePopover, type LinePopoverProps,
|
|
179
196
|
ChargeForm, type ChargeFormProps,
|
|
180
197
|
Catalogue, formatStockSyncTime, Receipt, injectPrintStyle, SyncStatus, OrdersList, type OrderHistoryRow, orderReference,
|
|
181
|
-
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps,
|
|
198
|
+
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps, CustomerDisplayScreen,
|
|
199
|
+
ProductFilterBar, DEFAULT_PRODUCT_FILTERS, PRODUCT_FILTER_CHIPS, type ProductFilterBarProps, type ProductFilterChip, type ProductFilters,
|
|
182
200
|
} from './sale';
|
|
183
201
|
|
|
184
202
|
// Layout components
|
|
@@ -196,6 +214,11 @@ export {
|
|
|
196
214
|
type StoreSettingsChoiceScreenProps,
|
|
197
215
|
} from './layout';
|
|
198
216
|
|
|
217
|
+
// App shell
|
|
218
|
+
export {
|
|
219
|
+
AppShell, type AppShellProps, NavRail, type NavRailProps, NavDrawer, type NavDrawerProps, type ShellNavItem,
|
|
220
|
+
} from './shell';
|
|
221
|
+
|
|
199
222
|
// Reports components
|
|
200
223
|
export {
|
|
201
224
|
SalesRoom, type SalesRoomProps, SalesHero, type SalesHeroProps, SalesCards, type SalesCardsProps, type SalesCardId,
|
package/src/input/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { SearchInput, type SearchInputProps } from './search-input';
|
|
2
2
|
export { FilterChip, FilterChipGroup, type FilterChipProps, type FilterChipGroupProps, type ChipItem } from './filter-chip';
|
|
3
3
|
export { QuantityStepper, type QuantityStepperProps } from './quantity-stepper';
|
|
4
|
+
export { Keypad, DIGIT_ROWS, type KeypadKey, type KeypadProps } from './keypad';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Port of WCPOS v2 `packages/components/src/keypad/index.tsx` (monorepo main), MIT, WCPOS.
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import { cn } from '@tallyui/theme';
|
|
4
|
+
|
|
5
|
+
export interface KeypadKey {
|
|
6
|
+
/** What a press reports: a digit, `decimal`, `backspace`, or the caller's own key. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The accessible name: the digit, or the caller's own ("Delete last digit"). */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The key's text when it is not its label (`⌫`, named "Delete last digit"). */
|
|
11
|
+
text?: string;
|
|
12
|
+
/** The cells the key takes in its row (default 1). */
|
|
13
|
+
span?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface KeypadProps {
|
|
17
|
+
rows: readonly (readonly KeypadKey[])[];
|
|
18
|
+
onPress: (name: string) => void;
|
|
19
|
+
/** A key is `<testID>-key-<name>`. */
|
|
20
|
+
testID?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** v2's DIGIT_ROWS: 123 / 456 / 789; the caller adds its own last row. */
|
|
25
|
+
export const DIGIT_ROWS: KeypadKey[][] = ['123', '456', '789'].map((row) => [...row].map((digit) => ({ name: digit, label: digit })));
|
|
26
|
+
|
|
27
|
+
/** Rows of keys with no display or value, as v2's Keypad: the caller owns the entry. */
|
|
28
|
+
export function Keypad({ rows, onPress, testID, className }: KeypadProps) {
|
|
29
|
+
return <View testID={testID} className={cn('gap-2', className)}>
|
|
30
|
+
{rows.map((row, index) => <View key={index} className="flex-row gap-2">
|
|
31
|
+
{row.map(({ name, label, text, span }) => <Pressable key={name} testID={testID && `${testID}-key-${name}`} accessibilityRole="button"
|
|
32
|
+
accessibilityLabel={label} onPress={() => onPress(name)} style={{ flex: span ?? 1 }}
|
|
33
|
+
className="min-h-11 items-center justify-center rounded-md border border-border bg-card px-4 py-2">
|
|
34
|
+
<Text className="text-xl font-semibold text-foreground">{text ?? label}</Text>
|
|
35
|
+
</Pressable>)}
|
|
36
|
+
</View>)}
|
|
37
|
+
</View>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** What a cashier sees for a thrown value: an `Error`'s message alone (never its class name, which `String(e)` prefixes), "Something went wrong" when that is empty. A non-`Error` is shown as `String(value)`. */
|
|
2
|
+
export function errorText(error: unknown): string {
|
|
3
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
4
|
+
return text || 'Something went wrong';
|
|
5
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Pressable, ScrollView, View } from 'react-native';
|
|
|
3
3
|
import { formatMoney, 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
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { parsePrice } from '../sale/price-form';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { Checkbox } from '../ui/checkbox';
|
|
@@ -103,7 +104,7 @@ export function RefundForm({
|
|
|
103
104
|
try {
|
|
104
105
|
await onConfirm(value);
|
|
105
106
|
} catch (e) {
|
|
106
|
-
setThrown(
|
|
107
|
+
setThrown(errorText(e));
|
|
107
108
|
} finally {
|
|
108
109
|
busyRef.current = false;
|
|
109
110
|
setBusy(false);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Pressable, Text, View } from 'react-native';
|
|
2
|
+
import { Image } from '@tallyui/primitives';
|
|
3
|
+
import { cn } from '@tallyui/theme';
|
|
4
|
+
|
|
5
|
+
export interface CategoryTileProps {
|
|
6
|
+
name: string;
|
|
7
|
+
/** The category's photo; without one the tile shows the name's initial on a tint. */
|
|
8
|
+
imageUrl?: string;
|
|
9
|
+
/** Products in the category, shown under the name when above 0. */
|
|
10
|
+
count?: number;
|
|
11
|
+
onPress?: () => void;
|
|
12
|
+
testID?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A category as a square tile: its photo full-bleed with the name over the foot, or the name's initial on a
|
|
18
|
+
* tint when there is no photo.
|
|
19
|
+
*
|
|
20
|
+
* Ported from WCPOS v2 `TermTile`, packages/core/src/screens/main/pos/products/browse/term-tile.tsx
|
|
21
|
+
* (MIT, WCPOS): the picture fills the square (`contentFit="cover"`), else a tint; the name bold over two
|
|
22
|
+
* lines with the count under it.
|
|
23
|
+
*/
|
|
24
|
+
export function CategoryTile({ name, imageUrl, count, onPress, testID, className }: CategoryTileProps) {
|
|
25
|
+
const id = testID ?? 'category-tile';
|
|
26
|
+
return (
|
|
27
|
+
<Pressable testID={testID} role="button" accessibilityLabel={name} onPress={onPress}
|
|
28
|
+
className={cn('aspect-square overflow-hidden rounded-lg border border-border', imageUrl ? 'bg-card' : 'bg-primary/10', className)}>
|
|
29
|
+
{imageUrl ? (
|
|
30
|
+
<Image.Root testID={`${id}-image`} source={{ uri: imageUrl }} alt="" contentFit="cover"
|
|
31
|
+
className="absolute inset-0" style={{ width: '100%', height: '100%' }} />
|
|
32
|
+
) : (
|
|
33
|
+
<View testID={`${id}-fallback`} className="absolute inset-0 items-center justify-center">
|
|
34
|
+
<Text className="text-3xl font-semibold text-primary">{name.trim().charAt(0).toUpperCase() || '?'}</Text>
|
|
35
|
+
</View>
|
|
36
|
+
)}
|
|
37
|
+
<View className={cn('absolute inset-x-0 bottom-0 px-2.5 py-2', imageUrl && 'bg-card/80')}>
|
|
38
|
+
<Text className="font-bold text-foreground" numberOfLines={2}>{name}</Text>
|
|
39
|
+
{count !== undefined && count > 0 ? <Text className="text-xs text-muted-foreground">{count === 1 ? '1 product' : `${count} products`}</Text> : null}
|
|
40
|
+
</View>
|
|
41
|
+
</Pressable>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Text, View } from 'react-native';
|
|
2
|
+
import { cn } from '@tallyui/theme';
|
|
3
|
+
|
|
4
|
+
export interface InCartBadgeProps {
|
|
5
|
+
/** How many of the product the cart holds (e.g. from `cartQuantities`); nothing renders at 0. */
|
|
6
|
+
count: number;
|
|
7
|
+
/** Placement, e.g. `absolute right-2 top-2` for a tile's top-right corner. */
|
|
8
|
+
className?: string;
|
|
9
|
+
testID?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* How many of a product are in the cart: a primary circle with the count, hidden while there are none.
|
|
14
|
+
*
|
|
15
|
+
* Ported from WCPOS v2 `InCartCount`, packages/core/src/screens/main/pos/products/rows/in-cart-count.tsx
|
|
16
|
+
* (MIT, WCPOS), without its count beat.
|
|
17
|
+
*/
|
|
18
|
+
export function InCartBadge({ count, className, testID }: InCartBadgeProps) {
|
|
19
|
+
if (count <= 0) return null;
|
|
20
|
+
return (
|
|
21
|
+
<View testID={testID} accessibilityLabel={`${count} in cart`}
|
|
22
|
+
className={cn('h-6 min-w-6 items-center justify-center rounded-full bg-primary px-1.5', className)}>
|
|
23
|
+
<Text className="text-xs font-semibold tabular-nums text-primary-foreground">{String(count)}</Text>
|
|
24
|
+
</View>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/product/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { ProductTable, defaultProductColumns, useDefaultProductColumns, type Pro
|
|
|
10
10
|
export { ProductList, type ProductListProps } from './product-list';
|
|
11
11
|
export { CategoryNav, type CategoryNavProps, type CategoryItem } from './category-nav';
|
|
12
12
|
export { ProductVariantPicker, type ProductVariantPickerProps, type VariantOption } from './product-variant-picker';
|
|
13
|
+
export { InCartBadge, type InCartBadgeProps } from './in-cart-badge';
|
|
14
|
+
export { CategoryTile, type CategoryTileProps } from './category-tile';
|
|
@@ -4,6 +4,7 @@ import type { useRegisterSession } from '@tallyui/pos';
|
|
|
4
4
|
import { countVariance, TAX_ROUNDING_MIXED_NOTE, varianceText } from '@tallyui/pos';
|
|
5
5
|
|
|
6
6
|
import { formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
|
+
import { errorText } from '../lib/error-text';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
9
10
|
import { Text } from '../ui/text';
|
|
@@ -81,7 +82,7 @@ export function ClosureSheet({ register, currency, onPrint, onDone }: ClosureShe
|
|
|
81
82
|
try {
|
|
82
83
|
await onPrint();
|
|
83
84
|
} catch (e) {
|
|
84
|
-
setError(
|
|
85
|
+
setError(errorText(e));
|
|
85
86
|
} finally {
|
|
86
87
|
setBusy(false);
|
|
87
88
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import type { HandoverSlipData } from '@tallyui/pos';
|
|
3
|
+
|
|
4
|
+
import { formatMoney } from '@tallyui/core';
|
|
5
|
+
import { Text } from '../ui/text';
|
|
6
|
+
import { tenderLabel } from './register-count';
|
|
7
|
+
import { countLine } from './switch-confirm';
|
|
8
|
+
|
|
9
|
+
export interface HandoverSlipProps {
|
|
10
|
+
/** `handoverSlip(...)`'s result; `document` is not read here (it is what prints). */
|
|
11
|
+
slip: Omit<HandoverSlipData, 'document'>;
|
|
12
|
+
/** ISO 4217 code, for the expected figures. */
|
|
13
|
+
currency: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The hand-over slip on screen: what a closing cashier hands the next one (v2's "Hand-over slip", the open session's
|
|
18
|
+
* X report naming the cashier; WCPOS v2 monorepo `main` 51e7c4351 `switch-confirm.tsx` and `use-session-report.ts`).
|
|
19
|
+
* No dialog: the host places it, for example in a print preview. No expected figures while blind.
|
|
20
|
+
*/
|
|
21
|
+
export function HandoverSlip({ slip, currency }: HandoverSlipProps) {
|
|
22
|
+
const register = [slip.registerName, slip.openedAtTime && `open since ${slip.openedAtTime}`, slip.openedByName]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(' · ');
|
|
25
|
+
return (
|
|
26
|
+
<View testID="handover-slip" className="gap-2">
|
|
27
|
+
<Text testID="handover-slip-title" className="text-lg font-semibold">Hand-over slip</Text>
|
|
28
|
+
<Text testID="handover-slip-register" className="text-muted-foreground">{register}</Text>
|
|
29
|
+
<Text testID="handover-slip-cashier">{`Handed over by ${slip.cashierName}`}</Text>
|
|
30
|
+
<Text testID="handover-slip-sales">{countLine(slip.salesCount, 'sale', 'sales')}</Text>
|
|
31
|
+
{Object.entries(slip.expected ?? {}).map(([method, amount]) => (
|
|
32
|
+
<Text key={method} testID={`handover-slip-expected-${method}`} className="tabular-nums">
|
|
33
|
+
{`Expected ${tenderLabel(method)} ${formatMoney({ amount, currency })}`}
|
|
34
|
+
</Text>
|
|
35
|
+
))}
|
|
36
|
+
{slip.unsentSales > 0 && (
|
|
37
|
+
<Text testID="handover-slip-unsent-sales">{countLine(slip.unsentSales, 'unsent sale', 'unsent sales')}</Text>
|
|
38
|
+
)}
|
|
39
|
+
{slip.unsentTillUpdates > 0 && (
|
|
40
|
+
<Text testID="handover-slip-unsent-till-updates">
|
|
41
|
+
{countLine(slip.unsentTillUpdates, 'unsent till update', 'unsent till updates')}
|
|
42
|
+
</Text>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/register/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { RegisterPanel, type RegisterPanelProps } from './register-panel';
|
|
|
10
10
|
export { RegisterColumn, type RegisterColumnProps } from './register-column';
|
|
11
11
|
export { RegisterCount, APPROVAL_REQUIRED_TEXT, type RegisterCountProps } from './register-count';
|
|
12
12
|
export { ClosureSheet, type ClosureSheetProps } from './closure-sheet';
|
|
13
|
+
export { SwitchConfirm, type SwitchConfirmProps } from './switch-confirm';
|
|
14
|
+
export { HandoverSlip, type HandoverSlipProps } from './handover-slip';
|
|
@@ -3,6 +3,7 @@ import type { MovementType, useRegisterSession } from '@tallyui/pos';
|
|
|
3
3
|
import { movementFieldError, normalizeAmount, parseMinor } from '@tallyui/pos';
|
|
4
4
|
|
|
5
5
|
import { currencySymbol, minorUnitDigits } from '@tallyui/core';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { Button } from '../ui/button';
|
|
7
8
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
8
9
|
import { Input } from '../ui/input';
|
|
@@ -63,7 +64,7 @@ export function MovementSheet({ register, type, currency, onDone, onOpenChange,
|
|
|
63
64
|
if (type === 'no_sale') onOpenDrawer?.();
|
|
64
65
|
onOpenChange(false);
|
|
65
66
|
} catch (e) {
|
|
66
|
-
setError(
|
|
67
|
+
setError(errorText(e));
|
|
67
68
|
} finally {
|
|
68
69
|
busyRef.current = false;
|
|
69
70
|
setBusy(false);
|
|
@@ -5,6 +5,7 @@ import { parseMinor, validAmount } from '@tallyui/pos';
|
|
|
5
5
|
|
|
6
6
|
import { currencySymbol, formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
7
|
import { cn } from '@tallyui/theme';
|
|
8
|
+
import { errorText } from '../lib/error-text';
|
|
8
9
|
import { Button } from '../ui/button';
|
|
9
10
|
import { Input } from '../ui/input';
|
|
10
11
|
import { Label } from '../ui/label';
|
|
@@ -48,7 +49,7 @@ export function OpenRegisterCard({ register, currency, configuredFloatMinor, cla
|
|
|
48
49
|
try {
|
|
49
50
|
await register.actions.openSession({ expectedFloatMinor, countedFloatMinor: countedMinor });
|
|
50
51
|
} catch (e) {
|
|
51
|
-
setError(
|
|
52
|
+
setError(errorText(e));
|
|
52
53
|
} finally {
|
|
53
54
|
setBusy(false);
|
|
54
55
|
}
|