Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AutoSettleDaysField.android.tsx

50 lines1.7 KB

1import {
2 MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
3 MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
4} from "@t3tools/contracts";
5import { View } from "react-native";
6​
7import { AppText } from "../../../components/AppText";
8import { MaterialIconButton } from "../../../components/MaterialIconButton";
9import type { AutoSettleDaysFieldProps } from "./AutoSettleDaysField";
10​
11export function AutoSettleDaysField(props: AutoSettleDaysFieldProps) {
12 const adjust = (amount: number) => {
13 const next = Math.max(
14 MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
15 Math.min(MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS, props.value + amount),
16 );
17 if (next !== props.value) props.onValueChange(next);
18 };
19​
20 return (
21 <View className="shrink-0 flex-row items-center">
22 {/* Match the 32dp switch track while retaining 48dp button touch targets. */}
23 <View
24 pointerEvents="none"
25 className="absolute inset-x-0 rounded-full bg-subtle"
26 style={{ height: 32 }}
27 />
28 <MaterialIconButton
29 icon="minus"
30 accessibilityLabel="Decrease days before auto-settle"
31 disabled={props.value <= MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS}
32 onPress={() => adjust(-1)}
33 />
34 <AppText
35 className="min-w-8 text-center text-base"
36 style={{ fontVariant: ["tabular-nums"] }}
37 accessibilityLabel={`${props.value} ${props.value === 1 ? "day" : "days"} before auto-settle`}
38 accessibilityLiveRegion="polite"
39 >
40 {props.value}
41 </AppText>
42 <MaterialIconButton
43 icon="plus"
44 accessibilityLabel="Increase days before auto-settle"
45 disabled={props.value >= MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS}
46 onPress={() => adjust(1)}
47 />
48 </View>
49 );