Open History to see the last commit
1import { MaterialListRow } from "../../../components/MaterialListRow";
2import { useNavigation } from "@react-navigation/native";
3import type { ComponentProps } from "react";
4import { Platform, Pressable, View } from "react-native";
5
6import { SymbolView } from "../../../components/AppSymbol";
7import { AppText as Text } from "../../../components/AppText";
8import type { SettingsLegalDocumentTarget, SettingsSheetTarget } from "./settings-sheet-targets";
9import { cn } from "../../../lib/cn";
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 valuePosition?: "below" | "trailing";
19 readonly target?: SettingsSheetTarget;
20 readonly fullScreenTarget?: SettingsLegalDocumentTarget;
21 readonly onPress?: () => void;
22}) {
23 const navigation = useNavigation();
24 if (Platform.OS === "android") {
25 return (
26 <MaterialListRow
27 title={props.label}
28 subtitle={props.valuePosition === "trailing" ? undefined : props.value}
29 accessibilityLabel={[props.label, props.value].filter(Boolean).join(", ")}
30 trailing={
31 props.valuePosition === "trailing" && props.value ? (
32 <View className="flex-row items-center gap-3">
33 <Text className="text-sm text-foreground-muted">{props.value}</Text>
34 <SymbolView name="chevron.right" size={16} tintColorClassName="accent-chevron" />
35 </View>
36 ) : undefined
37 }
38 disabled={props.disabled}
39 leading={
40 <SymbolView
41 name={props.icon}
42 size={24}
43 tintColorClassName="accent-icon"
44 type="monochrome"
45 weight="regular"
46 />
47 }
48 onPress={() => {
49 if (props.target)
50 navigation.navigate("SettingsSheet", {
51 screen: "SettingsContent",
52 params: { screen: props.target },
53 });
54 else if (props.fullScreenTarget) navigation.navigate(props.fullScreenTarget);
55 else props.onPress?.();
56 }}
57 />
58 );
59 }
60 const content = (
61 <View className={cn("flex-row items-center gap-4 p-4", props.disabled && "opacity-[0.45]")}>
62 <SymbolView
63 name={props.icon}
64 size={22}
65 tintColorClassName="accent-icon"
66 type="monochrome"
67 weight="regular"
68 />
69 <>
70 <Text className="shrink-0 text-lg text-foreground" numberOfLines={1}>
71 {props.label}
72 </Text>
73 <View className="min-w-0 flex-1 items-end">
74 {props.value ? (
75 <Text
76 className="max-w-[180px] text-right text-base text-foreground-muted"
77 ellipsizeMode="middle"
78 numberOfLines={1}
79 >
80 {props.value}
81 </Text>
82 ) : null}
83 </View>
84 </>
85 <SymbolView
86 name="chevron.right"
87 size={16}
88 tintColorClassName="accent-chevron"
89 type="monochrome"
90 weight="semibold"
91 />
92 </View>
93 );
94
95 const target = props.target;
96 if (target) {
97 return (
98 <Pressable
99 accessibilityLabel={props.label}
100 accessibilityRole="button"
101 disabled={props.disabled}
102 onPress={() =>
103 navigation.navigate("SettingsSheet", {
104 screen: "SettingsContent",
105 params: { screen: target },
106 })
107 }
108 >
109 {content}
110 </Pressable>
111 );
112 }
113
114 const fullScreenTarget = props.fullScreenTarget;
115 if (fullScreenTarget) {
116 return (
117 <Pressable
118 accessibilityLabel={props.label}
119 accessibilityRole="button"
120 disabled={props.disabled}
121 onPress={() => navigation.navigate(fullScreenTarget)}
122 >
123 {content}
124 </Pressable>
125 );
126 }
127
128 return (
129 <Pressable
130 accessibilityLabel={props.label}
131 accessibilityRole="button"
132 disabled={props.disabled}
133 onPress={props.onPress}
134 >
135 {content}
136 </Pressable>
137 );
138}