The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { View } from "react-native"; |
| 3 | |
| 4 | import { AppText } from "./AppText"; |
| 5 | import { IconButton } from "./IconButton"; |
| 6 | import type { NumberFieldProps } from "./NumberField.types"; |
| 7 | |
| 8 | export function NumberField(props: NumberFieldProps) { |
| 9 | const gt = useGT(); |
| 10 | const adjust = (amount: number) => { |
| 11 | if (props.disabled) return; |
| 12 | const next = Math.max(props.min, Math.min(props.max, props.value + amount)); |
| 13 | if (next !== props.value) props.onValueChange(next); |
| 14 | }; |
| 15 | |
| 16 | return ( |
| 17 | <View className="shrink-0 flex-row items-center"> |
| 18 | <View |
| 19 | pointerEvents="none" |
| 20 | className="absolute inset-x-0 rounded-full bg-subtle" |
| 21 | style={{ height: 32 }} |
| 22 | /> |
| 23 | <IconButton |
| 24 | icon="minus" |
| 25 | accessibilityLabel={gt("Decrease {label}", { label: props.label })} |
| 26 | disabled={props.disabled || props.value <= props.min} |
| 27 | onPress={() => adjust(-1)} |
| 28 | /> |
| 29 | <AppText |
| 30 | textRole="body" |
| 31 | className="min-w-8 text-center" |
| 32 | style={{ fontVariant: ["tabular-nums"] }} |
| 33 | accessibilityLabel={gt("{label}: {value}", { |
| 34 | label: props.label, |
| 35 | value: props.formatValue?.(props.value) ?? props.value, |
| 36 | })} |
| 37 | accessibilityLiveRegion="polite" |
| 38 | > |
| 39 | {props.value} |
| 40 | </AppText> |
| 41 | <IconButton |
| 42 | icon="plus" |
| 43 | accessibilityLabel={gt("Increase {label}", { label: props.label })} |
| 44 | disabled={props.disabled || props.value >= props.max} |
| 45 | onPress={() => adjust(1)} |
| 46 | /> |
| 47 | </View> |
| 48 | ); |
| 49 | } |