Open History to see the last commit
1import { NativeAppBarExample } from "./NativeAppBarExample";
2import { Toast } from "../../components/ui/Toast";
3import { Progress } from "../../components/ui/Progress";
4import { useNavigation } from "@react-navigation/native";
5import { useRef, useState } from "react";
6import { View, type TextInputInstance } from "react-native";
7
8import { AppText, AppTextInput } from "../../components/ui/AppText";
9import { Sheet } from "../../components/ui/Sheet";
10import { Chip } from "../../components/ui/Chip";
11import { Menu } from "../../components/ui/Menu";
12import { ListActionRow } from "../../components/ui/ListActionRow";
13import { ListChoiceRow } from "../../components/ui/ListChoiceRow";
14import { ListRow } from "../../components/ui/ListRow";
15import { ListSection } from "../../components/ui/ListSection";
16import { ListToggleRow } from "../../components/ui/ListToggleRow";
17import { Button } from "../../components/ui/Button";
18import { IconButton } from "../../components/ui/IconButton";
19import { FloatingActionButton } from "../../components/ui/FloatingActionButton";
20import { SearchField } from "../../components/ui/SearchField";
21import { Notice } from "../../components/ui/Notice";
22import { NumberField } from "../../components/ui/NumberField";
23import { AppBar } from "../../components/ui/AppBar";
24import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
25import { SegmentedControl } from "../../components/ui/SegmentedControl";
26import { SliderRow } from "../../components/ui/SliderRow";
27import * as Dialog from "../../components/ui/Dialog";
28import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
29import { MOBILE_THEME_IDS } from "../../lib/mobileTheme";
30
31const CHOICES = [
32 { value: "overview", label: "Overview" },
33 { value: "activity", label: "Activity" },
34];
35
36/** Development-only, real controls with local state and no environment commands. */
37export function ComponentCatalogScreen() {
38 const navigation = useNavigation();
39 const appearance = useAppearancePreferences();
40 const [page, setPage] = useState("controls");
41 const [tab, setTab] = useState("overview");
42 const [enabled, setEnabled] = useState(true);
43 const [value, setValue] = useState(3);
44 const [text, setText] = useState("");
45 const [search, setSearch] = useState("");
46 const [sheet, setSheet] = useState(false);
47 const [notice, setNotice] = useState(true);
48 const searchRef = useRef<TextInputInstance>(null);
49 const announceAction = () => setNotice(true);
50 const confirm = () => {
51 Dialog.confirm({
52 title: "Discard changes?",
53 message: "This example only changes local catalog state.",
54 confirmText: "Discard",
55 destructive: true,
56 onConfirm: () => setText(""),
57 });
58 };
59 return (
60 <View className="flex-1 bg-screen">
61 <AppBar title="UI components" onBack={() => navigation.goBack()} sidebar={false} />
62 <ScreenScrollView
63 contentInsetAdjustmentBehavior="automatic"
64 contentContainerStyle={{ padding: 16, gap: 20, paddingBottom: 40 }}
65 keyboardShouldPersistTaps="handled"
66 >
67 <View className="gap-3">
68 <AppText className="text-sm text-foreground-muted">Theme preview</AppText>
69 <View className="flex-row flex-wrap gap-2">
70 {MOBILE_THEME_IDS.filter(
71 (id) => id !== "material-you" || appearance.systemColorsAvailable,
72 ).map((id) => (
73 <Chip
74 key={id}
75 label={id}
76 selected={appearance.themeId === id}
77 onPress={() => appearance.setThemeIdForBothAppearances(id)}
78 />
79 ))}
80 </View>
81 <SegmentedControl
82 options={[
83 { value: "light", label: "Light" },
84 { value: "dark", label: "Dark" },
85 ]}
86 selected={appearance.themeAppearance}
87 onSelect={appearance.setThemeMode}
88 size="compact"
89 />
90 </View>
91 <SegmentedControl
92 options={[
93 { value: "controls", label: "Controls" },
94 { value: "forms", label: "Forms" },
95 { value: "feedback", label: "Feedback" },
96 ]}
97 selected={page}
98 onSelect={setPage}
99 size="compact"
100 />
101 {page === "controls" ? (
102 <>
103 <View className="gap-3">
104 <AppText className="text-lg font-t3-semibold">Lists and selection</AppText>
105 <ListSection>
106 <ListRow icon="folder" label="Projects" detail="4" onPress={() => setSheet(true)} />
107 <ListToggleRow
108 icon="bell.badge"
109 label="Notifications"
110 description="Updates from your active threads"
111 value={enabled}
112 onValueChange={setEnabled}
113 />
114 <ListChoiceRow label="Selected option" selected onPress={announceAction} />
115 <ListActionRow
116 icon="trash"
117 label="Discard changes"
118 tone="danger"
119 onPress={confirm}
120 />
121 </ListSection>
122 <SegmentedControl
123 options={CHOICES}
124 selected={tab}
125 onSelect={setTab}
126 size="compact"
127 role="tab"
128 />
129 <View className="flex-row flex-wrap gap-2">
130 <Chip
131 label="Selected filter"
132 selected={enabled}
133 onPress={() => setEnabled(!enabled)}
134 />
135 <Chip label="Label" size="small" />
136 <Chip label="Disabled" disabled onPress={announceAction} />
137 </View>
138 </View>
139 <View className="gap-3">
140 <NativeAppBarExample />
141 <AppText className="text-lg font-t3-semibold">Buttons</AppText>
142 <View className="flex-row flex-wrap gap-2">
143 <Button label="Primary" tone="primary" onPress={announceAction} />
144 <Button label="Secondary" onPress={announceAction} />
145 <Button label="Contrast" tone="contrast" onPress={announceAction} />
146 </View>
147 <View className="flex-row flex-wrap gap-2">
148 <Button label="Disabled" disabled onPress={announceAction} />
149 <Button label="Loading" loading onPress={announceAction} />
150 <IconButton
151 accessibilityLabel="Open example sheet"
152 icon="plus"
153 variant="tonal"
154 onPress={() => setSheet(true)}
155 />
156 </View>
157 </View>
158 </>
159 ) : null}
160 {page === "forms" ? (
161 <View className="gap-3">
162 <AppText className="text-lg font-t3-semibold">Forms</AppText>
163 <AppTextInput
164 accessibilityLabel="Example name"
165 placeholder="Name"
166 value={text}
167 onChangeText={setText}
168 />
169 <View className="flex-row">
170 <SearchField
171 inputRef={searchRef}
172 accessibilityLabel="Search examples"
173 clearAccessibilityLabel="Clear examples search"
174 placeholder="Search examples"
175 value={search}
176 onChangeText={setSearch}
177 autoFocus={false}
178 />
179 </View>
180 <View className="flex-row items-center justify-between">
181 <AppText>Count</AppText>
182 <NumberField
183 label="Example count"
184 min={1}
185 max={10}
186 value={value}
187 onValueChange={setValue}
188 />
189 </View>
190 <ListSection>
191 <SliderRow
192 icon="textformat.size"
193 label="Example slider"
194 valueLabel={String(value)}
195 min={1}
196 max={10}
197 step={1}
198 value={value}
199 onChange={setValue}
200 />
201 </ListSection>
202 </View>
203 ) : null}
204 {page === "feedback" ? (
205 <View className="gap-3">
206 <AppText className="text-lg font-t3-semibold">Feedback and presentation</AppText>
207 <Notice message="This action could not finish. Try again." tone="danger" />
208 {notice ? (
209 <Toast
210 message="Changes are ready to review."
211 tone="success"
212 action={{
213 label: "Undo",
214 onPress: () => {
215 setNotice(false);
216 setText("Restored example");
217 },
218 }}
219 onDismiss={() => setNotice(false)}
220 />
221 ) : (
222 <Button label="Show notice" onPress={announceAction} />
223 )}
224 <View className="flex-row flex-wrap gap-2">
225 <Button label="Sheet" onPress={() => setSheet(true)} />
226 <Button label="Dialog" onPress={confirm} />
227 <Button
228 label="Alert"
229 onPress={() =>
230 Dialog.alert("Example alert", "Choose an action.", [
231 {
232 text: "More info",
233 onPress: () =>
234 Dialog.alert("More information", "This second alert stays open."),
235 },
236 { text: "Cancel", style: "cancel" },
237 { text: "Continue", onPress: announceAction },
238 ])
239 }
240 />
241 <Button
242 label="Prompt"
243 onPress={() =>
244 Dialog.prompt({
245 title: "Rename example",
246 initialValue: text,
247 confirmText: "Rename",
248 onConfirm: setText,
249 })
250 }
251 />
252 <Menu
253 title="Example menu"
254 actions={[
255 { id: "copy", title: "Copy", image: "doc.on.doc" },
256 { id: "discard", title: "Discard", attributes: { destructive: true } },
257 ]}
258 onPressAction={({ nativeEvent }) =>
259 nativeEvent.event === "discard" ? confirm() : announceAction()
260 }
261 >
262 <Chip label="Menu" trailingIcon="chevron.down" />
263 </Menu>
264 </View>
265 <Progress value={0.6} label="Example upload" />
266 <Progress label="Connecting" />
267 <View className="items-start">
268 <FloatingActionButton
269 label="New thread"
270 icon="plus"
271 variant="extended"
272 tone="primary"
273 onPress={() => setSheet(true)}
274 />
275 </View>
276 </View>
277 ) : null}
278 </ScreenScrollView>
279 {sheet ? (
280 <Sheet title="Example sheet" onClose={() => setSheet(false)}>
281 <ScreenScrollView
282 contentInsetAdjustmentBehavior="automatic"
283 contentContainerClassName="p-4"
284 >
285 <ListSection>
286 <ListChoiceRow
287 label="Overview"
288 selected={tab === "overview"}
289 onPress={() => setTab("overview")}
290 />
291 <ListChoiceRow
292 label="Activity"
293 selected={tab === "activity"}
294 onPress={() => setTab("activity")}
295 />
296 </ListSection>
297 </ScreenScrollView>
298 </Sheet>
299 ) : null}
300 </View>
301 );
302}