@marktiderman/genesis-ui-native 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/chunk-BAU4YQZV.js +760 -0
  2. package/dist/chunk-BAU4YQZV.js.map +1 -0
  3. package/dist/chunk-DGUM43GV.js +10 -0
  4. package/dist/chunk-DGUM43GV.js.map +1 -0
  5. package/dist/chunk-HNIEFTEL.js +43 -0
  6. package/dist/chunk-HNIEFTEL.js.map +1 -0
  7. package/dist/chunk-N4WHTQIO.js +20 -0
  8. package/dist/chunk-N4WHTQIO.js.map +1 -0
  9. package/dist/chunk-OHZD7KRO.js +11 -0
  10. package/dist/chunk-OHZD7KRO.js.map +1 -0
  11. package/dist/chunk-PTJ2KCLM.js +160 -0
  12. package/dist/chunk-PTJ2KCLM.js.map +1 -0
  13. package/dist/chunk-TXJT55JC.js +2213 -0
  14. package/dist/chunk-TXJT55JC.js.map +1 -0
  15. package/dist/chunk-ULS7I6ZS.js +183 -0
  16. package/dist/chunk-ULS7I6ZS.js.map +1 -0
  17. package/dist/chunk-ZVF6PONU.js +522 -0
  18. package/dist/chunk-ZVF6PONU.js.map +1 -0
  19. package/dist/components/index.d.ts +908 -0
  20. package/dist/components/index.js +8 -0
  21. package/dist/components/index.js.map +1 -0
  22. package/dist/data/index.d.ts +117 -0
  23. package/dist/data/index.js +770 -0
  24. package/dist/data/index.js.map +1 -0
  25. package/dist/hooks/index.d.ts +31 -0
  26. package/dist/hooks/index.js +5 -0
  27. package/dist/hooks/index.js.map +1 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.js +11 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/layouts/index.d.ts +364 -0
  32. package/dist/layouts/index.js +8 -0
  33. package/dist/layouts/index.js.map +1 -0
  34. package/dist/utils.d.ts +5 -0
  35. package/dist/utils.js +4 -0
  36. package/dist/utils.js.map +1 -0
  37. package/package.json +127 -0
  38. package/src/components/__tests__/accordion.test.tsx +122 -0
  39. package/src/components/__tests__/chip-group.test.tsx +45 -0
  40. package/src/components/__tests__/combobox.test.tsx +97 -0
  41. package/src/components/__tests__/drawer.test.tsx +98 -0
  42. package/src/components/__tests__/empty-state.test.tsx +66 -0
  43. package/src/components/__tests__/header-card.test.tsx +31 -0
  44. package/src/components/__tests__/layout.test.tsx +109 -0
  45. package/src/components/__tests__/list-item.test.tsx +31 -0
  46. package/src/components/__tests__/number-input.test.tsx +46 -0
  47. package/src/components/__tests__/pagination.test.tsx +43 -0
  48. package/src/components/__tests__/search-bar.test.tsx +41 -0
  49. package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
  50. package/src/components/__tests__/slider.test.tsx +134 -0
  51. package/src/components/__tests__/stepper.test.tsx +25 -0
  52. package/src/components/__tests__/toast.test.tsx +63 -0
  53. package/src/components/accordion.tsx +223 -0
  54. package/src/components/alert.tsx +131 -0
  55. package/src/components/avatar.tsx +68 -0
  56. package/src/components/badge.tsx +80 -0
  57. package/src/components/button.tsx +118 -0
  58. package/src/components/card.tsx +120 -0
  59. package/src/components/checkbox.tsx +60 -0
  60. package/src/components/chip-group.tsx +127 -0
  61. package/src/components/combobox.tsx +137 -0
  62. package/src/components/date-time-picker.tsx +127 -0
  63. package/src/components/dialog.tsx +131 -0
  64. package/src/components/drawer.tsx +131 -0
  65. package/src/components/dropdown-menu.tsx +133 -0
  66. package/src/components/empty-state.tsx +161 -0
  67. package/src/components/header-card.tsx +116 -0
  68. package/src/components/index.ts +259 -0
  69. package/src/components/inline-alert.tsx +150 -0
  70. package/src/components/input.tsx +51 -0
  71. package/src/components/label.tsx +35 -0
  72. package/src/components/layout/box.tsx +115 -0
  73. package/src/components/layout/flex.ts +24 -0
  74. package/src/components/layout/grid.tsx +73 -0
  75. package/src/components/layout/index.ts +27 -0
  76. package/src/components/layout/inline.tsx +63 -0
  77. package/src/components/layout/spacing.ts +116 -0
  78. package/src/components/layout/stack.tsx +58 -0
  79. package/src/components/list-item.tsx +108 -0
  80. package/src/components/number-input.tsx +119 -0
  81. package/src/components/pagination.tsx +132 -0
  82. package/src/components/popover.tsx +198 -0
  83. package/src/components/progress.tsx +50 -0
  84. package/src/components/radio-group.tsx +92 -0
  85. package/src/components/refresh-control.tsx +73 -0
  86. package/src/components/search-bar.tsx +128 -0
  87. package/src/components/section-list.tsx +54 -0
  88. package/src/components/segmented-control.tsx +79 -0
  89. package/src/components/select.tsx +178 -0
  90. package/src/components/separator.tsx +31 -0
  91. package/src/components/sheet.tsx +192 -0
  92. package/src/components/skeleton.tsx +104 -0
  93. package/src/components/slider.tsx +223 -0
  94. package/src/components/stepper.tsx +96 -0
  95. package/src/components/switch.tsx +35 -0
  96. package/src/components/tabs.tsx +147 -0
  97. package/src/components/text.tsx +62 -0
  98. package/src/components/textarea.tsx +52 -0
  99. package/src/components/toast.tsx +228 -0
  100. package/src/components/toggle.tsx +85 -0
  101. package/src/components/tooltip.tsx +104 -0
  102. package/src/data/NativeDataFilters.tsx +100 -0
  103. package/src/data/NativeDataPageShell.tsx +111 -0
  104. package/src/data/NativeDetailPanel.tsx +130 -0
  105. package/src/data/NativeEmptyState.tsx +46 -0
  106. package/src/data/NativeResourceForm.tsx +157 -0
  107. package/src/data/NativeResourceFormField.tsx +280 -0
  108. package/src/data/NativeResourcePage.tsx +505 -0
  109. package/src/data/index.ts +9 -0
  110. package/src/hooks/index.ts +16 -0
  111. package/src/hooks/use-genesis-extension.ts +81 -0
  112. package/src/hooks/use-reduced-motion.ts +32 -0
  113. package/src/hooks/use-theme-mode.ts +31 -0
  114. package/src/index.ts +5 -0
  115. package/src/layouts/__tests__/auth.test.tsx +150 -0
  116. package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
  117. package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
  118. package/src/layouts/__tests__/screen-container.test.tsx +79 -0
  119. package/src/layouts/__tests__/settings-page.test.tsx +107 -0
  120. package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
  121. package/src/layouts/auth.tsx +352 -0
  122. package/src/layouts/index.ts +61 -0
  123. package/src/layouts/nav-bar.tsx +200 -0
  124. package/src/layouts/notifications-page.tsx +274 -0
  125. package/src/layouts/screen-container.tsx +213 -0
  126. package/src/layouts/settings-page.tsx +195 -0
  127. package/src/layouts/settings-sub-page.tsx +183 -0
  128. package/src/nativewind.d.ts +40 -0
  129. package/src/utils.ts +6 -0
