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