Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SettingsRow.tsx

95 lines2.6 KB

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: target,
68 })
69 }
70 >
71 {content}
72 </Pressable>
73 );
74 }
75​
76 const fullScreenTarget = props.fullScreenTarget;
77 if (fullScreenTarget) {
78 return (
79 <Pressable
80 accessibilityLabel={props.label}
81 accessibilityRole="button"
82 disabled={props.disabled}
83 onPress={() => navigation.navigate(fullScreenTarget)}
84 >
85 {content}
86 </Pressable>
87 );
88 }
89​
90 return (
91 <Pressable accessibilityRole="button" disabled={props.disabled} onPress={props.onPress}>
92 {content}
93 </Pressable>
94 );