Open History to see the last commit
1import type { ReactNode } from "react";
2import { Platform, useWindowDimensions, View } from "react-native";
3
4import { cn } from "../../lib/cn";
5import { AppText } from "./AppText";
6import { SymbolView, type AppSymbolName } from "./AppSymbol";
7
8export interface ListRowContentProps {
9 readonly icon?: AppSymbolName;
10 readonly label: string;
11 readonly description?: string;
12 readonly detail?: string;
13 readonly disabled?: boolean;
14}
15
16export function ListRowLayout({
17 icon,
18 label,
19 description,
20 detail,
21 disabled,
22 accessory,
23 tone = "default",
24}: ListRowContentProps & { readonly accessory?: ReactNode; readonly tone?: "default" | "danger" }) {
25 const { fontScale } = useWindowDimensions();
26 const stackDetail = fontScale >= 1.5;
27 return (
28 <View
29 className={cn(
30 "min-h-14 flex-row items-center gap-3 px-4 py-3",
31 description && "min-h-18",
32 disabled && "opacity-45",
33 )}
34 >
35 {icon ? (
36 <View className="size-6 items-center justify-center">
37 <SymbolView
38 name={icon}
39 size={Platform.OS === "android" ? 24 : 22}
40 tintColorClassName={tone === "danger" ? "accent-danger-foreground" : "accent-icon"}
41 type="monochrome"
42 weight="regular"
43 />
44 </View>
45 ) : null}
46 <View className="min-w-0 flex-1 gap-1">
47 <AppText
48 textRole="body"
49 className={tone === "danger" ? "text-danger-foreground" : "text-foreground"}
50 >
51 {label}
52 </AppText>
53 {description ? (
54 <AppText textRole="footnote" className="text-foreground-muted">
55 {description}
56 </AppText>
57 ) : null}
58 {detail && stackDetail ? (
59 <AppText textRole="footnote" className="text-foreground-muted">
60 {detail}
61 </AppText>
62 ) : null}
63 </View>
64 {detail && !stackDetail ? (
65 <AppText
66 textRole="footnote"
67 className="max-w-[40%] shrink text-right text-foreground-muted"
68 numberOfLines={1}
69 ellipsizeMode="middle"
70 >
71 {detail}
72 </AppText>
73 ) : null}
74 {accessory}
75 </View>
76 );
77}