@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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement, useId, useState } from 'react';
|
|
3
|
+
import { Linking, Pressable, ScrollView, Text, View } from 'react-native';
|
|
4
|
+
import { Button } from './button.js';
|
|
5
|
+
import { splitContent, TextContent } from './internal/content.js';
|
|
6
|
+
import { useControllableValue } from './internal/state.js';
|
|
7
|
+
import { Cluster, Stack } from './layout.js';
|
|
8
|
+
import { useTramaMessages } from './localization.js';
|
|
9
|
+
import { DropdownMenu, DropdownMenuItem } from './menus.js';
|
|
10
|
+
import { getTone, sizeStep, useTramaAppearance, useTramaTheme } from './theme.js';
|
|
11
|
+
export function Link({ href, label, variant, size, underline, current, onOpenError, children, disabled, onPress, onHoverIn, onHoverOut, style, ...props }) {
|
|
12
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
13
|
+
const [hovered, setHovered] = useState(false);
|
|
14
|
+
const { body, named } = splitContent(children, { start: LinkStart, end: LinkEnd, indicator: LinkIndicator });
|
|
15
|
+
const look = resolve(variant, 'default');
|
|
16
|
+
const decoration = resolve(underline, 'always');
|
|
17
|
+
const textSize = resolve(size, 'inherit');
|
|
18
|
+
return (_jsxs(Pressable, { ...props, accessibilityRole: "link", accessibilityLabel: props.accessibilityLabel ?? label, accessibilityState: { ...props.accessibilityState, disabled: Boolean(disabled), selected: Boolean(current) }, "aria-disabled": Boolean(disabled), disabled: disabled, onHoverIn: (event) => {
|
|
19
|
+
setHovered(true);
|
|
20
|
+
onHoverIn?.(event);
|
|
21
|
+
}, onHoverOut: (event) => {
|
|
22
|
+
setHovered(false);
|
|
23
|
+
onHoverOut?.(event);
|
|
24
|
+
}, onPress: (event) => {
|
|
25
|
+
onPress?.(event);
|
|
26
|
+
const target = href?.trim();
|
|
27
|
+
if (!event.defaultPrevented &&
|
|
28
|
+
target &&
|
|
29
|
+
/^[a-z][a-z\d+.-]*:/iu.test(target) &&
|
|
30
|
+
!/^(?:javascript|data):/iu.test(target)) {
|
|
31
|
+
void Linking.openURL(target).catch((error) => onOpenError?.(error));
|
|
32
|
+
}
|
|
33
|
+
}, style: (state) => [
|
|
34
|
+
{
|
|
35
|
+
direction,
|
|
36
|
+
flexDirection: 'row',
|
|
37
|
+
gap: theme.space,
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
alignSelf: 'flex-start',
|
|
40
|
+
maxWidth: '100%',
|
|
41
|
+
minHeight: 44,
|
|
42
|
+
opacity: disabled ? 0.55 : state.pressed ? 0.72 : 1,
|
|
43
|
+
},
|
|
44
|
+
typeof style === 'function' ? style(state) : style,
|
|
45
|
+
], children: [named.start, _jsx(TextContent, { style: {
|
|
46
|
+
color: look === 'muted' ? theme.colors.muted : look === 'inverse' ? theme.colors.onAccent : theme.colors.accent,
|
|
47
|
+
fontFamily: theme.fontFamily,
|
|
48
|
+
fontSize: theme.fontSize + (textSize === 'inherit' ? 0 : sizeStep[textSize]),
|
|
49
|
+
fontWeight: '600',
|
|
50
|
+
textDecorationLine: decoration === 'always' || (decoration === 'hover' && hovered) ? 'underline' : 'none',
|
|
51
|
+
flexShrink: 1,
|
|
52
|
+
}, children: body.length ? body : (label ?? href) }), named.end, named.indicator] }));
|
|
53
|
+
}
|
|
54
|
+
export function LinkStart(props) {
|
|
55
|
+
return _jsx(View, { ...props });
|
|
56
|
+
}
|
|
57
|
+
export function LinkEnd(props) {
|
|
58
|
+
return _jsx(View, { ...props });
|
|
59
|
+
}
|
|
60
|
+
export function LinkIndicator(props) {
|
|
61
|
+
return _jsx(View, { ...props, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants" });
|
|
62
|
+
}
|
|
63
|
+
export function Kbd({ keys, label, size, variant, separator = 'plus', children, style, ...props }) {
|
|
64
|
+
const { theme, resolve } = useTramaAppearance();
|
|
65
|
+
const tokens = keys
|
|
66
|
+
?.split(/\+(?=.)/u)
|
|
67
|
+
.map((token) => token.trim())
|
|
68
|
+
.filter(Boolean) ?? [];
|
|
69
|
+
const design = resolve(variant, 'raised');
|
|
70
|
+
const font = {
|
|
71
|
+
fontFamily: theme.fontFamily,
|
|
72
|
+
color: theme.colors.text,
|
|
73
|
+
fontSize: theme.fontSize - 1 + sizeStep[resolve(size, 'md')],
|
|
74
|
+
};
|
|
75
|
+
return (_jsx(Cluster, { ...props, gap: "xs", accessible: Boolean(label ?? keys), accessibilityLabel: label ?? keys, style: style, children: tokens.length ? (tokens.map((token, index) => (_jsxs(Cluster, { gap: "xs", children: [index > 0 && separator !== 'none' && _jsx(Text, { style: font, children: separator === 'plus' ? '+' : '→' }), _jsx(Text, { style: [
|
|
76
|
+
font,
|
|
77
|
+
{
|
|
78
|
+
paddingHorizontal: theme.space,
|
|
79
|
+
paddingVertical: theme.space / 2,
|
|
80
|
+
borderRadius: theme.radius / 2,
|
|
81
|
+
backgroundColor: design === 'raised' || design === 'subtle' ? theme.colors.subtle : 'transparent',
|
|
82
|
+
borderWidth: design === 'outlined' || design === 'raised' ? 1 : 0,
|
|
83
|
+
borderColor: theme.colors.border,
|
|
84
|
+
},
|
|
85
|
+
], children: token })] }, `${index}:${token}`)))) : (_jsx(TextContent, { style: font, children: children })) }));
|
|
86
|
+
}
|
|
87
|
+
export function KbdGroup({ children, ...props }) {
|
|
88
|
+
return (_jsx(Cluster, { gap: "xs", ...props, children: children }));
|
|
89
|
+
}
|
|
90
|
+
export function IconButton({ label, children, variant = 'text', style, ...props }) {
|
|
91
|
+
return (_jsx(Button, { ...props, variant: variant, accessibilityLabel: label, style: (state) => [{ minWidth: 44, paddingHorizontal: 8 }, typeof style === 'function' ? style(state) : style], children: children }));
|
|
92
|
+
}
|
|
93
|
+
export function Breadcrumbs({ items, label, separator, maxItems, collapseMode = 'menu', expanded, defaultExpanded, onExpandedChange, ...props }) {
|
|
94
|
+
const { theme, resolve, direction } = useTramaAppearance();
|
|
95
|
+
const messages = useTramaMessages();
|
|
96
|
+
const [all, request] = useControllableValue(expanded, defaultExpanded ?? false, onExpandedChange);
|
|
97
|
+
const limit = resolve(maxItems, 4);
|
|
98
|
+
const visible = Number.isFinite(limit) ? Math.max(2, Math.floor(limit)) : items.length;
|
|
99
|
+
const hidden = items.length > visible && !all ? items.slice(1, items.length - visible + 2) : [];
|
|
100
|
+
const shown = hidden.length ? [...items.slice(0, 1), null, ...items.slice(1 + hidden.length)] : items;
|
|
101
|
+
return (_jsx(Cluster, { ...props, gap: "xs", accessibilityLabel: label ?? messages.breadcrumb, children: shown.map((item, index) => (_jsxs(Cluster, { gap: "xs", children: [index > 0 && (_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: _jsx(TextContent, { style: { color: theme.colors.muted }, children: separator ?? (direction === 'rtl' ? '‹' : '›') }) })), !item ? (collapseMode === 'expand' ? (_jsx(Button, { variant: "text", accessibilityLabel: messages.moreItems, onPress: () => request(true), children: "\u2026" })) : (_jsx(DropdownMenu, { label: messages.moreItems, children: hidden.map((entry, entryIndex) => (_jsx(DropdownMenuItem, { label: entry.label, disabled: entry.disabled, onSelect: () => {
|
|
102
|
+
entry.onPress?.();
|
|
103
|
+
if (entry.href)
|
|
104
|
+
void Linking.openURL(entry.href).catch(() => undefined);
|
|
105
|
+
} }, entry.value ?? entryIndex))) }))) : item.items?.length ? (_jsx(DropdownMenu, { label: item.label, disabled: item.disabled, children: item.items.map((entry, entryIndex) => (_jsx(DropdownMenuItem, { label: entry.label, disabled: entry.disabled, onSelect: () => {
|
|
106
|
+
entry.onPress?.();
|
|
107
|
+
if (entry.href)
|
|
108
|
+
void Linking.openURL(entry.href).catch(() => undefined);
|
|
109
|
+
} }, entry.value ?? entryIndex))) })) : (item.href || item.onPress) && index < shown.length - 1 ? (_jsxs(Link, { disabled: item.disabled, href: item.href, onPress: item.onPress, label: item.label, children: [item.icon && _jsx(LinkStart, { children: item.icon }), item.label] })) : (_jsxs(Cluster, { gap: "xs", children: [item.icon, _jsx(Text, { style: { color: theme.colors.text, fontWeight: index === shown.length - 1 ? '700' : '400' }, children: item.label })] }))] }, item?.value ?? item?.href ?? `${index}:${item?.label ?? 'more'}`))) }));
|
|
110
|
+
}
|
|
111
|
+
function boundedCount(value, maximum = Number.MAX_SAFE_INTEGER) {
|
|
112
|
+
return Number.isFinite(value) ? Math.min(maximum, Math.max(0, Math.floor(value))) : 0;
|
|
113
|
+
}
|
|
114
|
+
function pageWindow(page, total, siblings, boundaries) {
|
|
115
|
+
const pages = new Set();
|
|
116
|
+
const keep = (from, to) => {
|
|
117
|
+
for (let cursor = Math.max(1, from); cursor <= Math.min(total, to); cursor++)
|
|
118
|
+
pages.add(cursor);
|
|
119
|
+
};
|
|
120
|
+
keep(1, boundaries);
|
|
121
|
+
keep(page - siblings, page + siblings);
|
|
122
|
+
keep(total - boundaries + 1, total);
|
|
123
|
+
const result = [];
|
|
124
|
+
for (const candidate of [...pages].sort((a, b) => a - b)) {
|
|
125
|
+
const previous = result.at(-1);
|
|
126
|
+
if (typeof previous === 'number' && previous + 1 < candidate) {
|
|
127
|
+
result.push(previous + 2 === candidate ? previous + 1 : `gap-${candidate}`);
|
|
128
|
+
}
|
|
129
|
+
result.push(candidate);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
export function Pagination({ page, defaultPage, totalPages, totalItems, pageSize = 10, siblingCount = 1, boundaryCount = 1, variant, mode = 'pages', hasNext, hasPrevious, disabled, onPageChange, onNext, onPrevious, size, ...props }) {
|
|
134
|
+
const { resolve, theme } = useTramaAppearance();
|
|
135
|
+
const messages = useTramaMessages();
|
|
136
|
+
const [owned, request] = useControllableValue(page, defaultPage ?? 1);
|
|
137
|
+
const total = Math.max(1, boundedCount(totalPages ?? Math.ceil((totalItems ?? 0) / Math.max(1, pageSize))));
|
|
138
|
+
const current = Math.min(total, Math.max(1, boundedCount(owned)));
|
|
139
|
+
const cursor = mode === 'cursor';
|
|
140
|
+
const compact = resolve(variant, 'default') === 'compact';
|
|
141
|
+
function choose(candidate) {
|
|
142
|
+
if (!disabled &&
|
|
143
|
+
candidate >= 1 &&
|
|
144
|
+
candidate <= total &&
|
|
145
|
+
candidate !== current &&
|
|
146
|
+
onPageChange?.(candidate) !== false)
|
|
147
|
+
request(candidate);
|
|
148
|
+
}
|
|
149
|
+
return (_jsxs(Cluster, { ...props, gap: "xs", accessibilityLabel: props.accessibilityLabel ?? messages.pagination, children: [_jsx(Button, { size: size, variant: "text", disabled: disabled || (cursor ? !hasPrevious : current <= 1), onPress: () => {
|
|
150
|
+
if (cursor)
|
|
151
|
+
onPrevious?.();
|
|
152
|
+
else
|
|
153
|
+
choose(current - 1);
|
|
154
|
+
}, children: messages.previous }), cursor ? null : compact ? (_jsx(Text, { style: { color: theme.colors.muted }, children: messages.pageOf(current, total) })) : (pageWindow(current, total, boundedCount(siblingCount, 8), boundedCount(boundaryCount, 8)).map((item) => typeof item === 'number' ? (_jsx(Button, { size: size, variant: item === current ? 'contained' : 'text', accessibilityLabel: messages.pageNumber(item), accessibilityState: { selected: item === current }, disabled: disabled, onPress: () => choose(item), children: item }, item)) : (_jsx(Text, { accessible: false, style: { color: theme.colors.muted }, children: "\u2026" }, item)))), _jsx(Button, { size: size, variant: "text", disabled: disabled || (cursor ? !hasNext : current >= total), onPress: () => {
|
|
155
|
+
if (cursor)
|
|
156
|
+
onNext?.();
|
|
157
|
+
else
|
|
158
|
+
choose(current + 1);
|
|
159
|
+
}, children: messages.next })] }));
|
|
160
|
+
}
|
|
161
|
+
export function TabPanel({ value: _value, label: _label, disabled: _disabled, children, ...props }) {
|
|
162
|
+
const theme = useTramaTheme();
|
|
163
|
+
return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text }, children: children }) }));
|
|
164
|
+
}
|
|
165
|
+
export function Tabs({ value, defaultValue, onValueChange, orientation, placement, variant, panelPersistence = 'mounted', scroll, children, style, ...props }) {
|
|
166
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
167
|
+
const baseId = useId();
|
|
168
|
+
const panels = Children.toArray(children).flatMap((child) => isValidElement(child) && child.type === TabPanel ? [child] : []);
|
|
169
|
+
const [selected, request] = useControllableValue(value, defaultValue ?? '');
|
|
170
|
+
const current = panels.find((panel) => panel.props.value === selected && !panel.props.disabled)?.props.value ??
|
|
171
|
+
panels.find((panel) => !panel.props.disabled)?.props.value;
|
|
172
|
+
const vertical = resolve(orientation, 'horizontal') === 'vertical';
|
|
173
|
+
const end = resolve(placement, 'start') === 'end';
|
|
174
|
+
const look = resolve(variant, 'line');
|
|
175
|
+
const triggers = (_jsx(View, { accessibilityRole: "tablist", style: { flexDirection: vertical ? 'column' : 'row', flexWrap: scroll ? 'nowrap' : 'wrap' }, children: panels.map(({ props: panel }, index) => {
|
|
176
|
+
const active = panel.value === current;
|
|
177
|
+
return (_jsx(Pressable, { nativeID: `${baseId}-tab-${index}`, accessibilityRole: "tab", "aria-selected": active, "aria-controls": active || panelPersistence === 'mounted' ? `${baseId}-panel-${index}` : undefined, disabled: panel.disabled, accessibilityState: { selected: active, disabled: Boolean(panel.disabled) }, onPress: () => {
|
|
178
|
+
if (current !== panel.value && onValueChange?.(panel.value) !== false)
|
|
179
|
+
request(panel.value);
|
|
180
|
+
}, style: {
|
|
181
|
+
minHeight: 44,
|
|
182
|
+
justifyContent: 'center',
|
|
183
|
+
paddingHorizontal: theme.space * 3,
|
|
184
|
+
borderRadius: look === 'line' ? 0 : theme.radius,
|
|
185
|
+
borderColor: active ? theme.colors.accent : 'transparent',
|
|
186
|
+
borderBottomWidth: look === 'line' ? 2 : 0,
|
|
187
|
+
borderWidth: look === 'outlined' ? 1 : 0,
|
|
188
|
+
backgroundColor: active && look !== 'line'
|
|
189
|
+
? look === 'contained'
|
|
190
|
+
? theme.colors.accent
|
|
191
|
+
: theme.colors.subtle
|
|
192
|
+
: 'transparent',
|
|
193
|
+
opacity: panel.disabled ? 0.55 : 1,
|
|
194
|
+
}, children: _jsx(Text, { style: {
|
|
195
|
+
color: active
|
|
196
|
+
? look === 'contained'
|
|
197
|
+
? theme.colors.onAccent
|
|
198
|
+
: theme.colors.accent
|
|
199
|
+
: theme.colors.text,
|
|
200
|
+
fontWeight: active ? '700' : '400',
|
|
201
|
+
fontFamily: theme.fontFamily,
|
|
202
|
+
}, children: panel.label }) }, panel.value));
|
|
203
|
+
}) }));
|
|
204
|
+
return (_jsxs(View, { ...props, style: [
|
|
205
|
+
{
|
|
206
|
+
direction,
|
|
207
|
+
flexDirection: vertical ? (end ? 'row-reverse' : 'row') : end ? 'column-reverse' : 'column',
|
|
208
|
+
gap: theme.space * 3,
|
|
209
|
+
},
|
|
210
|
+
style,
|
|
211
|
+
], children: [scroll ? (_jsx(ScrollView, { horizontal: !vertical, style: { flexGrow: 0 }, children: triggers })) : (triggers), _jsx(View, { style: vertical ? { flex: 1, minWidth: 0 } : undefined, children: panels.map((panel, index) => {
|
|
212
|
+
const active = panel.props.value === current;
|
|
213
|
+
if (!active && panelPersistence === 'unmount')
|
|
214
|
+
return null;
|
|
215
|
+
return (_jsx(View, { nativeID: `${baseId}-panel-${index}`, role: "tabpanel", "aria-labelledby": `${baseId}-tab-${index}`, accessibilityElementsHidden: !active, importantForAccessibility: active ? 'auto' : 'no-hide-descendants', style: { display: active ? 'flex' : 'none' }, children: panel }, panel.props.value));
|
|
216
|
+
}) })] }));
|
|
217
|
+
}
|
|
218
|
+
export function StepperItem({ value: _value, label, status, icon, children, disabled: _disabled, ...props }) {
|
|
219
|
+
const { theme } = useTramaAppearance();
|
|
220
|
+
const ink = status === 'error' ? theme.colors.danger : status === 'current' ? theme.colors.accent : theme.colors.text;
|
|
221
|
+
return (_jsxs(Cluster, { ...props, gap: "xs", children: [icon, _jsx(Text, { style: { color: ink, fontWeight: status === 'current' ? '700' : '400' }, children: label }), children] }));
|
|
222
|
+
}
|
|
223
|
+
export function StepperPanel({ value: _value, label: _label, status: _status, disabled: _disabled, icon: _icon, children, ...props }) {
|
|
224
|
+
const theme = useTramaTheme();
|
|
225
|
+
return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text }, children: children }) }));
|
|
226
|
+
}
|
|
227
|
+
export function Stepper({ value, defaultValue, onValueChange, interactive, linear, disabled, orientation, color, children, ...props }) {
|
|
228
|
+
const { theme, resolve } = useTramaAppearance();
|
|
229
|
+
const { body, named } = splitContent(children, { panels: StepperPanel, items: StepperItem });
|
|
230
|
+
const steps = (named.panels ?? named.items ?? []).flatMap((child) => isValidElement(child) ? [child] : []);
|
|
231
|
+
const [selected, request] = useControllableValue(value, defaultValue ?? '');
|
|
232
|
+
const index = Math.max(0, steps.findIndex((step) => step.props.value === selected));
|
|
233
|
+
const horizontal = resolve(orientation, 'vertical') === 'horizontal';
|
|
234
|
+
const tone = getTone(theme, resolve(color, 'accent'));
|
|
235
|
+
return (_jsxs(Stack, { ...props, gap: "sm", children: [_jsx(Stack, { direction: horizontal ? 'row' : 'column', wrap: horizontal ? 'wrap' : 'nowrap', gap: "xs", children: steps.map(({ props: step }, stepIndex) => {
|
|
236
|
+
const status = step.status ?? (stepIndex === index ? 'current' : stepIndex < index ? 'complete' : 'pending');
|
|
237
|
+
const unavailable = disabled || step.disabled || (linear && stepIndex > index + 1);
|
|
238
|
+
const mark = (_jsx(View, { style: {
|
|
239
|
+
backgroundColor: status === 'current' ? tone.solid : theme.colors.subtle,
|
|
240
|
+
borderRadius: theme.radius * 2,
|
|
241
|
+
minWidth: 26,
|
|
242
|
+
minHeight: 26,
|
|
243
|
+
alignItems: 'center',
|
|
244
|
+
justifyContent: 'center',
|
|
245
|
+
}, children: step.icon ?? (_jsx(Text, { style: { color: status === 'current' ? tone.ink : tone.text }, children: status === 'complete' ? '✓' : stepIndex + 1 })) }));
|
|
246
|
+
const content = _jsx(StepperItem, { value: step.value, label: step.label, status: status, icon: mark });
|
|
247
|
+
return interactive ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { selected: stepIndex === index, disabled: Boolean(unavailable) }, "aria-disabled": Boolean(unavailable), disabled: unavailable, style: { justifyContent: 'center', minHeight: 44 }, onPress: () => {
|
|
248
|
+
if (stepIndex !== index && onValueChange?.(step.value) !== false)
|
|
249
|
+
request(step.value);
|
|
250
|
+
}, children: content }, step.value)) : (_jsx(View, { accessibilityState: { selected: stepIndex === index }, children: content }, step.value));
|
|
251
|
+
}) }), named.panels?.map((panel, panelIndex) => {
|
|
252
|
+
const active = panelIndex === index;
|
|
253
|
+
return (_jsx(View, { accessibilityElementsHidden: !active, importantForAccessibility: active ? 'auto' : 'no-hide-descendants', style: { display: active ? 'flex' : 'none' }, children: panel }, steps[panelIndex]?.props.value ?? panelIndex));
|
|
254
|
+
}), body] }));
|
|
255
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ViewProps } from 'react-native';
|
|
3
|
+
import { type ButtonProps } from './button.js';
|
|
4
|
+
import type { TramaResponsive } from './responsive.js';
|
|
5
|
+
type SurfaceSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
6
|
+
type SurfaceRadius = 'none' | 'sm' | 'md' | 'lg' | 'xl';
|
|
7
|
+
type SurfaceBackdrop = 'none' | 'dim';
|
|
8
|
+
export type OverlayReason = 'trigger' | 'close-button' | 'backdrop' | 'escape' | 'swipe' | 'programmatic';
|
|
9
|
+
export interface OverlayChangeDetail {
|
|
10
|
+
reason: OverlayReason;
|
|
11
|
+
}
|
|
12
|
+
export interface OverlayHandle {
|
|
13
|
+
show(): void;
|
|
14
|
+
hide(): void;
|
|
15
|
+
toggle(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface OverlayStateProps {
|
|
18
|
+
open?: boolean;
|
|
19
|
+
defaultOpen?: boolean;
|
|
20
|
+
onOpenChange?: (open: boolean, detail: OverlayChangeDetail) => void | false;
|
|
21
|
+
}
|
|
22
|
+
interface OverlayBaseProps extends ViewProps, OverlayStateProps {
|
|
23
|
+
heading?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
size?: TramaResponsive<SurfaceSize>;
|
|
27
|
+
radius?: TramaResponsive<SurfaceRadius>;
|
|
28
|
+
backdrop?: TramaResponsive<SurfaceBackdrop>;
|
|
29
|
+
backdropColor?: string;
|
|
30
|
+
closeOnOutside?: boolean;
|
|
31
|
+
closeOnEscape?: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare function Trigger({ children, onPress, ...props }: ButtonProps): import("react").JSX.Element;
|
|
34
|
+
declare function Close({ children, onPress, ...props }: ButtonProps): import("react").JSX.Element;
|
|
35
|
+
declare function Header(props: ViewProps): import("react").JSX.Element;
|
|
36
|
+
declare function Title({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
|
37
|
+
declare function Description({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
|
38
|
+
declare function Body({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
|
39
|
+
declare function Footer({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
|
40
|
+
export interface DialogProps extends OverlayBaseProps {
|
|
41
|
+
mode?: 'modal' | 'non-modal' | 'alert';
|
|
42
|
+
placement?: TramaResponsive<'top' | 'center' | 'bottom'>;
|
|
43
|
+
motion?: TramaResponsive<'none' | 'fade' | 'slide-up' | 'slide-down'>;
|
|
44
|
+
scrollBehavior?: 'inside' | 'outside';
|
|
45
|
+
}
|
|
46
|
+
export declare const Dialog: import("react").ForwardRefExoticComponent<DialogProps & import("react").RefAttributes<OverlayHandle>>;
|
|
47
|
+
export declare const DialogTrigger: typeof Trigger;
|
|
48
|
+
export declare const DialogClose: typeof Close;
|
|
49
|
+
export declare const DialogHeader: typeof Header;
|
|
50
|
+
export declare const DialogTitle: typeof Title;
|
|
51
|
+
export declare const DialogDescription: typeof Description;
|
|
52
|
+
export declare const DialogBody: typeof Body;
|
|
53
|
+
export declare const DialogFooter: typeof Footer;
|
|
54
|
+
export declare function DialogBackdropLayer({ children }: {
|
|
55
|
+
children?: ReactNode;
|
|
56
|
+
}): import("react").JSX.Element;
|
|
57
|
+
export interface DrawerProps extends OverlayBaseProps {
|
|
58
|
+
variant?: TramaResponsive<'overlay' | 'inline'>;
|
|
59
|
+
placement?: TramaResponsive<'start' | 'end' | 'top' | 'bottom'>;
|
|
60
|
+
motion?: TramaResponsive<'slide' | 'none'>;
|
|
61
|
+
swipe?: 'none' | 'close';
|
|
62
|
+
}
|
|
63
|
+
export declare const Drawer: import("react").ForwardRefExoticComponent<DrawerProps & import("react").RefAttributes<OverlayHandle>>;
|
|
64
|
+
export declare function DrawerTrigger(props: ButtonProps): import("react").JSX.Element;
|
|
65
|
+
export declare function DrawerClose(props: ButtonProps): import("react").JSX.Element;
|
|
66
|
+
export declare function DrawerHeader(props: ViewProps): import("react").JSX.Element;
|
|
67
|
+
export declare function DrawerTitle(props: ViewProps): import("react").JSX.Element;
|
|
68
|
+
export declare function DrawerDescription(props: ViewProps): import("react").JSX.Element;
|
|
69
|
+
export declare function DrawerBody(props: ViewProps): import("react").JSX.Element;
|
|
70
|
+
export declare function DrawerFooter(props: ViewProps): import("react").JSX.Element;
|
|
71
|
+
export declare function DrawerHandle({ style, ...props }: ViewProps): import("react").JSX.Element;
|
|
72
|
+
export interface PopoverProps extends Omit<OverlayBaseProps, 'size'> {
|
|
73
|
+
placement?: TramaResponsive<'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'>;
|
|
74
|
+
size?: TramaResponsive<'sm' | 'md' | 'lg' | 'auto'>;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
offset?: number;
|
|
77
|
+
}
|
|
78
|
+
export declare const Popover: import("react").ForwardRefExoticComponent<PopoverProps & import("react").RefAttributes<OverlayHandle>>;
|
|
79
|
+
export declare function PopoverTrigger(props: ButtonProps): import("react").JSX.Element;
|
|
80
|
+
export declare function PopoverClose(props: ButtonProps): import("react").JSX.Element;
|
|
81
|
+
export declare function PopoverHeader(props: ViewProps): import("react").JSX.Element;
|
|
82
|
+
export declare function PopoverTitle(props: ViewProps): import("react").JSX.Element;
|
|
83
|
+
export declare function PopoverDescription(props: ViewProps): import("react").JSX.Element;
|
|
84
|
+
export declare function PopoverBody(props: ViewProps): import("react").JSX.Element;
|
|
85
|
+
export declare function PopoverFooter(props: ViewProps): import("react").JSX.Element;
|
|
86
|
+
export declare function PopoverArrow({ style, ...props }: ViewProps): import("react").JSX.Element;
|
|
87
|
+
export interface FloatingPanelProps extends ViewProps, OverlayStateProps {
|
|
88
|
+
placement?: 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'center';
|
|
89
|
+
size?: 'sm' | 'md' | 'lg';
|
|
90
|
+
variant?: 'plain' | 'outlined' | 'elevated';
|
|
91
|
+
}
|
|
92
|
+
export declare function FloatingPanel({ open, defaultOpen, onOpenChange, placement, size, variant, style, ...props }: FloatingPanelProps): import("react").JSX.Element | null;
|
|
93
|
+
export declare function FloatingPanelHeader(props: ViewProps): import("react").JSX.Element;
|
|
94
|
+
export declare function FloatingPanelBody(props: ViewProps): import("react").JSX.Element;
|
|
95
|
+
export declare function FloatingPanelFooter(props: ViewProps): import("react").JSX.Element;
|
|
96
|
+
export declare function FloatingPanelClose(props: ButtonProps): import("react").JSX.Element;
|
|
97
|
+
export {};
|