anhedral 0.15.0 → 0.16.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 (308) hide show
  1. package/README.md +29 -38
  2. package/assets/stack/ai-schema.ts.txt +5 -0
  3. package/assets/stack/ai.ts.txt +30 -0
  4. package/assets/stack/api-index.ts.txt +15 -0
  5. package/assets/stack/auth-features.ts.txt +4 -0
  6. package/assets/stack/auth-journal.json.txt +13 -0
  7. package/assets/stack/auth-migration.sql.txt +53 -0
  8. package/assets/stack/auth-routes.ts.txt +11 -0
  9. package/assets/stack/auth-schema.ts.txt +64 -0
  10. package/assets/stack/auth-snapshot.json.txt +346 -0
  11. package/assets/stack/auth.ts.txt +32 -0
  12. package/assets/stack/billing-mode.ts.txt +8 -0
  13. package/assets/stack/billing-schema.ts.txt +11 -0
  14. package/assets/stack/desktop.rs.txt +21 -0
  15. package/assets/stack/entitlement-guard.ts.txt +32 -0
  16. package/assets/stack/entitlements.ts.txt +8 -0
  17. package/assets/stack/events-schema.ts.txt +12 -0
  18. package/assets/stack/events.ts.txt +59 -0
  19. package/assets/stack/mobile-auth.ts.txt +25 -0
  20. package/assets/stack/mobile-billing.tsx.txt +63 -0
  21. package/assets/stack/mobile-session.tsx.txt +83 -0
  22. package/assets/stack/native-button.tsx.txt +108 -0
  23. package/assets/stack/native-global.css.txt +4 -0
  24. package/assets/stack/native-lib-utils.ts.txt +5 -0
  25. package/assets/stack/native-metro.config.js.txt +6 -0
  26. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  27. package/assets/stack/native-tailwind.config.js.txt +73 -0
  28. package/assets/stack/native-text.tsx.txt +89 -0
  29. package/assets/stack/purchases.ts.txt +65 -0
  30. package/assets/stack/revenuecat.ts.txt +88 -0
  31. package/assets/stack/rtc-schema.ts.txt +10 -0
  32. package/assets/stack/rtc.ts.txt +122 -0
  33. package/assets/stack/security.ts.txt +31 -0
  34. package/assets/stack/storage.ts.txt +36 -0
  35. package/assets/stack/stripe.ts.txt +126 -0
  36. package/assets/stack/web-sign-in.tsx.txt +51 -0
  37. package/assets/ui/LICENSE.react-native-reusables +21 -0
  38. package/assets/ui/UPSTREAM.json +7 -1
  39. package/assets/ui/catalog.json +891 -0
  40. package/assets/ui/extensions/registry.json +6 -0
  41. package/assets/ui/native/_controls.tsx +521 -0
  42. package/assets/ui/native/_core.tsx +118 -0
  43. package/assets/ui/native/_data.tsx +200 -0
  44. package/assets/ui/native/_display.tsx +453 -0
  45. package/assets/ui/native/_feedback.tsx +242 -0
  46. package/assets/ui/native/_legacy-dialog.tsx +38 -0
  47. package/assets/ui/native/_motion.tsx +520 -0
  48. package/assets/ui/native/_overlay.tsx +402 -0
  49. package/assets/ui/native/_selection.tsx +366 -0
  50. package/assets/ui/native/accordion.tsx +1 -0
  51. package/assets/ui/native/alert-dialog.tsx +11 -0
  52. package/assets/ui/native/alert.tsx +1 -0
  53. package/assets/ui/native/aspect-ratio.tsx +1 -0
  54. package/assets/ui/native/attachment.tsx +8 -0
  55. package/assets/ui/native/avatar.tsx +8 -0
  56. package/assets/ui/native/badge.tsx +1 -0
  57. package/assets/ui/native/breadcrumb.tsx +9 -0
  58. package/assets/ui/native/bubble.tsx +1 -0
  59. package/assets/ui/native/button-group.tsx +1 -0
  60. package/assets/ui/native/button.tsx +2 -1
  61. package/assets/ui/native/calendar.tsx +170 -0
  62. package/assets/ui/native/card.tsx +16 -5
  63. package/assets/ui/native/carousel.tsx +1 -0
  64. package/assets/ui/native/chart.tsx +193 -0
  65. package/assets/ui/native/checkbox.tsx +1 -0
  66. package/assets/ui/native/code-block.tsx +137 -0
  67. package/assets/ui/native/collapsible.tsx +1 -0
  68. package/assets/ui/native/combobox.tsx +1 -0
  69. package/assets/ui/native/command.tsx +11 -0
  70. package/assets/ui/native/context-menu.tsx +16 -0
  71. package/assets/ui/native/data-table.tsx +1 -0
  72. package/assets/ui/native/date-picker.tsx +43 -0
  73. package/assets/ui/native/dialog.tsx +14 -74
  74. package/assets/ui/native/direction.tsx +1 -0
  75. package/assets/ui/native/drawer.tsx +10 -0
  76. package/assets/ui/native/dropdown-menu.tsx +16 -0
  77. package/assets/ui/native/empty.tsx +8 -0
  78. package/assets/ui/native/field.tsx +13 -0
  79. package/assets/ui/native/hover-card.tsx +1 -0
  80. package/assets/ui/native/input-group.tsx +8 -0
  81. package/assets/ui/native/input-otp.tsx +1 -0
  82. package/assets/ui/native/input.tsx +2 -1
  83. package/assets/ui/native/item.tsx +12 -0
  84. package/assets/ui/native/kbd.tsx +1 -0
  85. package/assets/ui/native/marker.tsx +1 -0
  86. package/assets/ui/native/menubar.tsx +17 -0
  87. package/assets/ui/native/message-scroller.tsx +6 -0
  88. package/assets/ui/native/message.tsx +10 -0
  89. package/assets/ui/native/native-select.tsx +1 -0
  90. package/assets/ui/native/navigation-menu.tsx +10 -0
  91. package/assets/ui/native/pagination.tsx +9 -0
  92. package/assets/ui/native/popover.tsx +1 -0
  93. package/assets/ui/native/progress.tsx +1 -0
  94. package/assets/ui/native/questionnaire.tsx +130 -0
  95. package/assets/ui/native/radio-group.tsx +1 -0
  96. package/assets/ui/native/registry.json +1103 -0
  97. package/assets/ui/native/resizable.tsx +1 -0
  98. package/assets/ui/native/scroll-area.tsx +1 -0
  99. package/assets/ui/native/select.tsx +11 -0
  100. package/assets/ui/native/separator.tsx +1 -0
  101. package/assets/ui/native/sheet.tsx +10 -0
  102. package/assets/ui/native/sidebar.tsx +22 -0
  103. package/assets/ui/native/skeleton.tsx +1 -0
  104. package/assets/ui/native/slider.tsx +1 -0
  105. package/assets/ui/native/spinner.tsx +1 -0
  106. package/assets/ui/native/switch.tsx +1 -0
  107. package/assets/ui/native/table.tsx +10 -0
  108. package/assets/ui/native/tabs.tsx +1 -0
  109. package/assets/ui/native/textarea.tsx +1 -0
  110. package/assets/ui/native/toast.tsx +11 -0
  111. package/assets/ui/native/toggle-group.tsx +1 -0
  112. package/assets/ui/native/toggle.tsx +1 -0
  113. package/assets/ui/native/tooltip.tsx +1 -0
  114. package/assets/ui/native/trace.tsx +20 -0
  115. package/assets/ui/native/typography.tsx +15 -0
  116. package/dist/bin.js +7 -12
  117. package/dist/capabilities.d.ts +4 -33
  118. package/dist/capabilities.js +2 -66
  119. package/dist/capability-catalog.d.ts +83 -0
  120. package/dist/capability-catalog.js +121 -0
  121. package/dist/capability-command.d.ts +3 -0
  122. package/dist/capability-command.js +188 -0
  123. package/dist/capability-editor.d.ts +17 -0
  124. package/dist/capability-editor.js +97 -0
  125. package/dist/capability-recipes.d.ts +4 -0
  126. package/dist/capability-recipes.js +520 -0
  127. package/dist/capability-references.d.ts +4 -0
  128. package/dist/capability-references.js +7 -0
  129. package/dist/cli-commands.d.ts +1 -2
  130. package/dist/cli-commands.js +10 -104
  131. package/dist/cli-output.d.ts +1 -2
  132. package/dist/cli-output.js +6 -251
  133. package/dist/command-schema.js +39 -322
  134. package/dist/dependencies.d.ts +29 -6
  135. package/dist/dependencies.js +61 -14
  136. package/dist/index.d.ts +1 -42
  137. package/dist/index.js +1 -27
  138. package/dist/platforms/mobile.js +1 -20
  139. package/dist/platforms/web.d.ts +1 -1
  140. package/dist/platforms/web.js +27 -75
  141. package/dist/project-config.d.ts +2 -13
  142. package/dist/project-config.js +10 -82
  143. package/dist/registry/options.js +1 -5
  144. package/dist/registry/resolve.d.ts +1 -1
  145. package/dist/registry/resolve.js +2 -10
  146. package/dist/registry/usage.js +3 -9
  147. package/dist/scaffold/backend.js +0 -3
  148. package/dist/scaffold/database.js +2 -1
  149. package/dist/scaffold/documentation.js +82 -20
  150. package/dist/scaffold/expo-runtime.js +3 -4
  151. package/dist/scaffold/native-ui.js +12 -7
  152. package/dist/scaffold/stack-documentation.js +1 -1
  153. package/dist/scaffold/storage.d.ts +2 -0
  154. package/dist/scaffold/storage.js +21 -0
  155. package/dist/scaffold/workspace.js +26 -21
  156. package/dist/stack-registry.d.ts +2 -8
  157. package/dist/stack-registry.js +11 -87
  158. package/dist/standard.js +1 -11
  159. package/dist/ui-catalog.d.ts +26 -0
  160. package/dist/ui-catalog.js +31 -0
  161. package/dist/ui-command.d.ts +3 -0
  162. package/dist/ui-command.js +219 -0
  163. package/dist/ui-project.d.ts +22 -0
  164. package/dist/ui-project.js +110 -0
  165. package/dist/version.d.ts +1 -1
  166. package/dist/version.js +1 -1
  167. package/docs/anhedral-stack.md +4 -20
  168. package/docs/capabilities.md +110 -0
  169. package/docs/native-ui.md +102 -0
  170. package/docs/software-factory.md +16 -44
  171. package/docs/stack-standard.md +11 -60
  172. package/docs/ui.md +33 -0
  173. package/docs/verification.md +191 -0
  174. package/package.json +19 -18
  175. package/dist/access.d.ts +0 -10
  176. package/dist/access.js +0 -93
  177. package/dist/auth-schema-snapshot.d.ts +0 -346
  178. package/dist/auth-schema-snapshot.js +0 -347
  179. package/dist/auth-schema.d.ts +0 -1
  180. package/dist/auth-schema.js +0 -57
  181. package/dist/capability-contract.d.ts +0 -47
  182. package/dist/capability-contract.js +0 -129
  183. package/dist/catalog-model.d.ts +0 -24
  184. package/dist/catalog-model.js +0 -1
  185. package/dist/catalog-registration.d.ts +0 -16
  186. package/dist/catalog-registration.js +0 -22
  187. package/dist/catalog-snapshot.d.ts +0 -5
  188. package/dist/catalog-snapshot.js +0 -97
  189. package/dist/cli-delivery.d.ts +0 -3
  190. package/dist/cli-delivery.js +0 -112
  191. package/dist/cloudflare.d.ts +0 -25
  192. package/dist/cloudflare.js +0 -226
  193. package/dist/delivery-evidence.d.ts +0 -62
  194. package/dist/delivery-evidence.js +0 -157
  195. package/dist/delivery.d.ts +0 -82
  196. package/dist/delivery.js +0 -489
  197. package/dist/inspector-model.d.ts +0 -123
  198. package/dist/inspector-model.js +0 -1
  199. package/dist/integration-service-readers.d.ts +0 -12
  200. package/dist/integration-service-readers.js +0 -92
  201. package/dist/lifecycle-model.d.ts +0 -15
  202. package/dist/lifecycle-model.js +0 -20
  203. package/dist/lifecycle.d.ts +0 -11
  204. package/dist/lifecycle.js +0 -91
  205. package/dist/management.d.ts +0 -3
  206. package/dist/management.js +0 -47
  207. package/dist/mobile-delivery.d.ts +0 -77
  208. package/dist/mobile-delivery.js +0 -370
  209. package/dist/project-catalog.d.ts +0 -41
  210. package/dist/project-catalog.js +0 -288
  211. package/dist/project-inspector.d.ts +0 -4
  212. package/dist/project-inspector.js +0 -671
  213. package/dist/project-lifecycle.d.ts +0 -25
  214. package/dist/project-lifecycle.js +0 -57
  215. package/dist/project-state.d.ts +0 -47
  216. package/dist/project-state.js +0 -480
  217. package/dist/provider-auth.d.ts +0 -41
  218. package/dist/provider-auth.js +0 -180
  219. package/dist/provider-readiness.d.ts +0 -30
  220. package/dist/provider-readiness.js +0 -85
  221. package/dist/providers/adapters.d.ts +0 -17
  222. package/dist/providers/adapters.js +0 -103
  223. package/dist/providers/api.d.ts +0 -29
  224. package/dist/providers/api.js +0 -253
  225. package/dist/providers/config.d.ts +0 -15
  226. package/dist/providers/config.js +0 -136
  227. package/dist/providers/definitions.d.ts +0 -115
  228. package/dist/providers/definitions.js +0 -42
  229. package/dist/providers/provision.d.ts +0 -24
  230. package/dist/providers/provision.js +0 -76
  231. package/dist/providers/receipts.d.ts +0 -20
  232. package/dist/providers/receipts.js +0 -56
  233. package/dist/providers/recovery-verification.d.ts +0 -7
  234. package/dist/providers/recovery-verification.js +0 -52
  235. package/dist/providers/recovery.d.ts +0 -30
  236. package/dist/providers/recovery.js +0 -34
  237. package/dist/providers/runtime.d.ts +0 -10
  238. package/dist/providers/runtime.js +0 -234
  239. package/dist/providers/schema.d.ts +0 -28
  240. package/dist/providers/schema.js +0 -49
  241. package/dist/providers/state.d.ts +0 -55
  242. package/dist/providers/state.js +0 -283
  243. package/dist/provision.d.ts +0 -47
  244. package/dist/provision.js +0 -208
  245. package/dist/r2-service-data.d.ts +0 -2
  246. package/dist/r2-service-data.js +0 -136
  247. package/dist/readiness.d.ts +0 -23
  248. package/dist/readiness.js +0 -117
  249. package/dist/registry/add.d.ts +0 -24
  250. package/dist/registry/add.js +0 -210
  251. package/dist/registry/bootstrap.d.ts +0 -3
  252. package/dist/registry/bootstrap.js +0 -5
  253. package/dist/registry/commands.d.ts +0 -3
  254. package/dist/registry/commands.js +0 -83
  255. package/dist/registry/preview.d.ts +0 -11
  256. package/dist/registry/preview.js +0 -91
  257. package/dist/registry/receipt.d.ts +0 -3
  258. package/dist/registry/receipt.js +0 -68
  259. package/dist/repository.d.ts +0 -24
  260. package/dist/repository.js +0 -96
  261. package/dist/scaffold/auth.d.ts +0 -2
  262. package/dist/scaffold/auth.js +0 -76
  263. package/dist/scaffold/billing-config.d.ts +0 -1
  264. package/dist/scaffold/billing-config.js +0 -73
  265. package/dist/scaffold/billing-contracts.d.ts +0 -2
  266. package/dist/scaffold/billing-contracts.js +0 -48
  267. package/dist/scaffold/billing-providers.d.ts +0 -1
  268. package/dist/scaffold/billing-providers.js +0 -249
  269. package/dist/scaffold/billing-schema.d.ts +0 -1
  270. package/dist/scaffold/billing-schema.js +0 -34
  271. package/dist/scaffold/billing-security.d.ts +0 -1
  272. package/dist/scaffold/billing-security.js +0 -46
  273. package/dist/scaffold/billing-server.d.ts +0 -1
  274. package/dist/scaffold/billing-server.js +0 -139
  275. package/dist/scaffold/billing-store.d.ts +0 -1
  276. package/dist/scaffold/billing-store.js +0 -72
  277. package/dist/scaffold/billing.d.ts +0 -2
  278. package/dist/scaffold/billing.js +0 -208
  279. package/dist/scaffold/expo-auth.d.ts +0 -3
  280. package/dist/scaffold/expo-auth.js +0 -203
  281. package/dist/scaffold/expo-billing.d.ts +0 -3
  282. package/dist/scaffold/expo-billing.js +0 -257
  283. package/dist/scaffold/integrations.d.ts +0 -2
  284. package/dist/scaffold/integrations.js +0 -11
  285. package/dist/scaffold/managed-email.d.ts +0 -3
  286. package/dist/scaffold/managed-email.js +0 -47
  287. package/dist/scaffold/password-reset.d.ts +0 -1
  288. package/dist/scaffold/password-reset.js +0 -99
  289. package/dist/scaffold/private-files.d.ts +0 -2
  290. package/dist/scaffold/private-files.js +0 -78
  291. package/dist/scaffold/web-billing.d.ts +0 -2
  292. package/dist/scaffold/web-billing.js +0 -48
  293. package/dist/service-deletion.d.ts +0 -29
  294. package/dist/service-deletion.js +0 -195
  295. package/dist/service-descriptor.d.ts +0 -10
  296. package/dist/service-descriptor.js +0 -71
  297. package/dist/service-model.d.ts +0 -49
  298. package/dist/service-model.js +0 -8
  299. package/dist/service-operations.d.ts +0 -29
  300. package/dist/service-operations.js +0 -48
  301. package/dist/service-readers.d.ts +0 -8
  302. package/dist/service-readers.js +0 -216
  303. package/dist/services-command.d.ts +0 -39
  304. package/dist/services-command.js +0 -96
  305. package/dist/ship.d.ts +0 -35
  306. package/dist/ship.js +0 -107
  307. package/docs/assets/anhedral-stack-light.png +0 -0
  308. package/docs/assets/anhedral-stack.png +0 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry.json",
