@tallyui/components 3.13.0 → 3.14.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 +275 -27
- package/dist/index.js +1985 -1226
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +57 -0
- package/src/cart/cart-line.tsx +32 -17
- package/src/cart/index.ts +1 -0
- package/src/checkout/cash-tendered.tsx +5 -7
- package/src/index.ts +18 -2
- 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 +37 -21
- package/src/sale/catalogue.tsx +34 -5
- package/src/sale/customer-display-screen.tsx +92 -0
- package/src/sale/index.ts +4 -2
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +28 -4
- package/src/sale/product-filter-bar.tsx +58 -0
- package/src/sale/tender-pane.tsx +179 -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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Port of WCPOS v2 `packages/core/src/screens/main/components/drawer-content/index.tsx` (the `rail`
|
|
2
|
+
// presentation) and `drawer-content/rail/index.tsx`, MIT, WCPOS.
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import { cn } from '@tallyui/theme';
|
|
6
|
+
import { Text } from '../ui/text';
|
|
7
|
+
import { NavButton, splitGroups, type ShellNavItem } from './nav-item';
|
|
8
|
+
|
|
9
|
+
export interface NavRailProps {
|
|
10
|
+
items: ShellNavItem[];
|
|
11
|
+
activeId?: string;
|
|
12
|
+
onNavigate: (id: string) => void;
|
|
13
|
+
className?: string;
|
|
14
|
+
testID?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The wide layout's permanent icon column. Its width is 16 spacing units, the `h-12 w-12` item
|
|
19
|
+
* plus 2 units each side (64 at Regular), so it follows the scale step as v2's does. Icon-only:
|
|
20
|
+
* the label shows to the right on hover or keyboard focus, v2's web tooltip.
|
|
21
|
+
*/
|
|
22
|
+
export function NavRail({ items, activeId, onNavigate, className, testID = 'nav-rail' }: NavRailProps) {
|
|
23
|
+
const [hinted, setHinted] = React.useState<string | null>(null);
|
|
24
|
+
const renderItem = (item: ShellNavItem) => (
|
|
25
|
+
<View key={item.id} className="relative z-10">
|
|
26
|
+
<NavButton
|
|
27
|
+
item={item}
|
|
28
|
+
active={item.id === activeId}
|
|
29
|
+
onPress={() => onNavigate(item.id)}
|
|
30
|
+
onHoverIn={() => setHinted(item.id)}
|
|
31
|
+
onHoverOut={() => setHinted((id) => (id === item.id ? null : id))}
|
|
32
|
+
onFocus={() => setHinted(item.id)}
|
|
33
|
+
onBlur={() => setHinted((id) => (id === item.id ? null : id))}
|
|
34
|
+
/>
|
|
35
|
+
{hinted === item.id && (
|
|
36
|
+
<View
|
|
37
|
+
testID={`nav-rail-label-${item.id}`}
|
|
38
|
+
pointerEvents="none"
|
|
39
|
+
className="absolute left-full top-2 z-50 ml-3 rounded-md border border-border bg-popover px-3 py-1.5 shadow-md"
|
|
40
|
+
>
|
|
41
|
+
<Text className="text-sm text-popover-foreground" numberOfLines={1}>{item.label}</Text>
|
|
42
|
+
</View>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
const [top, bottom] = splitGroups(items);
|
|
47
|
+
return (
|
|
48
|
+
<View
|
|
49
|
+
role="navigation"
|
|
50
|
+
aria-label="Main"
|
|
51
|
+
testID={testID}
|
|
52
|
+
className={cn('z-10 w-16 items-center border-r border-border bg-card py-2', className)}
|
|
53
|
+
>
|
|
54
|
+
<View className="gap-2">{top.map(renderItem)}</View>
|
|
55
|
+
{bottom.length > 0 && <View className="mt-auto gap-2">{bottom.map(renderItem)}</View>}
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a bar inside the shell reads: v2's `useBarMenu` (`packages/core/src/screens/main/components/
|
|
5
|
+
* bar-controls/index.tsx`, MIT, WCPOS) gives the menu only below the wide boundary, where there is
|
|
6
|
+
* a drawer to open; on wide the rail is always on screen.
|
|
7
|
+
*/
|
|
8
|
+
export interface ShellState {
|
|
9
|
+
phone: boolean;
|
|
10
|
+
openMenu?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ShellContext = React.createContext<ShellState | null>(null);
|
|
14
|
+
|
|
15
|
+
/** The enclosing `AppShell`'s state, or `null` outside one. */
|
|
16
|
+
export function useShell(): ShellState | null {
|
|
17
|
+
return React.useContext(ShellContext);
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Line } from 'react-native-svg';
|
|
2
|
+
import { createSvgIcon } from './svg-icon';
|
|
3
|
+
|
|
4
|
+
export const MenuIcon = createSvgIcon('MenuIcon', () => (
|
|
5
|
+
<>
|
|
6
|
+
<Line x1={4} y1={6} x2={20} y2={6} />
|
|
7
|
+
<Line x1={4} y1={12} x2={20} y2={12} />
|
|
8
|
+
<Line x1={4} y1={18} x2={20} y2={18} />
|
|
9
|
+
</>
|
|
10
|
+
));
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { useState, type JSX } from 'react';
|
|
2
|
-
import { Pressable, Text, TextInput, View } from 'react-native';
|
|
3
|
-
import { formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
4
|
-
import type { useSale } from '@tallyui/pos';
|
|
5
|
-
import { tenderLabel } from '../register/register-count';
|
|
6
|
-
import { parsePrice } from './price-form';
|
|
7
|
-
|
|
8
|
-
export function SplitTender({ sale }: { sale: ReturnType<typeof useSale> }): JSX.Element | null {
|
|
9
|
-
const { order, stage } = sale;
|
|
10
|
-
const [method, setMethod] = useState<'cash' | 'external'>('cash');
|
|
11
|
-
const [amount, setAmount] = useState<string | null>(null);
|
|
12
|
-
const [reference, setReference] = useState('');
|
|
13
|
-
const [error, setError] = useState<string | null>(null);
|
|
14
|
-
if (stage.kind !== 'tender') return null;
|
|
15
|
-
const money = (value: number) => formatMoney({ amount: value, currency: order.currency });
|
|
16
|
-
const digits = minorUnitDigits(order.currency);
|
|
17
|
-
const amountText = amount ?? (order.balanceDueMinor / 10 ** digits).toFixed(digits);
|
|
18
|
-
const incomplete = order.balanceDueMinor > 0 || order.payments.length === 0;
|
|
19
|
-
function add() {
|
|
20
|
-
const parsed = parsePrice(amountText, order.currency);
|
|
21
|
-
if (typeof parsed === 'string') { setError(parsed); return; }
|
|
22
|
-
const id = sale.addTender({ method, amountMinor: parsed,
|
|
23
|
-
...(method === 'external' && reference ? { reference } : {}) });
|
|
24
|
-
if (id === null) {
|
|
25
|
-
setError("That tender wasn't added: nothing is due, or the amount isn't valid.");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
setError(null);
|
|
29
|
-
setReference('');
|
|
30
|
-
setAmount(null);
|
|
31
|
-
}
|
|
32
|
-
return <View dataSet={{ print: 'hide' }} className="gap-4 p-4">
|
|
33
|
-
<View testID="split-tender-summary" className="gap-2">
|
|
34
|
-
<Text className="text-foreground">Total: {money(order.totalMinor)}</Text>
|
|
35
|
-
<Text className="text-foreground">Paid: {money(order.paidMinor)}</Text>
|
|
36
|
-
<Text className="text-foreground">Remaining: {money(order.balanceDueMinor)}</Text>
|
|
37
|
-
{order.changeDueMinor > 0 ? <Text className="text-foreground">Change: {money(order.changeDueMinor)}</Text> : null}
|
|
38
|
-
</View>
|
|
39
|
-
<View testID="split-tender-list" className="gap-2">
|
|
40
|
-
{order.payments.map((payment) => <View key={payment.id} testID={`split-tender-row-${payment.id}`} className="gap-2">
|
|
41
|
-
<Text className="text-foreground">{tenderLabel(payment.method)} {money(payment.amountMinor)}</Text>
|
|
42
|
-
{payment.reference ? <Text className="text-foreground">{payment.reference}</Text> : null}
|
|
43
|
-
<Pressable testID={`split-tender-remove-${payment.id}`} accessibilityRole="button" accessibilityLabel="Remove tender"
|
|
44
|
-
onPress={() => sale.removeTender(payment.id)} className="rounded-md border border-border bg-card px-4 py-3">
|
|
45
|
-
<Text className="text-center text-foreground">Remove</Text>
|
|
46
|
-
</Pressable>
|
|
47
|
-
</View>)}
|
|
48
|
-
</View>
|
|
49
|
-
<View testID="split-tender-add" className="gap-2">
|
|
50
|
-
<View className="flex-row gap-2">
|
|
51
|
-
{(['cash', 'external'] as const).map((value) => <Pressable key={value}
|
|
52
|
-
testID={`split-tender-method-${value === 'cash' ? 'cash' : 'card'}`} accessibilityRole="button"
|
|
53
|
-
accessibilityState={{ selected: method === value }} onPress={() => setMethod(value)}
|
|
54
|
-
className={`rounded-md border border-border px-4 py-3 ${method === value ? 'bg-primary' : 'bg-card'}`}>
|
|
55
|
-
<Text className={`text-center ${method === value ? 'text-primary-foreground' : 'text-foreground'}`}>{tenderLabel(value)}</Text>
|
|
56
|
-
</Pressable>)}
|
|
57
|
-
</View>
|
|
58
|
-
<TextInput testID="split-tender-amount" accessibilityLabel="Tender amount" inputMode="decimal"
|
|
59
|
-
value={amountText} onChangeText={setAmount} className="rounded-md border border-border px-3 py-2 text-foreground" />
|
|
60
|
-
{method === 'external' ? <TextInput testID="split-tender-reference" accessibilityLabel="Terminal reference"
|
|
61
|
-
placeholder="Terminal reference" maxLength={255} value={reference} onChangeText={setReference}
|
|
62
|
-
className="rounded-md border border-border px-3 py-2 text-foreground" /> : null}
|
|
63
|
-
{error ? <Text testID="split-tender-error" accessibilityRole="alert" className="text-destructive">{error}</Text> : null}
|
|
64
|
-
<Pressable testID="split-tender-add-button" accessibilityRole="button" onPress={add} className="rounded-md bg-primary px-4 py-3">
|
|
65
|
-
<Text className="text-center font-semibold text-primary-foreground">Add</Text>
|
|
66
|
-
</Pressable>
|
|
67
|
-
</View>
|
|
68
|
-
<Pressable testID="split-tender-complete" accessibilityRole="button" disabled={incomplete} onPress={sale.complete}
|
|
69
|
-
className={`rounded-md bg-primary px-4 py-3 ${incomplete ? 'opacity-50' : ''}`}>
|
|
70
|
-
<Text className="text-center font-semibold text-primary-foreground">Complete sale</Text>
|
|
71
|
-
</Pressable>
|
|
72
|
-
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
73
|
-
{sale.canContinue ? <>
|
|
74
|
-
<Text className="text-foreground">This sale is stored and will be sent. Continue to the next sale.</Text>
|
|
75
|
-
<Pressable accessibilityRole="button" onPress={() => sale.continueSale()} className="rounded-md bg-primary px-4 py-3">
|
|
76
|
-
<Text className="text-center font-semibold text-primary-foreground">Continue</Text>
|
|
77
|
-
</Pressable>
|
|
78
|
-
</> : null}
|
|
79
|
-
<Pressable accessibilityRole="button" onPress={sale.cancelTender} className="rounded-md border border-border bg-card px-4 py-3"><Text className="text-center text-foreground">Back</Text></Pressable>
|
|
80
|
-
</View>;
|
|
81
|
-
}
|