The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { T, useGT } from "gt-react-native"; |
| 2 | import { useState } from "react"; |
| 3 | import { Pressable } from "react-native"; |
| 4 | |
| 5 | import { AppText } from "./AppText"; |
| 6 | import { ListRowLayout, type ListRowContentProps } from "./ListRowLayout"; |
| 7 | import { ThemedSwitch } from "./ThemedSwitch"; |
| 8 | |
| 9 | /** |
| 10 | * A mixed row flips the value last picked on it, so a pick that some environments dropped can be |
| 11 | * undone. Before any pick, it sets the value on everywhere. |
| 12 | */ |
| 13 | export function ListToggleRow( |
| 14 | props: Omit<ListRowContentProps, "detail"> & { |
| 15 | readonly value: boolean | null; |
| 16 | readonly onValueChange: (value: boolean) => void; |
| 17 | }, |
| 18 | ) { |
| 19 | const gt = useGT(); |
| 20 | const [picked, setPicked] = useState(false); |
| 21 | const pick = (value: boolean) => { |
| 22 | setPicked(value); |
| 23 | props.onValueChange(value); |
| 24 | }; |
| 25 | return ( |
| 26 | <ListRowLayout |
| 27 | icon={props.icon} |
| 28 | label={props.label} |
| 29 | description={props.description} |
| 30 | disabled={props.disabled} |
| 31 | accessory={ |
| 32 | props.value === null ? ( |
| 33 | <Pressable |
| 34 | accessibilityLabel={ |
| 35 | picked |
| 36 | ? gt("Set {label} off for selected environments", { label: props.label }) |
| 37 | : gt("Set {label} on for selected environments", { label: props.label }) |
| 38 | } |
| 39 | accessibilityRole="button" |
| 40 | accessibilityHint={props.description} |
| 41 | accessibilityState={{ disabled: Boolean(props.disabled) }} |
| 42 | disabled={props.disabled} |
| 43 | className="rounded-full bg-subtle px-3 py-2 active:opacity-70" |
| 44 | onPress={() => pick(!picked)} |
| 45 | > |
| 46 | <AppText className="text-sm font-t3-medium text-foreground"> |
| 47 | {picked ? <T>Mixed · Set off</T> : <T>Mixed · Set on</T>} |
| 48 | </AppText> |
| 49 | </Pressable> |
| 50 | ) : ( |
| 51 | <ThemedSwitch |
| 52 | accessibilityLabel={props.label} |
| 53 | accessibilityHint={props.description} |
| 54 | disabled={props.disabled} |
| 55 | onValueChange={pick} |
| 56 | value={props.value} |
| 57 | /> |
| 58 | ) |
| 59 | } |
| 60 | /> |
| 61 | ); |
| 62 | } |