3
+ "name": "anhedral-native",
4
+ "homepage": "https://anhedral.com",
5
+ "items": []
6
+ }
@@ -0,0 +1,521 @@
1
+ import { createContext, useContext, useId, useRef, type ReactNode } from 'react';
2
+ import {
3
+ View,
4
+ Pressable,
5
+ Switch as NativeSwitch,
6
+ TextInput,
7
+ type ViewProps,
8
+ type TextInputProps,
9
+ type PressableProps,
10
+ } from 'react-native';
11
+ import { useTheme } from '../theme';
12
+ import { Box, LabelText, Muted, Surface, content, plainText, row, useControllable } from './_core';
13
+ import { Button, type ButtonProps } from './button';
14
+ import { Input } from './input';
15
+
16
+ export function Checkbox({
17
+ checked,
18
+ defaultChecked = false,
19
+ onCheckedChange,
20
+ disabled,
21
+ children,
22
+ accessibilityLabel,
23
+ style,
24
+ ...props
25
+ }: Omit<PressableProps, 'children'> & {
26
+ checked?: boolean | 'indeterminate';
27
+ defaultChecked?: boolean;
28
+ onCheckedChange?: (checked: boolean) => void;
29
+ children?: ReactNode;
30
+ }) {
31
+ const [value, set] = useControllable<boolean | 'indeterminate'>(checked, defaultChecked, (next) =>
32
+ onCheckedChange?.(next === true),
33
+ );
34
+ const { colors } = useTheme();
35
+ return (
36
+ <Pressable
37
+ {...props}
38
+ accessibilityRole="checkbox"
39
+ accessibilityLabel={accessibilityLabel ?? (plainText(children) || undefined)}
40
+ accessibilityState={{
41
+ checked: value === 'indeterminate' ? 'mixed' : value,
42
+ disabled: !!disabled,
43
+ }}
44
+ disabled={disabled}
45
+ onPress={() => set(value !== true)}
46
+ style={(state) => [
47
+ row({ minHeight: 44, opacity: disabled ? 0.5 : 1 }),
48
+ typeof style === 'function' ? style(state) : style,
49
+ ]}
50
+ >
51
+ <View
52
+ style={{
53
+ width: 22,
54
+ height: 22,
55
+ borderRadius: 4,
56
+ borderWidth: 1,
57
+ borderColor: colors.primary,
58
+ backgroundColor: value ? colors.primary : colors.background,
59
+ alignItems: 'center',
60
+ justifyContent: 'center',
61
+ }}
62
+ >
63
+ <LabelText style={{ color: colors['primary-foreground'] }}>
64
+ {value === 'indeterminate' ? '−' : value ? '✓' : ''}
65
+ </LabelText>
66
+ </View>
67
+ {content(children)}
68
+ </Pressable>
69
+ );
70
+ }
71
+ export function Switch({
72
+ checked,
73
+ defaultChecked = false,
74
+ onCheckedChange,
75
+ ...props
76
+ }: Omit<React.ComponentProps<typeof NativeSwitch>, 'value' | 'onValueChange'> & {
77
+ checked?: boolean;
78
+ defaultChecked?: boolean;
79
+ onCheckedChange?: (checked: boolean) => void;
80
+ }) {
81
+ const [value, set] = useControllable(checked, defaultChecked, onCheckedChange);
82
+ const { colors } = useTheme();
83
+ return (
84
+ <NativeSwitch
85
+ accessible
86
+ trackColor={{ false: colors.input, true: colors.primary }}
87
+ {...props}
88
+ accessibilityRole="switch"
89
+ accessibilityState={{ checked: value, disabled: !!props.disabled }}
90
+ value={value}
91
+ onValueChange={set}
92
+ />
93
+ );
94
+ }
95
+ export function Toggle({
96
+ pressed,
97
+ defaultPressed = false,
98
+ onPressedChange,
99
+ disabled,
100
+ ...props
101
+ }: ButtonProps & {
102
+ pressed?: boolean;
103
+ defaultPressed?: boolean;
104
+ onPressedChange?: (pressed: boolean) => void;
105
+ }) {
106
+ const [value, set] = useControllable(pressed, defaultPressed, onPressedChange);
107
+ return (
108
+ <Button
109
+ {...props}
110
+ disabled={disabled}
111
+ variant={value ? 'secondary' : 'ghost'}
112
+ accessibilityState={{ selected: value, disabled: !!disabled }}
113
+ onPress={() => set(!value)}
114
+ />
115
+ );
116
+ }
117
+ type GroupValue = {
118
+ value: string[];
119
+ set: (value: string[]) => void;
120
+ multiple: boolean;
121
+ disabled?: boolean;
122
+ };
123
+ const ToggleContext = createContext<GroupValue | null>(null);
124
+ export function ToggleGroup({
125
+ type = 'single',
126
+ value,
127
+ defaultValue,
128
+ onValueChange,
129
+ disabled,
130
+ children,
131
+ style,
132
+ ...props
133
+ }: ViewProps & {
134
+ type?: 'single' | 'multiple';
135
+ value?: string | string[];
136
+ defaultValue?: string | string[];
137
+ onValueChange?: (value: string | string[]) => void;
138
+ disabled?: boolean;
139
+ }) {
140
+ const asArray = (input?: string | string[]) =>
141
+ Array.isArray(input) ? input : input ? [input] : [];
142
+ const [selected, set] = useControllable(
143
+ value === undefined ? undefined : asArray(value),
144
+ asArray(defaultValue),
145
+ (next) => onValueChange?.(type === 'multiple' ? next : (next[0] ?? '')),
146
+ );
147
+ return (
148
+ <ToggleContext.Provider
149
+ value={{ value: selected, set, multiple: type === 'multiple', disabled }}
150
+ >
151
+ <View {...props} style={row(style)}>
152
+ {children}
153
+ </View>
154
+ </ToggleContext.Provider>
155
+ );
156
+ }
157
+ export function ToggleGroupItem({ value, disabled, ...props }: ButtonProps & { value: string }) {
158
+ const group = useContext(ToggleContext);
159
+ if (!group) throw Error('ToggleGroupItem requires ToggleGroup.');
160
+ const selected = group.value.includes(value);
161
+ return (
162
+ <Toggle
163
+ {...props}
164
+ disabled={disabled || group.disabled}
165
+ pressed={selected}
166
+ onPressedChange={() =>
167
+ group.set(
168
+ group.multiple
169
+ ? selected
170
+ ? group.value.filter((item) => item !== value)
171
+ : [...group.value, value]
172
+ : selected
173
+ ? []
174
+ : [value],
175
+ )
176
+ }
177
+ />
178
+ );
179
+ }
180
+ const RadioContext = createContext<{
181
+ value: string;
182
+ set: (value: string) => void;
183
+ disabled?: boolean;
184
+ } | null>(null);
185
+ export function RadioGroup({
186
+ value,
187
+ defaultValue = '',
188
+ onValueChange,
189
+ disabled,
190
+ ...props
191
+ }: ViewProps & {
192
+ value?: string;
193
+ defaultValue?: string;
194
+ onValueChange?: (value: string) => void;
195
+ disabled?: boolean;
196
+ }) {
197
+ const [selected, set] = useControllable(value, defaultValue, onValueChange);
198
+ return (
199
+ <RadioContext.Provider value={{ value: selected, set, disabled }}>
200
+ <Box accessibilityRole="radiogroup" {...props} />
201
+ </RadioContext.Provider>
202
+ );
203
+ }
204
+ export function RadioGroupItem({
205
+ value,
206
+ children,
207
+ disabled,
208
+ ...props
209
+ }: Omit<ButtonProps, 'children'> & { value: string; children?: ReactNode }) {
210
+ const group = useContext(RadioContext);
211
+ if (!group) throw Error('RadioGroupItem requires RadioGroup.');
212
+ return (
213
+ <Button
214
+ {...props}
215
+ disabled={disabled || group.disabled}
216
+ variant="outline"
217
+ accessibilityRole="radio"
218
+ accessibilityLabel={props.accessibilityLabel ?? plainText(children)}
219
+ accessibilityState={{
220
+ checked: group.value === value,
221
+ disabled: !!(disabled || group.disabled),
222
+ }}
223
+ onPress={() => group.set(value)}
224
+ >
225
+ <LabelText accessibilityElementsHidden>{group.value === value ? '●' : '○'}</LabelText>
226
+ {content(children)}
227
+ </Button>
228
+ );
229
+ }
230
+ const TabsContext = createContext<{
231
+ value: string;
232
+ set: (value: string) => void;
233
+ id: string;
234
+ } | null>(null);
235
+ export function Tabs({
236
+ value,
237
+ defaultValue = '',
238
+ onValueChange,
239
+ ...props
240
+ }: ViewProps & { value?: string; defaultValue?: string; onValueChange?: (value: string) => void }) {
241
+ const [selected, set] = useControllable(value, defaultValue, onValueChange);
242
+ const id = useId();
243
+ return (
244
+ <TabsContext.Provider value={{ value: selected, set, id }}>
245
+ <Box {...props} />
246
+ </TabsContext.Provider>
247
+ );
248
+ }
249
+ export const TabsList = ({ style, ...props }: ViewProps) => (
250
+ <Box accessibilityRole="tablist" {...props} style={row(style)} />
251
+ );
252
+ export function TabsTrigger({ value, ...props }: ButtonProps & { value: string }) {
253
+ const tabs = useContext(TabsContext);
254
+ if (!tabs) throw Error('TabsTrigger requires Tabs.');
255
+ return (
256
+ <Button
257
+ {...props}
258
+ nativeID={`${tabs.id}-${value}-trigger`}
259
+ accessibilityRole="tab"
260
+ accessibilityState={{ selected: tabs.value === value, disabled: !!props.disabled }}
261
+ variant={tabs.value === value ? 'secondary' : 'ghost'}
262
+ onPress={() => tabs.set(value)}
263
+ />
264
+ );
265
+ }
266
+ export function TabsContent({
267
+ value,
268
+ forceMount = false,
269
+ ...props
270
+ }: ViewProps & { value: string; forceMount?: boolean }) {
271
+ const tabs = useContext(TabsContext);
272
+ if (!tabs) throw Error('TabsContent requires Tabs.');
273
+ const hidden = tabs.value !== value;
274
+ if (hidden && !forceMount) return null;
275
+ return (
276
+ <Box
277
+ {...props}
278
+ accessibilityLabelledBy={`${tabs.id}-${value}-trigger`}
279
+ accessibilityElementsHidden={hidden}
280
+ importantForAccessibility={hidden ? 'no-hide-descendants' : 'auto'}
281
+ style={[hidden && { display: 'none' }, props.style]}
282
+ />
283
+ );
284
+ }
285
+ const DisclosureContext = createContext<{
286
+ open: boolean;
287
+ set: (value: boolean) => void;
288
+ disabled?: boolean;
289
+ id: string;
290
+ } | null>(null);
291
+ export function Collapsible({
292
+ open,
293
+ defaultOpen = false,
294
+ onOpenChange,
295
+ disabled,
296
+ ...props
297
+ }: ViewProps & {
298
+ open?: boolean;
299
+ defaultOpen?: boolean;
300
+ onOpenChange?: (open: boolean) => void;
301
+ disabled?: boolean;
302
+ }) {
303
+ const [value, set] = useControllable(open, defaultOpen, onOpenChange);
304
+ const id = useId();
305
+ return (
306
+ <DisclosureContext.Provider value={{ open: value, set, disabled, id }}>
307
+ <Box {...props} />
308
+ </DisclosureContext.Provider>
309
+ );
310
+ }
311
+ export function CollapsibleTrigger(props: ButtonProps) {
312
+ const state = useContext(DisclosureContext);
313
+ if (!state) throw Error('CollapsibleTrigger requires Collapsible.');
314
+ return (
315
+ <Button
316
+ {...props}
317
+ nativeID={`${state.id}-trigger`}
318
+ disabled={state.disabled || props.disabled}
319
+ accessibilityState={{ expanded: state.open, disabled: !!(state.disabled || props.disabled) }}
320
+ onPress={() => state.set(!state.open)}
321
+ />
322
+ );
323
+ }
324
+ export function CollapsibleContent({
325
+ forceMount = false,
326
+ ...props
327
+ }: ViewProps & { forceMount?: boolean }) {
328
+ const state = useContext(DisclosureContext);
329
+ if (!state) throw Error('CollapsibleContent requires Collapsible.');
330
+ if (!state.open && !forceMount) return null;
331
+ return (
332
+ <Box
333
+ {...props}
334
+ nativeID={`${state.id}-content`}
335
+ accessibilityLabelledBy={`${state.id}-trigger`}
336
+ accessibilityElementsHidden={!state.open}
337
+ style={[!state.open && { display: 'none' }, props.style]}
338
+ />
339
+ );
340
+ }
341
+ const AccordionContext = createContext<(GroupValue & { collapsible: boolean }) | null>(null);
342
+ export function Accordion({
343
+ type = 'single',
344
+ value,
345
+ defaultValue,
346
+ onValueChange,
347
+ disabled,
348
+ collapsible = false,
349
+ ...props
350
+ }: ViewProps & {
351
+ type?: 'single' | 'multiple';
352
+ value?: string | string[];
353
+ defaultValue?: string | string[];
354
+ onValueChange?: (value: string | string[]) => void;
355
+ disabled?: boolean;
356
+ collapsible?: boolean;
357
+ }) {
358
+ const list = (input?: string | string[]) => (Array.isArray(input) ? input : input ? [input] : []);
359
+ const [selected, set] = useControllable(
360
+ value === undefined ? undefined : list(value),
361
+ list(defaultValue),
362
+ (next) => onValueChange?.(type === 'multiple' ? next : (next[0] ?? '')),
363
+ );
364
+ return (
365
+ <AccordionContext.Provider
366
+ value={{ value: selected, set, multiple: type === 'multiple', disabled, collapsible }}
367
+ >
368
+ <Box {...props} />
369
+ </AccordionContext.Provider>
370
+ );
371
+ }
372
+ export function AccordionItem({
373
+ value,
374
+ disabled,
375
+ ...props
376
+ }: ViewProps & { value: string; disabled?: boolean }) {
377
+ const group = useContext(AccordionContext);
378
+ if (!group) throw Error('AccordionItem requires Accordion.');
379
+ return (
380
+ <Collapsible
381
+ {...props}
382
+ disabled={disabled || group.disabled}
383
+ open={group.value.includes(value)}
384
+ onOpenChange={(open) => {
385
+ if (!open && !group.multiple && !group.collapsible) return;
386
+ group.set(
387
+ group.multiple
388
+ ? open
389
+ ? [...group.value, value]
390
+ : group.value.filter((item) => item !== value)
391
+ : open
392
+ ? [value]
393
+ : [],
394
+ );
395
+ }}
396
+ />
397
+ );
398
+ }
399
+ export const AccordionTrigger = CollapsibleTrigger;
400
+ export const AccordionContent = CollapsibleContent;
401
+ const FieldContext = createContext({ invalid: false, id: '' });
402
+ export function Field({ invalid = false, style, ...props }: ViewProps & { invalid?: boolean }) {
403
+ const id = useId();
404
+ return (
405
+ <FieldContext.Provider value={{ invalid, id }}>
406
+ <Box {...props} style={style} />
407
+ </FieldContext.Provider>
408
+ );
409
+ }
410
+ export const FieldGroup = Box;
411
+ export const FieldSet = Box;
412
+ export const FieldContent = Box;
413
+ export const FieldLegend = ({ style, ...props }: React.ComponentProps<typeof LabelText>) => (
414
+ <LabelText accessibilityRole="header" {...props} style={[{ fontWeight: '600' }, style]} />
415
+ );
416
+ export const FieldLabel = ({ ...props }: React.ComponentProps<typeof LabelText>) => {
417
+ const field = useContext(FieldContext);
418
+ return <LabelText nativeID={`${field.id}-label`} {...props} />;
419
+ };
420
+ export const FieldTitle = FieldLabel;
421
+ export const FieldDescription = Muted;
422
+ export function FieldError({
423
+ children,
424
+ errors,
425
+ ...props
426
+ }: React.ComponentProps<typeof LabelText> & { errors?: ({ message?: string } | undefined)[] }) {
427
+ const { colors } = useTheme();
428
+ const message =
429
+ children ?? [...new Set(errors?.map((error) => error?.message).filter(Boolean))].join('\n');
430
+ return message ? (
431
+ <LabelText
432
+ accessibilityRole="alert"
433
+ accessibilityLiveRegion="polite"
434
+ {...props}
435
+ style={[{ color: colors.destructive }, props.style]}
436
+ >
437
+ {message}
438
+ </LabelText>
439
+ ) : null;
440
+ }
441
+ export function FieldInput(props: React.ComponentProps<typeof Input>) {
442
+ const field = useContext(FieldContext);
443
+ return <Input accessibilityLabelledBy={`${field.id}-label`} invalid={field.invalid} {...props} />;
444
+ }
445
+ export const FieldSeparator = ({ children }: { children?: ReactNode }) => <Muted>{children}</Muted>;
446
+ export const InputGroup = Surface;
447
+ export const InputGroupAddon = ({ style, ...props }: ViewProps) => (
448
+ <Box {...props} style={row(style)} />
449
+ );
450
+ export const InputGroupText = Muted;
451
+ export const InputGroupButton = Button;
452
+ export const InputGroupInput = Input;
453
+ export const Textarea = ({ style, ...props }: TextInputProps) => (
454
+ <Input {...props} multiline textAlignVertical="top" style={[{ minHeight: 100 }, style]} />
455
+ );
456
+ export const InputGroupTextarea = Textarea;
457
+ const OTPContext = createContext({ value: '', maxLength: 6, focus: () => {}, disabled: false });
458
+ export function InputOTP({
459
+ value,
460
+ defaultValue = '',
461
+ onChange,
462
+ onComplete,
463
+ maxLength = 6,
464
+ disabled = false,
465
+ children,
466
+ ...props
467
+ }: Omit<TextInputProps, 'value' | 'defaultValue' | 'onChange' | 'onChangeText' | 'maxLength'> & {
468
+ value?: string;
469
+ defaultValue?: string;
470
+ onChange?: (value: string) => void;
471
+ onComplete?: (value: string) => void;
472
+ maxLength?: number;
473
+ disabled?: boolean;
474
+ children?: ReactNode;
475
+ }) {
476
+ const length = Math.max(1, Math.min(32, Math.floor(maxLength) || 6));
477
+ const [code, set] = useControllable(value, defaultValue, onChange);
478
+ const input = useRef<TextInput>(null);
479
+ return (
480
+ <OTPContext.Provider
481
+ value={{ value: code, maxLength: length, disabled, focus: () => input.current?.focus() }}
482
+ >
483
+ <Box>
484
+ <Input
485
+ {...props}
486
+ ref={input}
487
+ accessibilityLabel={props.accessibilityLabel ?? 'One-time code'}
488
+ editable={!disabled}
489
+ keyboardType="number-pad"
490
+ textContentType="oneTimeCode"
491
+ autoComplete="one-time-code"
492
+ maxLength={length}
493
+ value={code}
494
+ onChangeText={(next) => {
495
+ const cleaned = next.replace(/\D/g, '').slice(0, length);
496
+ set(cleaned);
497
+ if (cleaned.length === length && cleaned !== code) onComplete?.(cleaned);
498
+ }}
499
+ />
500
+ {children}
501
+ </Box>
502
+ </OTPContext.Provider>
503
+ );
504
+ }
505
+ export const InputOTPGroup = ({ style, ...props }: ViewProps) => (
506
+ <Box {...props} style={row(style)} />
507
+ );
508
+ export function InputOTPSlot({ index }: { index: number }) {
509
+ const otp = useContext(OTPContext);
510
+ return (
511
+ <Button
512
+ disabled={otp.disabled}
513
+ variant="outline"
514
+ accessibilityLabel={`Digit ${index + 1} of ${otp.maxLength}`}
515
+ onPress={otp.focus}
516
+ >
517
+ {otp.value[index] ?? '·'}
518
+ </Button>
519
+ );
520
+ }
521
+ export const InputOTPSeparator = () => <Muted accessibilityElementsHidden>−</Muted>;
@@ -0,0 +1,118 @@
1
+ import {
2
+ Children,
3
+ isValidElement,
4
+ createContext,
5
+ useContext,
6
+ useRef,
7
+ useState,
8
+ type ReactNode,
9
+ } from 'react';
10
+ import {
11
+ View,
12
+ I18nManager,
13
+ Platform,
14
+ Text as NativeText,
15
+ type ViewProps,
16
+ type TextProps,
17
+ type StyleProp,
18
+ type ViewStyle,
19
+ } from 'react-native';
20
+ import { useTheme } from '../theme';
21
+
22
+ export function useControllable<T>(value: T | undefined, initial: T, change?: (value: T) => void) {
23
+ const [internal, setInternal] = useState(initial);
24
+ const current = value === undefined ? internal : value;
25
+ const latest = useRef(current);
26
+ latest.current = current;
27
+ const set = (next: T | ((previous: T) => T)) => {
28
+ const resolved =
29
+ typeof next === 'function' ? (next as (previous: T) => T)(latest.current) : next;
30
+ if (Object.is(resolved, latest.current)) return;
31
+ if (value === undefined) {
32
+ latest.current = resolved;
33
+ setInternal(resolved);
34
+ }
35
+ change?.(resolved);
36
+ };
37
+ return [current, set] as const;
38
+ }
39
+ export const monospace = Platform.OS === 'ios' ? 'Menlo' : 'monospace';
40
+ export function plainText(node: ReactNode): string {
41
+ return Children.toArray(node)
42
+ .map((child) =>
43
+ typeof child === 'string' || typeof child === 'number' || typeof child === 'bigint'
44
+ ? String(child)
45
+ : isValidElement<{ children?: ReactNode }>(child)
46
+ ? plainText(child.props.children)
47
+ : '',
48
+ )
49
+ .join('');
50
+ }
51
+ export function content(children: ReactNode) {
52
+ return Children.map(children, (child) =>
53
+ typeof child === 'string' || typeof child === 'number' || typeof child === 'bigint' ? (
54
+ <LabelText>{String(child)}</LabelText>
55
+ ) : (
56
+ child
57
+ ),
58
+ );
59
+ }
60
+ export function Box({ children, style, ...props }: ViewProps) {
61
+ return (
62
+ <View {...props} style={[{ gap: 8 }, style]}>
63
+ {content(children)}
64
+ </View>
65
+ );
66
+ }
67
+ export function LabelText({ style, ...props }: TextProps) {
68
+ const { colors } = useTheme();
69
+ return (
70
+ <NativeText
71
+ {...props}
72
+ style={[{ color: colors.foreground, fontSize: 14, lineHeight: 21 }, style]}
73
+ />
74
+ );
75
+ }
76
+ export function Muted({ style, ...props }: TextProps) {
77
+ const { colors } = useTheme();
78
+ return <LabelText {...props} style={[{ color: colors['muted-foreground'] }, style]} />;
79
+ }
80
+ export function Surface({ style, ...props }: ViewProps) {
81
+ const { colors } = useTheme();
82
+ return (
83
+ <Box
84
+ {...props}
85
+ style={[
86
+ {
87
+ backgroundColor: colors.card,
88
+ borderColor: colors.border,
89
+ borderWidth: 1,
90
+ borderRadius: 10,
91
+ padding: 12,
92
+ },
93
+ style,
94
+ ]}
95
+ />
96
+ );
97
+ }
98
+ export function row(style?: StyleProp<ViewStyle>): StyleProp<ViewStyle> {
99
+ return [{ flexDirection: 'row', alignItems: 'center', gap: 8, flexWrap: 'wrap' }, style];
100
+ }
101
+ export function clamp(value: number, min: number, max: number) {
102
+ return Math.min(max, Math.max(min, Number.isFinite(value) ? value : min));
103
+ }
104
+ const DirectionContext = createContext<'ltr' | 'rtl'>(I18nManager.isRTL ? 'rtl' : 'ltr');
105
+ export function DirectionProvider({
106
+ dir = 'ltr',
107
+ children,
108
+ }: {
109
+ dir?: 'ltr' | 'rtl';
110
+ children: ReactNode;
111
+ }) {
112
+ return (
113
+ <DirectionContext.Provider value={dir}>
114
+ <View style={{ direction: dir }}>{children}</View>
115
+ </DirectionContext.Provider>
116
+ );
117
+ }
118
+ export const useDirection = () => useContext(DirectionContext);