@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.
- package/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/accordion.d.ts +29 -0
- package/dist/accordion.js +137 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +95 -0
- package/dist/avatar.d.ts +36 -0
- package/dist/avatar.js +91 -0
- package/dist/bars.d.ts +44 -0
- package/dist/bars.js +74 -0
- package/dist/button.d.ts +30 -0
- package/dist/button.js +90 -0
- package/dist/calendar.d.ts +71 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +41 -0
- package/dist/card.js +139 -0
- package/dist/choices.d.ts +87 -0
- package/dist/choices.js +228 -0
- package/dist/collections.d.ts +131 -0
- package/dist/collections.js +230 -0
- package/dist/color-code.d.ts +37 -0
- package/dist/color-code.js +158 -0
- package/dist/compositions.d.ts +110 -0
- package/dist/compositions.js +190 -0
- package/dist/controls.d.ts +85 -0
- package/dist/controls.js +221 -0
- package/dist/drag-drop.d.ts +65 -0
- package/dist/drag-drop.js +482 -0
- package/dist/feedback.d.ts +30 -0
- package/dist/feedback.js +81 -0
- package/dist/file-upload.d.ts +67 -0
- package/dist/file-upload.js +251 -0
- package/dist/generated/icons.d.ts +1037 -0
- package/dist/generated/icons.js +3 -0
- package/dist/generated/tokens.d.ts +64 -0
- package/dist/generated/tokens.js +65 -0
- package/dist/icon.d.ts +31 -0
- package/dist/icon.js +28 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/input.d.ts +43 -0
- package/dist/input.js +115 -0
- package/dist/interactive-layout.d.ts +26 -0
- package/dist/interactive-layout.js +117 -0
- package/dist/internal/content.d.ts +17 -0
- package/dist/internal/content.js +24 -0
- package/dist/internal/drag-geometry.d.ts +16 -0
- package/dist/internal/drag-geometry.js +25 -0
- package/dist/internal/keyboard.d.ts +20 -0
- package/dist/internal/keyboard.js +101 -0
- package/dist/internal/motion.d.ts +1 -0
- package/dist/internal/motion.js +24 -0
- package/dist/internal/number-format.d.ts +4 -0
- package/dist/internal/number-format.js +25 -0
- package/dist/internal/pointer-capture.d.ts +1 -0
- package/dist/internal/pointer-capture.js +16 -0
- package/dist/internal/state.d.ts +6 -0
- package/dist/internal/state.js +28 -0
- package/dist/internal/system-drag.d.ts +48 -0
- package/dist/internal/system-drag.js +93 -0
- package/dist/internal/table-drag.d.ts +56 -0
- package/dist/internal/table-drag.js +237 -0
- package/dist/internal/table-editing.d.ts +49 -0
- package/dist/internal/table-editing.js +278 -0
- package/dist/internal/table-editor.d.ts +11 -0
- package/dist/internal/table-editor.js +31 -0
- package/dist/internal/table-grid.d.ts +44 -0
- package/dist/internal/table-grid.js +153 -0
- package/dist/internal/table-model.d.ts +132 -0
- package/dist/internal/table-model.js +231 -0
- package/dist/internal/table-source.d.ts +9 -0
- package/dist/internal/table-source.js +80 -0
- package/dist/internal/tour-target.d.ts +23 -0
- package/dist/internal/tour-target.js +81 -0
- package/dist/keyboard.d.ts +14 -0
- package/dist/keyboard.js +27 -0
- package/dist/layout.d.ts +35 -0
- package/dist/layout.js +77 -0
- package/dist/loader.d.ts +18 -0
- package/dist/loader.js +79 -0
- package/dist/localization.d.ts +106 -0
- package/dist/localization.js +310 -0
- package/dist/media.d.ts +35 -0
- package/dist/media.js +96 -0
- package/dist/menus.d.ts +103 -0
- package/dist/menus.js +422 -0
- package/dist/navigation.d.ts +111 -0
- package/dist/navigation.js +255 -0
- package/dist/overlays.d.ts +97 -0
- package/dist/overlays.js +364 -0
- package/dist/pill.d.ts +33 -0
- package/dist/pill.js +90 -0
- package/dist/progress.d.ts +27 -0
- package/dist/progress.js +154 -0
- package/dist/responsive.d.ts +15 -0
- package/dist/responsive.js +27 -0
- package/dist/select.d.ts +74 -0
- package/dist/select.js +181 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +34 -0
- package/dist/switch.d.ts +26 -0
- package/dist/switch.js +69 -0
- package/dist/table.d.ts +122 -0
- package/dist/table.js +928 -0
- package/dist/text-fields.d.ts +39 -0
- package/dist/text-fields.js +134 -0
- package/dist/theme.d.ts +47 -0
- package/dist/theme.js +71 -0
- package/dist/transient.d.ts +80 -0
- package/dist/transient.js +273 -0
- package/package.json +50 -4
package/dist/menus.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, createContext, forwardRef, isValidElement, useContext, useEffect, useId, useImperativeHandle, useRef, useState, } from 'react';
|
|
3
|
+
import { AccessibilityInfo, Platform, Pressable, ScrollView, Text, View, useWindowDimensions, } from 'react-native';
|
|
4
|
+
import { Button } from './button.js';
|
|
5
|
+
import { Input } from './input.js';
|
|
6
|
+
import { splitContent, TextContent } from './internal/content.js';
|
|
7
|
+
import { matchesKeyboardShortcut } from './internal/keyboard.js';
|
|
8
|
+
import { useControllableValue } from './internal/state.js';
|
|
9
|
+
import { Cluster, Stack } from './layout.js';
|
|
10
|
+
import { useTramaMessages } from './localization.js';
|
|
11
|
+
import { Dialog, Popover, PopoverArrow, PopoverTrigger, } from './overlays.js';
|
|
12
|
+
import { Separator } from './separator.js';
|
|
13
|
+
import { getTone, useTramaAppearance, useTramaTheme } from './theme.js';
|
|
14
|
+
const MenuContext = createContext(null);
|
|
15
|
+
const RadioMenuContext = createContext(null);
|
|
16
|
+
function MenuRow({ value, label, description, shortcut, kind = 'item', color = 'neutral', checked, defaultChecked, closeOnSelect = kind === 'item', onSelect, onCheckedChange, children, disabled, style, actionRef, highlighted, ...props }) {
|
|
17
|
+
const menu = useContext(MenuContext);
|
|
18
|
+
const radio = useContext(RadioMenuContext);
|
|
19
|
+
const { theme, direction } = useTramaAppearance();
|
|
20
|
+
const [local, request] = useControllableValue(checked, defaultChecked ?? false);
|
|
21
|
+
const id = value ?? label;
|
|
22
|
+
const selected = kind === 'radio' && radio ? radio.value === id : local;
|
|
23
|
+
const checkable = kind !== 'item';
|
|
24
|
+
const tone = getTone(theme, color);
|
|
25
|
+
const control = useRef(null);
|
|
26
|
+
function activate() {
|
|
27
|
+
if (disabled || onSelect?.(id) === false)
|
|
28
|
+
return;
|
|
29
|
+
if (checkable) {
|
|
30
|
+
const next = kind === 'radio' || !selected;
|
|
31
|
+
if (next !== selected && onCheckedChange?.(next) !== false) {
|
|
32
|
+
if (kind === 'radio' && radio)
|
|
33
|
+
radio.choose(id);
|
|
34
|
+
else
|
|
35
|
+
request(next);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (closeOnSelect)
|
|
39
|
+
menu?.close();
|
|
40
|
+
}
|
|
41
|
+
useImperativeHandle(actionRef, () => ({ activate, measure: (...args) => control.current?.measureLayout(...args) }));
|
|
42
|
+
return (_jsxs(Pressable, { ...props, ref: control, accessibilityRole: kind === 'checkbox' ? 'checkbox' : kind === 'radio' ? 'radio' : 'menuitem', "aria-checked": checkable ? selected : undefined, "aria-disabled": Boolean(disabled), accessibilityState: { disabled: Boolean(disabled), ...(checkable ? { checked: selected } : {}) }, accessibilityLabel: props.accessibilityLabel ?? label, accessibilityHint: props.accessibilityHint ?? description, disabled: disabled, onPress: activate, style: (state) => [
|
|
43
|
+
{
|
|
44
|
+
direction,
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
alignItems: 'center',
|
|
47
|
+
minHeight: Math.max(44, theme.controlHeight),
|
|
48
|
+
gap: theme.space * 2,
|
|
49
|
+
padding: theme.space * 2,
|
|
50
|
+
borderRadius: theme.radius / 2,
|
|
51
|
+
opacity: disabled ? 0.55 : 1,
|
|
52
|
+
backgroundColor: state.pressed || selected || highlighted ? tone.soft : 'transparent',
|
|
53
|
+
},
|
|
54
|
+
typeof style === 'function' ? style(state) : style,
|
|
55
|
+
], children: [children, _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { color: tone.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily }, children: label }), description && _jsx(Text, { style: { color: theme.colors.muted, fontFamily: theme.fontFamily }, children: description })] }), shortcut && _jsx(Text, { style: { color: theme.colors.muted, fontSize: theme.fontSize - 2 }, children: shortcut }), checkable && (_jsx(Text, { accessible: false, style: { color: tone.text, minWidth: 18 }, children: selected ? '✓' : '' }))] }));
|
|
56
|
+
}
|
|
57
|
+
function Group({ label, value, defaultValue, onValueChange, children, ...props }) {
|
|
58
|
+
const theme = useTramaTheme();
|
|
59
|
+
const [current, request] = useControllableValue(value, defaultValue ?? '');
|
|
60
|
+
return (_jsx(RadioMenuContext.Provider, { value: {
|
|
61
|
+
value: current,
|
|
62
|
+
choose(next) {
|
|
63
|
+
if (next !== current && onValueChange?.(next) !== false)
|
|
64
|
+
request(next);
|
|
65
|
+
},
|
|
66
|
+
}, children: _jsxs(Stack, { ...props, gap: "xs", children: [label && (_jsx(Text, { accessibilityRole: "header", style: { color: theme.colors.muted, fontWeight: '700', padding: theme.space * 2 }, children: label })), children] }) }));
|
|
67
|
+
}
|
|
68
|
+
function Submenu({ children, label, ...props }) {
|
|
69
|
+
const menu = useContext(MenuContext);
|
|
70
|
+
const { direction } = useTramaAppearance();
|
|
71
|
+
return (_jsx(MenuRow, { ...props, label: label, closeOnSelect: false, shortcut: direction === 'rtl' ? '‹' : '›', onSelect: () => {
|
|
72
|
+
menu?.show(label, children);
|
|
73
|
+
} }));
|
|
74
|
+
}
|
|
75
|
+
function useMenu({ open, defaultOpen, onOpenChange }) {
|
|
76
|
+
const [visible, setVisible] = useControllableValue(open, defaultOpen ?? false);
|
|
77
|
+
const [pages, setPages] = useState([]);
|
|
78
|
+
function request(next, reason) {
|
|
79
|
+
if (visible === next || onOpenChange?.(next, { reason }) === false)
|
|
80
|
+
return;
|
|
81
|
+
if (!next)
|
|
82
|
+
setPages([]);
|
|
83
|
+
setVisible(next);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
pages,
|
|
87
|
+
visible,
|
|
88
|
+
request,
|
|
89
|
+
back: () => setPages((current) => current.slice(0, -1)),
|
|
90
|
+
menu: {
|
|
91
|
+
close: () => request(false, 'close-button'),
|
|
92
|
+
show: (title, children) => setPages((current) => [...current, { title, children }]),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function MenuContent({ children, menu }) {
|
|
97
|
+
const messages = useTramaMessages();
|
|
98
|
+
const current = menu.pages.at(-1);
|
|
99
|
+
return (_jsxs(MenuContext.Provider, { value: menu.menu, children: [current && (_jsx(Button, { variant: "text", onPress: menu.back, children: messages.back })), current?.children ?? children] }));
|
|
100
|
+
}
|
|
101
|
+
export const DropdownMenu = forwardRef(function DropdownMenu({ open, defaultOpen, onOpenChange, label, disabled, placement, children, ...props }, ref) {
|
|
102
|
+
const menu = useMenu({ open, defaultOpen, onOpenChange });
|
|
103
|
+
const { body, named } = splitContent(children, { trigger: DropdownMenuTrigger, arrow: DropdownMenuArrow });
|
|
104
|
+
const trigger = named.trigger?.[0];
|
|
105
|
+
const arrow = named.arrow?.[0];
|
|
106
|
+
return (_jsxs(Popover, { ...props, ref: ref, size: "auto", label: label, disabled: disabled, open: menu.visible, placement: placement, onOpenChange: (next, { reason }) => menu.request(next, reason), children: [isValidElement(trigger) && (_jsx(PopoverTrigger, { ...trigger.props, disabled: disabled || trigger.props.disabled })), isValidElement(arrow) && _jsx(PopoverArrow, { ...arrow.props }), _jsx(MenuContent, { menu: menu, children: body })] }));
|
|
107
|
+
});
|
|
108
|
+
export function DropdownMenuTrigger(props) {
|
|
109
|
+
return _jsx(Button, { ...props });
|
|
110
|
+
}
|
|
111
|
+
export function DropdownMenuItem(props) {
|
|
112
|
+
return _jsx(MenuRow, { ...props });
|
|
113
|
+
}
|
|
114
|
+
export function DropdownMenuGroup(props) {
|
|
115
|
+
return _jsx(Group, { ...props });
|
|
116
|
+
}
|
|
117
|
+
export function DropdownMenuSubmenu(props) {
|
|
118
|
+
return _jsx(Submenu, { ...props });
|
|
119
|
+
}
|
|
120
|
+
export function DropdownMenuSeparator(props) {
|
|
121
|
+
return _jsx(Separator, { ...props, spacing: "sm" });
|
|
122
|
+
}
|
|
123
|
+
export function DropdownMenuItemMedia(props) {
|
|
124
|
+
return _jsx(View, { ...props });
|
|
125
|
+
}
|
|
126
|
+
export function DropdownMenuArrow(props) {
|
|
127
|
+
return _jsx(PopoverArrow, { ...props });
|
|
128
|
+
}
|
|
129
|
+
const ContextTarget = createContext(null);
|
|
130
|
+
export const ContextMenu = forwardRef(function ContextMenu({ open, defaultOpen, onOpenChange, label, disabled, children, ...props }, ref) {
|
|
131
|
+
const menu = useMenu({ open, defaultOpen, onOpenChange });
|
|
132
|
+
const messages = useTramaMessages();
|
|
133
|
+
const { body, named } = splitContent(children, { target: ContextMenuTarget });
|
|
134
|
+
useImperativeHandle(ref, () => ({
|
|
135
|
+
show: () => {
|
|
136
|
+
if (!disabled)
|
|
137
|
+
menu.request(true, 'programmatic');
|
|
138
|
+
},
|
|
139
|
+
hide: () => menu.request(false, 'programmatic'),
|
|
140
|
+
toggle: () => {
|
|
141
|
+
if (!disabled || menu.visible)
|
|
142
|
+
menu.request(!menu.visible, 'programmatic');
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
145
|
+
return (_jsxs(ContextTarget.Provider, { value: () => {
|
|
146
|
+
if (!disabled)
|
|
147
|
+
menu.request(true, 'trigger');
|
|
148
|
+
}, children: [named.target ?? _jsx(ContextMenuTarget, { children: label ?? messages.openMenu }), _jsx(Dialog, { ...props, label: label, placement: "bottom", open: menu.visible, onOpenChange: (next, { reason }) => menu.request(next, reason), children: _jsx(MenuContent, { menu: menu, children: body }) })] }));
|
|
149
|
+
});
|
|
150
|
+
export function ContextMenuTarget({ children, onLongPress, onPress, ...props }) {
|
|
151
|
+
const launch = useContext(ContextTarget);
|
|
152
|
+
const { theme } = useTramaAppearance();
|
|
153
|
+
return (_jsx(Pressable, { ...props, accessibilityRole: "button", onLongPress: (event) => {
|
|
154
|
+
onLongPress?.(event);
|
|
155
|
+
launch?.();
|
|
156
|
+
}, onPress: onPress ?? launch, style: props.style ?? { minHeight: 44, justifyContent: 'center' }, children: _jsx(TextContent, { style: { color: theme.colors.text, fontFamily: theme.fontFamily }, children: children }) }));
|
|
157
|
+
}
|
|
158
|
+
export function ContextMenuItem(props) {
|
|
159
|
+
return _jsx(MenuRow, { ...props });
|
|
160
|
+
}
|
|
161
|
+
export function ContextMenuGroup(props) {
|
|
162
|
+
return _jsx(Group, { ...props });
|
|
163
|
+
}
|
|
164
|
+
export function ContextMenuSubmenu(props) {
|
|
165
|
+
return _jsx(Submenu, { ...props });
|
|
166
|
+
}
|
|
167
|
+
export function ContextMenuSeparator(props) {
|
|
168
|
+
return _jsx(Separator, { ...props, spacing: "sm" });
|
|
169
|
+
}
|
|
170
|
+
export function ContextMenuItemMedia(props) {
|
|
171
|
+
return _jsx(View, { ...props });
|
|
172
|
+
}
|
|
173
|
+
export function ContextMenuArrow(props) {
|
|
174
|
+
return _jsx(MenuArrow, { ...props });
|
|
175
|
+
}
|
|
176
|
+
function MenuArrow({ style, ...props }) {
|
|
177
|
+
const theme = useTramaTheme();
|
|
178
|
+
return (_jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none", style: [
|
|
179
|
+
{
|
|
180
|
+
width: 7,
|
|
181
|
+
height: 7,
|
|
182
|
+
borderColor: theme.colors.border,
|
|
183
|
+
borderWidth: 1,
|
|
184
|
+
transform: [{ rotate: '45deg' }],
|
|
185
|
+
backgroundColor: theme.colors.surface,
|
|
186
|
+
},
|
|
187
|
+
style,
|
|
188
|
+
] }));
|
|
189
|
+
}
|
|
190
|
+
const MenubarContext = createContext(null);
|
|
191
|
+
export function Menubar({ value, defaultValue, onValueChange, children, ...props }) {
|
|
192
|
+
const [active, request] = useControllableValue(value, defaultValue ?? '', onValueChange);
|
|
193
|
+
return (_jsx(MenubarContext.Provider, { value: { value: active, setValue: request }, children: _jsx(Cluster, { ...props, children: children }) }));
|
|
194
|
+
}
|
|
195
|
+
export function MenubarMenu({ value, label, children, ...props }) {
|
|
196
|
+
const menubar = useContext(MenubarContext);
|
|
197
|
+
const id = value ?? label ?? '';
|
|
198
|
+
return (_jsx(DropdownMenu, { ...props, label: label, open: menubar && id ? menubar.value === id : undefined, onOpenChange: (next) => menubar?.setValue(next ? id : ''), children: children }));
|
|
199
|
+
}
|
|
200
|
+
export function MenubarItem(props) {
|
|
201
|
+
return _jsx(MenuRow, { ...props });
|
|
202
|
+
}
|
|
203
|
+
export function MenubarGroup(props) {
|
|
204
|
+
return _jsx(Group, { ...props });
|
|
205
|
+
}
|
|
206
|
+
export function MenubarSubmenu(props) {
|
|
207
|
+
return _jsx(Submenu, { ...props });
|
|
208
|
+
}
|
|
209
|
+
export function MenubarSeparator(props) {
|
|
210
|
+
return _jsx(Separator, { ...props, spacing: "sm" });
|
|
211
|
+
}
|
|
212
|
+
export function MenubarItemMedia(props) {
|
|
213
|
+
return _jsx(View, { ...props });
|
|
214
|
+
}
|
|
215
|
+
const CommandNavigation = createContext(() => undefined);
|
|
216
|
+
const CommandFocus = createContext(null);
|
|
217
|
+
export const CommandMenu = forwardRef(function CommandMenu({ open, defaultOpen, onOpenChange, heading, searchLabel, placeholder, emptyText, query, defaultQuery, onQueryChange, triggerLabel, listHeight = 320, shortcuts = false, openShortcut, children, ...props }, ref) {
|
|
218
|
+
const [text, requestQuery] = useControllableValue(query, defaultQuery ?? '', onQueryChange);
|
|
219
|
+
const menu = useMenu({
|
|
220
|
+
open,
|
|
221
|
+
defaultOpen,
|
|
222
|
+
onOpenChange(next, detail) {
|
|
223
|
+
if (onOpenChange?.(next, detail) === false)
|
|
224
|
+
return false;
|
|
225
|
+
if (!next)
|
|
226
|
+
changeQuery('');
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
const [active, setActive] = useState(null);
|
|
230
|
+
const actions = useRef(new Map());
|
|
231
|
+
const list = useRef(null);
|
|
232
|
+
const results = useRef(null);
|
|
233
|
+
const search = useRef(null);
|
|
234
|
+
const scrollOffset = useRef(0);
|
|
235
|
+
const listViewport = useRef(0);
|
|
236
|
+
const resultsId = useId();
|
|
237
|
+
const { height } = useWindowDimensions();
|
|
238
|
+
const messages = useTramaMessages();
|
|
239
|
+
const { body, named } = splitContent(children, { pages: CommandPage });
|
|
240
|
+
const current = menu.pages.at(-1);
|
|
241
|
+
const enabled = new Map();
|
|
242
|
+
const found = filterCommands(current?.children ?? body, text.trim().toLocaleLowerCase(), enabled, new Set());
|
|
243
|
+
const highlighted = active === null ? undefined : enabled.get(active);
|
|
244
|
+
const maxHeight = Math.min(Number.isFinite(listHeight) ? Math.max(44, listHeight) : 320, Math.max(44, height * 0.48));
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
if (!active || !highlighted || !results.current)
|
|
247
|
+
return;
|
|
248
|
+
if (Platform.OS !== 'web')
|
|
249
|
+
AccessibilityInfo.announceForAccessibility(highlighted.label);
|
|
250
|
+
actions.current.get(active)?.measure(results.current, (_x, y, _w, itemHeight) => {
|
|
251
|
+
const top = scrollOffset.current;
|
|
252
|
+
const viewport = listViewport.current;
|
|
253
|
+
if (y < top || y + itemHeight > top + viewport)
|
|
254
|
+
list.current?.scrollTo({ y: y < top ? y : Math.max(0, y + itemHeight - viewport), animated: false });
|
|
255
|
+
});
|
|
256
|
+
}, [active, highlighted]);
|
|
257
|
+
function resetResults() {
|
|
258
|
+
setActive(null);
|
|
259
|
+
scrollOffset.current = 0;
|
|
260
|
+
list.current?.scrollTo({ y: 0, animated: false });
|
|
261
|
+
}
|
|
262
|
+
function changeQuery(value) {
|
|
263
|
+
requestQuery(value);
|
|
264
|
+
resetResults();
|
|
265
|
+
}
|
|
266
|
+
function back() {
|
|
267
|
+
changeQuery('');
|
|
268
|
+
menu.back();
|
|
269
|
+
search.current?.focus();
|
|
270
|
+
}
|
|
271
|
+
function moveResult(delta) {
|
|
272
|
+
const keys = [...enabled.keys()];
|
|
273
|
+
if (!keys.length)
|
|
274
|
+
return false;
|
|
275
|
+
const index = active === null ? -1 : keys.indexOf(active);
|
|
276
|
+
const next = index < 0 ? (delta > 0 ? 0 : keys.length - 1) : Math.max(0, Math.min(index + delta, keys.length - 1));
|
|
277
|
+
setActive(keys[next]);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
function activate(id) {
|
|
281
|
+
const action = id === undefined ? undefined : actions.current.get(id);
|
|
282
|
+
if (!action)
|
|
283
|
+
return false;
|
|
284
|
+
action.activate();
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
function handleKey(event) {
|
|
288
|
+
if (event.isComposing)
|
|
289
|
+
return false;
|
|
290
|
+
const browser = Platform.OS === 'web' ? globalThis.navigator : undefined;
|
|
291
|
+
const apple = Platform.OS === 'ios' || /Mac|iPhone|iPad|iPod/.test(browser?.platform ?? '');
|
|
292
|
+
if (matchesKeyboardShortcut(event, openShortcut, apple)) {
|
|
293
|
+
menu.request(!menu.visible, 'programmatic');
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
if (!menu.visible)
|
|
297
|
+
return false;
|
|
298
|
+
if (shortcuts) {
|
|
299
|
+
for (const [id, item] of enabled) {
|
|
300
|
+
if (matchesKeyboardShortcut(event, item.shortcut, apple))
|
|
301
|
+
return activate(id);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
305
|
+
return false;
|
|
306
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp')
|
|
307
|
+
return moveResult(event.key === 'ArrowDown' ? 1 : -1);
|
|
308
|
+
if (event.repeat)
|
|
309
|
+
return false;
|
|
310
|
+
if (event.key === 'Enter')
|
|
311
|
+
return activate(highlighted ? (active ?? undefined) : enabled.keys().next().value);
|
|
312
|
+
if (event.key === 'Escape') {
|
|
313
|
+
if (current)
|
|
314
|
+
back();
|
|
315
|
+
else
|
|
316
|
+
menu.request(false, 'escape');
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
const keyboardEvents = {
|
|
322
|
+
'aria-controls': Platform.OS === 'web' ? resultsId : undefined,
|
|
323
|
+
};
|
|
324
|
+
const dialogKeyboardEvents = {
|
|
325
|
+
onKeyDown(event) {
|
|
326
|
+
if (Platform.OS === 'web' && event.nativeEvent.key === 'Escape' && handleKey(event.nativeEvent)) {
|
|
327
|
+
event.preventDefault();
|
|
328
|
+
event.stopPropagation();
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
useImperativeHandle(ref, () => ({
|
|
333
|
+
show: () => menu.request(true, 'programmatic'),
|
|
334
|
+
hide: () => menu.request(false, 'programmatic'),
|
|
335
|
+
toggle: () => menu.request(!menu.visible, 'programmatic'),
|
|
336
|
+
handleKey,
|
|
337
|
+
}));
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
if (!menu.visible)
|
|
340
|
+
setActive(null);
|
|
341
|
+
}, [menu.visible]);
|
|
342
|
+
return (_jsxs(CommandNavigation.Provider, { value: (id) => {
|
|
343
|
+
const page = named.pages?.find((candidate) => isValidElement(candidate) && candidate.props.value === id);
|
|
344
|
+
if (isValidElement(page)) {
|
|
345
|
+
changeQuery('');
|
|
346
|
+
menu.menu.show(page.props.label, page.props.children);
|
|
347
|
+
search.current?.focus();
|
|
348
|
+
}
|
|
349
|
+
}, children: [triggerLabel && (_jsx(Button, { variant: "outlined", onPress: () => menu.request(true, 'trigger'), children: triggerLabel })), _jsx(Dialog, { ...props, ...dialogKeyboardEvents, heading: current?.title ?? heading ?? messages.openMenu, open: menu.visible, scrollBehavior: "outside", closeOnEscape: Platform.OS !== 'web', onOpenChange: (next, { reason }) => {
|
|
350
|
+
if (!next && reason === 'escape' && current)
|
|
351
|
+
back();
|
|
352
|
+
else
|
|
353
|
+
menu.request(next, reason);
|
|
354
|
+
}, children: _jsxs(MenuContext.Provider, { value: menu.menu, children: [current && (_jsx(Button, { variant: "text", onPress: back, children: messages.back })), _jsx(Input, { ...keyboardEvents, ref: search, autoFocus: true, label: searchLabel ?? messages.search, placeholder: placeholder ?? messages.search, value: text, onChangeText: changeQuery, submitBehavior: "submit", onKeyPress: Platform.OS === 'web'
|
|
355
|
+
? (event) => {
|
|
356
|
+
if (handleKey(event.nativeEvent)) {
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
event.stopPropagation();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
: undefined, onSubmitEditing: () => activate(highlighted ? (active ?? undefined) : enabled.keys().next().value) }), Platform.OS === 'web' && (_jsx(Text, { accessibilityLiveRegion: "polite", style: { width: 1, height: 1, position: 'absolute', overflow: 'hidden' }, children: highlighted?.label })), _jsx(ScrollView, { ref: list, nativeID: resultsId, style: { maxHeight, flexGrow: 0 }, keyboardShouldPersistTaps: "handled", onLayout: ({ nativeEvent }) => {
|
|
362
|
+
listViewport.current = nativeEvent.layout.height;
|
|
363
|
+
}, onScroll: ({ nativeEvent }) => {
|
|
364
|
+
scrollOffset.current = nativeEvent.contentOffset.y;
|
|
365
|
+
}, scrollEventThrottle: 16, children: _jsx(View, { ref: results, collapsable: false, children: _jsx(CommandFocus.Provider, { value: {
|
|
366
|
+
active: highlighted ? active : null,
|
|
367
|
+
register(id, action) {
|
|
368
|
+
if (action)
|
|
369
|
+
actions.current.set(id, action);
|
|
370
|
+
else
|
|
371
|
+
actions.current.delete(id);
|
|
372
|
+
},
|
|
373
|
+
}, children: found.length > 0 ? found : _jsx(TextContent, { children: emptyText ?? messages.noResults }) }) }) })] }) })] }));
|
|
374
|
+
});
|
|
375
|
+
function filterCommands(children, query, enabled, seen) {
|
|
376
|
+
const matches = [];
|
|
377
|
+
for (const child of Children.toArray(children)) {
|
|
378
|
+
if (isValidElement(child) && child.type === CommandItem) {
|
|
379
|
+
if ([child.props.label, child.props.description, ...(child.props.keywords ?? [])]
|
|
380
|
+
.join(' ')
|
|
381
|
+
.toLocaleLowerCase()
|
|
382
|
+
.includes(query)) {
|
|
383
|
+
const id = child.props.value ?? child.props.label;
|
|
384
|
+
if (seen.has(id))
|
|
385
|
+
continue;
|
|
386
|
+
seen.add(id);
|
|
387
|
+
matches.push(child);
|
|
388
|
+
if (!child.props.disabled)
|
|
389
|
+
enabled.set(id, child.props);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else if (isValidElement(child) && child.type === CommandGroup) {
|
|
393
|
+
const matchesGroup = child.props.label?.toLocaleLowerCase().includes(query);
|
|
394
|
+
const items = filterCommands(child.props.children, matchesGroup ? '' : query, enabled, seen);
|
|
395
|
+
if (items.length)
|
|
396
|
+
matches.push(cloneElement(child, {}, items));
|
|
397
|
+
}
|
|
398
|
+
else if (!query)
|
|
399
|
+
matches.push(child);
|
|
400
|
+
}
|
|
401
|
+
return matches;
|
|
402
|
+
}
|
|
403
|
+
export function CommandItem({ page, keywords: _keywords, onSelect, ...props }) {
|
|
404
|
+
const navigate = useContext(CommandNavigation);
|
|
405
|
+
const resultFocus = useContext(CommandFocus);
|
|
406
|
+
const id = props.value ?? props.label;
|
|
407
|
+
return (_jsx(MenuRow, { ...props, highlighted: resultFocus?.active === id, actionRef: resultFocus && !props.disabled ? (action) => resultFocus.register(id, action) : undefined, closeOnSelect: page ? false : props.closeOnSelect, onSelect: (id) => {
|
|
408
|
+
if (onSelect?.(id) === false)
|
|
409
|
+
return false;
|
|
410
|
+
if (page)
|
|
411
|
+
navigate(page);
|
|
412
|
+
} }));
|
|
413
|
+
}
|
|
414
|
+
export function CommandPage({ children }) {
|
|
415
|
+
return _jsx(_Fragment, { children: children });
|
|
416
|
+
}
|
|
417
|
+
export function CommandGroup(props) {
|
|
418
|
+
return _jsx(Group, { ...props });
|
|
419
|
+
}
|
|
420
|
+
export function CommandSeparator(props) {
|
|
421
|
+
return _jsx(Separator, { ...props, spacing: "sm" });
|
|
422
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PressableProps, type ViewProps } from 'react-native';
|
|
3
|
+
import { type ButtonProps } from './button.js';
|
|
4
|
+
import type { TramaResponsive } from './responsive.js';
|
|
5
|
+
import { type TramaColor, type TramaSize } from './theme.js';
|
|
6
|
+
export interface LinkProps extends Omit<PressableProps, 'children'> {
|
|
7
|
+
href?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
variant?: TramaResponsive<'default' | 'muted' | 'inverse'>;
|
|
10
|
+
size?: TramaResponsive<'inherit' | TramaSize>;
|
|
11
|
+
underline?: TramaResponsive<'always' | 'hover' | 'none'>;
|
|
12
|
+
current?: boolean | 'page' | 'step' | 'location' | 'date' | 'time';
|
|
13
|
+
onOpenError?: (error: unknown) => void;
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare function Link({ href, label, variant, size, underline, current, onOpenError, children, disabled, onPress, onHoverIn, onHoverOut, style, ...props }: LinkProps): import("react").JSX.Element;
|
|
17
|
+
export declare function LinkStart(props: ViewProps): import("react").JSX.Element;
|
|
18
|
+
export declare function LinkEnd(props: ViewProps): import("react").JSX.Element;
|
|
19
|
+
export declare function LinkIndicator(props: ViewProps): import("react").JSX.Element;
|
|
20
|
+
export interface KbdProps extends ViewProps {
|
|
21
|
+
keys?: string;
|
|
22
|
+
label?: string;
|
|
23
|
+
size?: TramaResponsive<TramaSize>;
|
|
24
|
+
variant?: TramaResponsive<'raised' | 'outlined' | 'subtle' | 'plain'>;
|
|
25
|
+
separator?: 'plus' | 'then' | 'none';
|
|
26
|
+
}
|
|
27
|
+
export declare function Kbd({ keys, label, size, variant, separator, children, style, ...props }: KbdProps): import("react").JSX.Element;
|
|
28
|
+
export declare function KbdGroup({ children, ...props }: ViewProps): import("react").JSX.Element;
|
|
29
|
+
export interface IconButtonProps extends Omit<ButtonProps, 'children' | 'leading' | 'trailing'> {
|
|
30
|
+
label: string;
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
export declare function IconButton({ label, children, variant, style, ...props }: IconButtonProps): import("react").JSX.Element;
|
|
34
|
+
export interface BreadcrumbItem {
|
|
35
|
+
value?: string;
|
|
36
|
+
label: string;
|
|
37
|
+
href?: string;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
icon?: ReactNode;
|
|
40
|
+
items?: readonly BreadcrumbItem[];
|
|
41
|
+
onPress?: () => void;
|
|
42
|
+
}
|
|
43
|
+
export interface BreadcrumbsProps extends ViewProps {
|
|
44
|
+
items: readonly BreadcrumbItem[];
|
|
45
|
+
label?: string;
|
|
46
|
+
separator?: ReactNode;
|
|
47
|
+
maxItems?: TramaResponsive<number>;
|
|
48
|
+
collapseMode?: 'expand' | 'menu';
|
|
49
|
+
expanded?: boolean;
|
|
50
|
+
defaultExpanded?: boolean;
|
|
51
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
52
|
+
}
|
|
53
|
+
export declare function Breadcrumbs({ items, label, separator, maxItems, collapseMode, expanded, defaultExpanded, onExpandedChange, ...props }: BreadcrumbsProps): import("react").JSX.Element;
|
|
54
|
+
export interface PaginationProps extends ViewProps {
|
|
55
|
+
page?: number;
|
|
56
|
+
defaultPage?: number;
|
|
57
|
+
totalPages?: number;
|
|
58
|
+
totalItems?: number;
|
|
59
|
+
pageSize?: number;
|
|
60
|
+
siblingCount?: number;
|
|
61
|
+
boundaryCount?: number;
|
|
62
|
+
variant?: TramaResponsive<'default' | 'compact'>;
|
|
63
|
+
mode?: 'pages' | 'cursor';
|
|
64
|
+
hasNext?: boolean;
|
|
65
|
+
hasPrevious?: boolean;
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
onPageChange?: (page: number) => void | false;
|
|
68
|
+
onNext?: () => void;
|
|
69
|
+
onPrevious?: () => void;
|
|
70
|
+
size?: TramaResponsive<TramaSize>;
|
|
71
|
+
}
|
|
72
|
+
export declare function Pagination({ page, defaultPage, totalPages, totalItems, pageSize, siblingCount, boundaryCount, variant, mode, hasNext, hasPrevious, disabled, onPageChange, onNext, onPrevious, size, ...props }: PaginationProps): import("react").JSX.Element;
|
|
73
|
+
export interface TabPanelProps extends ViewProps {
|
|
74
|
+
value: string;
|
|
75
|
+
label: string;
|
|
76
|
+
disabled?: boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare function TabPanel({ value: _value, label: _label, disabled: _disabled, children, ...props }: TabPanelProps): import("react").JSX.Element;
|
|
79
|
+
export interface TabsProps extends ViewProps {
|
|
80
|
+
value?: string;
|
|
81
|
+
defaultValue?: string;
|
|
82
|
+
onValueChange?: (value: string) => void | false;
|
|
83
|
+
orientation?: TramaResponsive<'horizontal' | 'vertical'>;
|
|
84
|
+
placement?: TramaResponsive<'start' | 'end'>;
|
|
85
|
+
variant?: TramaResponsive<'line' | 'soft' | 'contained' | 'outlined'>;
|
|
86
|
+
panelPersistence?: 'mounted' | 'unmount';
|
|
87
|
+
scroll?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export declare function Tabs({ value, defaultValue, onValueChange, orientation, placement, variant, panelPersistence, scroll, children, style, ...props }: TabsProps): import("react").JSX.Element;
|
|
90
|
+
export type StepStatus = 'pending' | 'current' | 'complete' | 'error';
|
|
91
|
+
export interface StepperItemProps extends ViewProps {
|
|
92
|
+
value: string;
|
|
93
|
+
label: string;
|
|
94
|
+
status?: StepStatus;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
icon?: ReactNode;
|
|
97
|
+
}
|
|
98
|
+
export declare function StepperItem({ value: _value, label, status, icon, children, disabled: _disabled, ...props }: StepperItemProps): import("react").JSX.Element;
|
|
99
|
+
export type StepperPanelProps = StepperItemProps;
|
|
100
|
+
export declare function StepperPanel({ value: _value, label: _label, status: _status, disabled: _disabled, icon: _icon, children, ...props }: StepperPanelProps): import("react").JSX.Element;
|
|
101
|
+
export interface StepperProps extends ViewProps {
|
|
102
|
+
value?: string;
|
|
103
|
+
defaultValue?: string;
|
|
104
|
+
onValueChange?: (value: string) => void | false;
|
|
105
|
+
interactive?: boolean;
|
|
106
|
+
linear?: boolean;
|
|
107
|
+
disabled?: boolean;
|
|
108
|
+
orientation?: TramaResponsive<'horizontal' | 'vertical'>;
|
|
109
|
+
color?: TramaResponsive<TramaColor>;
|
|
110
|
+
}
|
|
111
|
+
export declare function Stepper({ value, defaultValue, onValueChange, interactive, linear, disabled, orientation, color, children, ...props }: StepperProps): import("react").JSX.Element;
|