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

MaterialListRow.tsx

57 lines2.0 KB

1import type { ComponentProps, ReactNode } from "react";
2import { Platform, Pressable, View } from "react-native";
3​
4import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
5import { cn } from "../lib/cn";
6import { AppText } from "./AppText";
7import { SymbolView } from "./AppSymbol";
8​
9/** Shared geometry for Material navigation and selection lists. Group rows in one card. */
10export function MaterialListRow({
11 title,
12 subtitle,
13 leading,
14 trailing,
15 className,
16 ...props
17}: Omit<ComponentProps<typeof Pressable>, "children"> & {
18 readonly title: string;
19 readonly subtitle?: string | null;
20 readonly leading?: ReactNode;
21 readonly trailing?: ReactNode;
22}) {
23 const { themeVariables } = useAppearancePreferences();
24 return (
25 <Pressable
26 accessibilityRole="button"
27 accessibilityLabel={[title, subtitle].filter(Boolean).join(", ")}
28 android_ripple={{ color: themeVariables["--color-subtle-strong"] }}
29 // Give the scroll view time to claim drags before starting the ripple.
30 unstable_pressDelay={Platform.OS === "android" ? 50 : undefined}
31 {...props}
32 className={cn(
33 "flex-row items-center gap-4 overflow-hidden bg-card px-4 py-3",
34 subtitle ? "min-h-18" : "min-h-14",
35 props.disabled && "opacity-45",
36 className,
37 )}
38 >
39 {leading ? <View className="size-6 items-center justify-center">{leading}</View> : null}
40 <View className="min-w-0 flex-1 gap-1">
41 <AppText className="text-base text-foreground" numberOfLines={2}>
42 {title}
43 </AppText>
44 {subtitle ? (
45 <AppText className="text-sm text-foreground-muted" numberOfLines={2}>
46 {subtitle}
47 </AppText>
48 ) : null}
49 </View>
50 {trailing !== undefined ? (
51 trailing
52 ) : !props.disabled ? (
53 <SymbolView name="chevron.right" size={16} tintColorClassName="accent-chevron" />
54 ) : null}
55 </Pressable>
56 );