@trama-ui/react-native 0.0.0-stage → 0.7.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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -2
  3. package/dist/accordion.d.ts +29 -0
  4. package/dist/accordion.js +137 -0
  5. package/dist/alert.d.ts +30 -0
  6. package/dist/alert.js +95 -0
  7. package/dist/avatar.d.ts +36 -0
  8. package/dist/avatar.js +91 -0
  9. package/dist/bars.d.ts +44 -0
  10. package/dist/bars.js +74 -0
  11. package/dist/button.d.ts +30 -0
  12. package/dist/button.js +90 -0
  13. package/dist/calendar.d.ts +71 -0
  14. package/dist/calendar.js +276 -0
  15. package/dist/card.d.ts +41 -0
  16. package/dist/card.js +139 -0
  17. package/dist/choices.d.ts +87 -0
  18. package/dist/choices.js +228 -0
  19. package/dist/collections.d.ts +131 -0
  20. package/dist/collections.js +230 -0
  21. package/dist/color-code.d.ts +37 -0
  22. package/dist/color-code.js +158 -0
  23. package/dist/compositions.d.ts +110 -0
  24. package/dist/compositions.js +190 -0
  25. package/dist/controls.d.ts +85 -0
  26. package/dist/controls.js +221 -0
  27. package/dist/drag-drop.d.ts +65 -0
  28. package/dist/drag-drop.js +482 -0
  29. package/dist/feedback.d.ts +30 -0
  30. package/dist/feedback.js +81 -0
  31. package/dist/file-upload.d.ts +67 -0
  32. package/dist/file-upload.js +251 -0
  33. package/dist/generated/icons.d.ts +1037 -0
  34. package/dist/generated/icons.js +3 -0
  35. package/dist/generated/tokens.d.ts +64 -0
  36. package/dist/generated/tokens.js +65 -0
  37. package/dist/icon.d.ts +31 -0
  38. package/dist/icon.js +28 -0
  39. package/dist/index.d.ts +43 -0
  40. package/dist/index.js +43 -0
  41. package/dist/input.d.ts +43 -0
  42. package/dist/input.js +115 -0
  43. package/dist/interactive-layout.d.ts +26 -0
  44. package/dist/interactive-layout.js +117 -0
  45. package/dist/internal/content.d.ts +17 -0
  46. package/dist/internal/content.js +24 -0
  47. package/dist/internal/drag-geometry.d.ts +16 -0
  48. package/dist/internal/drag-geometry.js +25 -0
  49. package/dist/internal/keyboard.d.ts +20 -0
  50. package/dist/internal/keyboard.js +101 -0
  51. package/dist/internal/motion.d.ts +1 -0
  52. package/dist/internal/motion.js +24 -0
  53. package/dist/internal/number-format.d.ts +4 -0
  54. package/dist/internal/number-format.js +25 -0
  55. package/dist/internal/pointer-capture.d.ts +1 -0
  56. package/dist/internal/pointer-capture.js +16 -0
  57. package/dist/internal/state.d.ts +6 -0
  58. package/dist/internal/state.js +28 -0
  59. package/dist/internal/system-drag.d.ts +48 -0
  60. package/dist/internal/system-drag.js +93 -0
  61. package/dist/internal/table-drag.d.ts +56 -0
  62. package/dist/internal/table-drag.js +237 -0
  63. package/dist/internal/table-editing.d.ts +49 -0
  64. package/dist/internal/table-editing.js +278 -0
  65. package/dist/internal/table-editor.d.ts +11 -0
  66. package/dist/internal/table-editor.js +31 -0
  67. package/dist/internal/table-grid.d.ts +44 -0
  68. package/dist/internal/table-grid.js +153 -0
  69. package/dist/internal/table-model.d.ts +132 -0
  70. package/dist/internal/table-model.js +231 -0
  71. package/dist/internal/table-source.d.ts +9 -0
  72. package/dist/internal/table-source.js +80 -0
  73. package/dist/internal/tour-target.d.ts +23 -0
  74. package/dist/internal/tour-target.js +81 -0
  75. package/dist/keyboard.d.ts +14 -0
  76. package/dist/keyboard.js +27 -0
  77. package/dist/layout.d.ts +35 -0
  78. package/dist/layout.js +77 -0
  79. package/dist/loader.d.ts +18 -0
  80. package/dist/loader.js +79 -0
  81. package/dist/localization.d.ts +106 -0
  82. package/dist/localization.js +310 -0
  83. package/dist/media.d.ts +35 -0
  84. package/dist/media.js +96 -0
  85. package/dist/menus.d.ts +103 -0
  86. package/dist/menus.js +422 -0
  87. package/dist/navigation.d.ts +111 -0
  88. package/dist/navigation.js +255 -0
  89. package/dist/overlays.d.ts +97 -0
  90. package/dist/overlays.js +364 -0
  91. package/dist/pill.d.ts +33 -0
  92. package/dist/pill.js +90 -0
  93. package/dist/progress.d.ts +27 -0
  94. package/dist/progress.js +154 -0
  95. package/dist/responsive.d.ts +15 -0
  96. package/dist/responsive.js +27 -0
  97. package/dist/select.d.ts +74 -0
  98. package/dist/select.js +181 -0
  99. package/dist/separator.d.ts +13 -0
  100. package/dist/separator.js +34 -0
  101. package/dist/switch.d.ts +26 -0
  102. package/dist/switch.js +69 -0
  103. package/dist/table.d.ts +122 -0
  104. package/dist/table.js +928 -0
  105. package/dist/text-fields.d.ts +39 -0
  106. package/dist/text-fields.js +134 -0
  107. package/dist/theme.d.ts +47 -0
  108. package/dist/theme.js +71 -0
  109. package/dist/transient.d.ts +80 -0
  110. package/dist/transient.js +273 -0
  111. package/package.json +50 -4
