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

SettingsSwitchRow.tsx

46 lines1.5 KB

1import type { ComponentProps } from "react";
2import { Switch, View } from "react-native";
3​
4import { SymbolView } from "../../../components/AppSymbol";
5import { AppText as Text } from "../../../components/AppText";
6import { useThemeColor } from "../../../lib/useThemeColor";
7​
8type SymbolName = ComponentProps<typeof SymbolView>["name"];
9​
10export function SettingsSwitchRow(props: {
11 readonly disabled?: boolean;
12 readonly icon: SymbolName;
13 readonly label: string;
14 readonly subtitle?: string;
15 readonly value: boolean;
16 readonly onValueChange: (value: boolean) => void;
17}) {
18 const icon = useThemeColor("--color-icon");
19 const activeTrack = String(useThemeColor("--color-switch-active"));
20 const track = String(useThemeColor("--color-secondary-border"));
21​
22 return (
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 name={props.icon} size={22} tintColor={icon} type="monochrome" weight="regular" />
31 <View className="min-w-0 flex-1">
32 <Text className="text-lg text-foreground">{props.label}</Text>
33 {props.subtitle ? (
34 <Text className="text-sm text-foreground-muted">{props.subtitle}</Text>
35 ) : null}
36 </View>
37 <Switch
38 disabled={props.disabled}
39 ios_backgroundColor={track}
40 onValueChange={props.onValueChange}
41 trackColor={{ false: track, true: activeTrack }}
42 value={props.value}
43 />
44 </View>
45 );