@tallyui/components 3.17.0 → 3.19.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 +460 -34
- package/dist/index.js +3632 -1898
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +42 -4
- package/src/cart/cart-line.tsx +42 -18
- package/src/cart/cart-note-input.tsx +10 -2
- package/src/cart/index.ts +1 -1
- package/src/customer/customer-select.tsx +21 -3
- package/src/index.ts +27 -0
- package/src/order/index.ts +1 -0
- package/src/order/order-filter-bar.tsx +247 -0
- package/src/product/camera-scan-button.tsx +28 -0
- package/src/product/camera-scanner-panel.tsx +156 -0
- package/src/product/index.ts +5 -0
- package/src/product/scanner-viewfinder.tsx +76 -0
- package/src/product/variation-picker.tsx +128 -0
- package/src/register/register-bar.tsx +2 -6
- package/src/register/register-panel.tsx +47 -24
- package/src/register/register-side-sheet.tsx +175 -0
- package/src/reports/date-range-menu.tsx +109 -0
- package/src/reports/filters-bar.tsx +11 -21
- package/src/reports/hero.tsx +8 -4
- package/src/reports/index.ts +1 -0
- package/src/sale/cart.tsx +44 -8
- package/src/sale/catalogue.tsx +98 -21
- package/src/sale/charge-form.tsx +12 -6
- package/src/sale/customer-display-pairing.tsx +111 -0
- package/src/sale/index.ts +1 -0
- package/src/sale/line-popover.tsx +17 -1
- package/src/sale/order-reference.ts +1 -1
- package/src/sale/orders-list.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +163 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/tax-calculation-settings.tsx +97 -0
- package/src/tax/index.ts +1 -0
- package/src/tax/tax-based-on.tsx +196 -0
- package/src/ui/avatar/index.tsx +22 -4
- package/src/ui/button/index.tsx +1 -1
- package/src/ui/calendar/index.tsx +119 -0
- package/src/ui/calendar/month-grid.ts +40 -0
- package/src/ui/combobox/index.tsx +1 -1
- package/src/ui/dialog/index.tsx +20 -8
- package/src/ui/icon/chevron-down-icon.tsx +4 -0
- package/src/ui/icon/grip-icon.tsx +10 -0
- package/src/ui/icon/scan-icon.tsx +13 -0
- package/src/ui/icon/shopping-cart-icon.tsx +10 -0
- package/src/ui/icon-button/index.tsx +1 -1
- package/src/ui/index.ts +11 -1
- package/src/ui/input/index.tsx +1 -1
- package/src/ui/select/index.tsx +22 -4
- package/src/ui/switch/index.tsx +18 -7
- package/src/ui/textarea/index.tsx +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings › Tax › Calculation: "Calculate tax based on", and read-only rows for the settings that live in WooCommerce.
|
|
3
|
+
* Port of WCPOS v2 `packages/core/src/screens/main/settings/tax.tsx:139-183` and `option-lists.ts` `taxBasedOn`;
|
|
4
|
+
* the labels are v2's English strings from core.json. StoreSettings has no `calcTaxes`, so v2's "Enable taxes" row is left out.
|
|
5
|
+
*/
|
|
6
|
+
import { View } from 'react-native';
|
|
7
|
+
import type { woocommerceTax } from '@tallyui/core';
|
|
8
|
+
import { cn } from '@tallyui/theme';
|
|
9
|
+
import { Button } from '../ui/button';
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
|
|
11
|
+
import { Text } from '../ui/text';
|
|
12
|
+
import { SettingsGroup } from './settings-group';
|
|
13
|
+
import { SettingsRow } from './settings-row';
|
|
14
|
+
|
|
15
|
+
type TaxBasedOn = woocommerceTax.TaxBasedOn;
|
|
16
|
+
|
|
17
|
+
export interface TaxCalculationSettingsProps {
|
|
18
|
+
taxBasedOn: TaxBasedOn;
|
|
19
|
+
onTaxBasedOnChange?: (value: TaxBasedOn) => void;
|
|
20
|
+
pricesIncludeTax?: boolean;
|
|
21
|
+
shippingTaxClass?: string;
|
|
22
|
+
taxRoundAtSubtotal?: boolean;
|
|
23
|
+
/** "Set in WooCommerce": a link when given, plain text otherwise. */
|
|
24
|
+
onOpenStoreTaxSettings?: () => void;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const OPTIONS: { value: TaxBasedOn; label: string }[] = [
|
|
29
|
+
{ value: 'shipping', label: 'Customer shipping address' },
|
|
30
|
+
{ value: 'billing', label: 'Customer billing address' },
|
|
31
|
+
{ value: 'base', label: 'Shop base address' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** The class name rule of @tallyui/pos `taxDerivation` (re-implemented here: components import only types from pos). */
|
|
35
|
+
function classLabel(slug: string): string {
|
|
36
|
+
if (slug === '' || slug === 'standard') return 'Standard';
|
|
37
|
+
const words = slug.replace(/-/g, ' ');
|
|
38
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const yesNo = (value: boolean) => (value ? 'Yes' : 'No');
|
|
42
|
+
|
|
43
|
+
/** A SettingsRow whose description, "Set in WooCommerce", is a link when `onOpen` is given. */
|
|
44
|
+
function LockedRow({ id, label, value, onOpen }: { id: string; label: string; value: string; onOpen?: () => void }) {
|
|
45
|
+
return (
|
|
46
|
+
<View testID={`settings-tax-locked-${id}`} className="flex-row items-center gap-3 px-4 py-3">
|
|
47
|
+
<View className="flex-1 gap-0.5">
|
|
48
|
+
<Text className="text-sm font-medium text-foreground">{label}</Text>
|
|
49
|
+
{onOpen ? (
|
|
50
|
+
<Button variant="link" size="sm" role="link" onPress={onOpen} className="h-11 self-start px-0">
|
|
51
|
+
<Text className="text-xs">Set in WooCommerce</Text>
|
|
52
|
+
</Button>
|
|
53
|
+
) : <Text className="text-xs text-muted-foreground">Set in WooCommerce</Text>}
|
|
54
|
+
</View>
|
|
55
|
+
<Text testID={`settings-tax-locked-${id}-value`} className="text-sm text-foreground">{value}</Text>
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function TaxCalculationSettings({ taxBasedOn, onTaxBasedOnChange, pricesIncludeTax, shippingTaxClass,
|
|
61
|
+
taxRoundAtSubtotal, onOpenStoreTaxSettings, className }: TaxCalculationSettingsProps) {
|
|
62
|
+
const value = OPTIONS.find((option) => option.value === taxBasedOn);
|
|
63
|
+
const disabled = !onTaxBasedOnChange;
|
|
64
|
+
return (
|
|
65
|
+
<SettingsGroup title="Calculation" className={className}>
|
|
66
|
+
<SettingsRow
|
|
67
|
+
label="Calculate tax based on"
|
|
68
|
+
action={(
|
|
69
|
+
<Select value={value} disabled={disabled}
|
|
70
|
+
onValueChange={(option) => { if (option && option.value !== taxBasedOn) onTaxBasedOnChange?.(option.value as TaxBasedOn); }}>
|
|
71
|
+
<SelectTrigger testID="settings-tax-based-on" accessibilityLabel="Calculate tax based on"
|
|
72
|
+
className={cn('h-11 w-56 gap-2', disabled && 'opacity-50')}>
|
|
73
|
+
<SelectValue placeholder="Select tax based on" className="shrink text-sm text-foreground" numberOfLines={1} />
|
|
74
|
+
<Text className="text-xs text-muted-foreground">▼</Text>
|
|
75
|
+
</SelectTrigger>
|
|
76
|
+
<SelectContent className="w-56">
|
|
77
|
+
{OPTIONS.map((option) => (
|
|
78
|
+
<SelectItem key={option.value} value={option.value} label={option.label}
|
|
79
|
+
testID={`settings-tax-based-on-${option.value}`} className="min-h-11">
|
|
80
|
+
<Text className="text-sm">{option.label}</Text>
|
|
81
|
+
</SelectItem>
|
|
82
|
+
))}
|
|
83
|
+
</SelectContent>
|
|
84
|
+
</Select>
|
|
85
|
+
)}
|
|
86
|
+
/>
|
|
87
|
+
{pricesIncludeTax === undefined ? null
|
|
88
|
+
: <LockedRow id="prices_include_tax" label="Prices entered with tax" value={yesNo(pricesIncludeTax)} onOpen={onOpenStoreTaxSettings} />}
|
|
89
|
+
{shippingTaxClass === undefined ? null : (
|
|
90
|
+
<LockedRow id="shipping_tax_class" label="Shipping tax class" onOpen={onOpenStoreTaxSettings}
|
|
91
|
+
value={shippingTaxClass === 'inherit' ? 'Based on cart items' : classLabel(shippingTaxClass)} />
|
|
92
|
+
)}
|
|
93
|
+
{taxRoundAtSubtotal === undefined ? null
|
|
94
|
+
: <LockedRow id="tax_round_at_subtotal" label="Round tax at subtotal level" value={yesNo(taxRoundAtSubtotal)} onOpen={onOpenStoreTaxSettings} />}
|
|
95
|
+
</SettingsGroup>
|
|
96
|
+
);
|
|
97
|
+
}
|
package/src/tax/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TaxBasedOn, type TaxBasedOnProps } from './tax-based-on';
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Port of WCPOS v2 (monorepo next) packages/core/src/components/product/tax-based-on/ (index.tsx and
|
|
2
|
+
// display-current-tax-rates.tsx) and packages/components/src/derivation/; MIT, WCPOS. The copy is v2's core.json English.
|
|
3
|
+
import { useState, type ReactNode } from 'react';
|
|
4
|
+
import { ScrollView, StyleSheet, View } from 'react-native';
|
|
5
|
+
import type { woocommerceTax } from '@tallyui/core';
|
|
6
|
+
import type { TaxDerivation, TaxRateWhy } from '@tallyui/pos';
|
|
7
|
+
import { Popover } from '@tallyui/primitives';
|
|
8
|
+
import { cn } from '@tallyui/theme';
|
|
9
|
+
import { Button } from '../ui/button';
|
|
10
|
+
import { XIcon } from '../ui/icon/x-icon';
|
|
11
|
+
import { Text } from '../ui/text';
|
|
12
|
+
|
|
13
|
+
type TaxBasedOn = woocommerceTax.TaxBasedOn;
|
|
14
|
+
type StepState = 'fact' | 'result' | 'failed' | 'quiet';
|
|
15
|
+
|
|
16
|
+
export interface TaxBasedOnProps {
|
|
17
|
+
derivation: TaxDerivation;
|
|
18
|
+
/** "Change in Settings › Tax"; the link shows only when given. */
|
|
19
|
+
onChangeSetting?: () => void;
|
|
20
|
+
/** "View all tax rates"; the footer shows only when given. */
|
|
21
|
+
onViewAllRates?: () => void;
|
|
22
|
+
/** Country code to display name; defaults to Intl.DisplayNames('en', region) as "{Name} ({CODE})", the code alone if Intl lacks it. */
|
|
23
|
+
countryName?: (code: string) => string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SETTING_LABEL: Record<TaxBasedOn, string> = {
|
|
28
|
+
shipping: 'Customer shipping address', billing: 'Customer billing address', base: 'Shop base address',
|
|
29
|
+
};
|
|
30
|
+
const VALUE_LABEL: Record<TaxBasedOn, string> = { ...SETTING_LABEL, base: 'Shop base' };
|
|
31
|
+
const FALLBACK_NOTE: Record<NonNullable<TaxDerivation['fallback']>, string> = {
|
|
32
|
+
'shipping-to-billing': 'This order has no shipping address, so tax uses the billing address',
|
|
33
|
+
'shipping-to-shop': 'This order has no shipping or billing address, so tax uses the shop address',
|
|
34
|
+
'billing-to-shop': 'This order has no billing address, so tax uses the shop address',
|
|
35
|
+
};
|
|
36
|
+
const BEAD: Record<StepState, string> = {
|
|
37
|
+
fact: 'bg-muted-foreground', result: 'bg-foreground', failed: 'bg-destructive', quiet: 'border-2 border-border',
|
|
38
|
+
};
|
|
39
|
+
/** v2's TABLE_HEAD_TEXT, as cart-columns' heads draw it. */
|
|
40
|
+
const CAPTION = 'text-xs font-medium uppercase tracking-wide text-muted-foreground';
|
|
41
|
+
const FIELDS = [['country', 'Country'], ['state', 'State'], ['city', 'City'], ['postcode', 'Postcode']] as const;
|
|
42
|
+
|
|
43
|
+
function intlCountryName(code: string): string {
|
|
44
|
+
try {
|
|
45
|
+
const name = new Intl.DisplayNames(['en'], { type: 'region' }).of(code.toUpperCase());
|
|
46
|
+
return name && name !== code.toUpperCase() ? `${name} (${code.toUpperCase()})` : code;
|
|
47
|
+
} catch {
|
|
48
|
+
return code;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function whyText(why: TaxRateWhy, countryName: (code: string) => string): string {
|
|
53
|
+
switch (why.field) {
|
|
54
|
+
case 'postcode': return `postcode ${why.pattern}`;
|
|
55
|
+
case 'country': return `anywhere in ${countryName(why.country)}`;
|
|
56
|
+
case 'anywhere': return 'anywhere';
|
|
57
|
+
default: return why.field;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function postalLine(location: woocommerceTax.TaxAddress, countryName: (code: string) => string): string {
|
|
62
|
+
const local = [location.city, location.state, location.postcode].filter(Boolean).join(' ');
|
|
63
|
+
return [local, location.country ? countryName(location.country) : ''].filter(Boolean).join(', ') || '—';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function Step({ n, state, label, title, detail, last, children }: { n: number; state: StepState; label: string;
|
|
67
|
+
title?: string; detail?: string; last?: boolean; children?: ReactNode }) {
|
|
68
|
+
return (
|
|
69
|
+
<View testID={`tax-based-on-step-${n}`} dataSet={{ state }} className="flex-row gap-3">
|
|
70
|
+
<View className="items-center pt-0.5">
|
|
71
|
+
<View className={cn('size-4 items-center justify-center rounded-full', BEAD[state])}>
|
|
72
|
+
{state === 'failed' ? <View className="text-destructive-foreground"><XIcon size={10} strokeWidth={3} /></View> : null}
|
|
73
|
+
</View>
|
|
74
|
+
{last ? null : <View className={cn('mt-1 w-0.5 flex-1 bg-border', (state === 'failed' || state === 'quiet') && 'opacity-50')} />}
|
|
75
|
+
</View>
|
|
76
|
+
<View className={cn('min-w-0 flex-1 gap-0.5', !last && 'pb-4')}>
|
|
77
|
+
<Text className={CAPTION}>{label}</Text>
|
|
78
|
+
{title ? <Text className="text-base font-semibold text-foreground">{title}</Text> : null}
|
|
79
|
+
{detail ? <Text className="text-sm text-muted-foreground">{detail}</Text> : null}
|
|
80
|
+
{children}
|
|
81
|
+
</View>
|
|
82
|
+
</View>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function RateLine({ testID, name, why, percent, strong }: { testID: string; name: string; why?: string; percent: string; strong?: boolean }) {
|
|
87
|
+
return (
|
|
88
|
+
<View testID={testID} className={cn('flex-row items-baseline gap-3', strong ? 'min-h-8' : 'min-h-6')}>
|
|
89
|
+
<Text className={cn('min-w-0 flex-1 text-base', strong ? 'font-semibold text-foreground' : 'pl-3 text-muted-foreground')}>
|
|
90
|
+
{name}{why ? <Text className="text-muted-foreground">{` · ${why}`}</Text> : null}
|
|
91
|
+
</Text>
|
|
92
|
+
<Text className={cn('w-16 text-right text-base tabular-nums', strong ? 'font-semibold text-foreground' : 'text-muted-foreground')}>{percent}</Text>
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* v2's "Tax based on" trigger under the product table, and its popover: how the cart's tax rates were derived, from the
|
|
99
|
+
* setting, through the address used, to the rates that match it. A popover, not a hover card: a touch screen has no hover.
|
|
100
|
+
* Rate names show as the store gives them (this package has no HTML-entity decoder yet).
|
|
101
|
+
*/
|
|
102
|
+
export function TaxBasedOn({ derivation, onChangeSetting, onViewAllRates, countryName = intlCountryName, className }: TaxBasedOnProps) {
|
|
103
|
+
const [open, setOpen] = useState(false);
|
|
104
|
+
const { taxBasedOn, failure, classes, location } = derivation;
|
|
105
|
+
const setting = SETTING_LABEL[taxBasedOn];
|
|
106
|
+
const none = classes.length === 0;
|
|
107
|
+
const country = () => countryName(location.country);
|
|
108
|
+
const ratesTitle = derivation.noRateCause === 'not-covered' ? `The store's rates for ${country()} don't cover this address`
|
|
109
|
+
: derivation.noRateCause === 'no-rate-for-country' ? `The store has no tax rate for ${country()}`
|
|
110
|
+
: 'The store has no tax rate for this address';
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
114
|
+
<Popover.Trigger testID="tax-based-on-trigger" dataSet={{ tone: none ? 'bad' : 'normal' }} accessibilityLabel={`Tax based on: ${setting}`}
|
|
115
|
+
className={cn('min-h-11 min-w-0 shrink flex-row items-center gap-1 rounded-md px-1', className)}>
|
|
116
|
+
{none
|
|
117
|
+
? <Text testID="tax-based-on-warning" className="text-sm font-bold text-destructive">!</Text>
|
|
118
|
+
: <Text testID="tax-based-on-percent" className="text-sm text-muted-foreground">%</Text>}
|
|
119
|
+
<Text testID="tax-based-on-value" numberOfLines={1} className={cn('shrink text-sm', none ? 'text-destructive' : 'text-foreground')}>
|
|
120
|
+
{VALUE_LABEL[taxBasedOn]}
|
|
121
|
+
</Text>
|
|
122
|
+
<Text className="text-xs text-muted-foreground">▼</Text>
|
|
123
|
+
</Popover.Trigger>
|
|
124
|
+
<Popover.Portal>
|
|
125
|
+
<Popover.Overlay style={StyleSheet.absoluteFill} />
|
|
126
|
+
<Popover.Content testID="tax-based-on-content" side="top" align="start" sideOffset={4}
|
|
127
|
+
aria-label="Tax based on" aria-labelledby={undefined} aria-describedby={undefined}
|
|
128
|
+
className="max-h-full w-96 max-w-full rounded-md border border-border bg-popover p-2 shadow-md">
|
|
129
|
+
<ScrollView className="min-h-0 shrink" contentContainerClassName="p-2">
|
|
130
|
+
<Step n={1} state="fact" label="Calculated from" title={setting}>
|
|
131
|
+
{onChangeSetting ? (
|
|
132
|
+
<Button variant="link" size="sm" role="link" testID="tax-based-on-change-setting" onPress={onChangeSetting}
|
|
133
|
+
className="h-11 self-start px-0">
|
|
134
|
+
<Text>Change in Settings › Tax</Text>
|
|
135
|
+
</Button>
|
|
136
|
+
) : null}
|
|
137
|
+
</Step>
|
|
138
|
+
{failure === 'address' ? (
|
|
139
|
+
<Step n={2} state="failed" label="No address on the order"
|
|
140
|
+
title={`This order has no ${taxBasedOn === 'billing' ? 'billing' : 'shipping'} address, so no rate can match`}
|
|
141
|
+
detail="Add a customer with an address, or change the setting">
|
|
142
|
+
<AddressFields location={location} />
|
|
143
|
+
</Step>
|
|
144
|
+
) : (
|
|
145
|
+
<Step n={2} state="fact" label={derivation.fromOrder ? 'Address on the order' : 'Shop address'}
|
|
146
|
+
title={postalLine(location, countryName)} detail={derivation.fallback ? FALLBACK_NOTE[derivation.fallback] : undefined}>
|
|
147
|
+
<AddressFields location={location} />
|
|
148
|
+
</Step>
|
|
149
|
+
)}
|
|
150
|
+
{failure === 'address' ? <Step n={3} last state="quiet" label="Rates that match it" detail="None" />
|
|
151
|
+
: failure === 'rates' ? <Step n={3} last state="failed" label="No rate matches it" title={ratesTitle}
|
|
152
|
+
detail="Add one in WooCommerce › Tax, or change the setting" />
|
|
153
|
+
: (
|
|
154
|
+
<Step n={3} last state="result" label="Rates that match it">
|
|
155
|
+
<View className="mt-2">
|
|
156
|
+
{classes.map((group, index) => (
|
|
157
|
+
<View key={group.slug} className={index > 0 ? 'mt-1' : undefined}>
|
|
158
|
+
<RateLine strong testID={`tax-based-on-class-${group.slug}`} name={group.name} percent={group.percent} />
|
|
159
|
+
{group.rates.map((rate) => (
|
|
160
|
+
<RateLine key={rate.id} testID={`tax-based-on-rate-${rate.id}`} name={rate.name}
|
|
161
|
+
why={whyText(rate.why, countryName)} percent={rate.percent} />
|
|
162
|
+
))}
|
|
163
|
+
</View>
|
|
164
|
+
))}
|
|
165
|
+
</View>
|
|
166
|
+
</Step>
|
|
167
|
+
)}
|
|
168
|
+
</ScrollView>
|
|
169
|
+
{onViewAllRates ? (
|
|
170
|
+
<View className="mt-1 border-t border-border pt-1">
|
|
171
|
+
<Button variant="ghost" testID="tax-based-on-view-all" className="h-11 w-full justify-between px-2"
|
|
172
|
+
onPress={() => { setOpen(false); onViewAllRates(); }}>
|
|
173
|
+
<Text>View all tax rates</Text>
|
|
174
|
+
<Text className="text-muted-foreground">›</Text>
|
|
175
|
+
</Button>
|
|
176
|
+
</View>
|
|
177
|
+
) : null}
|
|
178
|
+
</Popover.Content>
|
|
179
|
+
</Popover.Portal>
|
|
180
|
+
</Popover.Root>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function AddressFields({ location }: { location: woocommerceTax.TaxAddress }) {
|
|
185
|
+
return (
|
|
186
|
+
<View className="mt-2 flex-row gap-3">
|
|
187
|
+
{FIELDS.map(([field, label]) => (
|
|
188
|
+
<View key={field} className="min-w-0 flex-1">
|
|
189
|
+
<Text className={CAPTION} numberOfLines={1}>{label}</Text>
|
|
190
|
+
<Text testID={`tax-based-on-field-${field}`} numberOfLines={1}
|
|
191
|
+
className={cn('text-base', location[field] ? 'text-foreground' : 'text-muted-foreground')}>{location[field] || '—'}</Text>
|
|
192
|
+
</View>
|
|
193
|
+
))}
|
|
194
|
+
</View>
|
|
195
|
+
);
|
|
196
|
+
}
|
package/src/ui/avatar/index.tsx
CHANGED
|
@@ -17,13 +17,31 @@ const avatarVariants = cva('relative overflow-hidden rounded-full', {
|
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
const avatarFallbackVariants = cva('flex h-full w-full items-center justify-center', {
|
|
21
|
+
variants: { tone: { muted: 'bg-muted', primary: 'bg-primary' } },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const avatarFallbackTextVariants = cva('text-sm font-medium', {
|
|
25
|
+
variants: { tone: { muted: 'text-muted-foreground', primary: 'text-primary-foreground' } },
|
|
26
|
+
});
|
|
27
|
+
|
|
20
28
|
type AvatarProps = ViewProps & VariantProps<typeof avatarVariants> & {
|
|
21
29
|
src?: string;
|
|
22
30
|
alt?: string;
|
|
23
31
|
fallback?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The fallback's colours. `'primary'` is v2's look (light initials on a solid primary circle),
|
|
34
|
+
* used by the Customers table and the customer dropdown.
|
|
35
|
+
*/
|
|
36
|
+
tone?: 'muted' | 'primary';
|
|
24
37
|
};
|
|
25
38
|
|
|
26
|
-
|
|
39
|
+
/** Up to two words of `name`, the first letter of each, upper case. */
|
|
40
|
+
function avatarInitials(name: string): string {
|
|
41
|
+
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Avatar({ className, size, src, alt, fallback, tone = 'muted', ...props }: AvatarProps) {
|
|
27
45
|
const [hasError, setHasError] = React.useState(false);
|
|
28
46
|
|
|
29
47
|
return (
|
|
@@ -36,8 +54,8 @@ function Avatar({ className, size, src, alt, fallback, ...props }: AvatarProps)
|
|
|
36
54
|
className="h-full w-full"
|
|
37
55
|
/>
|
|
38
56
|
) : (
|
|
39
|
-
<View className=
|
|
40
|
-
<Text className=
|
|
57
|
+
<View className={avatarFallbackVariants({ tone })}>
|
|
58
|
+
<Text className={avatarFallbackTextVariants({ tone })}>
|
|
41
59
|
{fallback ?? alt?.charAt(0)?.toUpperCase() ?? '?'}
|
|
42
60
|
</Text>
|
|
43
61
|
</View>
|
|
@@ -46,5 +64,5 @@ function Avatar({ className, size, src, alt, fallback, ...props }: AvatarProps)
|
|
|
46
64
|
);
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
export { Avatar, avatarVariants };
|
|
67
|
+
export { Avatar, avatarVariants, avatarInitials };
|
|
50
68
|
export type { AvatarProps };
|
package/src/ui/button/index.tsx
CHANGED
|
@@ -11,7 +11,7 @@ const buttonVariants = cva(
|
|
|
11
11
|
variant: {
|
|
12
12
|
default: 'bg-primary active:opacity-90',
|
|
13
13
|
destructive: 'bg-destructive active:opacity-90',
|
|
14
|
-
outline: 'border border-input bg-
|
|
14
|
+
outline: 'border border-input bg-card active:bg-accent',
|
|
15
15
|
secondary: 'bg-secondary active:opacity-80',
|
|
16
16
|
ghost: 'active:bg-accent',
|
|
17
17
|
link: 'web:underline-offset-4 web:hover:underline',
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A month calendar with single and range selection, `min`/`max` bounds and a week start. WCPOS v2
|
|
3
|
+
* wraps react-native-calendars (`components/src/calendar/calendar-impl.tsx`); this is a plain grid
|
|
4
|
+
* of Pressables with theme token classes instead, so it adds no dependency. Days are store days.
|
|
5
|
+
*/
|
|
6
|
+
import { useMemo, useState, type JSX } from 'react';
|
|
7
|
+
import { Pressable, Text, View } from 'react-native';
|
|
8
|
+
import type { DayRange, StoreDay } from '@tallyui/pos';
|
|
9
|
+
import { cn } from '@tallyui/theme';
|
|
10
|
+
import { addMonths, monthGrid, monthOf, pressRangeDay, type Month, type WeekDay } from './month-grid';
|
|
11
|
+
|
|
12
|
+
interface CalendarBaseProps {
|
|
13
|
+
min?: StoreDay;
|
|
14
|
+
max?: StoreDay;
|
|
15
|
+
/** Default 1 (Monday), as v2 hard-codes. */
|
|
16
|
+
weekStartsOn?: WeekDay;
|
|
17
|
+
/** The month shown first; defaults to the month of the value's start, else of `today`. */
|
|
18
|
+
initialMonth?: Month;
|
|
19
|
+
/** Today as a store day, for the today mark and the default month; the caller works it out in store time. */
|
|
20
|
+
today: StoreDay;
|
|
21
|
+
/** BCP 47 tag for the month and weekday names via Intl, default 'en-GB'. */
|
|
22
|
+
locale?: string;
|
|
23
|
+
testID?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
export type CalendarProps =
|
|
27
|
+
| (CalendarBaseProps & { mode: 'single'; value: StoreDay | null; onChange: (day: StoreDay) => void })
|
|
28
|
+
| (CalendarBaseProps & { mode: 'range'; value: DayRange | null; onChange: (range: DayRange) => void });
|
|
29
|
+
|
|
30
|
+
const utc = (day: StoreDay) => new Date(`${day}T00:00:00Z`);
|
|
31
|
+
// 1 January 2023 was a Sunday, so day `i` of that week is weekday `i`.
|
|
32
|
+
const weekdayDate = (weekday: number) => new Date(Date.UTC(2023, 0, 1 + weekday));
|
|
33
|
+
const rangeKey = (range: DayRange | null) => (range ? `${range.from}/${range.to}` : '');
|
|
34
|
+
|
|
35
|
+
export function Calendar(props: CalendarProps): JSX.Element {
|
|
36
|
+
const { min, max, weekStartsOn = 1, today, locale = 'en-GB', testID = 'calendar', className } = props;
|
|
37
|
+
const start = props.mode === 'single' ? props.value : props.value?.from ?? null;
|
|
38
|
+
const [month, setMonth] = useState<Month>(props.initialMonth ?? monthOf(start ?? today));
|
|
39
|
+
// The first tap of a range still being picked, and the one-day range it reported.
|
|
40
|
+
const [pick, setPick] = useState<{ anchor: StoreDay; reported: string } | null>(null);
|
|
41
|
+
const valueKey = props.mode === 'range' ? rangeKey(props.value) : '';
|
|
42
|
+
const [seen, setSeen] = useState(valueKey);
|
|
43
|
+
if (seen !== valueKey) {
|
|
44
|
+
setSeen(valueKey);
|
|
45
|
+
if (pick && pick.reported !== valueKey) setPick(null);
|
|
46
|
+
}
|
|
47
|
+
const format = useMemo(() => ({
|
|
48
|
+
title: new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric', timeZone: 'UTC' }),
|
|
49
|
+
weekday: new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' }),
|
|
50
|
+
full: new Intl.DateTimeFormat(locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }),
|
|
51
|
+
}), [locale]);
|
|
52
|
+
|
|
53
|
+
const outside = (day: StoreDay) => (min !== undefined && day < min) || (max !== undefined && day > max);
|
|
54
|
+
const prevDisabled = min !== undefined && addMonths(month, -1) < monthOf(min);
|
|
55
|
+
const nextDisabled = max !== undefined && addMonths(month, 1) > monthOf(max);
|
|
56
|
+
const press = (day: StoreDay) => {
|
|
57
|
+
if (outside(day)) return;
|
|
58
|
+
if (props.mode === 'single') return props.onChange(day);
|
|
59
|
+
const next = pressRangeDay(pick?.anchor ?? null, day);
|
|
60
|
+
setPick(next.anchor ? { anchor: next.anchor, reported: rangeKey(next.range) } : null);
|
|
61
|
+
props.onChange(next.range);
|
|
62
|
+
};
|
|
63
|
+
const look = (day: StoreDay): 'end' | 'inside' | null => {
|
|
64
|
+
if (props.mode === 'single') return props.value === day ? 'end' : null;
|
|
65
|
+
const range = props.value;
|
|
66
|
+
if (!range) return null;
|
|
67
|
+
if (day === range.from || day === range.to) return 'end';
|
|
68
|
+
return day > range.from && day < range.to ? 'inside' : null;
|
|
69
|
+
};
|
|
70
|
+
const arrow = (id: 'prev' | 'next', disabled: boolean, glyph: string, label: string) => (
|
|
71
|
+
<Pressable testID={`${testID}-${id}`} accessibilityRole="button" accessibilityLabel={label}
|
|
72
|
+
accessibilityState={{ disabled }} aria-disabled={disabled} disabled={disabled}
|
|
73
|
+
onPress={() => { if (!disabled) setMonth(addMonths(month, id === 'prev' ? -1 : 1)); }}
|
|
74
|
+
className={cn('h-9 w-9 items-center justify-center rounded-md active:bg-accent', disabled && 'opacity-40')}>
|
|
75
|
+
<Text className="text-xl text-primary">{glyph}</Text>
|
|
76
|
+
</Pressable>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<View testID={testID} className={cn('gap-1', className)}>
|
|
81
|
+
<View className="flex-row items-center justify-between">
|
|
82
|
+
{arrow('prev', prevDisabled, '‹', 'Previous month')}
|
|
83
|
+
<Text testID={`${testID}-title`} className="text-base font-medium text-foreground">{format.title.format(utc(`${month}-01`))}</Text>
|
|
84
|
+
{arrow('next', nextDisabled, '›', 'Next month')}
|
|
85
|
+
</View>
|
|
86
|
+
<View testID={`${testID}-weekdays`} className="flex-row">
|
|
87
|
+
{Array.from({ length: 7 }, (_, i) => (
|
|
88
|
+
<Text key={i} className="flex-1 text-center text-xs font-medium text-muted-foreground">
|
|
89
|
+
{format.weekday.format(weekdayDate((weekStartsOn + i) % 7))}
|
|
90
|
+
</Text>
|
|
91
|
+
))}
|
|
92
|
+
</View>
|
|
93
|
+
{monthGrid(month, weekStartsOn).map((week) => (
|
|
94
|
+
<View key={week[0].day} className="flex-row">
|
|
95
|
+
{week.map(({ day, inMonth }) => {
|
|
96
|
+
const disabled = outside(day);
|
|
97
|
+
const state = look(day);
|
|
98
|
+
const selected = state !== null;
|
|
99
|
+
return (
|
|
100
|
+
<Pressable key={day} testID={`${testID}-day-${day}`} accessibilityRole="button"
|
|
101
|
+
accessibilityLabel={format.full.format(utc(day))} accessibilityState={{ selected, disabled }}
|
|
102
|
+
aria-selected={selected} aria-disabled={disabled} disabled={disabled} onPress={() => press(day)}
|
|
103
|
+
className={cn('aspect-square min-h-9 min-w-9 flex-1 items-center justify-center rounded-md',
|
|
104
|
+
state === 'end' && 'bg-primary', state === 'inside' && 'bg-primary/15')}>
|
|
105
|
+
<Text className={cn('text-sm',
|
|
106
|
+
state === 'end' ? 'text-primary-foreground'
|
|
107
|
+
: disabled ? 'text-border'
|
|
108
|
+
: day === today ? 'font-medium text-primary'
|
|
109
|
+
: inMonth ? 'text-foreground' : 'text-muted-foreground')}>
|
|
110
|
+
{Number(day.slice(8))}
|
|
111
|
+
</Text>
|
|
112
|
+
</Pressable>
|
|
113
|
+
);
|
|
114
|
+
})}
|
|
115
|
+
</View>
|
|
116
|
+
))}
|
|
117
|
+
</View>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The calendar's date math, on store days (`yyyy-MM-dd`) and months (`yyyy-MM`). Everything is UTC
|
|
3
|
+
* day arithmetic, as pos `presetRange` does, so no `Date` is ever read in the device zone.
|
|
4
|
+
*/
|
|
5
|
+
import type { DayRange, StoreDay } from '@tallyui/pos';
|
|
6
|
+
|
|
7
|
+
export type Month = string;
|
|
8
|
+
/** 0 = Sunday, as `Date.getUTCDay`. */
|
|
9
|
+
export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
10
|
+
export interface GridDay { day: StoreDay; inMonth: boolean }
|
|
11
|
+
|
|
12
|
+
const DAY_MS = 86_400_000;
|
|
13
|
+
const iso = (at: number): StoreDay => new Date(at).toISOString().slice(0, 10);
|
|
14
|
+
|
|
15
|
+
export const monthOf = (day: StoreDay): Month => day.slice(0, 7);
|
|
16
|
+
|
|
17
|
+
export function addMonths(month: Month, n: number): Month {
|
|
18
|
+
const [year, m] = month.split('-').map(Number);
|
|
19
|
+
return iso(Date.UTC(year, m - 1 + n, 1)).slice(0, 7);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const compareDays = (a: StoreDay, b: StoreDay): number => (a < b ? -1 : a > b ? 1 : 0);
|
|
23
|
+
|
|
24
|
+
/** The weeks of `month`, each 7 days from `weekStartsOn`; leading and trailing days belong to the neighbouring months. */
|
|
25
|
+
export function monthGrid(month: Month, weekStartsOn: WeekDay): GridDay[][] {
|
|
26
|
+
const [year, m] = month.split('-').map(Number);
|
|
27
|
+
const first = Date.UTC(year, m - 1, 1);
|
|
28
|
+
const lead = (new Date(first).getUTCDay() - weekStartsOn + 7) % 7;
|
|
29
|
+
const length = new Date(Date.UTC(year, m, 0)).getUTCDate();
|
|
30
|
+
return Array.from({ length: Math.ceil((lead + length) / 7) }, (_, row) => Array.from({ length: 7 }, (_, col) => {
|
|
31
|
+
const day = iso(first + (row * 7 + col - lead) * DAY_MS);
|
|
32
|
+
return { day, inMonth: monthOf(day) === month };
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** v2's two-tap rule. `anchor` is the first tap of a range still being picked, or null. */
|
|
37
|
+
export function pressRangeDay(anchor: StoreDay | null, day: StoreDay): { range: DayRange; anchor: StoreDay | null } {
|
|
38
|
+
if (anchor === null) return { range: { from: day, to: day }, anchor: day };
|
|
39
|
+
return { range: compareDays(day, anchor) < 0 ? { from: day, to: anchor } : { from: anchor, to: day }, anchor: null };
|
|
40
|
+
}
|
|
@@ -13,7 +13,7 @@ const ComboboxTrigger = React.forwardRef<
|
|
|
13
13
|
<ComboboxPrimitive.Trigger
|
|
14
14
|
ref={ref}
|
|
15
15
|
className={cn(
|
|
16
|
-
'flex h-10 w-full flex-row items-center justify-between rounded-md border border-input bg-
|
|
16
|
+
'flex h-10 w-full flex-row items-center justify-between rounded-md border border-input bg-card px-3 py-2 text-sm web:ring-offset-background web:focus:outline-none web:focus:ring-2 web:focus:ring-ring web:focus:ring-offset-2',
|
|
17
17
|
className,
|
|
18
18
|
)}
|
|
19
19
|
{...props}
|
package/src/ui/dialog/index.tsx
CHANGED
|
@@ -22,19 +22,22 @@ const DialogOverlay = React.forwardRef<
|
|
|
22
22
|
});
|
|
23
23
|
DialogOverlay.displayName = 'DialogOverlay';
|
|
24
24
|
|
|
25
|
+
/** Where the content sits: centred (the default), or a full-height sheet on the right edge, full width on a phone. */
|
|
26
|
+
const SIDE_CLASS = {
|
|
27
|
+
center: 'fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border border-border bg-background p-6 shadow-lg',
|
|
28
|
+
right: 'fixed right-0 top-0 bottom-0 z-50 h-full w-full max-w-lg gap-4 rounded-none border-l border-border bg-background p-6 shadow-lg',
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
25
31
|
const DialogContent = React.forwardRef<
|
|
26
32
|
React.ComponentRef<typeof DialogPrimitive.Content>,
|
|
27
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
28
|
-
>(function DialogContent({ className, children, ...props }, ref) {
|
|
33
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { side?: keyof typeof SIDE_CLASS }
|
|
34
|
+
>(function DialogContent({ className, children, side = 'center', ...props }, ref) {
|
|
29
35
|
return (
|
|
30
36
|
<DialogPortal>
|
|
31
37
|
<DialogOverlay />
|
|
32
38
|
<DialogPrimitive.Content
|
|
33
39
|
ref={ref}
|
|
34
|
-
className={cn(
|
|
35
|
-
'fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border border-border bg-background p-6 shadow-lg',
|
|
36
|
-
className,
|
|
37
|
-
)}
|
|
40
|
+
className={cn(SIDE_CLASS[side], className)}
|
|
38
41
|
{...props}
|
|
39
42
|
>
|
|
40
43
|
{children}
|
|
@@ -56,13 +59,22 @@ function DialogFooter({ className, ...props }: React.ComponentPropsWithoutRef<ty
|
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
const TITLE_CLASS = 'text-lg font-semibold leading-none text-foreground';
|
|
63
|
+
|
|
64
|
+
/** tailwind-merge drops `leading-none` when a caller passes a text size; put it back unless the caller set a leading. */
|
|
65
|
+
function titleClass(className?: string) {
|
|
66
|
+
const merged = cn(TITLE_CLASS, className);
|
|
67
|
+
return /\bleading-/.test(merged) ? merged : `${merged} leading-none`;
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
const DialogTitle = React.forwardRef<
|
|
60
71
|
React.ComponentRef<typeof DialogPrimitive.Title>,
|
|
61
72
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
62
73
|
>(function DialogTitle({ className, ...props }, ref) {
|
|
74
|
+
const merged = titleClass(className);
|
|
63
75
|
return (
|
|
64
|
-
<TextClassContext.Provider value=
|
|
65
|
-
<DialogPrimitive.Title ref={ref} className={
|
|
76
|
+
<TextClassContext.Provider value={merged}>
|
|
77
|
+
<DialogPrimitive.Title ref={ref} className={merged} {...props} />
|
|
66
78
|
</TextClassContext.Provider>
|
|
67
79
|
);
|
|
68
80
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Line } from 'react-native-svg';
|
|
2
|
+
import { createSvgIcon } from './svg-icon';
|
|
3
|
+
|
|
4
|
+
/** A horizontal grip of two lines. */
|
|
5
|
+
export const GripIcon = createSvgIcon('GripIcon', () => (
|
|
6
|
+
<>
|
|
7
|
+
<Line x1={5} y1={10} x2={19} y2={10} />
|
|
8
|
+
<Line x1={5} y1={14} x2={19} y2={14} />
|
|
9
|
+
</>
|
|
10
|
+
));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Line, Path } from 'react-native-svg';
|
|
2
|
+
import { createSvgIcon } from './svg-icon';
|
|
3
|
+
|
|
4
|
+
/** A scan frame (four corners) with a centre line. */
|
|
5
|
+
export const ScanIcon = createSvgIcon('ScanIcon', () => (
|
|
6
|
+
<>
|
|
7
|
+
<Path d="M3 7V5a2 2 0 0 1 2-2h2" />
|
|
8
|
+
<Path d="M17 3h2a2 2 0 0 1 2 2v2" />
|
|
9
|
+
<Path d="M21 17v2a2 2 0 0 1-2 2h-2" />
|
|
10
|
+
<Path d="M7 21H5a2 2 0 0 1-2-2v-2" />
|
|
11
|
+
<Line x1={7} y1={12} x2={17} y2={12} />
|
|
12
|
+
</>
|
|
13
|
+
));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Circle, Path } from 'react-native-svg';
|
|
2
|
+
import { createSvgIcon } from './svg-icon';
|
|
3
|
+
|
|
4
|
+
export const ShoppingCartIcon = createSvgIcon('ShoppingCartIcon', () => (
|
|
5
|
+
<>
|
|
6
|
+
<Circle cx={9} cy={20} r={1.5} />
|
|
7
|
+
<Circle cx={18} cy={20} r={1.5} />
|
|
8
|
+
<Path d="M2 3h3l2.5 12h11.5l2-8H6.2" />
|
|
9
|
+
</>
|
|
10
|
+
));
|
|
@@ -11,7 +11,7 @@ const iconButtonVariants = cva(
|
|
|
11
11
|
variant: {
|
|
12
12
|
default: 'bg-primary active:opacity-90',
|
|
13
13
|
destructive: 'bg-destructive active:opacity-90',
|
|
14
|
-
outline: 'border border-input bg-
|
|
14
|
+
outline: 'border border-input bg-card active:bg-accent',
|
|
15
15
|
secondary: 'bg-secondary active:opacity-80',
|
|
16
16
|
ghost: 'active:bg-accent',
|
|
17
17
|
},
|