@@ -0,0 +1,190 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useRef, useState } from 'react';
3
+ import { Text, View } from 'react-native';
4
+ import { Alert } from './alert.js';
5
+ import { Avatar } from './avatar.js';
6
+ import { Button } from './button.js';
7
+ import { Card } from './card.js';
8
+ import { Input } from './input.js';
9
+ import { splitContent, TextContent } from './internal/content.js';
10
+ import { useControllableValue } from './internal/state.js';
11
+ import { Cluster, Grid, Stack } from './layout.js';
12
+ import { useTramaMessages } from './localization.js';
13
+ import { Link } from './navigation.js';
14
+ import { Popover, PopoverTrigger } from './overlays.js';
15
+ import { sizeStep, useTramaAppearance, useTramaTheme } from './theme.js';
16
+ export function PageHeader({ heading, description, eyebrow, layout, size, children, ...props }) {
17
+ const { theme, resolve } = useTramaAppearance();
18
+ const { body, named } = splitContent(children, {
19
+ actions: PageHeaderActions,
20
+ breadcrumbs: PageHeaderBreadcrumbs,
21
+ meta: PageHeaderMeta,
22
+ navigation: PageHeaderNavigation,
23
+ });
24
+ const split = resolve(layout, 'stacked') === 'split';
25
+ return (_jsxs(Stack, { ...props, gap: "sm", children: [named.breadcrumbs, _jsxs(Stack, { direction: split ? 'row' : 'column', gap: "sm", justify: "between", align: "start", children: [_jsxs(Stack, { gap: "xs", style: split ? { flex: 1, minWidth: 0 } : undefined, children: [eyebrow && _jsx(Text, { style: { color: theme.colors.accent, fontWeight: '700' }, children: eyebrow }), heading && (_jsx(Text, { accessibilityRole: "header", style: {
26
+ color: theme.colors.text,
27
+ fontSize: theme.fontSize + 12 + sizeStep[resolve(size, 'md')] * 3,
28
+ fontWeight: '700',
29
+ }, children: heading })), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), named.meta, _jsx(TextContent, { style: { color: theme.colors.text }, children: body })] }), named.actions] }), named.navigation] }));
30
+ }
31
+ export function PageHeaderActions(props) {
32
+ return _jsx(Cluster, { ...props });
33
+ }
34
+ export function PageHeaderBreadcrumbs(props) {
35
+ return _jsx(View, { ...props });
36
+ }
37
+ export function PageHeaderMeta({ children, ...props }) {
38
+ const theme = useTramaTheme();
39
+ return (_jsx(Cluster, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.muted }, children: children }) }));
40
+ }
41
+ export function PageHeaderNavigation(props) {
42
+ return _jsx(View, { ...props });
43
+ }
44
+ export function AppShell({ header, sidebar, footer, hideSidebar, sidebarPlacement, children, style, ...props }) {
45
+ const { theme, resolve } = useTramaAppearance();
46
+ return (_jsxs(Stack, { ...props, gap: "none", style: [{ flex: 1, backgroundColor: theme.colors.surface }, style], children: [header, _jsxs(Stack, { direction: resolve(sidebarPlacement, 'start') === 'start' ? 'row' : 'row-reverse', gap: "none", style: { flex: 1 }, children: [!resolve(hideSidebar, false) && sidebar, _jsx(View, { style: { flex: 1, minWidth: 0 }, children: children })] }), footer] }));
47
+ }
48
+ export function DashboardSections({ heading, columns, description, children, ...props }) {
49
+ return (_jsxs(Stack, { ...props, children: [_jsx(PageHeader, { heading: heading, description: description }), _jsx(Grid, { columns: columns ?? { base: 1, md: 2 }, children: children })] }));
50
+ }
51
+ export function MetricsCard({ value, trend, trendDirection = 'neutral', children, ...props }) {
52
+ const theme = useTramaTheme();
53
+ const trendColor = { up: theme.colors.successText, down: theme.colors.danger, neutral: theme.colors.muted };
54
+ return (_jsxs(Card, { ...props, children: [value !== undefined && (_jsx(Text, { style: { color: theme.colors.text, fontSize: theme.fontSize + 14, fontWeight: '700' }, children: value })), trend && (_jsxs(Text, { style: { color: trendColor[trendDirection] }, children: [trendDirection === 'up' ? '↑ ' : trendDirection === 'down' ? '↓ ' : '', trend] })), children] }));
55
+ }
56
+ export function ProfileHeader({ name, image, avatar, actions, meta, children, ...props }) {
57
+ return (_jsxs(Stack, { gap: "sm", children: [_jsx(Avatar, { src: image, alt: name, size: "xl", ...avatar }), _jsxs(PageHeader, { ...props, heading: props.heading ?? name, children: [meta && _jsx(PageHeaderMeta, { children: meta }), actions && _jsx(PageHeaderActions, { children: actions }), children] })] }));
58
+ }
59
+ export function SettingsLayout({ navigation, heading, description, placement = 'start', children, ...props }) {
60
+ return (_jsxs(Stack, { ...props, children: [_jsx(PageHeader, { heading: heading, description: description }), _jsxs(Stack, { direction: { base: 'column', md: placement === 'start' ? 'row' : 'row-reverse' }, children: [navigation, _jsx(View, { style: { flex: 1, minWidth: 0 }, children: children })] })] }));
61
+ }
62
+ export function SignInForm({ heading, description, emailLabel, passwordLabel, submitLabel, loading, error, onSubmit, children, ...props }) {
63
+ const messages = useTramaMessages();
64
+ const [email, setEmail] = useState('');
65
+ const [password, setPassword] = useState('');
66
+ const emailRef = useRef(null);
67
+ const passwordRef = useRef(null);
68
+ function submit() {
69
+ if (loading)
70
+ return;
71
+ const emailValid = emailRef.current?.reportValidity();
72
+ const passwordValid = passwordRef.current?.reportValidity();
73
+ if (!emailValid)
74
+ emailRef.current?.focus();
75
+ else if (!passwordValid)
76
+ passwordRef.current?.focus();
77
+ else
78
+ onSubmit?.({ email: email.trim(), password });
79
+ }
80
+ return (_jsxs(Stack, { ...props, children: [_jsx(PageHeader, { heading: heading ?? messages.signIn, description: description }), error && (_jsx(Alert, { severity: "danger", announcement: "polite", children: error })), _jsx(Input, { ref: emailRef, required: true, autoComplete: "email", autoCapitalize: "none", inputMode: "email", label: emailLabel ?? messages.email, value: email, onChangeText: setEmail, onSubmitEditing: () => passwordRef.current?.focus() }), _jsx(Input, { ref: passwordRef, required: true, autoComplete: "current-password", secureTextEntry: true, label: passwordLabel ?? messages.password, value: password, onChangeText: setPassword, onSubmitEditing: submit }), _jsx(Button, { loading: loading, onPress: submit, children: submitLabel ?? messages.signIn }), children] }));
81
+ }
82
+ const NavigationContext = createContext(null);
83
+ export function NavigationMenu({ value, defaultValue, onValueChange, expanded, defaultExpanded, onExpandedChange, placement, mode, position, variant, children, style, ...props }) {
84
+ const [current, request] = useControllableValue(value, defaultValue ?? '');
85
+ const [opened, requestOpen] = useControllableValue(expanded, defaultExpanded ?? []);
86
+ const { resolve, theme } = useTramaAppearance();
87
+ const edge = resolve(placement, 'top');
88
+ const vertical = edge === 'start' || edge === 'end';
89
+ const fixed = resolve(position, 'inline') === 'fixed';
90
+ const look = resolve(variant, 'plain');
91
+ return (_jsx(NavigationContext.Provider, { value: {
92
+ current,
93
+ expanded: opened,
94
+ mode: resolve(mode, vertical ? 'inline' : 'popup'),
95
+ choose(id) {
96
+ if (id !== current && onValueChange?.(id) !== false)
97
+ request(id);
98
+ },
99
+ open(id) {
100
+ const next = opened.includes(id) ? opened.filter((item) => item !== id) : [...opened, id];
101
+ if (onExpandedChange?.(next) !== false)
102
+ requestOpen(next);
103
+ },
104
+ }, children: _jsx(Stack, { ...props, gap: "xs", direction: vertical ? 'column' : 'row', wrap: vertical ? 'nowrap' : 'wrap', role: "navigation", style: [
105
+ {
106
+ backgroundColor: look === 'soft' ? theme.colors.subtle : theme.colors.surface,
107
+ borderRadius: theme.radius,
108
+ borderWidth: look === 'outlined' ? 1 : 0,
109
+ borderColor: theme.colors.border,
110
+ padding: theme.space * 2,
111
+ },
112
+ fixed && {
113
+ position: 'absolute',
114
+ zIndex: 5,
115
+ start: edge !== 'end' ? 0 : undefined,
116
+ end: edge !== 'start' ? 0 : undefined,
117
+ top: edge !== 'bottom' ? 0 : undefined,
118
+ bottom: edge !== 'top' ? 0 : undefined,
119
+ },
120
+ style,
121
+ ], children: children }) }));
122
+ }
123
+ export function NavigationMenuItem({ value, label, href, children, onPress, disabled, ...props }) {
124
+ const navigation = useContext(NavigationContext);
125
+ const { body, named } = splitContent(children, {
126
+ media: NavigationMenuItemMedia,
127
+ panel: NavigationMenuContent,
128
+ submenu: NavigationMenuSubmenu,
129
+ indicator: NavigationMenuIndicator,
130
+ });
131
+ const current = navigation?.current === value;
132
+ const nested = named.panel ?? named.submenu;
133
+ const open = Boolean(navigation?.expanded.includes(value));
134
+ const head = body.length ? body : label;
135
+ if (nested && navigation?.mode === 'popup') {
136
+ return (_jsxs(Popover, { open: open, onOpenChange: () => navigation.open(value), disabled: disabled, label: label, children: [_jsx(PopoverTrigger, { ...props, variant: "text", disabled: disabled, leading: named.media, trailing: named.indicator, children: head }), _jsx(NavigationContext.Provider, { value: { ...navigation, mode: 'inline' }, children: nested })] }));
137
+ }
138
+ return (_jsxs(Stack, { gap: "xs", children: [href && !nested ? (_jsx(Link, { href: href, label: label, disabled: disabled, current: current, onPress: (event) => {
139
+ navigation?.choose(value);
140
+ onPress?.(event);
141
+ }, children: head })) : (_jsx(Button, { ...props, variant: props.variant ?? (current ? 'contained' : 'text'), disabled: disabled, "aria-expanded": nested ? open : undefined, leading: named.media, trailing: named.indicator, onPress: (event) => {
142
+ if (nested)
143
+ navigation?.open(value);
144
+ else
145
+ navigation?.choose(value);
146
+ onPress?.(event);
147
+ }, children: head })), nested && open && _jsx(Stack, { gap: "xs", children: nested })] }));
148
+ }
149
+ export function NavigationMenuContent(props) {
150
+ return _jsx(Stack, { gap: "xs", ...props });
151
+ }
152
+ export function NavigationMenuSubmenu(props) {
153
+ return _jsx(Stack, { gap: "xs", ...props });
154
+ }
155
+ export function NavigationMenuGroup({ children, label, ...props }) {
156
+ const theme = useTramaTheme();
157
+ return (_jsxs(Stack, { gap: "xs", ...props, children: [label && (_jsx(Text, { accessibilityRole: "header", style: { color: theme.colors.muted }, children: label })), children] }));
158
+ }
159
+ export function NavigationMenuItemMedia(props) {
160
+ return _jsx(View, { ...props });
161
+ }
162
+ export function NavigationMenuIndicator(props) {
163
+ return _jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none" });
164
+ }
165
+ export function Sidebar(props) {
166
+ return _jsx(NavigationMenu, { placement: "start", mode: "inline", ...props });
167
+ }
168
+ export function HeaderNavigation(props) {
169
+ return _jsx(NavigationMenu, { placement: "top", ...props });
170
+ }
171
+ const AnchorContext = createContext(null);
172
+ export function AnchorNavigation({ value, defaultValue, onNavigate, orientation, children, ...props }) {
173
+ const [current, request] = useControllableValue(value, defaultValue ?? '');
174
+ const { resolve } = useTramaAppearance();
175
+ return (_jsx(AnchorContext.Provider, { value: {
176
+ value: current,
177
+ choose(id) {
178
+ if (onNavigate?.(id) !== false)
179
+ request(id);
180
+ },
181
+ }, children: _jsx(Stack, { ...props, role: "navigation", direction: resolve(orientation, 'vertical') === 'vertical' ? 'column' : 'row', wrap: "wrap", gap: "xs", children: children }) }));
182
+ }
183
+ export function AnchorItem({ value, label, level = 1, children, onPress, ...props }) {
184
+ const owner = useContext(AnchorContext);
185
+ const { theme } = useTramaAppearance();
186
+ return (_jsx(View, { style: { paddingStart: Math.max(0, level - 1) * theme.space * 2 }, children: _jsx(Button, { variant: owner?.value === value ? 'contained' : 'text', ...props, onPress: (event) => {
187
+ owner?.choose(value);
188
+ onPress?.(event);
189
+ }, children: children ?? label }) }));
190
+ }
@@ -0,0 +1,85 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ViewProps } from 'react-native';
3
+ import { type ButtonProps } from './button.js';
4
+ import { type FieldHandle, type InputProps } from './input.js';
5
+ import type { OverlayStateProps } from './overlays.js';
6
+ import type { TramaResponsive } from './responsive.js';
7
+ import { type TramaColor, type TramaSize } from './theme.js';
8
+ export interface CollapsibleTriggerProps extends ButtonProps {
9
+ label?: string;
10
+ }
11
+ export declare function CollapsibleTrigger(props: CollapsibleTriggerProps): import("react").JSX.Element;
12
+ export declare function CollapsibleContent({ children, ...props }: ViewProps): import("react").JSX.Element;
13
+ export declare function CollapsibleIndicator(props: ViewProps): import("react").JSX.Element;
14
+ export interface CollapsibleProps extends ViewProps, OverlayStateProps {
15
+ label?: string;
16
+ disabled?: boolean;
17
+ variant?: TramaResponsive<'plain' | 'soft' | 'outlined'>;
18
+ size?: TramaResponsive<TramaSize>;
19
+ panelPersistence?: 'mounted' | 'unmount';
20
+ }
21
+ export declare function Collapsible({ open, defaultOpen, onOpenChange, label, disabled, variant, size, panelPersistence, children, style, ...props }: CollapsibleProps): import("react").JSX.Element;
22
+ export interface InlineEditProps extends ViewProps {
23
+ label?: string;
24
+ value?: string;
25
+ defaultValue?: string;
26
+ onValueChange?: (value: string) => void | false;
27
+ editing?: boolean;
28
+ defaultEditing?: boolean;
29
+ onEditingChange?: (editing: boolean) => void;
30
+ disabled?: boolean;
31
+ required?: boolean;
32
+ error?: string;
33
+ invalid?: boolean;
34
+ inputProps?: Omit<InputProps, 'value' | 'defaultValue' | 'onChangeText'>;
35
+ }
36
+ export declare function InlineEdit({ label, value, defaultValue, onValueChange, editing, defaultEditing, onEditingChange, disabled, required, error, invalid, inputProps, children, ...props }: InlineEditProps): import("react").JSX.Element;
37
+ export declare function InlineEditActions(props: ViewProps): import("react").JSX.Element;
38
+ export interface FilterBarProps extends ViewProps {
39
+ query?: string;
40
+ defaultQuery?: string;
41
+ onQueryChange?: (query: string) => void;
42
+ searchLabel?: string;
43
+ resetLabel?: string;
44
+ placeholder?: string;
45
+ resultCount?: number;
46
+ disabled?: boolean;
47
+ onReset?: () => void;
48
+ }
49
+ export declare function FilterBar({ query, defaultQuery, onQueryChange, searchLabel, resetLabel, placeholder, resultCount, disabled, onReset, children, ...props }: FilterBarProps): import("react").JSX.Element;
50
+ interface ValueControlProps extends ViewProps {
51
+ label?: string;
52
+ description?: string;
53
+ hint?: string;
54
+ invalid?: boolean;
55
+ error?: string;
56
+ required?: boolean;
57
+ disabled?: boolean;
58
+ readOnly?: boolean;
59
+ color?: TramaResponsive<TramaColor>;
60
+ size?: TramaResponsive<TramaSize>;
61
+ }
62
+ export interface RatingProps extends ValueControlProps {
63
+ value?: number;
64
+ defaultValue?: number;
65
+ onValueChange?: (value: number) => void | false;
66
+ max?: number;
67
+ allowClear?: boolean;
68
+ icon?: (active: boolean) => ReactNode;
69
+ }
70
+ export declare const Rating: import("react").ForwardRefExoticComponent<RatingProps & import("react").RefAttributes<FieldHandle>>;
71
+ export type SliderValue = number | readonly [number, number];
72
+ export interface SliderProps extends ValueControlProps {
73
+ value?: SliderValue;
74
+ defaultValue?: SliderValue;
75
+ onValueChange?: (value: SliderValue) => void;
76
+ onValueCommit?: (value: SliderValue) => void;
77
+ min?: number;
78
+ max?: number;
79
+ step?: number;
80
+ range?: boolean;
81
+ showValue?: boolean;
82
+ orientation?: TramaResponsive<'horizontal' | 'vertical'>;
83
+ }
84
+ export declare const Slider: import("react").ForwardRefExoticComponent<SliderProps & import("react").RefAttributes<FieldHandle>>;
85
+ export {};
@@ -0,0 +1,221 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
3
+ import { PanResponder, Pressable, Text, View } from 'react-native';
4
+ import { Button } from './button.js';
5
+ import { Input } from './input.js';
6
+ import { FieldMessage, splitContent, TextContent } from './internal/content.js';
7
+ import { useControllableValue, useFieldValidation } from './internal/state.js';
8
+ import { Cluster, Stack } from './layout.js';
9
+ import { useTramaMessages } from './localization.js';
10
+ import { getTone, sizeStep, useTramaAppearance, useTramaTheme } from './theme.js';
11
+ export function CollapsibleTrigger(props) {
12
+ return _jsx(Button, { ...props });
13
+ }
14
+ export function CollapsibleContent({ children, ...props }) {
15
+ const theme = useTramaTheme();
16
+ return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text }, children: children }) }));
17
+ }
18
+ export function CollapsibleIndicator(props) {
19
+ return _jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none" });
20
+ }
21
+ export function Collapsible({ open, defaultOpen, onOpenChange, label, disabled, variant, size, panelPersistence = 'mounted', children, style, ...props }) {
22
+ const [visible, request] = useControllableValue(open, defaultOpen ?? false);
23
+ const { theme, resolve } = useTramaAppearance();
24
+ const messages = useTramaMessages();
25
+ const { body, named } = splitContent(children, {
26
+ trigger: CollapsibleTrigger,
27
+ indicator: CollapsibleIndicator,
28
+ content: CollapsibleContent,
29
+ });
30
+ const trigger = named.trigger?.[0];
31
+ const triggerProps = trigger && typeof trigger === 'object' && 'props' in trigger ? trigger.props : {};
32
+ const design = resolve(variant, 'plain');
33
+ return (_jsxs(Stack, { ...props, gap: "xs", style: [
34
+ {
35
+ backgroundColor: design === 'soft' ? theme.colors.subtle : 'transparent',
36
+ borderColor: theme.colors.border,
37
+ borderRadius: theme.radius,
38
+ borderWidth: design === 'outlined' ? 1 : 0,
39
+ },
40
+ style,
41
+ ], children: [_jsx(Button, { ...triggerProps, variant: triggerProps.variant ?? 'text', size: triggerProps.size ?? size, accessibilityLabel: triggerProps.accessibilityLabel ?? triggerProps.label ?? label, "aria-expanded": visible, accessibilityState: { expanded: visible }, disabled: disabled || triggerProps.disabled, trailing: named.indicator ?? (_jsx(Text, { accessible: false, style: { color: theme.colors.muted }, children: visible ? '−' : '+' })), onPress: (event) => {
42
+ triggerProps.onPress?.(event);
43
+ if (onOpenChange?.(!visible, { reason: 'trigger' }) !== false)
44
+ request(!visible);
45
+ }, children: triggerProps.children ?? label ?? (visible ? messages.closeSurface : messages.moreItems) }), (visible || panelPersistence === 'mounted') && (_jsx(View, { accessibilityElementsHidden: !visible, importantForAccessibility: visible ? 'auto' : 'no-hide-descendants', style: { display: visible ? 'flex' : 'none', padding: theme.space * 2 }, children: named.content ?? _jsx(CollapsibleContent, { children: body }) }))] }));
46
+ }
47
+ export function InlineEdit({ label, value, defaultValue, onValueChange, editing, defaultEditing, onEditingChange, disabled, required, error, invalid, inputProps, children, ...props }) {
48
+ const [current, request] = useControllableValue(value, defaultValue ?? '');
49
+ const [active, setActive] = useControllableValue(editing, defaultEditing ?? false, onEditingChange);
50
+ const [draft, setDraft] = useState();
51
+ const input = useRef(null);
52
+ const theme = useTramaTheme();
53
+ const messages = useTramaMessages();
54
+ const { body, named } = splitContent(children, { actions: InlineEditActions });
55
+ function close() {
56
+ setDraft(undefined);
57
+ setActive(false);
58
+ }
59
+ function save() {
60
+ if (disabled || !input.current?.reportValidity())
61
+ return;
62
+ const next = draft ?? current;
63
+ if (onValueChange?.(next) === false)
64
+ return;
65
+ request(next);
66
+ close();
67
+ }
68
+ return (_jsx(Stack, { ...props, gap: "xs", children: active ? (_jsxs(_Fragment, { children: [_jsx(Input, { ...inputProps, ref: input, label: label ?? inputProps?.label, autoFocus: true, disabled: disabled, required: required, invalid: invalid, error: error, value: draft ?? current, onChangeText: setDraft, onSubmitEditing: save }), _jsxs(InlineEditActions, { children: [_jsx(Button, { size: "sm", onPress: save, disabled: disabled, children: messages.saveValue }), _jsx(Button, { size: "sm", variant: "text", onPress: close, children: messages.cancel })] }), named.actions] })) : (_jsxs(Cluster, { children: [body.length ? body : _jsx(Text, { style: { color: theme.colors.text }, children: current || label }), _jsx(Button, { variant: "text", disabled: disabled, onPress: () => setActive(true), children: messages.editValue })] })) }));
69
+ }
70
+ export function InlineEditActions(props) {
71
+ return _jsx(Cluster, { ...props });
72
+ }
73
+ export function FilterBar({ query, defaultQuery, onQueryChange, searchLabel, resetLabel, placeholder, resultCount, disabled, onReset, children, ...props }) {
74
+ const [text, request] = useControllableValue(query, defaultQuery ?? '', onQueryChange);
75
+ const messages = useTramaMessages();
76
+ const theme = useTramaTheme();
77
+ return (_jsxs(Stack, { ...props, gap: "xs", children: [_jsx(Input, { label: searchLabel ?? messages.search, placeholder: placeholder ?? messages.search, value: text, onChangeText: request, disabled: disabled }), _jsxs(Cluster, { children: [children, _jsx(Button, { variant: "text", disabled: disabled, onPress: () => {
78
+ request('');
79
+ onReset?.();
80
+ }, children: resetLabel ?? messages.resetFilters }), resultCount !== undefined && resultCount >= 0 && (_jsx(Text, { style: { color: theme.colors.muted }, children: messages.resultsCount(resultCount) }))] })] }));
81
+ }
82
+ export const Rating = forwardRef(function Rating({ value, defaultValue, onValueChange, max = 5, allowClear = true, label, description, hint, invalid, error, required, disabled, readOnly, color, size, icon, ...props }, ref) {
83
+ const { theme, resolve } = useTramaAppearance();
84
+ const messages = useTramaMessages();
85
+ const [owned, change] = useControllableValue(value, defaultValue ?? 0);
86
+ const total = Number.isFinite(max) ? Math.min(20, Math.max(1, Math.floor(max))) : 5;
87
+ const current = Math.min(total, Math.max(0, Number.isFinite(owned) ? owned : 0));
88
+ const locked = Boolean(disabled || readOnly);
89
+ const tone = getTone(theme, resolve(color, 'yellow'));
90
+ const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), required && current === 0 ? messages.chooseOption : '', locked);
91
+ useImperativeHandle(ref, () => ({
92
+ checkValidity: validation.checkValidity,
93
+ reportValidity: validation.reportValidity,
94
+ }));
95
+ return (_jsxs(Stack, { ...props, gap: "xs", accessibilityLabel: props.accessibilityLabel ?? label, children: [label && (_jsxs(Text, { style: { color: theme.colors.text }, children: [label, required ? ' *' : ''] })), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), _jsx(Cluster, { gap: "none", accessibilityRole: "radiogroup", children: Array.from({ length: total }, (_, index) => {
96
+ const score = index + 1;
97
+ const active = score <= current;
98
+ return (_jsx(Pressable, { accessibilityRole: "radio", accessibilityLabel: messages.ratingValue(score, total), accessibilityState: { checked: score === current, disabled: locked }, "aria-checked": score === current, "aria-disabled": locked, disabled: locked, onPress: () => {
99
+ const next = allowClear && score === current ? 0 : score;
100
+ if (next !== current && onValueChange?.(next) !== false)
101
+ change(next);
102
+ }, style: {
103
+ minHeight: 44,
104
+ minWidth: 44,
105
+ justifyContent: 'center',
106
+ alignItems: 'center',
107
+ opacity: disabled ? 0.55 : 1,
108
+ }, children: icon?.(active) ?? (_jsx(Text, { accessible: false, style: {
109
+ color: active ? tone.text : theme.colors.muted,
110
+ fontSize: theme.fontSize + 8 + sizeStep[resolve(size, 'md')],
111
+ }, children: active ? '★' : '☆' })) }, score));
112
+ }) }), _jsx(FieldMessage, { message: validation.message || hint || '', invalid: Boolean(validation.message), theme: theme })] }));
113
+ });
114
+ export const Slider = forwardRef(function Slider({ value, defaultValue, onValueChange, onValueCommit, min, max, step, range, label, description, hint, invalid, error, required, disabled, readOnly, color, size, showValue, orientation, ...props }, ref) {
115
+ const { theme, direction, resolve } = useTramaAppearance();
116
+ const messages = useTramaMessages();
117
+ const low = min !== undefined && Number.isFinite(min) ? min : 0;
118
+ const high = max !== undefined && Number.isFinite(max) && max > low ? max : low + 100;
119
+ const increment = step !== undefined && Number.isFinite(step) && step > 0 ? step : 1;
120
+ const [owned, update] = useControllableValue(value, defaultValue ?? (range ? [low, high] : low), onValueChange);
121
+ const hasRange = range ?? typeof owned !== 'number';
122
+ const clamped = (next) => Math.min(high, Math.max(low, Number.isFinite(next) ? next : low));
123
+ const supplied = typeof owned === 'number' ? [owned, high] : owned;
124
+ const values = hasRange ? supplied.map(clamped).sort((a, b) => a - b) : [clamped(supplied[0])];
125
+ const [extent, setExtent] = useState(0);
126
+ const vertical = resolve(orientation, 'horizontal') === 'vertical';
127
+ const locked = Boolean(disabled || readOnly);
128
+ const movement = useRef(null);
129
+ const tone = getTone(theme, resolve(color, 'accent'));
130
+ const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), required && !values.length ? messages.chooseOption : '', locked);
131
+ useImperativeHandle(ref, () => ({
132
+ checkValidity: validation.checkValidity,
133
+ reportValidity: validation.reportValidity,
134
+ }));
135
+ function bounded(next, thumb) {
136
+ const rounded = clamped(Number((low + Math.round((clamped(next) - low) / increment) * increment).toPrecision(12)));
137
+ if (!hasRange)
138
+ return rounded;
139
+ return thumb === 0
140
+ ? [Math.min(rounded, values[1]), values[1]]
141
+ : [values[0], Math.max(rounded, values[0])];
142
+ }
143
+ function translate(position) {
144
+ const fraction = Math.min(1, Math.max(0, position / Math.max(1, extent)));
145
+ return low + (vertical || direction === 'rtl' ? 1 - fraction : fraction) * (high - low);
146
+ }
147
+ const pan = PanResponder.create({
148
+ onStartShouldSetPanResponder: () => !locked && extent > 0,
149
+ onPanResponderGrant: (event) => {
150
+ const start = vertical ? event.nativeEvent.locationY : event.nativeEvent.locationX;
151
+ const next = translate(start);
152
+ const thumb = hasRange && Math.abs(next - values[1]) < Math.abs(next - values[0]) ? 1 : 0;
153
+ const result = bounded(next, thumb);
154
+ movement.current = { start, thumb, last: result };
155
+ update(result);
156
+ },
157
+ onPanResponderMove: (_event, gesture) => {
158
+ const active = movement.current;
159
+ if (!active || locked)
160
+ return;
161
+ const result = bounded(translate(active.start + (vertical ? gesture.dy : gesture.dx)), active.thumb);
162
+ active.last = result;
163
+ update(result);
164
+ },
165
+ onPanResponderRelease: () => {
166
+ if (!locked && movement.current)
167
+ onValueCommit?.(movement.current.last);
168
+ movement.current = null;
169
+ },
170
+ onPanResponderTerminate: () => {
171
+ movement.current = null;
172
+ },
173
+ });
174
+ const sizeValue = theme.space * (5 + sizeStep[resolve(size, 'md')]);
175
+ function percent(number) {
176
+ return `${(100 * (number - low)) / (high - low)}%`;
177
+ }
178
+ const from = hasRange ? values[0] : low;
179
+ const to = values.at(-1) ?? low;
180
+ const length = `${(100 * (to - from)) / (high - low)}%`;
181
+ return (_jsxs(Stack, { ...props, gap: "xs", children: [(label || showValue) && (_jsxs(Cluster, { justify: "between", children: [label && _jsx(Text, { style: { color: theme.colors.text }, children: label }), showValue && _jsx(Text, { style: { color: theme.colors.muted }, children: values.join(' – ') })] })), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), _jsxs(View, { ...pan.panHandlers, onLayout: (event) => setExtent(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width), style: {
182
+ direction,
183
+ width: vertical ? 44 : '100%',
184
+ height: vertical ? 180 : 44,
185
+ justifyContent: 'center',
186
+ alignItems: 'center',
187
+ }, children: [_jsx(View, { pointerEvents: "none", style: {
188
+ width: vertical ? theme.space : '100%',
189
+ height: vertical ? '100%' : theme.space,
190
+ borderRadius: theme.radius,
191
+ backgroundColor: theme.colors.border,
192
+ }, children: _jsx(View, { style: {
193
+ backgroundColor: tone.solid,
194
+ borderRadius: theme.radius,
195
+ position: 'absolute',
196
+ ...(vertical
197
+ ? { bottom: percent(from), width: '100%', height: length }
198
+ : { start: percent(from), width: length, height: '100%' }),
199
+ } }) }), values.map((amount, thumb) => (_jsx(View, { pointerEvents: "none", accessible: true, accessibilityRole: "adjustable", accessibilityLabel: hasRange ? `${label ?? ''} ${thumb === 0 ? messages.minimum : messages.maximum}`.trim() : label, accessibilityHint: validation.message || hint || description, accessibilityState: { disabled: locked }, accessibilityValue: { min: low, max: high, now: amount }, accessibilityActions: locked ? [] : [{ name: 'increment' }, { name: 'decrement' }], onAccessibilityAction: (event) => {
200
+ if (locked)
201
+ return;
202
+ const action = event.nativeEvent.actionName;
203
+ if (action !== 'increment' && action !== 'decrement')
204
+ return;
205
+ const result = bounded(amount + (action === 'increment' ? increment : -increment), thumb);
206
+ update(result);
207
+ onValueCommit?.(result);
208
+ }, style: {
209
+ position: 'absolute',
210
+ width: sizeValue,
211
+ height: sizeValue,
212
+ borderRadius: sizeValue / 2,
213
+ backgroundColor: tone.solid,
214
+ borderWidth: 2,
215
+ borderColor: theme.colors.surface,
216
+ opacity: disabled ? 0.55 : 1,
217
+ ...(vertical
218
+ ? { bottom: percent(amount), marginBottom: -sizeValue / 2 }
219
+ : { start: percent(amount), marginStart: -sizeValue / 2 }),
220
+ } }, thumb)))] }), _jsx(FieldMessage, { message: validation.message || hint || '', invalid: Boolean(validation.message), theme: theme })] }));
221
+ });
@@ -0,0 +1,65 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ import { type PressableProps, type ScrollViewProps, type ViewProps } from 'react-native';
3
+ import { type SystemDragContent, type SystemDragSurfaceProps, type SystemDropDetail, type SystemDropError, type SystemDropKind } from './internal/system-drag.js';
4
+ import { type DropdownMenuProps, type MenuItemProps } from './menus.js';
5
+ export type { SystemDragContent, SystemDragFile, SystemDragSurfaceProps, SystemDropDetail, SystemDropError, SystemDropItem, SystemDropKind, } from './internal/system-drag.js';
6
+ export interface DragItem {
7
+ id: string;
8
+ type?: string;
9
+ data?: unknown;
10
+ }
11
+ export interface DropDetail {
12
+ item: DragItem;
13
+ target: string;
14
+ }
15
+ export interface DragDropProviderProps extends ViewProps {
16
+ onDragStart?: (item: DragItem) => void | false;
17
+ onDrop?: (detail: DropDetail) => void;
18
+ onDragEnd?: (item: DragItem, target?: string) => void;
19
+ systemSurface?: ComponentType<SystemDragSurfaceProps>;
20
+ onSystemDrop?: (detail: SystemDropDetail & {
21
+ target: string;
22
+ }) => void;
23
+ }
24
+ export declare function DragDropProvider({ onDragStart, onDrop, onDragEnd, systemSurface, onSystemDrop, children, ...props }: DragDropProviderProps): import("react").JSX.Element;
25
+ export interface DragScrollAreaProps extends ScrollViewProps {
26
+ edgeSize?: number;
27
+ maxStep?: number;
28
+ }
29
+ export declare function DragScrollArea({ edgeSize, maxStep, horizontal, style, scrollEnabled, onScroll, onLayout, onContentSizeChange, children, ...props }: DragScrollAreaProps): import("react").JSX.Element;
30
+ export interface DragHandleProps extends Omit<PressableProps, 'children'> {
31
+ item: DragItem;
32
+ label?: string;
33
+ children?: ReactNode;
34
+ preview?: ReactNode;
35
+ systemDrag?: SystemDragContent;
36
+ }
37
+ export declare function DragHandle({ item, label, children, preview, systemDrag, disabled, style, onPress, onPressIn, ...props }: DragHandleProps): import("react").JSX.Element;
38
+ export interface DropZoneProps extends ViewProps {
39
+ id: string;
40
+ disabled?: boolean;
41
+ accepts?: (item: DragItem) => boolean;
42
+ onDrop?: (item: DragItem) => void | false;
43
+ systemDrop?: readonly SystemDropKind[];
44
+ onSystemDrop?: (detail: SystemDropDetail) => void | false;
45
+ onSystemDropError?: (error: SystemDropError) => void;
46
+ }
47
+ export declare function DropZone({ id, accepts, onDrop, disabled, systemDrop, onSystemDrop, onSystemDropError, children, style, ...props }: DropZoneProps): import("react").JSX.Element;
48
+ export interface DragPreviewProps extends ViewProps {
49
+ renderItem?: (item: DragItem) => ReactNode;
50
+ }
51
+ export declare function DragPreview({ renderItem, children, style, ...props }: DragPreviewProps): import("react").JSX.Element | null;
52
+ export interface DropIndicatorProps extends ViewProps {
53
+ target?: string;
54
+ visible?: boolean;
55
+ orientation?: 'horizontal' | 'vertical';
56
+ }
57
+ export declare function DropIndicator({ target, visible, orientation, style, ...props }: DropIndicatorProps): import("react").JSX.Element | null;
58
+ export interface MoveMenuProps extends DropdownMenuProps {
59
+ onMove?: (destination: string) => void;
60
+ }
61
+ export declare function MoveMenu({ children, onMove, label, ...props }: MoveMenuProps): import("react").JSX.Element;
62
+ export interface MoveOptionProps extends MenuItemProps {
63
+ value: string;
64
+ }
65
+ export declare function MoveOption({ value, onSelect, ...props }: MoveOptionProps): import("react").JSX.Element;