@@ -0,0 +1,274 @@
1
+ /**
2
+ * NotificationsPage — feed-style notifications list.
3
+ *
4
+ * Composes:
5
+ * - SectionList grouped by relative date (Today / Yesterday / Earlier)
6
+ * - Pull-to-refresh
7
+ * - Empty state slot (auto-rendered when `items` is empty)
8
+ * - Mark-all-read action surfaced via `headerRight` helper
9
+ * - Per-row "mark read" action exposed via the consumer's row press
10
+ * (swipe-to-mark-read is documented as Maestro / E2E only because it
11
+ * requires gesture-handler — consumers wire it via their own row
12
+ * wrapper; this layout exposes the unread state via row props).
13
+ *
14
+ * Layer-3 customization: `headerTitle`, `headerLeft`, `headerRight`,
15
+ * `headerOptions`. Use `getNotificationsPageStackOptions()` to wire a
16
+ * "Mark all read" action via `headerRight` automatically.
17
+ *
18
+ * @stability Beta
19
+ */
20
+ import { type ReactNode } from "react";
21
+ import {
22
+ Pressable,
23
+ RefreshControl,
24
+ SectionList,
25
+ Text,
26
+ View,
27
+ } from "react-native";
28
+ import { SafeAreaView } from "react-native-safe-area-context";
29
+ import { NativeSectionListHeader } from "../components/section-list";
30
+ import { NativeListItem } from "../components/list-item";
31
+ import { NativeEmptyState } from "../components/empty-state";
32
+ import { cn } from "../utils";
33
+ import {
34
+ composeHeaderOptions,
35
+ type ScreenHeaderProps,
36
+ } from "./screen-container";
37
+
38
+ export interface NotificationItem {
39
+ /** Stable id. */
40
+ id: string;
41
+ /** Headline text. */
42
+ title: string;
43
+ /** Optional secondary line. */
44
+ body?: string;
45
+ /** ISO date string OR Date instance. Used for grouping. */
46
+ timestamp: string | Date;
47
+ /** Read flag. Unread rows render with emphasis (a leading dot). */
48
+ unread?: boolean;
49
+ /** Optional press handler — typically opens the related screen. */
50
+ onPress?: () => void;
51
+ /** Optional leading slot (avatar / icon). */
52
+ leading?: ReactNode;
53
+ /** testID override. Falls back to `notifications-row-<id>`. */
54
+ testID?: string;
55
+ }
56
+
57
+ export interface NotificationsPageProps extends ScreenHeaderProps {
58
+ /** Notification items. Empty array → empty state. */
59
+ items: NotificationItem[];
60
+ /** When true, the SectionList shows the refresh spinner. */
61
+ refreshing?: boolean;
62
+ /** Pull-to-refresh handler. */
63
+ onRefresh?: () => void | Promise<void>;
64
+ /** Mark-all-read handler. When provided, exposes a header action. */
65
+ onMarkAllRead?: () => void;
66
+ /** Override the auto-rendered empty state. */
67
+ emptyState?: ReactNode;
68
+ /** Optional override of the empty-state title. */
69
+ emptyTitle?: string;
70
+ /** Optional override of the empty-state body copy. */
71
+ emptyBody?: string;
72
+ /** Override root container styling. */
73
+ className?: string;
74
+ /** testID on the root container. Default `"notifications-page"`. */
75
+ testID?: string;
76
+ }
77
+
78
+ /**
79
+ * Compose `<Stack.Screen options={...}>` for a NotificationsPage. Wires
80
+ * a "Mark all read" action via `headerRight` when `onMarkAllRead` is
81
+ * passed.
82
+ */
83
+ export function getNotificationsPageStackOptions(props: {
84
+ headerTitle?: string;
85
+ onMarkAllRead?: () => void;
86
+ large?: boolean;
87
+ scrollEdgeBehavior?: ScreenHeaderProps["scrollEdgeBehavior"];
88
+ headerLeft?: ScreenHeaderProps["headerLeft"];
89
+ headerRight?: ScreenHeaderProps["headerRight"];
90
+ headerOptions?: ScreenHeaderProps["headerOptions"];
91
+ }): Record<string, unknown> {
92
+ const {
93
+ headerTitle,
94
+ onMarkAllRead,
95
+ large,
96
+ scrollEdgeBehavior,
97
+ headerLeft,
98
+ headerRight,
99
+ headerOptions,
100
+ } = props;
101
+
102
+ const resolvedHeaderRight =
103
+ headerRight ??
104
+ (onMarkAllRead
105
+ ? () => (
106
+ <Pressable
107
+ testID="notifications-mark-all-read"
108
+ accessibilityRole="button"
109
+ accessibilityLabel="Mark all read"
110
+ onPress={onMarkAllRead}
111
+ hitSlop={8}
112
+ className="min-h-[44px] justify-center px-3"
113
+ >
114
+ <Text className="text-base text-primary">Mark all read</Text>
115
+ </Pressable>
116
+ )
117
+ : undefined);
118
+
119
+ return composeHeaderOptions({
120
+ headerTitle: headerTitle ?? "Notifications",
121
+ headerLeft,
122
+ headerRight: resolvedHeaderRight,
123
+ large: large ?? true,
124
+ scrollEdgeBehavior: scrollEdgeBehavior ?? "match",
125
+ headerOptions,
126
+ });
127
+ }
128
+
129
+ // Returns a stable section title for a timestamp. Computes against the
130
+ // caller's local clock for consistency with the rest of the app.
131
+ function bucketFor(ts: string | Date, now = new Date()): string {
132
+ const d = typeof ts === "string" ? new Date(ts) : ts;
133
+ const startOfDay = (date: Date) => {
134
+ const x = new Date(date);
135
+ x.setHours(0, 0, 0, 0);
136
+ return x.getTime();
137
+ };
138
+ const today = startOfDay(now);
139
+ const yesterday = today - 24 * 60 * 60 * 1000;
140
+ const day = startOfDay(d);
141
+ if (day === today) return "Today";
142
+ if (day === yesterday) return "Yesterday";
143
+ return "Earlier";
144
+ }
145
+
146
+ interface Section {
147
+ title: string;
148
+ data: NotificationItem[];
149
+ }
150
+
151
+ function groupByDate(items: NotificationItem[], now = new Date()): Section[] {
152
+ const map = new Map<string, NotificationItem[]>();
153
+ // Iterate in input order so stable sort within bucket.
154
+ for (const item of items) {
155
+ const bucket = bucketFor(item.timestamp, now);
156
+ const arr = map.get(bucket) ?? [];
157
+ arr.push(item);
158
+ map.set(bucket, arr);
159
+ }
160
+ // Stable section order: Today / Yesterday / Earlier.
161
+ const order = ["Today", "Yesterday", "Earlier"];
162
+ return order
163
+ .filter((title) => map.has(title))
164
+ .map((title) => ({
165
+ title,
166
+ data: map.get(title) ?? [],
167
+ }));
168
+ }
169
+
170
+ // Expose internal helpers for unit tests via a side-channel export.
171
+ export const __test = { bucketFor, groupByDate };
172
+
173
+ export function NotificationsPage({
174
+ items,
175
+ refreshing,
176
+ onRefresh,
177
+ emptyState,
178
+ emptyTitle,
179
+ emptyBody,
180
+ className,
181
+ testID = "notifications-page",
182
+ }: NotificationsPageProps) {
183
+ // Note: header props (headerTitle, headerLeft, headerRight, large,
184
+ // scrollEdgeBehavior, headerOptions) are accepted on the type for API
185
+ // ergonomics but consumed by getNotificationsPageStackOptions() at the
186
+ // consumer's <Stack.Screen> level — not by this component.
187
+
188
+ const sections = groupByDate(items);
189
+
190
+ if (items.length === 0) {
191
+ return (
192
+ <SafeAreaView
193
+ testID={testID}
194
+ edges={["left", "right", "bottom"]}
195
+ className={cn("flex-1 bg-background", className)}
196
+ >
197
+ {emptyState ?? (
198
+ <NativeEmptyState
199
+ variant="first-run"
200
+ title={emptyTitle ?? "No notifications"}
201
+ body={
202
+ emptyBody ??
203
+ "When you get a notification, it'll show up here."
204
+ }
205
+ testID={`${testID}-empty`}
206
+ />
207
+ )}
208
+ </SafeAreaView>
209
+ );
210
+ }
211
+
212
+ return (
213
+ <SafeAreaView
214
+ testID={testID}
215
+ edges={["left", "right", "bottom"]}
216
+ className={cn("flex-1 bg-background", className)}
217
+ >
218
+ <SectionList<NotificationItem, Section>
219
+ testID={`${testID}-list`}
220
+ sections={sections}
221
+ keyExtractor={(item) => item.id}
222
+ renderSectionHeader={({ section }) => (
223
+ <NativeSectionListHeader title={section.title} />
224
+ )}
225
+ renderItem={({ item }) => (
226
+ <NativeListItem
227
+ testID={item.testID ?? `${testID}-row-${item.id}`}
228
+ title={item.title}
229
+ subtitle={item.body}
230
+ leading={
231
+ item.leading ?? (
232
+ <UnreadDot
233
+ unread={!!item.unread}
234
+ testID={`${testID}-row-${item.id}-unread`}
235
+ />
236
+ )
237
+ }
238
+ onPress={item.onPress}
239
+ />
240
+ )}
241
+ ItemSeparatorComponent={() => <View className="h-px bg-border ml-4" />}
242
+ refreshControl={
243
+ onRefresh ? (
244
+ <RefreshControl
245
+ testID={`${testID}-refresh`}
246
+ refreshing={!!refreshing}
247
+ onRefresh={onRefresh}
248
+ />
249
+ ) : undefined
250
+ }
251
+ contentContainerClassName="pb-8"
252
+ />
253
+ </SafeAreaView>
254
+ );
255
+ }
256
+
257
+ function UnreadDot({
258
+ unread,
259
+ testID,
260
+ }: {
261
+ unread: boolean;
262
+ testID?: string;
263
+ }) {
264
+ if (!unread) {
265
+ return <View className="h-2 w-2" testID={testID} />;
266
+ }
267
+ return (
268
+ <View
269
+ testID={testID}
270
+ accessibilityLabel="Unread"
271
+ className="h-2 w-2 rounded-full bg-primary"
272
+ />
273
+ );
274
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * ScreenContainer — Layer-2 page primitive.
3
+ *
4
+ * Wires the chrome every layout needs without imposing layout structure:
5
+ * - Safe-area edges (configurable via `safeAreaEdges`)
6
+ * - StatusBar style (light / dark / auto)
7
+ * - Scroll vs static body
8
+ * - Tokens-aware background (`bg-background`)
9
+ *
10
+ * Header customization is delegated: pass `headerLeft`, `headerRight`,
11
+ * `large`, `scrollEdgeBehavior`, `safeAreaEdges`, plus any direct
12
+ * `headerOptions` passthrough to `<Stack.Screen options={...} />`. We
13
+ * **do not** render the navigation header ourselves — Expo Router /
14
+ * React Navigation render the platform-native header. Consumer either:
15
+ *
16
+ * (a) Wraps the screen in `<ScreenContainer>` and ALSO declares
17
+ * `<Stack.Screen options={headerOptionsFromProps(props)} />` at the
18
+ * top of the screen (we export a helper `composeHeaderOptions` for
19
+ * this), OR
20
+ * (b) Imports `<NavBarTitle>` / `<NavBarSearchBar>` / `<NavBarSaveButton>`
21
+ * sub-primitives and threads them through `headerLeft` / `headerRight`
22
+ * options manually.
23
+ *
24
+ * The Layer-3/4 layouts (SettingsPage, etc.) compose ScreenContainer + a
25
+ * helper that wires Stack.Screen so consumers get the 3-line ergonomics.
26
+ *
27
+ * @stability Beta
28
+ */
29
+ import type { ReactNode } from "react";
30
+ import { ScrollView, StatusBar, View } from "react-native";
31
+ import { SafeAreaView } from "react-native-safe-area-context";
32
+ import { cn } from "../utils";
33
+ import { useThemeMode } from "../hooks/use-theme-mode";
34
+
35
+ export type SafeAreaEdge = "top" | "bottom" | "left" | "right";
36
+
37
+ export type ScrollEdgeBehavior = "match" | "transparent" | "opaque";
38
+
39
+ export interface ScreenContainerProps {
40
+ /** Screen body. Pass any node tree. */
41
+ children: ReactNode;
42
+ /** When `true`, the body is wrapped in a vertical ScrollView. Default `false`. */
43
+ scroll?: boolean;
44
+ /**
45
+ * SafeAreaView edges. Defaults to `["left", "right"]` — top/bottom are
46
+ * normally handled by the navigation header / tab bar.
47
+ */
48
+ safeAreaEdges?: SafeAreaEdge[];
49
+ /**
50
+ * StatusBar appearance. `"auto"` follows the resolved theme mode.
51
+ */
52
+ statusBar?: "light" | "dark" | "auto" | "hidden";
53
+ /**
54
+ * Force light or dark theme on this screen regardless of OS preference.
55
+ * Default `"system"` (follow OS).
56
+ */
57
+ themeMode?: "light" | "dark" | "system";
58
+ /** Override root container className. */
59
+ className?: string;
60
+ /** Override inner content container className (the ScrollView's contentContainerClassName when scroll=true). */
61
+ contentClassName?: string;
62
+ /**
63
+ * `keyboardShouldPersistTaps` for the inner ScrollView. Default `"handled"`.
64
+ * Only used when `scroll` is true.
65
+ */
66
+ keyboardShouldPersistTaps?: "always" | "never" | "handled";
67
+ /** testID on the root container. */
68
+ testID?: string;
69
+ }
70
+
71
+ /**
72
+ * Layer-3 named-prop slots that layouts can accept and forward to
73
+ * `composeHeaderOptions()` for `<Stack.Screen options={...}>`.
74
+ */
75
+ export interface ScreenHeaderProps {
76
+ /** Custom header title. Falls back to `<Stack.Screen name>` mapping. */
77
+ headerTitle?: string;
78
+ /** Custom node rendered on the left of the nav bar. */
79
+ headerLeft?: () => ReactNode;
80
+ /** Custom node rendered on the right of the nav bar. */
81
+ headerRight?: () => ReactNode;
82
+ /** When true, iOS uses large-title mode + scroll-edge appearance. */
83
+ large?: boolean;
84
+ /** iOS scroll-edge behavior. `"match"` collapses, `"transparent"` always transparent, `"opaque"` always opaque. */
85
+ scrollEdgeBehavior?: ScrollEdgeBehavior;
86
+ /** Direct passthrough merged INTO the resolved options object. Wins over named props. */
87
+ headerOptions?: Record<string, unknown>;
88
+ }
89
+
90
+ /**
91
+ * Compose a `<Stack.Screen options={...}>` object from Layer-3 named
92
+ * props + a direct `headerOptions` passthrough. Layouts call this and
93
+ * pass the result to `<Stack.Screen>` so the host's expo-router stack
94
+ * renders a platform-native large title / scroll-edge appearance.
95
+ *
96
+ * Usage (in a layout primitive):
97
+ *
98
+ * const opts = composeHeaderOptions({
99
+ * headerTitle: "Settings",
100
+ * large: true,
101
+ * scrollEdgeBehavior: "match",
102
+ * headerOptions: rest.headerOptions,
103
+ * });
104
+ * return <><Stack.Screen options={opts} /><ScreenContainer>...</ScreenContainer></>;
105
+ */
106
+ export function composeHeaderOptions(
107
+ props: ScreenHeaderProps,
108
+ ): Record<string, unknown> {
109
+ const {
110
+ headerTitle,
111
+ headerLeft,
112
+ headerRight,
113
+ large,
114
+ scrollEdgeBehavior,
115
+ headerOptions,
116
+ } = props;
117
+
118
+ const opts: Record<string, unknown> = {};
119
+ if (headerTitle !== undefined) opts.title = headerTitle;
120
+ if (headerLeft) opts.headerLeft = headerLeft;
121
+ if (headerRight) opts.headerRight = headerRight;
122
+ if (large) {
123
+ // iOS large-title mode. Android falls back to standard.
124
+ opts.headerLargeTitle = true;
125
+ if (scrollEdgeBehavior === "transparent") {
126
+ opts.headerTransparent = true;
127
+ } else if (scrollEdgeBehavior === "opaque") {
128
+ opts.headerLargeTitleShadowVisible = true;
129
+ }
130
+ }
131
+ // Direct passthrough wins.
132
+ if (headerOptions) {
133
+ Object.assign(opts, headerOptions);
134
+ }
135
+ return opts;
136
+ }
137
+
138
+ const DEFAULT_EDGES: SafeAreaEdge[] = ["left", "right"];
139
+
140
+ /**
141
+ * Resolve the StatusBar bar style from the user's `statusBar` setting +
142
+ * the resolved theme mode. `"auto"` follows theme; explicit overrides
143
+ * win; anything else falls back to `"default"`.
144
+ */
145
+ function resolveBarStyle(
146
+ statusBar: "light" | "dark" | "auto" | "hidden",
147
+ resolvedMode: "light" | "dark",
148
+ ): "default" | "light-content" | "dark-content" {
149
+ if (statusBar === "auto") {
150
+ return resolvedMode === "dark" ? "light-content" : "dark-content";
151
+ }
152
+ if (statusBar === "light") return "light-content";
153
+ if (statusBar === "dark") return "dark-content";
154
+ return "default";
155
+ }
156
+
157
+ export function ScreenContainer({
158
+ children,
159
+ scroll = false,
160
+ safeAreaEdges = DEFAULT_EDGES,
161
+ statusBar = "auto",
162
+ themeMode = "system",
163
+ className,
164
+ contentClassName,
165
+ keyboardShouldPersistTaps = "handled",
166
+ testID,
167
+ }: ScreenContainerProps) {
168
+ const osMode = useThemeMode();
169
+ const resolvedMode = themeMode === "system" ? osMode : themeMode;
170
+ const barStyle = resolveBarStyle(statusBar, resolvedMode);
171
+
172
+ const body = scroll ? (
173
+ <ScrollView
174
+ testID={testID ? `${testID}-scroll` : undefined}
175
+ keyboardShouldPersistTaps={keyboardShouldPersistTaps}
176
+ contentInsetAdjustmentBehavior="automatic"
177
+ contentContainerClassName={cn("flex-grow", contentClassName)}
178
+ >
179
+ {children}
180
+ </ScrollView>
181
+ ) : (
182
+ <View
183
+ testID={testID ? `${testID}-body` : undefined}
184
+ className={cn("flex-1", contentClassName)}
185
+ >
186
+ {children}
187
+ </View>
188
+ );
189
+
190
+ return (
191
+ <SafeAreaView
192
+ testID={testID ?? "screen-container"}
193
+ edges={safeAreaEdges}
194
+ className={cn("flex-1 bg-background", className)}
195
+ >
196
+ {statusBar !== "hidden" ? (
197
+ <StatusBar
198
+ barStyle={
199
+ barStyle as
200
+ | "default"
201
+ | "light-content"
202
+ | "dark-content"
203
+ }
204
+ translucent
205
+ backgroundColor="transparent"
206
+ />
207
+ ) : (
208
+ <StatusBar hidden />
209
+ )}
210
+ {body}
211
+ </SafeAreaView>
212
+ );
213
+ }
@@ -0,0 +1,195 @@
1
+ /**
2
+ * SettingsPage — top-level settings layout.
3
+ *
4
+ * Composes `<ScreenContainer scroll>` underneath, renders a sectioned
5
+ * `ListItem` list, and surfaces an optional dangerous-action footer
6
+ * (e.g., "Sign out", "Delete account") in destructive tone.
7
+ *
8
+ * Why ship a layout: every consumer rebuilds this list with the same
9
+ * three pieces (sections → rows → footer). Genesis ships the assembly so
10
+ * consumers compose, not rebuild.
11
+ *
12
+ * Layer-3 customization: pass `headerTitle`, `headerLeft`, `headerRight`,
13
+ * `large`, `scrollEdgeBehavior`, OR a direct `headerOptions={...}`
14
+ * passthrough. The composed options are rendered via the consumer's own
15
+ * `<Stack.Screen options={...}>` — see `getStackScreenOptions()` helper.
16
+ *
17
+ * Layer-2 escape hatch: drop down to `<ScreenContainer>` if the layout
18
+ * structure doesn't fit (see standards/usage-doctrine.md).
19
+ *
20
+ * @stability Beta
21
+ */
22
+ import { Fragment, type ReactNode } from "react";
23
+ import { View } from "react-native";
24
+ import { NativeListItem, NativeListItemDivider } from "../components/list-item";
25
+ import { NativeSectionListHeader } from "../components/section-list";
26
+ import { NativeText } from "../components/text";
27
+ import { NativeButton } from "../components/button";
28
+ import { cn } from "../utils";
29
+ import {
30
+ ScreenContainer,
31
+ composeHeaderOptions,
32
+ type ScreenHeaderProps,
33
+ } from "./screen-container";
34
+
35
+ export interface SettingsPageRow {
36
+ /** Stable id for keying. */
37
+ id: string;
38
+ title: string;
39
+ subtitle?: string;
40
+ /** Leading slot (icon, avatar, etc.). */
41
+ leading?: ReactNode;
42
+ /** Trailing slot (badge, switch, version string, etc.). */
43
+ trailing?: ReactNode;
44
+ /** When true, renders a chevron at the row end (drill-in affordance). */
45
+ showChevron?: boolean;
46
+ /** Press handler — required for chevron rows. */
47
+ onPress?: () => void;
48
+ /** Disable the row (greyed + non-pressable). */
49
+ disabled?: boolean;
50
+ /** testID override for the row. Falls back to `settings-row-<id>`. */
51
+ testID?: string;
52
+ }
53
+
54
+ export interface SettingsPageSection {
55
+ /** Stable id for keying. */
56
+ id: string;
57
+ /** Optional uppercase section header. Pass `null` to skip the header for an unlabeled section. */
58
+ title?: string;
59
+ /** Optional caption rendered under the rows (compliance text, hint, etc.). */
60
+ footnote?: string;
61
+ /** Rows in render order. */
62
+ rows: SettingsPageRow[];
63
+ }
64
+
65
+ export interface SettingsPageProps extends ScreenHeaderProps {
66
+ /** Sectioned content. Order is preserved. */
67
+ sections: SettingsPageSection[];
68
+ /**
69
+ * Optional dangerous-action row(s) shown after the last section in a
70
+ * destructive-tone footer. Typical: "Sign out", "Delete account".
71
+ */
72
+ dangerousActions?: {
73
+ label: string;
74
+ onPress: () => void;
75
+ /** When true, renders with extra emphasis. Default `false`. */
76
+ emphasized?: boolean;
77
+ testID?: string;
78
+ }[];
79
+ /** Override root container styling. */
80
+ className?: string;
81
+ /** testID on the root container. Default `"settings-page"`. */
82
+ testID?: string;
83
+ /** Pass-through children rendered ABOVE the first section (e.g., a profile card). */
84
+ children?: ReactNode;
85
+ }
86
+
87
+ /**
88
+ * Convenience helper for callers that want to wire `<Stack.Screen options={...}>`
89
+ * without re-importing composeHeaderOptions. Defaults `large: true` and
90
+ * `scrollEdgeBehavior: "match"` to match the Apple HIG large-title settings
91
+ * pattern out of the box.
92
+ */
93
+ export function getSettingsPageStackOptions(
94
+ props: ScreenHeaderProps & { headerTitle?: string },
95
+ ): Record<string, unknown> {
96
+ return composeHeaderOptions({
97
+ headerTitle: props.headerTitle ?? "Settings",
98
+ large: props.large ?? true,
99
+ scrollEdgeBehavior: props.scrollEdgeBehavior ?? "match",
100
+ headerLeft: props.headerLeft,
101
+ headerRight: props.headerRight,
102
+ headerOptions: props.headerOptions,
103
+ });
104
+ }
105
+
106
+ export function SettingsPage({
107
+ sections,
108
+ dangerousActions,
109
+ className,
110
+ testID = "settings-page",
111
+ children,
112
+ }: SettingsPageProps) {
113
+ // Note: header props (headerTitle, headerLeft, headerRight, etc.) are
114
+ // accepted on the type for API ergonomics but consumed by
115
+ // getSettingsPageStackOptions() at the consumer's <Stack.Screen> level.
116
+
117
+ return (
118
+ <ScreenContainer
119
+ scroll
120
+ safeAreaEdges={["left", "right", "bottom"]}
121
+ testID={testID}
122
+ contentClassName="pb-8"
123
+ className={className}
124
+ >
125
+ {children ? <View className="px-4 pt-2">{children}</View> : null}
126
+
127
+ {sections.map((section) => (
128
+ <View
129
+ key={section.id}
130
+ testID={`${testID}-section-${section.id}`}
131
+ className="mt-6"
132
+ >
133
+ {section.title ? (
134
+ <NativeSectionListHeader
135
+ title={section.title}
136
+ testID={`${testID}-section-${section.id}-header`}
137
+ />
138
+ ) : null}
139
+ <View className="border-y border-border bg-background">
140
+ {section.rows.map((row, rowIndex) => (
141
+ <Fragment key={row.id}>
142
+ <NativeListItem
143
+ testID={row.testID ?? `${testID}-row-${row.id}`}
144
+ title={row.title}
145
+ subtitle={row.subtitle}
146
+ leading={row.leading}
147
+ trailing={row.trailing}
148
+ showChevron={row.showChevron}
149
+ onPress={row.onPress}
150
+ disabled={row.disabled}
151
+ />
152
+ {rowIndex < section.rows.length - 1 ? (
153
+ <NativeListItemDivider className="ml-4" />
154
+ ) : null}
155
+ </Fragment>
156
+ ))}
157
+ </View>
158
+ {section.footnote ? (
159
+ <NativeText
160
+ preset="body-sm"
161
+ className="px-4 pt-2 text-muted-foreground"
162
+ >
163
+ {section.footnote}
164
+ </NativeText>
165
+ ) : null}
166
+ </View>
167
+ ))}
168
+
169
+ {dangerousActions && dangerousActions.length > 0 ? (
170
+ <View
171
+ testID={`${testID}-dangerous-actions`}
172
+ className={cn("mt-8 gap-2 px-4")}
173
+ >
174
+ {dangerousActions.map((action) => (
175
+ <NativeButton
176
+ key={action.label}
177
+ testID={action.testID ?? `${testID}-danger-${slug(action.label)}`}
178
+ variant={action.emphasized ? "destructive" : "outline"}
179
+ onPress={action.onPress}
180
+ >
181
+ {action.label}
182
+ </NativeButton>
183
+ ))}
184
+ </View>
185
+ ) : null}
186
+ </ScreenContainer>
187
+ );
188
+ }
189
+
190
+ function slug(s: string): string {
191
+ return s
192
+ .toLowerCase()
193
+ .replace(/[^a-z0-9]+/g, "-")
194
+ .replace(/^-|-$/g, "");
195
+ }