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

SettingsActionRow.tsx

57 lines1.7 KB

1import type { ComponentProps } from "react";
2import { ActivityIndicator, Platform, Pressable } from "react-native";
3​
4import { SymbolView } from "../../../components/AppSymbol";
5import { AppText as Text } from "../../../components/AppText";
6import { MaterialListRow } from "../../../components/MaterialListRow";
7import { cn } from "../../../lib/cn";
8​
9export function SettingsActionRow(props: {
10 readonly icon: ComponentProps<typeof SymbolView>["name"];
11 readonly label: string;
12 readonly tone?: "default" | "danger";
13 readonly disabled?: boolean;
14 readonly loading?: boolean;
15 readonly onPress: () => void;
16}) {
17 const danger = props.tone === "danger";
18 const textClassName = danger ? "tabular-nums text-danger-foreground" : "text-foreground";
19 const iconColorClassName = danger ? "accent-danger-foreground" : "accent-icon";
20 const icon = (
21 <SymbolView
22 name={props.icon}
23 size={Platform.OS === "android" ? 24 : 22}
24 tintColorClassName={iconColorClassName}
25 type="monochrome"
26 weight="regular"
27 />
28 );
29 const spinner = props.loading ? <ActivityIndicator colorClassName={iconColorClassName} /> : null;
30​
31 if (Platform.OS === "android") {
32 return (
33 <MaterialListRow
34 className="bg-grouped-card"
35 title={props.label}
36 titleClassName={textClassName}
37 leading={icon}
38 trailing={spinner}
39 disabled={props.disabled}
40 onPress={props.onPress}
41 />
42 );
43 }
44​
45 return (
46 <Pressable
47 accessibilityRole="button"
48 disabled={props.disabled}
49 onPress={props.onPress}
50 className="flex-row items-center gap-4 p-4 disabled:opacity-40"
51 >
52 {icon}
53 <Text className={cn("flex-1 text-lg", textClassName)}>{props.label}</Text>
54 {spinner}
55 </Pressable>
56 );