anhedral 0.16.0 → 0.18.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 +42 -20
- package/assets/contracts/LICENSE +201 -0
- package/assets/contracts/LICENSE.environment +201 -0
- package/assets/contracts/LICENSE.operations +201 -0
- package/assets/contracts/deployment-provenance.json +15 -0
- package/assets/contracts/environment-provenance.json +11 -0
- package/assets/contracts/operations-provenance.json +11 -0
- package/assets/launch/application.server.ts.txt +13 -0
- package/assets/launch/auth-client.ts.txt +4 -0
- package/assets/launch/home.tsx.txt +20 -0
- package/assets/launch/minimal-application.server.ts.txt +5 -0
- package/assets/launch/minimal-server.ts.txt +7 -0
- package/assets/launch/request-context.ts.txt +3 -0
- package/assets/launch/root.tsx.txt +27 -0
- package/assets/launch/router.tsx.txt +21 -0
- package/assets/launch/server.ts.txt +13 -0
- package/assets/launch/sign-in.tsx.txt +53 -0
- package/assets/launch/styles.css.txt +19 -0
- package/assets/security/credential-patterns.d.mts +3 -0
- package/assets/security/credential-patterns.mjs +59 -0
- package/assets/stack/api-index.ts.txt +6 -1
- package/assets/stack/event-retention.sql.txt +10 -0
- package/assets/stack/stripe.ts.txt +30 -13
- package/assets/ui/UPSTREAM.json +1 -18
- package/dist/bin.js +55 -36
- package/dist/capabilities.d.ts +1 -1
- package/dist/capability-catalog.d.ts +44 -11
- package/dist/capability-catalog.js +96 -11
- package/dist/capability-command.d.ts +2 -2
- package/dist/capability-command.js +178 -27
- package/dist/capability-editor.js +6 -5
- package/dist/capability-recipes.js +54 -6
- package/dist/cli-arguments.d.ts +2 -0
- package/dist/cli-arguments.js +101 -50
- package/dist/cli-commands.d.ts +1 -1
- package/dist/cli-commands.js +30 -6
- package/dist/cli-errors.d.ts +18 -0
- package/dist/cli-errors.js +63 -0
- package/dist/cli-output.d.ts +22 -0
- package/dist/cli-output.js +42 -7
- package/dist/command-runner.d.ts +1 -0
- package/dist/command-runner.js +88 -0
- package/dist/command-schema.d.ts +16 -0
- package/dist/command-schema.js +390 -21
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +201 -0
- package/dist/composition.d.ts +35 -0
- package/dist/composition.js +28 -0
- package/dist/contracts/cli-transport.d.ts +217 -0
- package/dist/contracts/cli-transport.js +167 -0
- package/dist/contracts/deployment.d.ts +282 -0
- package/dist/contracts/deployment.js +234 -0
- package/dist/contracts/environment-file.d.ts +7 -0
- package/dist/contracts/environment-file.js +112 -0
- package/dist/contracts/environment-transport.d.ts +79 -0
- package/dist/contracts/environment-transport.js +110 -0
- package/dist/contracts/runtime-logs-transport.d.ts +127 -0
- package/dist/contracts/runtime-logs-transport.js +50 -0
- package/dist/contracts/source-bundle.d.ts +11 -0
- package/dist/contracts/source-bundle.js +197 -0
- package/dist/contracts/source-profile.d.ts +4 -0
- package/dist/contracts/source-profile.js +5 -0
- package/dist/contracts/staging-transport.d.ts +79 -0
- package/dist/contracts/staging-transport.js +43 -0
- package/dist/dependencies.d.ts +10 -4
- package/dist/dependencies.js +17 -54
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/launch.d.ts +21 -0
- package/dist/launch.js +250 -0
- package/dist/platform-command.d.ts +9 -0
- package/dist/platform-command.js +584 -0
- package/dist/platform-environment.d.ts +18 -0
- package/dist/platform-environment.js +257 -0
- package/dist/platform-operations.d.ts +26 -0
- package/dist/platform-operations.js +155 -0
- package/dist/platform-source.d.ts +8 -0
- package/dist/platform-source.js +111 -0
- package/dist/platform-state.d.ts +13 -0
- package/dist/platform-state.js +207 -0
- package/dist/platforms/tanstack.d.ts +8 -0
- package/dist/platforms/tanstack.js +155 -0
- package/dist/registry/options.js +34 -31
- package/dist/registry/resolve.js +2 -0
- package/dist/registry/usage.d.ts +4 -1
- package/dist/registry/usage.js +58 -4
- package/dist/scaffold/documentation.js +17 -48
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/workspace.js +11 -7
- package/dist/stack-registry.d.ts +2 -4
- package/dist/stack-registry.js +1 -11
- package/dist/standard.js +21 -6
- package/dist/transaction.js +28 -3
- package/dist/ui-command.d.ts +4 -2
- package/dist/ui-command.js +79 -38
- package/dist/ui-project.d.ts +2 -0
- package/dist/ui-project.js +38 -8
- package/dist/util.js +40 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +22 -88
- package/docs/software-factory.md +189 -16
- package/docs/stack-standard.md +6 -18
- package/docs/ui.md +9 -22
- package/docs/verification.md +6 -1067
- package/package.json +33 -22
- 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/docs/anhedral-stack.md +0 -7
- package/docs/native-ui.md +0 -102
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anhedral",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "Generate the Anhedral Stack as editable source: start with web UI, then add backend, storage and payments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./deployment": {
|
|
12
|
+
"types": "./dist/contracts/deployment.d.ts",
|
|
13
|
+
"import": "./dist/contracts/deployment.js"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
@@ -26,12 +30,18 @@
|
|
|
26
30
|
"docs/stack-standard.md",
|
|
27
31
|
"docs/software-factory.md",
|
|
28
32
|
"docs/verification.md",
|
|
29
|
-
"docs/anhedral-stack.md",
|
|
30
|
-
"assets/ui",
|
|
31
|
-
"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",
|
|
42
|
+
"assets/contracts",
|
|
43
|
+
"assets/security",
|
|
44
|
+
"assets/launch"
|
|
35
45
|
],
|
|
36
46
|
"homepage": "https://github.com/anhedral/anhedral-cli#readme",
|
|
37
47
|
"repository": {
|
|
@@ -51,14 +61,14 @@
|
|
|
51
61
|
"scripts": {
|
|
52
62
|
"scaffold": "node dist/bin.js init",
|
|
53
63
|
"clean": "node scripts/clean.mjs",
|
|
54
|
-
"build": "pnpm clean && tsc && node scripts/prepare-cli.mjs",
|
|
64
|
+
"build": "node scripts/standalone-checkout.mjs && pnpm clean && tsc && node scripts/prepare-cli.mjs",
|
|
55
65
|
"prepare": "pnpm build",
|
|
56
66
|
"typecheck": "tsc --noEmit",
|
|
57
|
-
"check:hygiene": "node scripts/check-source-hygiene.mjs",
|
|
67
|
+
"check:hygiene": "node scripts/check-source-hygiene.mjs && node scripts/check-environment-contract.mjs && node scripts/check-operations-contract.mjs",
|
|
58
68
|
"check:security": "node scripts/check-security-policy.mjs",
|
|
59
69
|
"check:release-policy": "node scripts/check-release-policy.mjs",
|
|
60
70
|
"check:release-secrets": "node scripts/check-release-secrets.mjs",
|
|
61
|
-
"lint": "pnpm typecheck && pnpm format:check && pnpm check:hygiene && pnpm check:release-policy",
|
|
71
|
+
"lint": "pnpm typecheck && pnpm format:check && pnpm check:hygiene && pnpm check:release-policy && pnpm check:boundaries",
|
|
62
72
|
"audit:osv": "node scripts/audit-osv.mjs",
|
|
63
73
|
"test": "pnpm test:unit",
|
|
64
74
|
"pretest": "pnpm build",
|
|
@@ -77,29 +87,29 @@
|
|
|
77
87
|
"test:standard": "pnpm build && node --test tests/test-standard.test.mjs",
|
|
78
88
|
"test:unit": "node --test --test-concurrency=4 --test-reporter=spec tests/*.test.mjs",
|
|
79
89
|
"test:integration": "pnpm build && node tests/test-generated-apps.mjs",
|
|
80
|
-
"format": "prettier --write src scripts tests \"assets/patches/*.mjs\" assets/ui && node scripts/stack-template-format.mjs --write",
|
|
81
|
-
"format:check": "prettier --check src scripts tests \"assets/patches/*.mjs\" assets/ui && node scripts/stack-template-format.mjs",
|
|
90
|
+
"format": "prettier --write src scripts tests \"assets/patches/*.mjs\" assets/ui assets/security && node scripts/stack-template-format.mjs --write",
|
|
91
|
+
"format:check": "prettier --check src scripts tests \"assets/patches/*.mjs\" assets/ui assets/security && node scripts/stack-template-format.mjs",
|
|
82
92
|
"plugin:build": "node scripts/check-plugin.mjs",
|
|
83
93
|
"plugin:check": "node scripts/check-plugin.mjs",
|
|
84
94
|
"test:patch": "node tests/test-braces-install.mjs && node tests/test-forge-install.mjs",
|
|
85
|
-
"test:
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
95
|
+
"test:next-runtime": "pnpm build && node scripts/next-runtime-smoke.mjs",
|
|
96
|
+
"check:boundaries": "node scripts/repository-boundaries.mjs",
|
|
97
|
+
"test:tanstack-runtime": "pnpm build && node scripts/tanstack-runtime-smoke.mjs",
|
|
98
|
+
"check:standalone": "node scripts/standalone-checkout.mjs"
|
|
89
99
|
},
|
|
90
100
|
"keywords": [
|
|
91
101
|
"cli",
|
|
92
102
|
"scaffold",
|
|
93
103
|
"typescript",
|
|
94
|
-
"
|
|
104
|
+
"anhedral-stack",
|
|
105
|
+
"tanstack-start",
|
|
95
106
|
"hono",
|
|
107
|
+
"better-auth",
|
|
96
108
|
"cloudflare",
|
|
97
109
|
"d1",
|
|
98
110
|
"r2",
|
|
99
111
|
"drizzle",
|
|
100
|
-
"
|
|
101
|
-
"nextjs",
|
|
102
|
-
"opennext"
|
|
112
|
+
"stripe"
|
|
103
113
|
],
|
|
104
114
|
"license": "Apache-2.0",
|
|
105
115
|
"packageManager": "pnpm@10.34.5",
|
|
@@ -107,11 +117,12 @@
|
|
|
107
117
|
"@types/node": "20.19.43",
|
|
108
118
|
"hono": "4.13.13",
|
|
109
119
|
"prettier": "3.9.10",
|
|
110
|
-
"typescript": "5.9.3"
|
|
111
|
-
"zod": "4.6.6"
|
|
120
|
+
"typescript": "5.9.3"
|
|
112
121
|
},
|
|
113
122
|
"dependencies": {
|
|
114
123
|
"jsonc-parser": "3.3.1",
|
|
115
|
-
"yaml": "2.9.1"
|
|
124
|
+
"yaml": "2.9.1",
|
|
125
|
+
"zod": "4.6.6",
|
|
126
|
+
"ignore": "7.0.14"
|
|
116
127
|
}
|
|
117
128
|
}
|
|
@@ -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>;
|