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

MaterialListRow.tsx

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