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

SettingsSwitchRow.tsx

55 lines1.7 KB

1import { cn } from "../../../lib/cn";
2import type { ComponentProps } from "react";
3import { Platform, View } from "react-native";
4​
5import { SymbolView } from "../../../components/AppSymbol";
6import { AppText as Text } from "../../../components/AppText";
7import { ThemedSwitch } from "../../../components/ThemedSwitch";
8​
9type SymbolName = ComponentProps<typeof SymbolView>["name"];
10​
11export function SettingsSwitchRow(props: {
12 readonly disabled?: boolean;
13 readonly icon: SymbolName;
14 readonly label: string;
15 readonly subtitle?: string;
16 readonly value: boolean;
17 readonly onValueChange: (value: boolean) => void;
18}) {
19 return (
20 <View
21 className={cn(
22 "flex-row items-center gap-4",
23 Platform.OS === "android" ? "min-h-14 px-4 py-3" : "p-4",
24 Platform.OS === "android" && props.subtitle && "min-h-18",
25 props.disabled && "opacity-[0.45]",
26 )}
27 >
28 <SymbolView
29 name={props.icon}
30 size={Platform.OS === "android" ? 24 : 22}
31 tintColorClassName="accent-icon"
32 type="monochrome"
33 weight="regular"
34 />
35 <View className={cn("min-w-0 flex-1", Platform.OS === "android" && "gap-1")}>
36 <Text
37 className={
38 Platform.OS === "android" ? "text-base text-foreground" : "text-lg text-foreground"
39 }
40 >
41 {props.label}
42 </Text>
43 {props.subtitle ? (
44 <Text className="text-sm text-foreground-muted">{props.subtitle}</Text>
45 ) : null}
46 </View>
47 <ThemedSwitch
48 accessibilityLabel={props.label}
49 disabled={props.disabled}
50 onValueChange={props.onValueChange}
51 value={props.value}
52 />
53 </View>
54 );