Open History to see the last commit
1import { useNavigation } from "@react-navigation/native";
2import type { ComponentProps } from "react";
3import { Pressable, View } from "react-native";
4
5import { SymbolView } from "../../../components/AppSymbol";
6
7import { AppText as Text } from "../../../components/AppText";
8import type { SettingsLegalDocumentTarget, SettingsSheetTarget } from "./settings-sheet-targets";
9
10type SymbolName = ComponentProps<typeof SymbolView>["name"];
11
12export function SettingsRow(props: {
13 readonly disabled?: boolean;
14 readonly icon: SymbolName;
15 readonly label: string;
16 readonly value?: string;
17 readonly target?: SettingsSheetTarget;
18 readonly fullScreenTarget?: SettingsLegalDocumentTarget;
19 readonly onPress?: () => void;
20}) {
21 const navigation = useNavigation();
22 const content = (
23 <View
24 className={
25 props.disabled
26 ? "flex-row items-center gap-4 p-4 opacity-[0.45]"
27 : "flex-row items-center gap-4 p-4"
28 }
29 >
30 <SymbolView
31 name={props.icon}
32 size={22}
33 tintColorClassName={"accent-icon"}
34 type="monochrome"
35 weight="regular"
36 />
37 <Text className="shrink-0 text-lg text-foreground" numberOfLines={1}>
38 {props.label}
39 </Text>
40 <View className="min-w-0 flex-1 items-end">
41 {props.value ? (
42 <Text
43 className="max-w-[180px] text-right text-base text-foreground-muted"
44 ellipsizeMode="middle"
45 numberOfLines={1}
46 >
47 {props.value}
48 </Text>
49 ) : null}
50 </View>
51 <SymbolView
52 name="chevron.right"
53 size={16}
54 tintColorClassName={"accent-chevron"}
55 type="monochrome"
56 weight="semibold"
57 />
58 </View>
59 );
60
61 const target = props.target;
62 if (target) {
63 return (
64 <Pressable
65 accessibilityLabel={props.label}
66 accessibilityRole="button"
67 disabled={props.disabled}
68 onPress={() =>
69 navigation.navigate("SettingsSheet", {
70 screen: "SettingsContent",
71 params: { screen: target },
72 })
73 }
74 >
75 {content}
76 </Pressable>
77 );
78 }
79
80 const fullScreenTarget = props.fullScreenTarget;
81 if (fullScreenTarget) {
82 return (
83 <Pressable
84 accessibilityLabel={props.label}
85 accessibilityRole="button"
86 disabled={props.disabled}
87 onPress={() => navigation.navigate(fullScreenTarget)}
88 >
89 {content}
90 </Pressable>
91 );
92 }
93
94 return (
95 <Pressable accessibilityRole="button" disabled={props.disabled} onPress={props.onPress}>
96 {content}
97 </Pressable>
98 );
99}