Open History to see the last commit
1import type { ReactNode } from "react";
2import { Pressable, View } from "react-native";
3import { AppText as Text } from "../../components/AppText";
4import { SymbolView } from "../../components/AppSymbol";
5import { cn } from "../../lib/cn";
6import type { ModelOption } from "../../lib/modelOptions";
7
8export type ModelRowProps = {
9 readonly option: ModelOption;
10 readonly selected: boolean;
11 readonly onPress: () => void;
12 readonly isFavorite: boolean;
13 readonly favoritesLoaded: boolean;
14 readonly onToggleFavorite: () => void;
15 readonly isFirst: boolean;
16 readonly isLast: boolean;
17};
18
19export type ChoiceRowProps = {
20 readonly label: string;
21 readonly description?: string;
22 readonly selected: boolean;
23 readonly onPress: () => void;
24 readonly isLast: boolean;
25};
26
27type RowSelectionProps = {
28 readonly leadingSelection?: ReactNode;
29 readonly trailingSelection?: ReactNode;
30 readonly minimumHeight?: number;
31};
32
33export function ModelRowContent(
34 props: ModelRowProps &
35 RowSelectionProps & {
36 readonly labelNumberOfLines: number;
37 readonly selectedClassName?: string;
38 },
39) {
40 return (
41 <View
42 style={props.minimumHeight === undefined ? undefined : { minHeight: props.minimumHeight }}
43 className={cn(
44 "mx-4 min-h-11 flex-row items-center gap-2 bg-grouped-card px-4",
45 props.selectedClassName,
46 props.isFirst && "rounded-t-2xl",
47 props.isLast ? "rounded-b-2xl" : "border-b border-border-subtle",
48 )}
49 >
50 <Pressable
51 accessibilityLabel={[props.option.label, props.option.subtitle].filter(Boolean).join(", ")}
52 accessibilityRole="radio"
53 accessibilityState={{
54 checked: props.selected,
55 disabled: props.option.isUnavailable === true,
56 }}
57 className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2 active:opacity-70"
58 disabled={props.option.isUnavailable}
59 onPress={props.onPress}
60 >
61 {props.leadingSelection}
62 <View className="min-w-0 flex-1">
63 <View className="flex-row items-center gap-2">
64 <Text
65 className="min-w-0 shrink text-base font-t3-medium text-foreground"
66 numberOfLines={props.labelNumberOfLines}
67 >
68 {props.option.label}
69 </Text>
70 {props.option.isDefault ? (
71 <View className="rounded-md bg-subtle-strong px-1.5 py-0.5">
72 <Text className="text-3xs font-t3-bold text-foreground-muted">Default</Text>
73 </View>
74 ) : null}
75 {props.option.isLegacy ? (
76 <View className="rounded-md bg-subtle px-1.5 py-0.5">
77 <Text className="text-3xs font-t3-bold text-foreground-muted">Legacy</Text>
78 </View>
79 ) : null}
80 {props.option.isUnavailable ? (
81 <Text className="text-xs text-foreground">Unavailable</Text>
82 ) : null}
83 </View>
84 {props.option.subtitle ? (
85 <Text
86 className="text-xs text-foreground-muted"
87 numberOfLines={props.labelNumberOfLines}
88 >
89 {props.option.subtitle}
90 </Text>
91 ) : null}
92 </View>
93 {props.trailingSelection}
94 </Pressable>
95 <Pressable
96 accessibilityLabel={`${props.isFavorite ? "Remove from" : "Add to"} favorites: ${
97 props.option.providerLabel
98 }, ${props.option.label}`}
99 accessibilityRole="button"
100 accessibilityState={{ disabled: !props.favoritesLoaded, selected: props.isFavorite }}
101 className="min-h-11 min-w-11 items-center justify-center"
102 disabled={!props.favoritesLoaded}
103 onPress={props.onToggleFavorite}
104 >
105 <SymbolView
106 name={props.isFavorite ? "star.fill" : "star"}
107 size={18}
108 tintColorClassName={props.isFavorite ? "accent-icon" : "accent-icon-subtle"}
109 type="monochrome"
110 />
111 </Pressable>
112 </View>
113 );
114}
115
116/** Single option inside a submenu panel. */
117export function ChoiceRowContent(props: ChoiceRowProps & RowSelectionProps) {
118 return (
119 <Pressable
120 accessibilityLabel={props.description ? `${props.label}. ${props.description}` : props.label}
121 accessibilityRole="radio"
122 accessibilityState={{ checked: props.selected }}
123 onPress={props.onPress}
124 style={props.minimumHeight === undefined ? undefined : { minHeight: props.minimumHeight }}
125 className={cn(
126 "min-h-14 flex-row items-center gap-3 bg-grouped-card px-4 py-3 active:bg-subtle",
127 !props.isLast && "border-b border-border-subtle",
128 )}
129 >
130 {props.leadingSelection}
131 <View className="min-w-0 flex-1 gap-0.5">
132 <Text className="text-base font-t3-medium text-foreground">{props.label}</Text>
133 {props.description ? (
134 <Text className="text-sm leading-5 text-foreground-muted">{props.description}</Text>
135 ) : null}
136 </View>
137 {props.trailingSelection}
138 </Pressable>
139 );
140}