@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,230 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, createContext, isValidElement, useContext, useState } from 'react';
3
+ import { FlatList, Pressable, 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 { Checkbox } from './choices.js';
8
+ import { splitContent, TextContent } from './internal/content.js';
9
+ import { useControllableValue } from './internal/state.js';
10
+ import { Cluster, Grid, Stack } from './layout.js';
11
+ import { useTramaMessages } from './localization.js';
12
+ import { useTramaAppearance, useTramaTheme } from './theme.js';
13
+ const ListContext = createContext(null);
14
+ function chooseItem(current, id, multiple) {
15
+ return current.includes(id) ? current.filter((value) => value !== id) : multiple ? [...current, id] : [id];
16
+ }
17
+ export function List({ items, selection = 'none', value, defaultValue, onValueChange, disabled, variant, layout, columns, virtualized, height, renderItem, children, style, ...props }) {
18
+ const { theme, direction, resolve } = useTramaAppearance();
19
+ const [owned, request] = useControllableValue(value, defaultValue ?? (selection === 'multiple' ? [] : ''));
20
+ const selected = typeof owned === 'string' ? (owned ? [owned] : []) : owned;
21
+ const treatment = resolve(variant, 'plain');
22
+ const body = items
23
+ ? items.map((item) => _jsx(View, { children: renderItem?.(item) ?? _jsx(ListItem, { ...item }) }, item.value))
24
+ : children;
25
+ function choose(id) {
26
+ if (disabled || selection === 'none')
27
+ return;
28
+ const next = chooseItem(selected, id, selection === 'multiple');
29
+ const state = selection === 'multiple' ? next : (next[0] ?? '');
30
+ if (onValueChange?.(state) !== false)
31
+ request(state);
32
+ }
33
+ return (_jsx(ListContext.Provider, { value: { selection, selected, disabled, choose }, children: _jsx(View, { ...props, style: [
34
+ {
35
+ direction,
36
+ height,
37
+ borderRadius: theme.radius,
38
+ borderColor: theme.colors.border,
39
+ borderWidth: treatment === 'outlined' ? 1 : 0,
40
+ backgroundColor: treatment === 'soft' ? theme.colors.subtle : 'transparent',
41
+ },
42
+ style,
43
+ ], children: items && virtualized && height !== undefined ? (_jsx(FlatList, { data: items, keyExtractor: (item) => item.value, extraData: owned, renderItem: ({ item }) => _jsx(_Fragment, { children: renderItem?.(item) ?? _jsx(ListItem, { ...item }) }) })) : resolve(layout, 'stack') === 'grid' ? (_jsx(Grid, { columns: columns, children: body })) : (_jsx(Stack, { gap: "xs", children: body })) }) }));
44
+ }
45
+ export function ListItem({ value, label, description, media, disabled, onPress, children, style, ...props }) {
46
+ const group = useContext(ListContext);
47
+ const { theme } = useTramaAppearance();
48
+ const { body, named } = splitContent(children, { media: ListItemMedia, actions: ListItemActions });
49
+ const selectable = Boolean(group && group.selection !== 'none');
50
+ const active = Boolean(group?.selected.includes(value));
51
+ const unavailable = Boolean(disabled || group?.disabled);
52
+ const content = (_jsxs(_Fragment, { children: [named.media ?? media, _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontWeight: '600' }, children: label }), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), _jsx(TextContent, { style: { color: theme.colors.text }, children: body })] })] }));
53
+ const row = {
54
+ flex: 1,
55
+ flexDirection: 'row',
56
+ alignItems: 'center',
57
+ gap: theme.space * 2,
58
+ minHeight: 44,
59
+ padding: theme.space * 2,
60
+ };
61
+ return (_jsxs(Cluster, { ...props, wrap: "nowrap", gap: "xs", style: [{ borderRadius: theme.radius, backgroundColor: active ? theme.colors.subtle : 'transparent' }, style], children: [selectable || onPress ? (_jsx(Pressable, { style: row, accessibilityRole: selectable ? 'checkbox' : 'button', accessibilityLabel: label, accessibilityHint: description, accessibilityState: { checked: selectable ? active : undefined, disabled: unavailable }, "aria-checked": selectable ? active : undefined, "aria-disabled": unavailable, disabled: unavailable, onPress: (event) => {
62
+ if (selectable)
63
+ group?.choose(value);
64
+ onPress?.(event);
65
+ }, children: content })) : (_jsx(View, { style: row, children: content })), named.actions] }));
66
+ }
67
+ export function ListItemMedia(props) {
68
+ return _jsx(View, { ...props });
69
+ }
70
+ export function ListItemActions(props) {
71
+ return _jsx(Cluster, { ...props });
72
+ }
73
+ const DescriptionLayout = createContext('stacked');
74
+ export function DescriptionList({ layout, columns, children, ...props }) {
75
+ const { resolve } = useTramaAppearance();
76
+ const arrangement = resolve(layout, 'stacked');
77
+ return (_jsx(DescriptionLayout.Provider, { value: arrangement, children: arrangement === 'grid' ? (_jsx(Grid, { ...props, columns: columns, children: children })) : (_jsx(Stack, { ...props, gap: "sm", children: children })) }));
78
+ }
79
+ export function DescriptionListItem({ term, description, children, ...props }) {
80
+ const theme = useTramaTheme();
81
+ const horizontal = useContext(DescriptionLayout) === 'split';
82
+ const { body, named } = splitContent(children, { actions: DescriptionListActions });
83
+ return (_jsxs(Stack, { ...props, gap: "xs", direction: horizontal ? 'row' : 'column', children: [_jsx(Text, { style: { color: theme.colors.muted, fontWeight: '600', width: horizontal ? '35%' : undefined }, children: term }), _jsxs(View, { style: horizontal ? { flex: 1, minWidth: 0 } : undefined, children: [description && _jsx(Text, { style: { color: theme.colors.text }, children: description }), _jsx(TextContent, { style: { color: theme.colors.text }, children: body })] }), named.actions] }));
84
+ }
85
+ export function DescriptionListActions(props) {
86
+ return _jsx(Cluster, { ...props });
87
+ }
88
+ export function Timeline({ orientation, children, ...props }) {
89
+ const { resolve } = useTramaAppearance();
90
+ return (_jsx(Stack, { ...props, direction: resolve(orientation, 'vertical') === 'horizontal' ? 'row' : 'column', wrap: "wrap", gap: "sm", children: children }));
91
+ }
92
+ export function TimelineItem({ heading, description, time, status, children, style, ...props }) {
93
+ const { theme } = useTramaAppearance();
94
+ const { body, named } = splitContent(children, { media: TimelineItemMedia, actions: TimelineItemActions });
95
+ const dot = status === 'error' ? theme.colors.danger : status === 'complete' ? theme.colors.successSolid : theme.colors.accent;
96
+ return (_jsxs(Stack, { ...props, direction: "row", gap: "sm", style: [{ borderStartWidth: 1, borderColor: theme.colors.border, paddingStart: theme.space * 3 }, style], children: [named.media ?? (_jsx(View, { accessibilityElementsHidden: true, style: {
97
+ width: theme.space * 2,
98
+ height: theme.space * 2,
99
+ marginTop: theme.space,
100
+ borderRadius: theme.space,
101
+ backgroundColor: dot,
102
+ } })), _jsxs(Stack, { gap: "xs", style: { flexShrink: 1 }, children: [heading && (_jsx(Text, { accessibilityRole: "header", style: { color: theme.colors.text, fontWeight: '700' }, children: heading })), time && _jsx(Text, { style: { color: theme.colors.muted }, children: time }), description && _jsx(Text, { style: { color: theme.colors.text }, children: description }), _jsx(TextContent, { style: { color: theme.colors.text }, children: body }), named.actions] })] }));
103
+ }
104
+ export function TimelineItemActions(props) {
105
+ return _jsx(Cluster, { ...props });
106
+ }
107
+ export function TimelineItemMedia(props) {
108
+ return _jsx(View, { ...props });
109
+ }
110
+ export function ActivityFeed({ items, children, ...props }) {
111
+ return (_jsx(Timeline, { ...props, children: items?.map(({ id, actor, title, description, time, image }) => (_jsx(TimelineItem, { heading: title, description: description, time: time, children: actor && (_jsx(TimelineItemMedia, { children: _jsx(Avatar, { size: "sm", alt: actor, src: image }) })) }, id))) ?? children }));
112
+ }
113
+ export function TransferItem({ value: _value, disabled: _disabled, label, media, children, ...props }) {
114
+ const theme = useTramaTheme();
115
+ return (_jsxs(Cluster, { ...props, children: [media, _jsx(Text, { style: { color: theme.colors.text }, children: label }), children] }));
116
+ }
117
+ export function TransferItemMedia(props) {
118
+ return _jsx(View, { ...props });
119
+ }
120
+ export function TransferList({ items, value, defaultValue, onValueChange, sourceLabel, targetLabel, disabled, children, ...props }) {
121
+ const [owned, request] = useControllableValue(value, defaultValue ?? []);
122
+ const [checked, setChecked] = useState([]);
123
+ const messages = useTramaMessages();
124
+ const { theme } = useTramaAppearance();
125
+ const records = items ??
126
+ Children.toArray(children).flatMap((element) => isValidElement(element) && element.type === TransferItem
127
+ ? [
128
+ {
129
+ ...element.props,
130
+ media: element.props.media ?? splitContent(element.props.children, { media: TransferItemMedia }).named.media,
131
+ },
132
+ ]
133
+ : []);
134
+ const included = [...new Set(owned)].filter((id) => records.some((item) => item.value === id));
135
+ const source = records.filter((item) => !included.includes(item.value));
136
+ const target = records.filter((item) => included.includes(item.value));
137
+ const available = (entries) => entries.filter((entry) => !entry.disabled && checked.includes(entry.value));
138
+ function move(toTarget) {
139
+ if (disabled)
140
+ return;
141
+ const selected = available(toTarget ? source : target).map((entry) => entry.value);
142
+ if (!selected.length)
143
+ return;
144
+ const next = toTarget ? [...included, ...selected] : included.filter((id) => !selected.includes(id));
145
+ if (onValueChange?.(next) !== false) {
146
+ request(next);
147
+ setChecked((previous) => previous.filter((id) => !selected.includes(id)));
148
+ }
149
+ }
150
+ const column = (label, entries, toTarget) => (_jsxs(Stack, { gap: "xs", children: [_jsx(Text, { accessibilityRole: "header", style: { color: theme.colors.text, fontWeight: '700' }, children: label }), entries.map((entry) => (_jsx(Checkbox, { label: entry.label, checked: checked.includes(entry.value), disabled: disabled || entry.disabled, onCheckedChange: () => {
151
+ setChecked((previous) => chooseItem(previous, entry.value, true));
152
+ }, children: entry.media }, entry.value))), _jsx(Button, { variant: "outlined", disabled: disabled || available(entries).length === 0, onPress: () => move(toTarget), children: toTarget ? messages.addSelected : messages.removeSelected })] }));
153
+ return (_jsxs(Grid, { ...props, columns: { base: 1, md: 2 }, children: [column(sourceLabel ?? messages.availableItems, source, true), column(targetLabel ?? messages.chosenItems, target, false)] }));
154
+ }
155
+ export function TreeItem({ children }) {
156
+ return _jsx(_Fragment, { children: children });
157
+ }
158
+ export function TreeItemMedia(props) {
159
+ return _jsx(View, { ...props });
160
+ }
161
+ export function TreeItemBadge(props) {
162
+ return _jsx(View, { ...props });
163
+ }
164
+ export function TreeItemDescription(props) {
165
+ return _jsx(DescriptionListActions, { ...props });
166
+ }
167
+ export function TreeItemLabel(props) {
168
+ return _jsx(View, { ...props });
169
+ }
170
+ function treeRecords(children) {
171
+ return Children.toArray(children).flatMap((element) => {
172
+ if (!isValidElement(element) || element.type !== TreeItem)
173
+ return [];
174
+ const { children: content, ...entry } = element.props;
175
+ const { body, named } = splitContent(content, {
176
+ media: TreeItemMedia,
177
+ badge: TreeItemBadge,
178
+ label: TreeItemLabel,
179
+ description: TreeItemDescription,
180
+ });
181
+ const label = named.label?.[0];
182
+ const description = named.description?.[0];
183
+ const childText = (part) => isValidElement(part) && typeof part.props.children === 'string' ? part.props.children : undefined;
184
+ return [
185
+ {
186
+ ...entry,
187
+ label: childText(label) ?? entry.label,
188
+ description: childText(description) ?? entry.description,
189
+ media: named.media ?? entry.media,
190
+ badge: named.badge ?? entry.badge,
191
+ children: treeRecords(body),
192
+ },
193
+ ];
194
+ });
195
+ }
196
+ export function TreeView({ items, expanded, defaultExpanded, onExpandedChange, value, defaultValue, onValueChange, selection = 'none', selectionStyle = 'highlight', size, children, ...props }) {
197
+ const { theme, resolve } = useTramaAppearance();
198
+ const [open, requestOpen] = useControllableValue(expanded, defaultExpanded ?? []);
199
+ const [selected, requestSelected] = useControllableValue(value, defaultValue ?? []);
200
+ const records = items ?? treeRecords(children);
201
+ const messages = useTramaMessages();
202
+ function render(nodes, depth) {
203
+ return nodes.map((node) => {
204
+ const active = selected.includes(node.value);
205
+ const expandedNode = open.includes(node.value);
206
+ const branch = Boolean(node.children?.length);
207
+ const indentation = depth * theme.space * 4;
208
+ function toggle() {
209
+ const next = chooseItem(open, node.value, true);
210
+ if (onExpandedChange?.(next) !== false)
211
+ requestOpen(next);
212
+ }
213
+ function select() {
214
+ const next = chooseItem(selected, node.value, selection === 'multiple');
215
+ if (onValueChange?.(next) !== false)
216
+ requestSelected(next);
217
+ }
218
+ return (_jsxs(View, { children: [_jsxs(Cluster, { wrap: "nowrap", gap: "xs", style: { marginStart: indentation, backgroundColor: active ? theme.colors.subtle : 'transparent' }, children: [branch && (_jsx(Button, { variant: "text", size: size, disabled: node.disabled, "aria-expanded": expandedNode, accessibilityLabel: expandedNode ? messages.collapseItem(node.label) : messages.expandItem(node.label), onPress: toggle, children: expandedNode ? '−' : '+' })), node.media, selectionStyle === 'checkbox' && selection !== 'none' ? (_jsx(Checkbox, { label: node.label, description: node.description, disabled: node.disabled, checked: active, onCheckedChange: select })) : selection === 'none' && !branch ? (_jsxs(View, { children: [_jsx(Text, { style: { color: theme.colors.text }, children: node.label }), node.description && _jsx(Text, { style: { color: theme.colors.muted }, children: node.description })] })) : (_jsx(Button, { variant: "text", size: resolve(size, 'md'), disabled: node.disabled, accessibilityState: { selected: active }, onPress: selection === 'none' ? toggle : select, children: node.label })), node.badge] }), branch && expandedNode && node.children && render(node.children, depth + 1)] }, node.value));
219
+ });
220
+ }
221
+ return (_jsx(Stack, { ...props, gap: "xs", children: render(records, 0) }));
222
+ }
223
+ export function ErrorSummary({ heading, announcement = 'assertive', children, ...props }) {
224
+ const messages = useTramaMessages();
225
+ return (_jsx(Alert, { ...props, severity: "danger", heading: heading ?? messages.reviewField, announcement: announcement, children: _jsx(Stack, { gap: "xs", children: children }) }));
226
+ }
227
+ export function ErrorSummaryItem({ label, onActivate, children, ...props }) {
228
+ const theme = useTramaTheme();
229
+ return (_jsxs(View, { ...props, children: [onActivate ? (_jsx(Button, { variant: "text", color: "red", onPress: onActivate, children: label })) : (_jsx(Text, { style: { color: theme.colors.danger, paddingVertical: theme.space }, children: label })), children] }));
230
+ }
@@ -0,0 +1,37 @@
1
+ import { type ViewProps } from 'react-native';
2
+ import { type FieldHandle } from './input.js';
3
+ export interface ColorPickerProps extends ViewProps {
4
+ label?: string;
5
+ value?: string;
6
+ defaultValue?: string;
7
+ onValueChange?: (color: string) => void | false;
8
+ onValueCommit?: (color: string) => void;
9
+ swatches?: readonly string[];
10
+ showChannels?: boolean;
11
+ alpha?: boolean;
12
+ required?: boolean;
13
+ disabled?: boolean;
14
+ readOnly?: boolean;
15
+ invalid?: boolean;
16
+ error?: string;
17
+ }
18
+ export declare const ColorPicker: import("react").ForwardRefExoticComponent<ColorPickerProps & import("react").RefAttributes<FieldHandle>>;
19
+ export interface ColorPickerSwatchProps extends ViewProps {
20
+ color: string;
21
+ label?: string;
22
+ disabled?: boolean;
23
+ selected?: boolean;
24
+ onSelect?: (color: string) => void | false;
25
+ }
26
+ export declare function ColorPickerSwatch({ color, label, disabled, selected, onSelect, style, accessibilityLabel, ...props }: ColorPickerSwatchProps): import("react").JSX.Element;
27
+ export interface CodeBlockProps extends ViewProps {
28
+ code: string;
29
+ heading?: string;
30
+ language?: string;
31
+ lineNumbers?: boolean;
32
+ wrap?: boolean;
33
+ highlightLines?: readonly number[];
34
+ onCopy?: (code: string) => void | Promise<void>;
35
+ onCopyError?: (error: unknown) => void;
36
+ }
37
+ export declare function CodeBlock({ code, heading, language, lineNumbers, wrap, highlightLines, onCopy, onCopyError, style, ...props }: CodeBlockProps): import("react").JSX.Element;
@@ -0,0 +1,158 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, cloneElement, forwardRef, isValidElement, useImperativeHandle, useRef, useState } from 'react';
3
+ import { Platform, Pressable, ScrollView, Text, View } from 'react-native';
4
+ import { Button } from './button.js';
5
+ import { Slider } from './controls.js';
6
+ import { TextEntry } from './input.js';
7
+ import { useControllableValue } from './internal/state.js';
8
+ import { Cluster } from './layout.js';
9
+ import { useTramaMessages } from './localization.js';
10
+ import { useTramaAppearance, useTramaTheme } from './theme.js';
11
+ const channels = ['r', 'g', 'b', 'a'];
12
+ function toHex(value) {
13
+ const hex = value.trim().replace(/^#/u, '').toUpperCase();
14
+ if (/^(?:[0-9A-F]{3}|[0-9A-F]{4})$/u.test(hex))
15
+ return '#' + [...hex].map((part) => part + part).join('');
16
+ return /^(?:[0-9A-F]{6}|[0-9A-F]{8})$/u.test(hex) ? '#' + hex : '';
17
+ }
18
+ export const ColorPicker = forwardRef(function ColorPicker({ label, value, defaultValue, onValueChange, onValueCommit, swatches, showChannels, alpha, required, disabled, readOnly, invalid, error, children, style, ...props }, ref) {
19
+ const { theme, direction } = useTramaAppearance();
20
+ const messages = useTramaMessages();
21
+ const [current, setColor] = useControllableValue(value, defaultValue ?? '');
22
+ const [draft, setDraft] = useState(null);
23
+ const control = useRef(null);
24
+ const locked = Boolean(disabled || readOnly);
25
+ const visible = toHex(current);
26
+ const digits = visible.slice(1).padEnd(6, '0').padEnd(8, 'F');
27
+ useImperativeHandle(ref, () => ({
28
+ checkValidity: () => control.current?.checkValidity() ?? true,
29
+ reportValidity: () => control.current?.reportValidity() ?? true,
30
+ }));
31
+ function diagnose(text) {
32
+ if (!text)
33
+ return '';
34
+ const color = toHex(text);
35
+ return !color || (!alpha && color.length > 7) ? messages.enterColor : '';
36
+ }
37
+ function choose(candidate, commit = false) {
38
+ const next = candidate ? toHex(candidate) : '';
39
+ if (locked || diagnose(candidate) || onValueChange?.(next) === false)
40
+ return;
41
+ setColor(next);
42
+ if (commit)
43
+ onValueCommit?.(next);
44
+ }
45
+ function colorAt(index, number) {
46
+ const updated = number.toString(16).padStart(2, '0');
47
+ return '#' + digits.slice(0, index * 2) + updated + digits.slice(index * 2 + 2, alpha ? 8 : 6);
48
+ }
49
+ const selections = [
50
+ ...(swatches ?? []).map((color) => _jsx(ColorPickerSwatch, { color: color }, color)),
51
+ ...Children.toArray(children),
52
+ ];
53
+ return (_jsxs(View, { ...props, style: [{ gap: theme.space * 2, direction }, style], children: [_jsx(TextEntry, { ref: control, label: label ?? messages.color, value: draft ?? current, required: required, disabled: disabled, readOnly: readOnly, invalid: invalid, error: error, maxLength: alpha ? 9 : 7, autoCorrect: false, autoCapitalize: "characters", placeholder: "#2D7654", onChangeText: (text) => {
54
+ setDraft(text);
55
+ if (!diagnose(text))
56
+ choose(text);
57
+ }, onBlur: () => {
58
+ if (draft !== null && !diagnose(draft)) {
59
+ onValueCommit?.(toHex(draft));
60
+ setDraft(null);
61
+ }
62
+ }, validateValue: diagnose }), selections.length > 0 && (_jsx(Cluster, { gap: "xs", children: selections.map((child) => isValidElement(child) && child.type === ColorPickerSwatch
63
+ ? cloneElement(child, {
64
+ disabled: locked || child.props.disabled,
65
+ selected: visible !== '' && toHex(child.props.color) === visible,
66
+ onSelect: (candidate) => {
67
+ if (child.props.onSelect?.(candidate) !== false) {
68
+ choose(candidate, true);
69
+ setDraft(null);
70
+ }
71
+ },
72
+ })
73
+ : child) })), visible ? (_jsx(View, { accessible: true, accessibilityLabel: visible, style: {
74
+ height: 40,
75
+ borderWidth: 1,
76
+ borderColor: theme.colors.border,
77
+ borderRadius: theme.radius,
78
+ backgroundColor: visible,
79
+ } })) : null, showChannels &&
80
+ channels.slice(0, alpha ? 4 : 3).map((channel, index) => (_jsx(Slider, { label: messages.colorChannels[channel], max: 255, min: 0, step: 1, value: parseInt(digits.slice(index * 2, index * 2 + 2), 16), disabled: disabled, readOnly: readOnly, onValueChange: (number) => {
81
+ if (typeof number === 'number') {
82
+ choose(colorAt(index, number));
83
+ setDraft(null);
84
+ }
85
+ }, onValueCommit: (number) => {
86
+ if (typeof number === 'number')
87
+ onValueCommit?.(toHex(colorAt(index, number)));
88
+ } }, channel)))] }));
89
+ });
90
+ export function ColorPickerSwatch({ color, label, disabled, selected, onSelect, style, accessibilityLabel, ...props }) {
91
+ const theme = useTramaTheme();
92
+ const hex = toHex(color);
93
+ return (_jsx(Pressable, { ...props, accessibilityRole: "button", accessibilityLabel: accessibilityLabel ?? label ?? color, accessibilityState: { selected: Boolean(selected), disabled: disabled || !hex }, disabled: disabled || !hex, onPress: () => onSelect?.(color), style: [
94
+ {
95
+ minWidth: 44,
96
+ minHeight: 44,
97
+ padding: 6,
98
+ justifyContent: 'center',
99
+ alignItems: 'center',
100
+ borderRadius: theme.radius,
101
+ borderWidth: 2,
102
+ borderColor: selected ? theme.colors.accent : 'transparent',
103
+ },
104
+ style,
105
+ ], children: _jsx(View, { pointerEvents: "none", style: {
106
+ width: 28,
107
+ height: 28,
108
+ borderRadius: theme.radius / 2,
109
+ backgroundColor: hex || theme.colors.subtle,
110
+ borderColor: theme.colors.border,
111
+ borderWidth: 1,
112
+ opacity: disabled ? 0.6 : 1,
113
+ } }) }));
114
+ }
115
+ export function CodeBlock({ code, heading, language, lineNumbers, wrap, highlightLines, onCopy, onCopyError, style, ...props }) {
116
+ const theme = useTramaTheme();
117
+ const messages = useTramaMessages();
118
+ const [status, setStatus] = useState('idle');
119
+ const display = [heading, language].filter(Boolean).join(' · ');
120
+ const mono = Platform.select({ ios: 'Menlo', android: 'monospace', default: 'monospace' });
121
+ const lines = code.split(/\r?\n/u);
122
+ const numberWidth = String(lines.length).length;
123
+ async function copy() {
124
+ if (!onCopy || status === 'busy')
125
+ return;
126
+ setStatus('busy');
127
+ try {
128
+ await onCopy(code);
129
+ setStatus('copied');
130
+ }
131
+ catch (error) {
132
+ setStatus('error');
133
+ onCopyError?.(error);
134
+ }
135
+ }
136
+ const body = (_jsx(View, { style: { padding: theme.space * 3, direction: 'ltr' }, children: lines.map((line, index) => (_jsxs(View, { style: {
137
+ flexDirection: 'row',
138
+ backgroundColor: highlightLines?.includes(index + 1) ? theme.colors.surface : 'transparent',
139
+ }, children: [lineNumbers && (_jsx(Text, { accessible: false, style: { color: theme.colors.muted, fontFamily: mono, marginEnd: theme.space * 2 }, children: String(index + 1).padStart(numberWidth) })), _jsx(Text, { selectable: true, style: { color: theme.colors.text, fontFamily: mono, flexShrink: wrap ? 1 : 0 }, children: line || ' ' })] }, index))) }));
140
+ return (_jsxs(View, { ...props, style: [
141
+ {
142
+ overflow: 'hidden',
143
+ borderWidth: 1,
144
+ borderColor: theme.colors.border,
145
+ borderRadius: theme.radius,
146
+ backgroundColor: theme.colors.subtle,
147
+ },
148
+ style,
149
+ ], children: [(display || onCopy) && (_jsxs(Cluster, { style: {
150
+ paddingHorizontal: theme.space * 3,
151
+ paddingVertical: theme.space * 2,
152
+ borderBottomWidth: 1,
153
+ borderColor: theme.colors.border,
154
+ justifyContent: 'space-between',
155
+ }, children: [display && _jsx(Text, { style: { color: theme.colors.muted }, children: display }), onCopy && (_jsx(Button, { variant: "text", size: "sm", loading: status === 'busy', onPress: () => {
156
+ void copy();
157
+ }, children: status === 'copied' ? messages.copied : status === 'error' ? messages.retry : messages.copyCode }))] })), wrap ? body : _jsx(ScrollView, { horizontal: true, children: body })] }));
158
+ }
@@ -0,0 +1,110 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ViewProps } from 'react-native';
3
+ import { type AvatarProps } from './avatar.js';
4
+ import { type ButtonProps } from './button.js';
5
+ import { type CardProps } from './card.js';
6
+ import { type GridColumns } from './layout.js';
7
+ import type { TramaResponsive } from './responsive.js';
8
+ import { type TramaSize } from './theme.js';
9
+ export interface PageHeaderProps extends ViewProps {
10
+ heading?: string;
11
+ description?: string;
12
+ eyebrow?: string;
13
+ layout?: TramaResponsive<'stacked' | 'split'>;
14
+ size?: TramaResponsive<TramaSize>;
15
+ }
16
+ export declare function PageHeader({ heading, description, eyebrow, layout, size, children, ...props }: PageHeaderProps): import("react").JSX.Element;
17
+ export declare function PageHeaderActions(props: ViewProps): import("react").JSX.Element;
18
+ export declare function PageHeaderBreadcrumbs(props: ViewProps): import("react").JSX.Element;
19
+ export declare function PageHeaderMeta({ children, ...props }: ViewProps): import("react").JSX.Element;
20
+ export declare function PageHeaderNavigation(props: ViewProps): import("react").JSX.Element;
21
+ export interface AppShellProps extends ViewProps {
22
+ header?: ReactNode;
23
+ sidebar?: ReactNode;
24
+ footer?: ReactNode;
25
+ hideSidebar?: TramaResponsive<boolean>;
26
+ sidebarPlacement?: TramaResponsive<'start' | 'end'>;
27
+ }
28
+ export declare function AppShell({ header, sidebar, footer, hideSidebar, sidebarPlacement, children, style, ...props }: AppShellProps): import("react").JSX.Element;
29
+ export interface DashboardSectionsProps extends ViewProps {
30
+ heading?: string;
31
+ columns?: TramaResponsive<GridColumns>;
32
+ description?: string;
33
+ }
34
+ export declare function DashboardSections({ heading, columns, description, children, ...props }: DashboardSectionsProps): import("react").JSX.Element;
35
+ export interface MetricsCardProps extends CardProps {
36
+ value?: string | number;
37
+ trend?: string;
38
+ trendDirection?: 'up' | 'down' | 'neutral';
39
+ }
40
+ export declare function MetricsCard({ value, trend, trendDirection, children, ...props }: MetricsCardProps): import("react").JSX.Element;
41
+ export interface ProfileHeaderProps extends PageHeaderProps {
42
+ name?: string;
43
+ image?: string;
44
+ avatar?: AvatarProps;
45
+ actions?: ReactNode;
46
+ meta?: ReactNode;
47
+ }
48
+ export declare function ProfileHeader({ name, image, avatar, actions, meta, children, ...props }: ProfileHeaderProps): import("react").JSX.Element;
49
+ export interface SettingsLayoutProps extends ViewProps {
50
+ navigation?: ReactNode;
51
+ heading?: string;
52
+ description?: string;
53
+ placement?: 'start' | 'end';
54
+ }
55
+ export declare function SettingsLayout({ navigation, heading, description, placement, children, ...props }: SettingsLayoutProps): import("react").JSX.Element;
56
+ export interface SignInFormProps extends ViewProps {
57
+ heading?: string;
58
+ description?: string;
59
+ emailLabel?: string;
60
+ passwordLabel?: string;
61
+ submitLabel?: string;
62
+ loading?: boolean;
63
+ error?: string;
64
+ onSubmit?: (credentials: {
65
+ email: string;
66
+ password: string;
67
+ }) => void;
68
+ }
69
+ export declare function SignInForm({ heading, description, emailLabel, passwordLabel, submitLabel, loading, error, onSubmit, children, ...props }: SignInFormProps): import("react").JSX.Element;
70
+ export interface NavigationMenuProps extends ViewProps {
71
+ value?: string;
72
+ defaultValue?: string;
73
+ onValueChange?: (value: string) => void | false;
74
+ expanded?: readonly string[];
75
+ defaultExpanded?: readonly string[];
76
+ onExpandedChange?: (value: readonly string[]) => void | false;
77
+ placement?: TramaResponsive<'top' | 'bottom' | 'start' | 'end'>;
78
+ mode?: TramaResponsive<'inline' | 'popup'>;
79
+ position?: TramaResponsive<'inline' | 'fixed'>;
80
+ variant?: TramaResponsive<'plain' | 'soft' | 'outlined'>;
81
+ }
82
+ export declare function NavigationMenu({ value, defaultValue, onValueChange, expanded, defaultExpanded, onExpandedChange, placement, mode, position, variant, children, style, ...props }: NavigationMenuProps): import("react").JSX.Element;
83
+ export interface NavigationMenuItemProps extends ButtonProps {
84
+ value: string;
85
+ label: string;
86
+ href?: string;
87
+ }
88
+ export declare function NavigationMenuItem({ value, label, href, children, onPress, disabled, ...props }: NavigationMenuItemProps): import("react").JSX.Element;
89
+ export declare function NavigationMenuContent(props: ViewProps): import("react").JSX.Element;
90
+ export declare function NavigationMenuSubmenu(props: ViewProps): import("react").JSX.Element;
91
+ export declare function NavigationMenuGroup({ children, label, ...props }: ViewProps & {
92
+ label?: string;
93
+ }): import("react").JSX.Element;
94
+ export declare function NavigationMenuItemMedia(props: ViewProps): import("react").JSX.Element;
95
+ export declare function NavigationMenuIndicator(props: ViewProps): import("react").JSX.Element;
96
+ export declare function Sidebar(props: NavigationMenuProps): import("react").JSX.Element;
97
+ export declare function HeaderNavigation(props: NavigationMenuProps): import("react").JSX.Element;
98
+ export interface AnchorItemProps extends ButtonProps {
99
+ value: string;
100
+ label: string;
101
+ level?: number;
102
+ }
103
+ export interface AnchorNavigationProps extends ViewProps {
104
+ value?: string;
105
+ defaultValue?: string;
106
+ onNavigate?: (value: string) => void | false;
107
+ orientation?: TramaResponsive<'horizontal' | 'vertical'>;
108
+ }
109
+ export declare function AnchorNavigation({ value, defaultValue, onNavigate, orientation, children, ...props }: AnchorNavigationProps): import("react").JSX.Element;
110
+ export declare function AnchorItem({ value, label, level, children, onPress, ...props }: AnchorItemProps): import("react").JSX.Element;