@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/overlays.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useContext, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { Modal, PanResponder, Pressable, ScrollView, StyleSheet, View, useWindowDimensions, } 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 { useTramaMessages } from './localization.js';
|
|
8
|
+
import { useTramaAppearance, useTramaTheme } from './theme.js';
|
|
9
|
+
function useOverlay({ open, defaultOpen, onOpenChange }) {
|
|
10
|
+
const [visible, update] = useControllableValue(open, defaultOpen ?? false);
|
|
11
|
+
return {
|
|
12
|
+
visible,
|
|
13
|
+
request(next, reason) {
|
|
14
|
+
if (next !== visible && onOpenChange?.(next, { reason }) !== false)
|
|
15
|
+
update(next);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const OverlayControls = createContext(null);
|
|
20
|
+
const bounds = {
|
|
21
|
+
xs: 280,
|
|
22
|
+
sm: 360,
|
|
23
|
+
md: 480,
|
|
24
|
+
lg: 600,
|
|
25
|
+
xl: 800,
|
|
26
|
+
full: undefined,
|
|
27
|
+
};
|
|
28
|
+
function placementAlign(placement) {
|
|
29
|
+
return {
|
|
30
|
+
alignItems: placement === 'start' ? 'flex-start' : placement === 'end' ? 'flex-end' : 'center',
|
|
31
|
+
justifyContent: placement === 'top' ? 'flex-start' : placement === 'bottom' ? 'flex-end' : 'center',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function OverlaySurface({ state, placement, label, modal, drawer, alert, dismissOutside, dismissBack, backdrop, backdropColor, backdropContent, size, radius, motion, children, style, ...props }) {
|
|
35
|
+
const { theme, direction } = useTramaAppearance();
|
|
36
|
+
const { height } = useWindowDimensions();
|
|
37
|
+
if (!state.visible)
|
|
38
|
+
return null;
|
|
39
|
+
const side = Boolean(drawer && (placement === 'start' || placement === 'end'));
|
|
40
|
+
const radiusValue = { none: 0, sm: theme.radius / 2, md: theme.radius, lg: theme.radius * 1.5, xl: theme.radius * 2 }[radius];
|
|
41
|
+
const surface = (_jsx(View, { ...props, accessibilityViewIsModal: modal, accessibilityLabel: props.accessibilityLabel ?? label, role: alert ? 'alertdialog' : 'dialog', style: [
|
|
42
|
+
{
|
|
43
|
+
direction,
|
|
44
|
+
width: side && size !== 'full' ? '84%' : '100%',
|
|
45
|
+
maxWidth: side || !drawer ? bounds[size] : undefined,
|
|
46
|
+
height: side && modal ? '100%' : undefined,
|
|
47
|
+
maxHeight: modal && !side ? height * 0.9 : undefined,
|
|
48
|
+
backgroundColor: theme.colors.surface,
|
|
49
|
+
borderRadius: radiusValue,
|
|
50
|
+
borderWidth: 1,
|
|
51
|
+
borderColor: theme.colors.border,
|
|
52
|
+
padding: theme.space * 4,
|
|
53
|
+
gap: theme.space * 3,
|
|
54
|
+
},
|
|
55
|
+
style,
|
|
56
|
+
], children: children }));
|
|
57
|
+
if (!modal)
|
|
58
|
+
return surface;
|
|
59
|
+
return (_jsx(Modal, { transparent: true, visible: true, animationType: motion, statusBarTranslucent: true, onRequestClose: () => {
|
|
60
|
+
if (dismissBack)
|
|
61
|
+
state.request(false, 'escape');
|
|
62
|
+
}, children: _jsxs(View, { style: [styles.modal, { direction, padding: drawer ? 0 : theme.space * 4 }, placementAlign(placement)], children: [_jsx(Pressable, { accessible: false, importantForAccessibility: "no", onPress: dismissOutside ? () => state.request(false, 'backdrop') : undefined, style: [
|
|
63
|
+
StyleSheet.absoluteFill,
|
|
64
|
+
{
|
|
65
|
+
backgroundColor: backdrop === 'none' || backdropContent ? 'transparent' : (backdropColor ?? 'rgba(0,0,0,0.42)'),
|
|
66
|
+
},
|
|
67
|
+
] }), backdropContent, surface] }) }));
|
|
68
|
+
}
|
|
69
|
+
function Trigger({ children, onPress, ...props }) {
|
|
70
|
+
const state = useContext(OverlayControls);
|
|
71
|
+
return (_jsx(Button, { ...props, "aria-expanded": state?.visible, onPress: (event) => {
|
|
72
|
+
onPress?.(event);
|
|
73
|
+
state?.request(!state.visible, 'trigger');
|
|
74
|
+
}, children: children }));
|
|
75
|
+
}
|
|
76
|
+
function Close({ children, onPress, ...props }) {
|
|
77
|
+
const state = useContext(OverlayControls);
|
|
78
|
+
const messages = useTramaMessages();
|
|
79
|
+
return (_jsx(Button, { variant: "text", ...props, onPress: (event) => {
|
|
80
|
+
onPress?.(event);
|
|
81
|
+
state?.request(false, 'close-button');
|
|
82
|
+
}, children: children ?? messages.closeSurface }));
|
|
83
|
+
}
|
|
84
|
+
function Header(props) {
|
|
85
|
+
const theme = useTramaTheme();
|
|
86
|
+
return _jsx(View, { ...props, style: [{ gap: theme.space }, props.style] });
|
|
87
|
+
}
|
|
88
|
+
function Title({ children, style, ...props }) {
|
|
89
|
+
const theme = useTramaTheme();
|
|
90
|
+
return (_jsx(View, { ...props, style: style, children: _jsx(TextContent, { style: {
|
|
91
|
+
color: theme.colors.text,
|
|
92
|
+
fontSize: theme.fontSize + 6,
|
|
93
|
+
fontFamily: theme.fontFamily,
|
|
94
|
+
fontWeight: '700',
|
|
95
|
+
}, children: children }) }));
|
|
96
|
+
}
|
|
97
|
+
function Description({ children, style, ...props }) {
|
|
98
|
+
const theme = useTramaTheme();
|
|
99
|
+
return (_jsx(View, { ...props, style: style, children: _jsx(TextContent, { style: { color: theme.colors.muted, fontFamily: theme.fontFamily, fontSize: theme.fontSize }, children: children }) }));
|
|
100
|
+
}
|
|
101
|
+
function Body({ children, style, ...props }) {
|
|
102
|
+
const theme = useTramaTheme();
|
|
103
|
+
return (_jsx(View, { ...props, style: [{ gap: theme.space * 2 }, style], children: _jsx(TextContent, { style: { color: theme.colors.text, fontFamily: theme.fontFamily, fontSize: theme.fontSize }, children: children }) }));
|
|
104
|
+
}
|
|
105
|
+
function Footer({ children, style, ...props }) {
|
|
106
|
+
const { theme, direction } = useTramaAppearance();
|
|
107
|
+
return (_jsx(View, { ...props, style: [
|
|
108
|
+
{ direction, gap: theme.space * 2, justifyContent: 'flex-end', flexDirection: 'row', flexWrap: 'wrap' },
|
|
109
|
+
style,
|
|
110
|
+
], children: children }));
|
|
111
|
+
}
|
|
112
|
+
export const Dialog = forwardRef(function Dialog({ open, defaultOpen, onOpenChange, mode = 'modal', placement, motion, scrollBehavior = 'inside', label, heading, description, size, radius, backdrop, backdropColor, closeOnOutside, closeOnEscape, children, ...props }, ref) {
|
|
113
|
+
const state = useOverlay({ open, defaultOpen, onOpenChange });
|
|
114
|
+
const { resolve } = useTramaAppearance();
|
|
115
|
+
const { body, named } = splitContent(children, {
|
|
116
|
+
trigger: DialogTrigger,
|
|
117
|
+
header: DialogHeader,
|
|
118
|
+
footer: DialogFooter,
|
|
119
|
+
backdrop: DialogBackdropLayer,
|
|
120
|
+
});
|
|
121
|
+
useImperativeHandle(ref, () => ({
|
|
122
|
+
show: () => state.request(true, 'programmatic'),
|
|
123
|
+
hide: () => state.request(false, 'programmatic'),
|
|
124
|
+
toggle: () => state.request(!state.visible, 'programmatic'),
|
|
125
|
+
}));
|
|
126
|
+
const animation = resolve(motion, 'fade');
|
|
127
|
+
const content = _jsx(DialogBody, { children: body });
|
|
128
|
+
return (_jsxs(OverlayControls.Provider, { value: state, children: [named.trigger, _jsxs(OverlaySurface, { ...props, state: state, label: label ?? heading, alert: mode === 'alert', modal: mode !== 'non-modal', placement: resolve(placement, 'center'), size: resolve(size, 'md'), radius: resolve(radius, 'md'), backdrop: resolve(backdrop, 'dim'), backdropColor: backdropColor, backdropContent: named.backdrop, dismissOutside: mode !== 'alert' && (closeOnOutside ?? mode === 'modal'), dismissBack: mode !== 'alert' && (closeOnEscape ?? true), motion: animation === 'slide-up' || animation === 'slide-down' ? 'slide' : animation, children: [named.header ??
|
|
129
|
+
(heading || description ? (_jsxs(DialogHeader, { children: [heading && _jsx(DialogTitle, { children: heading }), description && _jsx(DialogDescription, { children: description })] })) : null), scrollBehavior === 'inside' && mode !== 'non-modal' ? (_jsx(ScrollView, { style: { flexGrow: 0, flexShrink: 1 }, keyboardShouldPersistTaps: "handled", children: content })) : (content), named.footer] })] }));
|
|
130
|
+
});
|
|
131
|
+
export const DialogTrigger = Trigger;
|
|
132
|
+
export const DialogClose = Close;
|
|
133
|
+
export const DialogHeader = Header;
|
|
134
|
+
export const DialogTitle = Title;
|
|
135
|
+
export const DialogDescription = Description;
|
|
136
|
+
export const DialogBody = Body;
|
|
137
|
+
export const DialogFooter = Footer;
|
|
138
|
+
export function DialogBackdropLayer({ children }) {
|
|
139
|
+
return (_jsx(View, { pointerEvents: "none", accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: StyleSheet.absoluteFill, children: children }));
|
|
140
|
+
}
|
|
141
|
+
const DrawerGesture = createContext(undefined);
|
|
142
|
+
export const Drawer = forwardRef(function Drawer({ open, defaultOpen, onOpenChange, variant, placement, motion, swipe = 'none', heading, description, label, size, radius, backdrop, backdropColor, closeOnOutside, closeOnEscape, children, ...props }, ref) {
|
|
143
|
+
const state = useOverlay({ open, defaultOpen, onOpenChange });
|
|
144
|
+
const { resolve, direction } = useTramaAppearance();
|
|
145
|
+
const dock = resolve(placement, 'end');
|
|
146
|
+
const overlay = resolve(variant, 'overlay') === 'overlay';
|
|
147
|
+
const { body, named } = splitContent(children, {
|
|
148
|
+
trigger: DrawerTrigger,
|
|
149
|
+
header: DrawerHeader,
|
|
150
|
+
footer: DrawerFooter,
|
|
151
|
+
handle: DrawerHandle,
|
|
152
|
+
});
|
|
153
|
+
useImperativeHandle(ref, () => ({
|
|
154
|
+
show: () => state.request(true, 'programmatic'),
|
|
155
|
+
hide: () => state.request(false, 'programmatic'),
|
|
156
|
+
toggle: () => state.request(!state.visible, 'programmatic'),
|
|
157
|
+
}));
|
|
158
|
+
const pan = useMemo(() => {
|
|
159
|
+
const inline = dock === 'start' || dock === 'end';
|
|
160
|
+
const sign = inline ? (dock === 'start' ? -1 : 1) * (direction === 'rtl' ? -1 : 1) : dock === 'top' ? -1 : 1;
|
|
161
|
+
return PanResponder.create({
|
|
162
|
+
onMoveShouldSetPanResponder: (_, gesture) => sign * (inline ? gesture.dx : gesture.dy) > 8,
|
|
163
|
+
onPanResponderRelease: (_, gesture) => {
|
|
164
|
+
if (sign * (inline ? gesture.dx : gesture.dy) >= 55)
|
|
165
|
+
state.request(false, 'swipe');
|
|
166
|
+
},
|
|
167
|
+
}).panHandlers;
|
|
168
|
+
}, [direction, dock, state]);
|
|
169
|
+
return (_jsxs(OverlayControls.Provider, { value: state, children: [named.trigger, _jsx(DrawerGesture.Provider, { value: swipe === 'close' ? pan : undefined, children: _jsxs(OverlaySurface, { ...props, state: state, drawer: true, label: label ?? heading, modal: overlay, placement: dock, size: resolve(size, 'md'), radius: resolve(radius, 'md'), backdrop: resolve(backdrop, 'dim'), backdropColor: backdropColor, dismissOutside: closeOnOutside ?? true, dismissBack: closeOnEscape ?? true, motion: resolve(motion, 'slide') === 'none' ? 'none' : dock === 'bottom' ? 'slide' : 'fade', children: [named.handle, named.header ??
|
|
170
|
+
(heading || description ? (_jsxs(DrawerHeader, { children: [heading && _jsx(DrawerTitle, { children: heading }), description && _jsx(DrawerDescription, { children: description })] })) : null), overlay ? (_jsx(ScrollView, { style: { flexGrow: 0, flexShrink: 1 }, keyboardShouldPersistTaps: "handled", children: _jsx(DrawerBody, { children: body }) })) : (_jsx(DrawerBody, { children: body })), named.footer] }) })] }));
|
|
171
|
+
});
|
|
172
|
+
export function DrawerTrigger(props) {
|
|
173
|
+
return _jsx(Trigger, { ...props });
|
|
174
|
+
}
|
|
175
|
+
export function DrawerClose(props) {
|
|
176
|
+
return _jsx(Close, { ...props });
|
|
177
|
+
}
|
|
178
|
+
export function DrawerHeader(props) {
|
|
179
|
+
return _jsx(Header, { ...props });
|
|
180
|
+
}
|
|
181
|
+
export function DrawerTitle(props) {
|
|
182
|
+
return _jsx(Title, { ...props });
|
|
183
|
+
}
|
|
184
|
+
export function DrawerDescription(props) {
|
|
185
|
+
return _jsx(Description, { ...props });
|
|
186
|
+
}
|
|
187
|
+
export function DrawerBody(props) {
|
|
188
|
+
return _jsx(Body, { ...props });
|
|
189
|
+
}
|
|
190
|
+
export function DrawerFooter(props) {
|
|
191
|
+
return _jsx(Footer, { ...props });
|
|
192
|
+
}
|
|
193
|
+
export function DrawerHandle({ style, ...props }) {
|
|
194
|
+
const pan = useContext(DrawerGesture);
|
|
195
|
+
const theme = useTramaTheme();
|
|
196
|
+
return (_jsx(View, { ...props, ...pan, style: [{ alignSelf: 'stretch', minHeight: 44, alignItems: 'center', justifyContent: 'center' }, style], children: _jsx(View, { style: {
|
|
197
|
+
width: theme.space * 8,
|
|
198
|
+
height: theme.space,
|
|
199
|
+
backgroundColor: theme.colors.border,
|
|
200
|
+
borderRadius: theme.radius,
|
|
201
|
+
} }) }));
|
|
202
|
+
}
|
|
203
|
+
export const Popover = forwardRef(function Popover({ open, defaultOpen, onOpenChange, placement, size, radius, offset, disabled, heading, description, label, closeOnEscape, closeOnOutside, backdrop, backdropColor, children, style, ...props }, ref) {
|
|
204
|
+
const state = useOverlay({ open, defaultOpen, onOpenChange });
|
|
205
|
+
const { resolve, theme, direction } = useTramaAppearance();
|
|
206
|
+
const trigger = useRef(null);
|
|
207
|
+
const { width, height } = useWindowDimensions();
|
|
208
|
+
const [anchor, setAnchor] = useState();
|
|
209
|
+
const [measured, setMeasured] = useState(0);
|
|
210
|
+
const { body, named } = splitContent(children, {
|
|
211
|
+
trigger: PopoverTrigger,
|
|
212
|
+
header: PopoverHeader,
|
|
213
|
+
footer: PopoverFooter,
|
|
214
|
+
arrow: PopoverArrow,
|
|
215
|
+
});
|
|
216
|
+
function measureAnchor() {
|
|
217
|
+
trigger.current?.measureInWindow((x, y, triggerWidth, triggerHeight) => setAnchor({ x, y, width: triggerWidth, height: triggerHeight }));
|
|
218
|
+
}
|
|
219
|
+
function show() {
|
|
220
|
+
measureAnchor();
|
|
221
|
+
state.request(true, 'trigger');
|
|
222
|
+
}
|
|
223
|
+
useImperativeHandle(ref, () => ({
|
|
224
|
+
show,
|
|
225
|
+
hide: () => state.request(false, 'programmatic'),
|
|
226
|
+
toggle: () => (state.visible ? state.request(false, 'programmatic') : show()),
|
|
227
|
+
}));
|
|
228
|
+
const menu = resolve(placement, 'bottom-start');
|
|
229
|
+
const popupSize = resolve(size, 'md');
|
|
230
|
+
const gap = Math.max(0, offset ?? theme.space * 2);
|
|
231
|
+
const popupWidth = Math.min(Math.max(0, width - theme.space * 4), popupSize === 'auto' ? Math.max(anchor?.width ?? 240, 180) : (bounds[popupSize] ?? 320));
|
|
232
|
+
const alignRight = menu.endsWith('end') !== (direction === 'rtl');
|
|
233
|
+
const x = Math.max(theme.space * 2, Math.min(width - popupWidth - theme.space * 2, anchor ? (alignRight ? anchor.x + anchor.width - popupWidth : anchor.x) : (width - popupWidth) / 2));
|
|
234
|
+
const above = Boolean(anchor && (menu.startsWith('top') || anchor.y + anchor.height + measured + gap > height));
|
|
235
|
+
const y = anchor
|
|
236
|
+
? above
|
|
237
|
+
? Math.max(theme.space * 2, anchor.y - measured - gap)
|
|
238
|
+
: anchor.y + anchor.height + gap
|
|
239
|
+
: height * 0.25;
|
|
240
|
+
const rounding = { none: 0, sm: theme.radius / 2, md: theme.radius, lg: theme.radius * 1.5, xl: theme.radius * 2 };
|
|
241
|
+
const arrowOffset = anchor
|
|
242
|
+
? Math.min(popupWidth - theme.space * 4, Math.max(theme.space * 2, anchor.x + anchor.width / 2 - x - theme.space))
|
|
243
|
+
: 0;
|
|
244
|
+
return (_jsxs(OverlayControls.Provider, { value: {
|
|
245
|
+
visible: state.visible,
|
|
246
|
+
request(next, reason) {
|
|
247
|
+
if (next && disabled)
|
|
248
|
+
return;
|
|
249
|
+
if (next)
|
|
250
|
+
show();
|
|
251
|
+
else
|
|
252
|
+
state.request(false, reason);
|
|
253
|
+
},
|
|
254
|
+
}, children: [_jsx(View, { ref: trigger, collapsable: false, onLayout: measureAnchor, style: { alignSelf: 'flex-start' }, children: named.trigger ?? (_jsx(PopoverTrigger, { variant: "outlined", disabled: disabled, children: label ?? heading })) }), state.visible && !disabled && (_jsxs(Modal, { transparent: true, visible: true, animationType: "none", statusBarTranslucent: true, onRequestClose: () => {
|
|
255
|
+
if (closeOnEscape !== false)
|
|
256
|
+
state.request(false, 'escape');
|
|
257
|
+
}, children: [_jsx(Pressable, { accessible: false, importantForAccessibility: "no", style: [
|
|
258
|
+
StyleSheet.absoluteFill,
|
|
259
|
+
{
|
|
260
|
+
backgroundColor: resolve(backdrop, 'none') === 'dim' ? (backdropColor ?? 'rgba(0,0,0,0.30)') : 'transparent',
|
|
261
|
+
},
|
|
262
|
+
], onPress: closeOnOutside === false ? undefined : () => state.request(false, 'backdrop') }), _jsxs(View, { ...props, accessibilityViewIsModal: true, role: "dialog", accessibilityLabel: label ?? heading, onLayout: (event) => {
|
|
263
|
+
setMeasured(event.nativeEvent.layout.height);
|
|
264
|
+
props.onLayout?.(event);
|
|
265
|
+
}, style: [
|
|
266
|
+
{
|
|
267
|
+
direction,
|
|
268
|
+
position: 'absolute',
|
|
269
|
+
top: y,
|
|
270
|
+
left: x,
|
|
271
|
+
width: popupWidth,
|
|
272
|
+
maxHeight: Math.max(44, height - y - theme.space * 2),
|
|
273
|
+
backgroundColor: theme.colors.surface,
|
|
274
|
+
borderRadius: rounding[resolve(radius, 'md')],
|
|
275
|
+
borderWidth: 1,
|
|
276
|
+
borderColor: theme.colors.border,
|
|
277
|
+
elevation: 5,
|
|
278
|
+
padding: theme.space * 3,
|
|
279
|
+
gap: theme.space * 2,
|
|
280
|
+
},
|
|
281
|
+
style,
|
|
282
|
+
], children: [named.arrow && anchor && (_jsx(View, { pointerEvents: "none", style: {
|
|
283
|
+
position: 'absolute',
|
|
284
|
+
[direction === 'rtl' ? 'end' : 'start']: arrowOffset,
|
|
285
|
+
top: above ? undefined : -theme.space,
|
|
286
|
+
bottom: above ? -theme.space : undefined,
|
|
287
|
+
}, children: named.arrow })), named.header ??
|
|
288
|
+
(heading || description ? (_jsxs(PopoverHeader, { children: [heading && _jsx(PopoverTitle, { children: heading }), description && _jsx(PopoverDescription, { children: description })] })) : null), _jsx(ScrollView, { style: { flexGrow: 0, flexShrink: 1 }, keyboardShouldPersistTaps: "handled", children: _jsx(PopoverBody, { children: body }) }), named.footer] })] }))] }));
|
|
289
|
+
});
|
|
290
|
+
export function PopoverTrigger(props) {
|
|
291
|
+
return _jsx(Trigger, { ...props });
|
|
292
|
+
}
|
|
293
|
+
export function PopoverClose(props) {
|
|
294
|
+
return _jsx(Close, { ...props });
|
|
295
|
+
}
|
|
296
|
+
export function PopoverHeader(props) {
|
|
297
|
+
return _jsx(Header, { ...props });
|
|
298
|
+
}
|
|
299
|
+
export function PopoverTitle(props) {
|
|
300
|
+
return _jsx(Title, { ...props });
|
|
301
|
+
}
|
|
302
|
+
export function PopoverDescription(props) {
|
|
303
|
+
return _jsx(Description, { ...props });
|
|
304
|
+
}
|
|
305
|
+
export function PopoverBody(props) {
|
|
306
|
+
return _jsx(Body, { ...props });
|
|
307
|
+
}
|
|
308
|
+
export function PopoverFooter(props) {
|
|
309
|
+
return _jsx(Footer, { ...props });
|
|
310
|
+
}
|
|
311
|
+
export function PopoverArrow({ style, ...props }) {
|
|
312
|
+
const theme = useTramaTheme();
|
|
313
|
+
return (_jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none", style: [
|
|
314
|
+
{
|
|
315
|
+
width: theme.space * 2,
|
|
316
|
+
height: theme.space * 2,
|
|
317
|
+
transform: [{ rotate: '45deg' }],
|
|
318
|
+
backgroundColor: theme.colors.surface,
|
|
319
|
+
},
|
|
320
|
+
style,
|
|
321
|
+
] }));
|
|
322
|
+
}
|
|
323
|
+
export function FloatingPanel({ open, defaultOpen = true, onOpenChange, placement = 'bottom-end', size = 'sm', variant = 'elevated', style, ...props }) {
|
|
324
|
+
const state = useOverlay({ open, defaultOpen, onOpenChange });
|
|
325
|
+
const { theme, direction } = useTramaAppearance();
|
|
326
|
+
if (!state.visible)
|
|
327
|
+
return null;
|
|
328
|
+
const center = placement === 'center';
|
|
329
|
+
return (_jsx(OverlayControls.Provider, { value: state, children: _jsx(View, { ...props, style: [
|
|
330
|
+
{
|
|
331
|
+
direction,
|
|
332
|
+
position: 'absolute',
|
|
333
|
+
alignSelf: center ? 'center' : undefined,
|
|
334
|
+
start: placement.endsWith('start') ? theme.space * 2 : undefined,
|
|
335
|
+
end: placement.endsWith('end') ? theme.space * 2 : undefined,
|
|
336
|
+
top: center ? '30%' : placement.startsWith('top') ? theme.space * 2 : undefined,
|
|
337
|
+
bottom: placement.startsWith('bottom') ? theme.space * 2 : undefined,
|
|
338
|
+
width: '90%',
|
|
339
|
+
maxWidth: bounds[size],
|
|
340
|
+
padding: theme.space * 3,
|
|
341
|
+
gap: theme.space * 2,
|
|
342
|
+
borderRadius: theme.radius,
|
|
343
|
+
backgroundColor: theme.colors.surface,
|
|
344
|
+
zIndex: 20,
|
|
345
|
+
borderWidth: variant === 'plain' ? 0 : 1,
|
|
346
|
+
borderColor: theme.colors.border,
|
|
347
|
+
elevation: variant === 'elevated' ? 6 : 0,
|
|
348
|
+
},
|
|
349
|
+
style,
|
|
350
|
+
] }) }));
|
|
351
|
+
}
|
|
352
|
+
export function FloatingPanelHeader(props) {
|
|
353
|
+
return _jsx(Header, { ...props });
|
|
354
|
+
}
|
|
355
|
+
export function FloatingPanelBody(props) {
|
|
356
|
+
return _jsx(Body, { ...props });
|
|
357
|
+
}
|
|
358
|
+
export function FloatingPanelFooter(props) {
|
|
359
|
+
return _jsx(Footer, { ...props });
|
|
360
|
+
}
|
|
361
|
+
export function FloatingPanelClose(props) {
|
|
362
|
+
return _jsx(Close, { ...props });
|
|
363
|
+
}
|
|
364
|
+
const styles = StyleSheet.create({ modal: { flex: 1 } });
|
package/dist/pill.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PressableProps, type ViewProps } from 'react-native';
|
|
3
|
+
import type { TramaResponsive } from './responsive.js';
|
|
4
|
+
import { type TramaColor, type TramaShape, type TramaSize } from './theme.js';
|
|
5
|
+
export type PillVariant = 'soft' | 'filled' | 'outlined' | 'dashed';
|
|
6
|
+
export interface PillProps extends ViewProps {
|
|
7
|
+
variant?: TramaResponsive<PillVariant>;
|
|
8
|
+
size?: TramaResponsive<TramaSize>;
|
|
9
|
+
shape?: TramaResponsive<TramaShape>;
|
|
10
|
+
color?: TramaResponsive<TramaColor>;
|
|
11
|
+
textColor?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
leading?: ReactNode;
|
|
14
|
+
trailing?: ReactNode;
|
|
15
|
+
actions?: ReactNode;
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
defaultSelected?: boolean;
|
|
18
|
+
onSelectedChange?: (selected: boolean) => void;
|
|
19
|
+
onPress?: PressableProps['onPress'];
|
|
20
|
+
onRemove?: PressableProps['onPress'];
|
|
21
|
+
removeLabel?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function Pill({ variant, size, shape, color, textColor, disabled, leading, trailing, actions, selected, defaultSelected, onSelectedChange, onPress, onRemove, removeLabel, accessibilityLabel, children, style, ...props }: PillProps): import("react").JSX.Element;
|
|
24
|
+
export interface PillActionProps extends Omit<PressableProps, 'children'> {
|
|
25
|
+
children?: ReactNode;
|
|
26
|
+
accessibilityLabel: string;
|
|
27
|
+
color?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function PillStart(props: ViewProps): import("react").JSX.Element;
|
|
30
|
+
export declare function PillEnd(props: ViewProps): import("react").JSX.Element;
|
|
31
|
+
export declare function PillActions(props: ViewProps): import("react").JSX.Element;
|
|
32
|
+
export declare function PillCloseIcon(props: ViewProps): import("react").JSX.Element;
|
|
33
|
+
export declare function PillAction({ children, color, style, disabled, accessibilityState, ...props }: PillActionProps): import("react").JSX.Element;
|
package/dist/pill.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Pressable, View } from 'react-native';
|
|
4
|
+
import { splitContent, TextContent } from './internal/content.js';
|
|
5
|
+
import { useControllableValue } from './internal/state.js';
|
|
6
|
+
import { useTramaMessages } from './localization.js';
|
|
7
|
+
import { getTone, shapeRadius, sizeStep, useTramaAppearance, } from './theme.js';
|
|
8
|
+
export function Pill({ variant, size, shape, color, textColor, disabled, leading, trailing, actions, selected, defaultSelected, onSelectedChange, onPress, onRemove, removeLabel, accessibilityLabel, children, style, ...props }) {
|
|
9
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
10
|
+
const messages = useTramaMessages();
|
|
11
|
+
const { body, named } = splitContent(children, {
|
|
12
|
+
start: PillStart,
|
|
13
|
+
end: PillEnd,
|
|
14
|
+
actions: PillActions,
|
|
15
|
+
closeIcon: PillCloseIcon,
|
|
16
|
+
});
|
|
17
|
+
const [active, request] = useControllableValue(selected, defaultSelected ?? false, onSelectedChange);
|
|
18
|
+
const [focused, setFocused] = useState(false);
|
|
19
|
+
const tone = getTone(theme, resolve(color, 'neutral'));
|
|
20
|
+
const appearance = resolve(variant, 'soft');
|
|
21
|
+
const step = sizeStep[resolve(size, 'md')];
|
|
22
|
+
const selectable = selected !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined;
|
|
23
|
+
const interactive = Boolean(onPress || selectable);
|
|
24
|
+
const solid = appearance === 'filled' || active;
|
|
25
|
+
const ink = textColor ?? (solid ? tone.ink : tone.text);
|
|
26
|
+
const contentStyle = {
|
|
27
|
+
flexDirection: 'row',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
minWidth: interactive ? 44 : undefined,
|
|
30
|
+
minHeight: interactive ? 44 : undefined,
|
|
31
|
+
flexShrink: 1,
|
|
32
|
+
gap: theme.space * 2,
|
|
33
|
+
paddingHorizontal: theme.space * (3 + step),
|
|
34
|
+
paddingVertical: theme.space,
|
|
35
|
+
};
|
|
36
|
+
const content = (_jsxs(_Fragment, { children: [named.start ?? leading, _jsx(TextContent, { style: {
|
|
37
|
+
color: ink,
|
|
38
|
+
fontFamily: theme.fontFamily,
|
|
39
|
+
fontSize: theme.fontSize - 1 + step,
|
|
40
|
+
fontWeight: '600',
|
|
41
|
+
flexShrink: 1,
|
|
42
|
+
}, children: body }), named.end ?? trailing] }));
|
|
43
|
+
return (_jsxs(View, { ...props, style: [
|
|
44
|
+
{
|
|
45
|
+
direction,
|
|
46
|
+
alignSelf: 'flex-start',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
flexDirection: 'row',
|
|
49
|
+
maxWidth: '100%',
|
|
50
|
+
backgroundColor: solid ? tone.solid : appearance === 'soft' ? tone.soft : 'transparent',
|
|
51
|
+
borderRadius: shapeRadius(theme, resolve(shape, 'pill')),
|
|
52
|
+
borderWidth: 1,
|
|
53
|
+
borderStyle: appearance === 'dashed' ? 'dashed' : 'solid',
|
|
54
|
+
borderColor: appearance === 'outlined' || appearance === 'dashed' || focused ? tone.text : 'transparent',
|
|
55
|
+
opacity: disabled ? 0.55 : 1,
|
|
56
|
+
},
|
|
57
|
+
style,
|
|
58
|
+
], children: [interactive ? (_jsx(Pressable, { accessibilityRole: selectable ? 'togglebutton' : 'button', "aria-checked": selectable ? active : undefined, "aria-disabled": Boolean(disabled), accessibilityLabel: accessibilityLabel, accessibilityState: { disabled: Boolean(disabled), ...(selectable ? { checked: active } : {}) }, disabled: disabled, onFocus: () => setFocused(true), onBlur: () => setFocused(false), onPress: (event) => {
|
|
59
|
+
if (disabled)
|
|
60
|
+
return;
|
|
61
|
+
if (selectable)
|
|
62
|
+
request(!active);
|
|
63
|
+
onPress?.(event);
|
|
64
|
+
}, style: ({ pressed }) => [contentStyle, { opacity: pressed ? 0.8 : 1 }], children: content })) : (_jsx(View, { accessibilityLabel: accessibilityLabel, style: contentStyle, children: content })), named.actions ?? actions, onRemove && (_jsx(PillAction, { disabled: disabled, accessibilityLabel: removeLabel ?? messages.removeItem, onPress: onRemove, color: ink, children: named.closeIcon ?? '×' }))] }));
|
|
65
|
+
}
|
|
66
|
+
export function PillStart(props) {
|
|
67
|
+
return _jsx(View, { ...props });
|
|
68
|
+
}
|
|
69
|
+
export function PillEnd(props) {
|
|
70
|
+
return _jsx(View, { ...props });
|
|
71
|
+
}
|
|
72
|
+
export function PillActions(props) {
|
|
73
|
+
return _jsx(View, { ...props, style: [{ flexDirection: 'row', alignItems: 'center' }, props.style] });
|
|
74
|
+
}
|
|
75
|
+
export function PillCloseIcon(props) {
|
|
76
|
+
return _jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none" });
|
|
77
|
+
}
|
|
78
|
+
export function PillAction({ children, color, style, disabled, accessibilityState, ...props }) {
|
|
79
|
+
const { theme } = useTramaAppearance();
|
|
80
|
+
return (_jsx(Pressable, { ...props, disabled: disabled, accessibilityRole: "button", accessibilityState: { ...accessibilityState, disabled: Boolean(disabled) }, style: (state) => [
|
|
81
|
+
{
|
|
82
|
+
minHeight: 44,
|
|
83
|
+
minWidth: 44,
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
justifyContent: 'center',
|
|
86
|
+
opacity: state.pressed ? 0.75 : 1,
|
|
87
|
+
},
|
|
88
|
+
typeof style === 'function' ? style(state) : style,
|
|
89
|
+
], children: _jsx(TextContent, { style: { color: color ?? theme.colors.text, fontFamily: theme.fontFamily, fontSize: theme.fontSize + 4 }, children: children }) }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
|
+
import type { TramaResponsive } from './responsive.js';
|
|
3
|
+
import { type TramaColor, type TramaSize } from './theme.js';
|
|
4
|
+
export type ProgressGeometry = 'linear' | 'circular' | 'dashboard';
|
|
5
|
+
export type ProgressVariant = 'solid' | 'soft' | 'striped';
|
|
6
|
+
export type ProgressFormat = 'percent' | 'value' | 'value-max';
|
|
7
|
+
export interface ProgressProps extends ViewProps {
|
|
8
|
+
value?: number;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
bufferValue?: number;
|
|
12
|
+
label?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
valueText?: string;
|
|
15
|
+
hideLabel?: boolean;
|
|
16
|
+
showValue?: TramaResponsive<boolean>;
|
|
17
|
+
indeterminate?: boolean;
|
|
18
|
+
size?: TramaResponsive<TramaSize>;
|
|
19
|
+
color?: TramaResponsive<TramaColor>;
|
|
20
|
+
geometry?: TramaResponsive<ProgressGeometry>;
|
|
21
|
+
variant?: TramaResponsive<ProgressVariant>;
|
|
22
|
+
radius?: TramaResponsive<'none' | 'sm' | 'md' | 'full'>;
|
|
23
|
+
valuePosition?: TramaResponsive<'top' | 'bottom' | 'inside'>;
|
|
24
|
+
format?: TramaResponsive<ProgressFormat>;
|
|
25
|
+
thickness?: TramaResponsive<number>;
|
|
26
|
+
}
|
|
27
|
+
export declare function Progress({ value, min, max, bufferValue, label, description, valueText, hideLabel, showValue, indeterminate, size, color, geometry, variant, radius, valuePosition, format, thickness, style, accessibilityLabel, accessibilityHint, ...props }: ProgressProps): import("react").JSX.Element;
|