anhedral 0.16.0 → 0.17.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.
- package/README.md +75 -18
- package/assets/ui/UPSTREAM.json +1 -18
- package/dist/capabilities.d.ts +1 -1
- package/dist/dependencies.d.ts +0 -3
- package/dist/dependencies.js +0 -54
- package/dist/registry/resolve.js +2 -0
- package/dist/scaffold/documentation.js +17 -48
- package/dist/scaffold/workspace.js +0 -6
- package/dist/stack-registry.d.ts +2 -4
- package/dist/stack-registry.js +1 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +10 -5
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/capabilities.md +1 -1
- package/docs/native-ui.md +47 -102
- package/docs/software-factory.md +37 -24
- package/docs/stack-standard.md +19 -21
- package/docs/ui.md +1 -1
- package/docs/verification.md +6 -1067
- package/package.json +10 -6
- package/assets/ui/native/_controls.tsx +0 -521
- package/assets/ui/native/_core.tsx +0 -118
- package/assets/ui/native/_data.tsx +0 -200
- package/assets/ui/native/_display.tsx +0 -453
- package/assets/ui/native/_feedback.tsx +0 -242
- package/assets/ui/native/_legacy-dialog.tsx +0 -38
- package/assets/ui/native/_motion.tsx +0 -520
- package/assets/ui/native/_overlay.tsx +0 -402
- package/assets/ui/native/_selection.tsx +0 -366
- package/assets/ui/native/accordion.tsx +0 -1
- package/assets/ui/native/alert-dialog.tsx +0 -11
- package/assets/ui/native/alert.tsx +0 -1
- package/assets/ui/native/aspect-ratio.tsx +0 -1
- package/assets/ui/native/attachment.tsx +0 -8
- package/assets/ui/native/avatar.tsx +0 -8
- package/assets/ui/native/badge.tsx +0 -1
- package/assets/ui/native/breadcrumb.tsx +0 -9
- package/assets/ui/native/bubble.tsx +0 -1
- package/assets/ui/native/button-group.tsx +0 -1
- package/assets/ui/native/button.tsx +0 -86
- package/assets/ui/native/calendar.tsx +0 -170
- package/assets/ui/native/card.tsx +0 -44
- package/assets/ui/native/carousel.tsx +0 -1
- package/assets/ui/native/chart.tsx +0 -193
- package/assets/ui/native/checkbox.tsx +0 -1
- package/assets/ui/native/code-block.tsx +0 -137
- package/assets/ui/native/collapsible.tsx +0 -1
- package/assets/ui/native/combobox.tsx +0 -1
- package/assets/ui/native/command.tsx +0 -11
- package/assets/ui/native/context-menu.tsx +0 -16
- package/assets/ui/native/data-table.tsx +0 -1
- package/assets/ui/native/date-picker.tsx +0 -43
- package/assets/ui/native/dialog.tsx +0 -15
- package/assets/ui/native/direction.tsx +0 -1
- package/assets/ui/native/drawer.tsx +0 -10
- package/assets/ui/native/dropdown-menu.tsx +0 -16
- package/assets/ui/native/empty.tsx +0 -8
- package/assets/ui/native/field.tsx +0 -13
- package/assets/ui/native/hover-card.tsx +0 -1
- package/assets/ui/native/input-group.tsx +0 -8
- package/assets/ui/native/input-otp.tsx +0 -1
- package/assets/ui/native/input.tsx +0 -28
- package/assets/ui/native/item.tsx +0 -12
- package/assets/ui/native/kbd.tsx +0 -1
- package/assets/ui/native/label.tsx +0 -4
- package/assets/ui/native/layout.tsx +0 -26
- package/assets/ui/native/marker.tsx +0 -1
- package/assets/ui/native/menubar.tsx +0 -17
- package/assets/ui/native/message-scroller.tsx +0 -6
- package/assets/ui/native/message.tsx +0 -10
- package/assets/ui/native/native-select.tsx +0 -1
- package/assets/ui/native/navigation-menu.tsx +0 -10
- package/assets/ui/native/pagination.tsx +0 -9
- package/assets/ui/native/popover.tsx +0 -1
- package/assets/ui/native/progress.tsx +0 -1
- package/assets/ui/native/questionnaire.tsx +0 -130
- package/assets/ui/native/radio-group.tsx +0 -1
- package/assets/ui/native/registry.json +0 -1103
- package/assets/ui/native/resizable.tsx +0 -1
- package/assets/ui/native/scroll-area.tsx +0 -1
- package/assets/ui/native/select.tsx +0 -11
- package/assets/ui/native/separator.tsx +0 -1
- package/assets/ui/native/sheet.tsx +0 -10
- package/assets/ui/native/sidebar.tsx +0 -22
- package/assets/ui/native/skeleton.tsx +0 -1
- package/assets/ui/native/slider.tsx +0 -1
- package/assets/ui/native/spinner.tsx +0 -1
- package/assets/ui/native/switch.tsx +0 -1
- package/assets/ui/native/table.tsx +0 -10
- package/assets/ui/native/tabs.tsx +0 -1
- package/assets/ui/native/text.tsx +0 -20
- package/assets/ui/native/textarea.tsx +0 -1
- package/assets/ui/native/theme-switcher.tsx +0 -22
- package/assets/ui/native/toast.tsx +0 -11
- package/assets/ui/native/toggle-group.tsx +0 -1
- package/assets/ui/native/toggle.tsx +0 -1
- package/assets/ui/native/tooltip.tsx +0 -1
- package/assets/ui/native/trace.tsx +0 -20
- package/assets/ui/native/typography.tsx +0 -15
- package/assets/ui/theme-storage.ts +0 -25
- package/assets/ui/theme.tsx +0 -66
- package/dist/platforms/mobile.d.ts +0 -2
- package/dist/platforms/mobile.js +0 -137
- package/dist/scaffold/expo-runtime.d.ts +0 -3
- package/dist/scaffold/expo-runtime.js +0 -42
- package/dist/scaffold/native-ui.d.ts +0 -2
- package/dist/scaffold/native-ui.js +0 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anhedral",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Start with Next.js and Anhedral UI, then progressively add APIs, data, clients, payments, realtime and AI as editable source.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -27,11 +27,18 @@
|
|
|
27
27
|
"docs/software-factory.md",
|
|
28
28
|
"docs/verification.md",
|
|
29
29
|
"docs/anhedral-stack.md",
|
|
30
|
-
"assets/
|
|
30
|
+
"docs/assets/anhedral-stack.png",
|
|
31
|
+
"docs/assets/anhedral-stack-light.png",
|
|
31
32
|
"docs/native-ui.md",
|
|
32
33
|
"docs/ui.md",
|
|
33
34
|
"assets/stack",
|
|
34
|
-
"docs/capabilities.md"
|
|
35
|
+
"docs/capabilities.md",
|
|
36
|
+
"assets/ui/web",
|
|
37
|
+
"assets/ui/catalog.json",
|
|
38
|
+
"assets/ui/extensions",
|
|
39
|
+
"assets/ui/LICENSE.shadcn",
|
|
40
|
+
"assets/ui/LICENSE.react-native-reusables",
|
|
41
|
+
"assets/ui/UPSTREAM.json"
|
|
35
42
|
],
|
|
36
43
|
"homepage": "https://github.com/anhedral/anhedral-cli#readme",
|
|
37
44
|
"repository": {
|
|
@@ -82,9 +89,6 @@
|
|
|
82
89
|
"plugin:build": "node scripts/check-plugin.mjs",
|
|
83
90
|
"plugin:check": "node scripts/check-plugin.mjs",
|
|
84
91
|
"test:patch": "node tests/test-braces-install.mjs && node tests/test-forge-install.mjs",
|
|
85
|
-
"test:native-ui": "pnpm build && pnpm --dir tests/native-ui typecheck && pnpm --dir tests/native-ui test",
|
|
86
|
-
"native-ui:docs": "node scripts/native-ui-catalog.mjs --write",
|
|
87
|
-
"native-ui:upstream": "node scripts/native-ui-catalog.mjs --upstream",
|
|
88
92
|
"test:next-runtime": "pnpm build && node scripts/next-runtime-smoke.mjs"
|
|
89
93
|
},
|
|
90
94
|
"keywords": [
|
|
@@ -1,521 +0,0 @@
|
|
|
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>;
|
|
@@ -1,118 +0,0 @@
|
|
|
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);
|