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

SettingsSwitchRow.tsx

40 lines1.3 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 value: boolean;
15 readonly onValueChange: (value: boolean) => void;
16}) {
17 const icon = useThemeColor("--color-icon");
18 const activeTrack = String(useThemeColor("--color-switch-active"));
19 const track = String(useThemeColor("--color-secondary-border"));
20​
21 return (
22 <View
23 className={
24 props.disabled
25 ? "flex-row items-center gap-4 p-4 opacity-[0.45]"
26 : "flex-row items-center gap-4 p-4"
27 }
28 >
29 <SymbolView name={props.icon} size={22} tintColor={icon} type="monochrome" weight="regular" />
30 <Text className="flex-1 text-lg text-foreground">{props.label}</Text>
31 <Switch
32 disabled={props.disabled}
33 ios_backgroundColor={track}
34 onValueChange={props.onValueChange}
35 trackColor={{ false: track, true: activeTrack }}
36 value={props.value}
37 />
38 </View>
39 );