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

NumberField.android.tsx

45 lines1.4 KB

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