@thanhphi/unistyles-ui 0.0.0-stage → 0.2.7
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 +384 -2
- package/dist/choices.d.ts +52 -0
- package/dist/choices.js +143 -0
- package/dist/colors/index.d.ts +79 -0
- package/dist/colors/index.js +2 -0
- package/dist/date.d.ts +40 -0
- package/dist/date.js +153 -0
- package/dist/fields.d.ts +140 -0
- package/dist/fields.js +233 -0
- package/dist/form/index.d.ts +14 -0
- package/dist/form/index.js +68 -0
- package/dist/icons.d.ts +10 -0
- package/dist/icons.js +52 -0
- package/dist/image.d.ts +20 -0
- package/dist/image.js +34 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +33 -0
- package/dist/list-picker.d.ts +45 -0
- package/dist/list-picker.js +76 -0
- package/dist/module/choices.js +135 -0
- package/dist/module/colors/index.js +1 -0
- package/dist/module/colors/package.json +1 -0
- package/dist/module/date.js +145 -0
- package/dist/module/fields.js +225 -0
- package/dist/module/form/index.js +62 -0
- package/dist/module/form/package.json +1 -0
- package/dist/module/icons.js +16 -0
- package/dist/module/image.js +31 -0
- package/dist/module/index.js +13 -0
- package/dist/module/list-picker.js +70 -0
- package/dist/module/overlays.js +138 -0
- package/dist/module/package.json +1 -0
- package/dist/module/primitives.js +432 -0
- package/dist/module/process-graph.js +125 -0
- package/dist/module/rich-html/html-styles.js +55 -0
- package/dist/module/rich-html/image-renderers.js +141 -0
- package/dist/module/rich-html/index.js +54 -0
- package/dist/module/rich-html/normalize-inline-colors.js +93 -0
- package/dist/module/rich-html/package.json +1 -0
- package/dist/module/rich-html/rich-html.js +118 -0
- package/dist/module/search.js +88 -0
- package/dist/module/theme.js +62 -0
- package/dist/module/toast.js +30 -0
- package/dist/module/ui-modal.js +145 -0
- package/dist/overlays.d.ts +72 -0
- package/dist/overlays.js +146 -0
- package/dist/primitives.d.ts +157 -0
- package/dist/primitives.js +480 -0
- package/dist/process-graph.d.ts +33 -0
- package/dist/process-graph.js +161 -0
- package/dist/rich-html/html-styles.d.ts +23 -0
- package/dist/rich-html/html-styles.js +63 -0
- package/dist/rich-html/image-renderers.d.ts +12 -0
- package/dist/rich-html/image-renderers.js +144 -0
- package/dist/rich-html/index.d.ts +18 -0
- package/dist/rich-html/index.js +92 -0
- package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
- package/dist/rich-html/normalize-inline-colors.js +99 -0
- package/dist/rich-html/rich-html.d.ts +7 -0
- package/dist/rich-html/rich-html.js +123 -0
- package/dist/search.d.ts +27 -0
- package/dist/search.js +91 -0
- package/dist/theme.d.ts +67 -0
- package/dist/theme.js +68 -0
- package/dist/toast.d.ts +3 -0
- package/dist/toast.js +69 -0
- package/dist/ui-modal.d.ts +17 -0
- package/dist/ui-modal.js +151 -0
- package/package.json +35 -4
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ActivityIndicator, Pressable, StyleSheet, View, useWindowDimensions, } from "react-native";
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
|
+
import { useUITheme } from "./theme.js";
|
|
5
|
+
import { Button, UIText } from "./primitives.js";
|
|
6
|
+
import { UIIcon } from "./icons.js";
|
|
7
|
+
import { UIModal } from "./ui-modal.js";
|
|
8
|
+
export function SheetHeader({ title, titleNumberOfLines = 1, headerStart, headerEnd, headerStyle, showHandle = false, closeAccessibilityLabel = "Close", onClose, closeDisabled, closeTestID, titleStyle, }) {
|
|
9
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
10
|
+
const showClose = headerEnd === undefined && !!onClose;
|
|
11
|
+
return (_jsxs(View, { children: [showHandle && (_jsx(View, { accessible: false, pointerEvents: "none", style: [
|
|
12
|
+
styles.handle,
|
|
13
|
+
{
|
|
14
|
+
width: s.xxl + s.md,
|
|
15
|
+
height: s.xs,
|
|
16
|
+
marginTop: s.md,
|
|
17
|
+
borderRadius: r.full,
|
|
18
|
+
backgroundColor: c.content3,
|
|
19
|
+
},
|
|
20
|
+
] })), (title != null ||
|
|
21
|
+
showClose ||
|
|
22
|
+
headerStart != null ||
|
|
23
|
+
headerEnd != null) && (_jsxs(View, { style: [
|
|
24
|
+
styles.sheetHeader,
|
|
25
|
+
{ paddingHorizontal: s.lg, paddingVertical: s.md },
|
|
26
|
+
showClose && {
|
|
27
|
+
paddingHorizontal: s.xxl * 2,
|
|
28
|
+
paddingTop: showHandle ? s.md : s.xxl + s.xs,
|
|
29
|
+
},
|
|
30
|
+
headerStyle,
|
|
31
|
+
], children: [headerStart === undefined && !showClose ? (_jsx(View, { style: styles.headerSide })) : (headerStart), _jsx(UIText, { accessibilityRole: "header", variant: "subtitle", weight: "600", numberOfLines: titleNumberOfLines, style: [styles.sheetTitle, titleStyle], children: title }), headerEnd === undefined && !showClose ? (_jsx(View, { style: styles.headerSide })) : (headerEnd)] })), showClose && (_jsx(Pressable, { testID: closeTestID, onPress: onClose, disabled: closeDisabled, accessibilityState: { disabled: !!closeDisabled }, hitSlop: s.sm, accessibilityRole: "button", accessibilityLabel: closeAccessibilityLabel, style: [
|
|
32
|
+
styles.closeCorner,
|
|
33
|
+
{ top: s.xs, right: s.md, opacity: closeDisabled ? 0.5 : 1 },
|
|
34
|
+
], children: _jsx(UIIcon, { name: "close", size: 22, color: c.content1 }) }))] }));
|
|
35
|
+
}
|
|
36
|
+
/** Native Modal children retain the provider of the app that rendered them. */
|
|
37
|
+
export function Sheet({ visible, onClose, onOpened, onClosed, title, description, titleNumberOfLines, closeAccessibilityLabel, children, style, headerStyle, headerStart, headerEnd, showHandle = true, heightRatio, animationType = "slide", keyboardAvoiding = false, }) {
|
|
38
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
39
|
+
const insets = useSafeAreaInsets();
|
|
40
|
+
const { height } = useWindowDimensions();
|
|
41
|
+
const panelHeight = heightRatio == null
|
|
42
|
+
? undefined
|
|
43
|
+
: Math.max(0, Math.min(height * heightRatio, height - insets.top));
|
|
44
|
+
return (_jsxs(UIModal, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, position: "bottom", animationType: animationType, keyboardAvoiding: keyboardAvoiding, statusBarTranslucent: true, containerStyle: { paddingTop: insets.top }, contentStyle: [
|
|
45
|
+
{
|
|
46
|
+
height: panelHeight,
|
|
47
|
+
maxHeight: panelHeight ?? "90%",
|
|
48
|
+
flexShrink: keyboardAvoiding || panelHeight != null ? 1 : undefined,
|
|
49
|
+
overflow: panelHeight != null ? "hidden" : undefined,
|
|
50
|
+
backgroundColor: c.background,
|
|
51
|
+
borderTopLeftRadius: r.sheet,
|
|
52
|
+
borderTopRightRadius: r.sheet,
|
|
53
|
+
paddingBottom: Math.max(s.xxl, insets.bottom),
|
|
54
|
+
},
|
|
55
|
+
style,
|
|
56
|
+
], children: [_jsx(SheetHeader, { title: title, titleNumberOfLines: titleNumberOfLines, closeAccessibilityLabel: closeAccessibilityLabel, headerStart: headerStart, headerEnd: headerEnd, headerStyle: headerStyle, showHandle: showHandle, onClose: onClose }), !!description && (_jsx(UIText, { variant: "caption", color: "content3", style: {
|
|
57
|
+
textAlign: "center",
|
|
58
|
+
paddingHorizontal: s.lg,
|
|
59
|
+
marginBottom: s.md,
|
|
60
|
+
}, children: description })), children] }));
|
|
61
|
+
}
|
|
62
|
+
export function ActionSheet({ items, onSelect, cancelText, ...props }) {
|
|
63
|
+
const { colors: c, spacing: s } = useUITheme();
|
|
64
|
+
return (_jsx(Sheet, { ...props, children: _jsxs(View, { style: { paddingHorizontal: s.lg }, children: [items.map((item) => (_jsxs(Pressable, { disabled: item.disabled, onPress: () => {
|
|
65
|
+
onSelect(item);
|
|
66
|
+
props.onClose();
|
|
67
|
+
}, accessibilityRole: "button", accessibilityState: { disabled: !!item.disabled }, style: [
|
|
68
|
+
styles.actionItem,
|
|
69
|
+
{
|
|
70
|
+
paddingVertical: s.lg,
|
|
71
|
+
gap: s.md,
|
|
72
|
+
borderBottomColor: c.divider,
|
|
73
|
+
opacity: item.disabled ? 0.5 : 1,
|
|
74
|
+
},
|
|
75
|
+
], children: [item.icon, _jsx(UIText, { color: item.destructive ? "danger" : "content1", children: item.label })] }, item.id))), cancelText != null && (_jsx(Button, { label: cancelText, variant: "ghost", onPress: props.onClose, style: { marginTop: s.sm } }))] }) }));
|
|
76
|
+
}
|
|
77
|
+
export function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }) {
|
|
78
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
79
|
+
return (_jsxs(UIModal, { visible: visible, animationType: "fade", onClose: loading ? undefined : onClose, statusBarTranslucent: true, containerStyle: { padding: s.xxl }, contentStyle: [
|
|
80
|
+
styles.dialog,
|
|
81
|
+
{
|
|
82
|
+
padding: s.xl,
|
|
83
|
+
gap: s.lg,
|
|
84
|
+
backgroundColor: c.background,
|
|
85
|
+
borderRadius: r.lg,
|
|
86
|
+
},
|
|
87
|
+
], children: [illustration, title != null && (_jsx(UIText, { variant: "subtitle", weight: "600", style: styles.center, children: title })), typeof message === "string" ? (_jsx(UIText, { color: "content2", style: styles.center, children: message })) : (message), _jsxs(View, { style: [styles.dialogActions, { gap: s.md }], children: [cancelText != null && (_jsx(Button, { label: cancelText, variant: "outline", disabled: loading, onPress: onClose, style: styles.flex })), _jsx(Button, { label: confirmText, variant: destructive ? "danger" : "primary", loading: loading, onPress: onConfirm, style: styles.flex })] })] }));
|
|
88
|
+
}
|
|
89
|
+
export function ResultDialog({ buttonText, ...props }) {
|
|
90
|
+
return (_jsx(ConfirmDialog, { ...props, confirmText: buttonText, onConfirm: props.onClose }));
|
|
91
|
+
}
|
|
92
|
+
export function LoadingOverlay({ visible, label, presentation = "modal", testID, }) {
|
|
93
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
94
|
+
if (!visible)
|
|
95
|
+
return null;
|
|
96
|
+
const content = (_jsx(View, { testID: testID, accessibilityViewIsModal: true, accessibilityLiveRegion: "polite", style: [
|
|
97
|
+
styles.dialogRoot,
|
|
98
|
+
{ backgroundColor: c.backdrop },
|
|
99
|
+
presentation === "inline" && {
|
|
100
|
+
...StyleSheet.absoluteFillObject,
|
|
101
|
+
zIndex: 10000,
|
|
102
|
+
elevation: 10000,
|
|
103
|
+
},
|
|
104
|
+
], children: _jsxs(View, { style: {
|
|
105
|
+
padding: s.xxl,
|
|
106
|
+
gap: s.md,
|
|
107
|
+
backgroundColor: c.background,
|
|
108
|
+
borderRadius: r.lg,
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
}, children: [_jsx(ActivityIndicator, { size: "large", color: c.primary500 }), label != null && _jsx(UIText, { children: label })] }) }));
|
|
111
|
+
if (presentation === "inline")
|
|
112
|
+
return content;
|
|
113
|
+
return (_jsx(UIModal, { visible: true, position: "fullScreen", animationType: "fade", backdropColor: "transparent", statusBarTranslucent: true, children: content }));
|
|
114
|
+
}
|
|
115
|
+
const styles = StyleSheet.create({
|
|
116
|
+
handle: { alignSelf: "center" },
|
|
117
|
+
closeCorner: {
|
|
118
|
+
position: "absolute",
|
|
119
|
+
width: 32,
|
|
120
|
+
height: 32,
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
justifyContent: "center",
|
|
123
|
+
zIndex: 1,
|
|
124
|
+
},
|
|
125
|
+
sheetHeader: { flexDirection: "row", alignItems: "center" },
|
|
126
|
+
headerSide: { width: 18 },
|
|
127
|
+
sheetTitle: { flex: 1, textAlign: "center" },
|
|
128
|
+
actionItem: {
|
|
129
|
+
flexDirection: "row",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
borderBottomWidth: 1,
|
|
132
|
+
},
|
|
133
|
+
dialogRoot: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
134
|
+
dialog: { width: "100%", maxWidth: 420, alignItems: "center" },
|
|
135
|
+
dialogActions: { flexDirection: "row", alignSelf: "stretch" },
|
|
136
|
+
center: { textAlign: "center" },
|
|
137
|
+
flex: { flex: 1 },
|
|
138
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { ActivityIndicator, Animated, Easing, Image, Keyboard, Pressable, Platform, StyleSheet, Text, TextInput, View, } from "react-native";
|
|
4
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
|
+
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
|
|
6
|
+
import { useUITheme } from "./theme.js";
|
|
7
|
+
import { UIIcon } from "./icons.js";
|
|
8
|
+
export function UIText({ variant = "body", color = "content1", weight, style, ...props }) {
|
|
9
|
+
const theme = useUITheme();
|
|
10
|
+
return (_jsx(Text, { ...props, style: [
|
|
11
|
+
{
|
|
12
|
+
color: theme.colors[color],
|
|
13
|
+
fontFamily: theme.typography.fontFamily,
|
|
14
|
+
fontSize: theme.typography[variant],
|
|
15
|
+
fontWeight: weight,
|
|
16
|
+
},
|
|
17
|
+
style,
|
|
18
|
+
] }));
|
|
19
|
+
}
|
|
20
|
+
export function Button({ label, children, variant = "primary", size = "normal", loading = false, throttleMs, leading, trailing, disabled, style, textStyle, accessibilityLabel, accessibilityState, onPress, onLongPress, onPressIn, onPressOut, ...props }) {
|
|
21
|
+
const { colors: c, radius: r, spacing: s, typography: t } = useUITheme();
|
|
22
|
+
const solid = variant === "primary" || variant === "danger";
|
|
23
|
+
const tint = variant === "danger" ? c.danger : c.primary500;
|
|
24
|
+
const fg = solid ? c.textPrimary : tint;
|
|
25
|
+
const enabledAt = useRef(0);
|
|
26
|
+
const runPress = (handler, event, startsCooldown) => {
|
|
27
|
+
if (!handler)
|
|
28
|
+
return;
|
|
29
|
+
const throttled = typeof throttleMs === "number" &&
|
|
30
|
+
Number.isFinite(throttleMs) &&
|
|
31
|
+
throttleMs > 0;
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
if (throttled && now < enabledAt.current)
|
|
34
|
+
return;
|
|
35
|
+
if (throttled && startsCooldown)
|
|
36
|
+
enabledAt.current = now + throttleMs;
|
|
37
|
+
handler(event);
|
|
38
|
+
};
|
|
39
|
+
return (_jsxs(Pressable, { ...props, onPress: onPress ? (event) => runPress(onPress, event, true) : undefined, onLongPress: onLongPress ? (event) => runPress(onLongPress, event, true) : undefined, onPressIn: onPressIn ? (event) => runPress(onPressIn, event, false) : undefined, onPressOut: onPressOut ? (event) => runPress(onPressOut, event, false) : undefined, disabled: disabled || loading, accessibilityRole: "button", accessibilityLabel: accessibilityLabel ?? label, accessibilityState: {
|
|
40
|
+
...accessibilityState,
|
|
41
|
+
disabled: !!disabled || loading,
|
|
42
|
+
busy: loading,
|
|
43
|
+
}, style: ({ pressed }) => [
|
|
44
|
+
styles.button,
|
|
45
|
+
{
|
|
46
|
+
minHeight: size === "small" ? s.xxl + s.md : s.xxl + s.xl,
|
|
47
|
+
paddingHorizontal: s.lg,
|
|
48
|
+
paddingVertical: size === "small" ? s.sm : s.md,
|
|
49
|
+
gap: s.sm,
|
|
50
|
+
borderRadius: r.lg,
|
|
51
|
+
borderWidth: variant === "outline" ? 1 : 0,
|
|
52
|
+
borderColor: disabled ? c.content4 : tint,
|
|
53
|
+
backgroundColor: solid
|
|
54
|
+
? disabled
|
|
55
|
+
? c.content4
|
|
56
|
+
: tint
|
|
57
|
+
: "transparent",
|
|
58
|
+
opacity: pressed ? 0.75 : 1,
|
|
59
|
+
},
|
|
60
|
+
style,
|
|
61
|
+
], children: [loading ? _jsx(ActivityIndicator, { color: fg, size: "small" }) : leading, label != null ? (_jsx(UIText, { weight: "600", style: [
|
|
62
|
+
{ color: disabled && !solid ? c.content3 : fg, fontSize: t.body },
|
|
63
|
+
textStyle,
|
|
64
|
+
], children: label })) : typeof children === "string" || typeof children === "number" ? (_jsx(UIText, { weight: "600", style: [{ color: fg }, textStyle], children: children })) : (children), trailing] }));
|
|
65
|
+
}
|
|
66
|
+
/** A header action with shared geometry, feedback, and active-state colors. */
|
|
67
|
+
export function HeaderAction({ icon, label, active = false, indicator = false, disabled, accessibilityLabel, accessibilityState, hitSlop, style, ...props }) {
|
|
68
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
69
|
+
const color = disabled ? c.content3 : active ? c.primary500 : c.content1;
|
|
70
|
+
return (_jsxs(Pressable, { ...props, disabled: disabled, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { ...accessibilityState, disabled: !!disabled }, hitSlop: hitSlop ?? s.sm - s.xs / 2, style: ({ pressed }) => [
|
|
71
|
+
styles.headerAction,
|
|
72
|
+
{
|
|
73
|
+
minWidth: s.xxl + s.sm,
|
|
74
|
+
minHeight: s.xxl + s.sm,
|
|
75
|
+
paddingHorizontal: label ? s.sm : 0,
|
|
76
|
+
gap: s.xs,
|
|
77
|
+
borderRadius: r.md,
|
|
78
|
+
backgroundColor: active ? c.primary50 : "transparent",
|
|
79
|
+
opacity: disabled ? 0.45 : pressed ? 0.6 : 1,
|
|
80
|
+
},
|
|
81
|
+
style,
|
|
82
|
+
], children: [typeof icon === "function" ? icon({ color, size: s.xxl }) : icon, label != null && (_jsx(UIText, { weight: "500", style: { color, fontSize: t.body }, children: label })), indicator && (_jsx(View, { pointerEvents: "none", style: [
|
|
83
|
+
styles.headerActionIndicator,
|
|
84
|
+
{
|
|
85
|
+
width: s.sm - s.xs / 2,
|
|
86
|
+
height: s.sm - s.xs / 2,
|
|
87
|
+
top: s.xs / 2,
|
|
88
|
+
right: s.xs / 2,
|
|
89
|
+
borderRadius: r.full,
|
|
90
|
+
backgroundColor: c.danger,
|
|
91
|
+
},
|
|
92
|
+
] }))] }));
|
|
93
|
+
}
|
|
94
|
+
export function ScreenHeader({ title, variant = "default", onBack, backIcon, backAccessibilityLabel = "Back", leading, trailing, safeArea = true, style, titleStyle, titleWeight = "600", search, }) {
|
|
95
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
96
|
+
const insets = useSafeAreaInsets();
|
|
97
|
+
const inputRef = useRef(null);
|
|
98
|
+
const [headerWidth, setHeaderWidth] = useState();
|
|
99
|
+
const [leadingWidth, setLeadingWidth] = useState(0);
|
|
100
|
+
const [trailingWidth, setTrailingWidth] = useState(0);
|
|
101
|
+
const searchActive = !!search?.active;
|
|
102
|
+
const foreground = variant === "onAccent" ? c.textPrimary : c.content1;
|
|
103
|
+
const overrides = StyleSheet.flatten(style);
|
|
104
|
+
const horizontalPadding = typeof overrides?.paddingHorizontal === "number"
|
|
105
|
+
? overrides.paddingHorizontal
|
|
106
|
+
: s.xxl;
|
|
107
|
+
const leftPadding = typeof overrides?.paddingLeft === "number"
|
|
108
|
+
? overrides.paddingLeft
|
|
109
|
+
: horizontalPadding;
|
|
110
|
+
const rightPadding = typeof overrides?.paddingRight === "number"
|
|
111
|
+
? overrides.paddingRight
|
|
112
|
+
: horizontalPadding;
|
|
113
|
+
const topPadding = typeof overrides?.paddingTop === "number"
|
|
114
|
+
? overrides.paddingTop
|
|
115
|
+
: safeArea ? insets.top : 0;
|
|
116
|
+
const leadingContent = leading ??
|
|
117
|
+
(onBack ? (_jsx(HeaderAction, { accessibilityLabel: backAccessibilityLabel, onPress: onBack, icon: backIcon ?? _jsx(UIIcon, { name: "back", color: foreground, size: s.xxl }) })) : null);
|
|
118
|
+
const hasActions = leadingContent != null || trailing != null;
|
|
119
|
+
const naturalSideWidth = hasActions
|
|
120
|
+
? Math.max(s.xxl + s.sm, leadingContent != null ? leadingWidth : 0, trailing != null ? trailingWidth : 0)
|
|
121
|
+
: 0;
|
|
122
|
+
const sideWidth = headerWidth == null
|
|
123
|
+
? naturalSideWidth
|
|
124
|
+
: Math.min(naturalSideWidth, Math.max(0, (headerWidth - leftPadding - rightPadding) / 2));
|
|
125
|
+
const measureWidth = (update) => (event) => update(event.nativeEvent.layout.width);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (searchActive && search?.autoFocus !== false)
|
|
128
|
+
inputRef.current?.focus();
|
|
129
|
+
}, [searchActive, search?.autoFocus]);
|
|
130
|
+
return (_jsx(View, { onLayout: measureWidth(setHeaderWidth), style: [
|
|
131
|
+
styles.header,
|
|
132
|
+
{
|
|
133
|
+
minHeight: s.xxl * 2 + s.sm + (safeArea ? insets.top : 0),
|
|
134
|
+
paddingTop: safeArea ? insets.top : 0,
|
|
135
|
+
paddingHorizontal: s.xxl,
|
|
136
|
+
...(variant === "surface"
|
|
137
|
+
? {
|
|
138
|
+
backgroundColor: c.background,
|
|
139
|
+
borderBottomWidth: 1,
|
|
140
|
+
borderBottomColor: c.divider,
|
|
141
|
+
}
|
|
142
|
+
: {}),
|
|
143
|
+
},
|
|
144
|
+
style,
|
|
145
|
+
], children: searchActive && search ? (_jsxs(_Fragment, { children: [search.leading != null && (_jsx(View, { style: [styles.headerActionRow, { marginRight: s.sm }], children: search.leading })), _jsxs(View, { style: [
|
|
146
|
+
styles.headerSearch,
|
|
147
|
+
{
|
|
148
|
+
height: s.xxl + s.md,
|
|
149
|
+
paddingHorizontal: s.sm,
|
|
150
|
+
gap: s.sm,
|
|
151
|
+
borderRadius: r.md,
|
|
152
|
+
backgroundColor: c.gray50,
|
|
153
|
+
},
|
|
154
|
+
], children: [_jsx(UIIcon, { name: "search", color: c.content3, size: t.subtitle }), _jsx(TextInput, { ref: inputRef, value: search.value, onChangeText: search.onChangeText, onSubmitEditing: () => search.onSubmit?.(search.value), placeholder: search.placeholder, placeholderTextColor: c.content3, accessibilityLabel: search.accessibilityLabel ?? search.placeholder ?? title, returnKeyType: "search", style: [
|
|
155
|
+
styles.headerSearchInput,
|
|
156
|
+
{
|
|
157
|
+
color: c.content1,
|
|
158
|
+
fontFamily: t.fontFamily,
|
|
159
|
+
fontSize: t.body,
|
|
160
|
+
},
|
|
161
|
+
] }), search.value.length > 0 && (_jsx(HeaderAction, { accessibilityLabel: search.clearAccessibilityLabel ?? "Clear search", onPress: () => {
|
|
162
|
+
search.onChangeText("");
|
|
163
|
+
search.onClear?.();
|
|
164
|
+
}, icon: ({ color }) => (_jsx(UIIcon, { name: "close", color: color, size: t.subtitle })) }))] }), _jsx(HeaderAction, { accessibilityLabel: search.cancelAccessibilityLabel ?? search.cancelLabel ?? "Cancel search", icon: search.cancelIcon, label: search.cancelIcon ? undefined : search.cancelLabel ?? "Cancel", style: { marginLeft: s.sm }, onPress: () => {
|
|
165
|
+
Keyboard.dismiss();
|
|
166
|
+
search.onCancel();
|
|
167
|
+
} })] })) : (_jsxs(_Fragment, { children: [_jsx(View, { style: [styles.headerSide, { width: sideWidth }] }), _jsx(UIText, { variant: "title", color: variant === "onAccent" ? "textPrimary" : "content1", weight: titleWeight === "platform"
|
|
168
|
+
? Platform.OS === "ios"
|
|
169
|
+
? "600"
|
|
170
|
+
: "bold"
|
|
171
|
+
: titleWeight, style: [styles.headerTitle, { fontSize: t.title }, titleStyle], numberOfLines: 1, ellipsizeMode: "tail", children: title }), _jsx(View, { style: [styles.headerSide, { width: sideWidth }] }), _jsx(View, { onLayout: measureWidth(setLeadingWidth), style: [
|
|
172
|
+
styles.headerActionsOverlay,
|
|
173
|
+
{ gap: s.sm, left: leftPadding, top: topPadding },
|
|
174
|
+
], children: leadingContent }), _jsx(View, { onLayout: measureWidth(setTrailingWidth), style: [
|
|
175
|
+
styles.headerActionsOverlay,
|
|
176
|
+
{ gap: s.sm, right: rightPadding, top: topPadding },
|
|
177
|
+
], children: trailing })] })) }));
|
|
178
|
+
}
|
|
179
|
+
export function FormHeader({ title, cancelText, confirmText, onCancel, onConfirm, confirmDisabled = false, style, titleStyle, actionTextStyle, disabledActionTextStyle, testID = "bottom-sheet-header", cancelTestID = "bottom-sheet-header-cancel", confirmTestID = "bottom-sheet-header-confirm", ...props }) {
|
|
180
|
+
const { colors: c, spacing: s, typography: t } = useUITheme();
|
|
181
|
+
const actionStyle = [
|
|
182
|
+
{ fontSize: t.body, fontWeight: "600", color: c.primary500 },
|
|
183
|
+
actionTextStyle,
|
|
184
|
+
];
|
|
185
|
+
return (_jsxs(View, { ...props, collapsable: false, testID: testID, style: [
|
|
186
|
+
{
|
|
187
|
+
position: "absolute",
|
|
188
|
+
top: 0,
|
|
189
|
+
left: 0,
|
|
190
|
+
right: 0,
|
|
191
|
+
height: s.xxl * 2 + s.xs,
|
|
192
|
+
flexDirection: "row",
|
|
193
|
+
alignItems: "center",
|
|
194
|
+
justifyContent: "space-between",
|
|
195
|
+
paddingHorizontal: s.xl,
|
|
196
|
+
borderBottomWidth: 1,
|
|
197
|
+
borderBottomColor: c.divider,
|
|
198
|
+
backgroundColor: c.background,
|
|
199
|
+
zIndex: 10,
|
|
200
|
+
},
|
|
201
|
+
style,
|
|
202
|
+
], children: [_jsx(Pressable, { onPress: onCancel, hitSlop: 8, testID: cancelTestID, accessibilityRole: "button", accessibilityLabel: cancelText, style: ({ pressed }) => ({ opacity: pressed ? 0.2 : 1 }), children: _jsx(UIText, { style: actionStyle, children: cancelText }) }), _jsx(UIText, { numberOfLines: 1, weight: "700", style: [
|
|
203
|
+
{
|
|
204
|
+
flex: 1,
|
|
205
|
+
marginHorizontal: s.md,
|
|
206
|
+
textAlign: "center",
|
|
207
|
+
fontSize: t.subtitle,
|
|
208
|
+
},
|
|
209
|
+
titleStyle,
|
|
210
|
+
], children: title }), _jsx(Pressable, { onPress: onConfirm, disabled: confirmDisabled, hitSlop: 8, testID: confirmTestID, accessibilityRole: "button", accessibilityLabel: confirmText, accessibilityState: { disabled: confirmDisabled }, style: ({ pressed }) => ({ opacity: pressed ? 0.2 : 1 }), children: _jsx(UIText, { style: [
|
|
211
|
+
actionStyle,
|
|
212
|
+
confirmDisabled && [{ color: c.content4 }, disabledActionTextStyle],
|
|
213
|
+
], children: confirmText }) })] }));
|
|
214
|
+
}
|
|
215
|
+
export function Skeleton({ width = "100%", height = 14, animated = true, variant = "shimmer", animationType = "overlay", duration, primaryColor, secondaryColor, style, onLayout, ...props }) {
|
|
216
|
+
const theme = useUITheme();
|
|
217
|
+
const opacity = useRef(new Animated.Value(1)).current;
|
|
218
|
+
const progress = useRef(new Animated.Value(0)).current;
|
|
219
|
+
const [measuredWidth, setMeasuredWidth] = useState(0);
|
|
220
|
+
const gradientId = `skeleton-${useId().replace(/:/g, "")}`;
|
|
221
|
+
const primary = primaryColor ?? theme.colors.gray200;
|
|
222
|
+
const secondary = secondaryColor ?? theme.colors.gray50;
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
opacity.setValue(1);
|
|
225
|
+
progress.setValue(0);
|
|
226
|
+
if (!animated) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const animationDuration = duration ?? (variant === "shimmer" ? 800 : 750);
|
|
230
|
+
const shimmerTiming = (toValue) => Animated.timing(progress, {
|
|
231
|
+
toValue,
|
|
232
|
+
duration: animationDuration,
|
|
233
|
+
easing: Easing.inOut(Easing.ease),
|
|
234
|
+
useNativeDriver: true,
|
|
235
|
+
isInteraction: false,
|
|
236
|
+
});
|
|
237
|
+
const animation = Animated.loop(variant === "shimmer"
|
|
238
|
+
? animationType === "overlay"
|
|
239
|
+
? shimmerTiming(1)
|
|
240
|
+
: Animated.sequence([shimmerTiming(1), shimmerTiming(0)])
|
|
241
|
+
: Animated.sequence([
|
|
242
|
+
Animated.timing(opacity, {
|
|
243
|
+
toValue: 0.45,
|
|
244
|
+
duration: animationDuration,
|
|
245
|
+
useNativeDriver: true,
|
|
246
|
+
isInteraction: false,
|
|
247
|
+
}),
|
|
248
|
+
Animated.timing(opacity, {
|
|
249
|
+
toValue: 1,
|
|
250
|
+
duration: animationDuration,
|
|
251
|
+
useNativeDriver: true,
|
|
252
|
+
isInteraction: false,
|
|
253
|
+
}),
|
|
254
|
+
]));
|
|
255
|
+
animation.start();
|
|
256
|
+
return () => animation.stop();
|
|
257
|
+
}, [animated, variant, animationType, duration, opacity, progress]);
|
|
258
|
+
return (_jsx(Animated.View, { ...props, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", onLayout: (event) => {
|
|
259
|
+
if (variant === "shimmer")
|
|
260
|
+
setMeasuredWidth(event.nativeEvent.layout.width);
|
|
261
|
+
onLayout?.(event);
|
|
262
|
+
}, style: [
|
|
263
|
+
{
|
|
264
|
+
width,
|
|
265
|
+
height,
|
|
266
|
+
opacity: variant === "pulse" ? opacity : 1,
|
|
267
|
+
borderRadius: variant === "shimmer" ? 0 : theme.radius.md,
|
|
268
|
+
backgroundColor: primary,
|
|
269
|
+
overflow: "hidden",
|
|
270
|
+
},
|
|
271
|
+
style,
|
|
272
|
+
], children: variant === "shimmer" && animated && (_jsx(Animated.View, { pointerEvents: "none", style: [
|
|
273
|
+
StyleSheet.absoluteFillObject,
|
|
274
|
+
animationType === "overlay"
|
|
275
|
+
? {
|
|
276
|
+
transform: [
|
|
277
|
+
{
|
|
278
|
+
translateX: progress.interpolate({
|
|
279
|
+
inputRange: [0, 1],
|
|
280
|
+
outputRange: [-measuredWidth, measuredWidth],
|
|
281
|
+
}),
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
}
|
|
285
|
+
: { opacity: progress },
|
|
286
|
+
], children: _jsxs(Svg, { width: "100%", height: "100%", children: [animationType === "overlay" && (_jsx(Defs, { children: _jsxs(LinearGradient, { id: gradientId, x1: "0%", y1: "0%", x2: "100%", y2: "0%", children: [_jsx(Stop, { offset: "0%", stopColor: primary }), _jsx(Stop, { offset: "50%", stopColor: secondary }), _jsx(Stop, { offset: "100%", stopColor: primary })] }) })), _jsx(Rect, { width: "100%", height: "100%", fill: animationType === "overlay" ? `url(#${gradientId})` : secondary })] }) })) }));
|
|
287
|
+
}
|
|
288
|
+
export function TextOrSkeleton({ showSkeleton, value, textStyle, skeletonStyle, skeletonProps, ...props }) {
|
|
289
|
+
return showSkeleton ? (_jsx(Skeleton, { ...skeletonProps, style: [skeletonProps?.style, skeletonStyle] })) : (_jsx(UIText, { ...props, style: [props.style, textStyle], children: value }));
|
|
290
|
+
}
|
|
291
|
+
export function InfoRow({ label, value, variant = "detail", loading = false, divider = false, labelWidth, valueNumberOfLines, style, labelStyle, valueStyle, }) {
|
|
292
|
+
const { spacing: s, colors: c, typography: t } = useUITheme();
|
|
293
|
+
const summary = variant === "summary";
|
|
294
|
+
const valueIsText = value == null || typeof value === "string" || typeof value === "number";
|
|
295
|
+
const typography = { fontSize: summary ? t.body : (t.body + t.label) / 2 };
|
|
296
|
+
const valueLayout = summary
|
|
297
|
+
? { flexShrink: 1, maxWidth: "55%" }
|
|
298
|
+
: { flex: 1 };
|
|
299
|
+
return (_jsxs(View, { style: [
|
|
300
|
+
styles.infoRow,
|
|
301
|
+
{
|
|
302
|
+
gap: s.md,
|
|
303
|
+
...(summary
|
|
304
|
+
? { paddingVertical: s.md, alignItems: "center" }
|
|
305
|
+
: { marginBottom: s.md + s.xs / 2 }),
|
|
306
|
+
...(divider
|
|
307
|
+
? { borderBottomWidth: 1, borderBottomColor: c.divider }
|
|
308
|
+
: {}),
|
|
309
|
+
},
|
|
310
|
+
style,
|
|
311
|
+
], children: [_jsx(UIText, { color: summary ? "content2" : "content3", style: [
|
|
312
|
+
typography,
|
|
313
|
+
summary ? { flex: 1 } : { width: labelWidth ?? s.xxl * 5 },
|
|
314
|
+
labelStyle,
|
|
315
|
+
], children: label }), loading ? (_jsx(Skeleton, { width: summary ? "55%" : undefined, style: valueLayout, height: t.body })) : valueIsText ? (_jsx(UIText, { weight: "500", numberOfLines: valueNumberOfLines ?? (summary ? 2 : 4), style: [
|
|
316
|
+
valueLayout,
|
|
317
|
+
typography,
|
|
318
|
+
{ textAlign: summary ? "right" : "left" },
|
|
319
|
+
valueStyle,
|
|
320
|
+
], children: value === "" || value == null ? "-" : value })) : (_jsx(View, { style: valueLayout, children: value }))] }));
|
|
321
|
+
}
|
|
322
|
+
export function EmptyState({ variant = "default", title, description, image, illustration, illustrationSize, illustrationAspectRatio = 1, action, titleStyle, descriptionStyle, style, onLayout, ...props }) {
|
|
323
|
+
const { spacing: s, colors: c } = useUITheme();
|
|
324
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
325
|
+
const illustrated = variant === "illustrated";
|
|
326
|
+
const imageSize = illustrationSize ??
|
|
327
|
+
(illustrated
|
|
328
|
+
? containerWidth > 0
|
|
329
|
+
? Math.min(containerWidth * (containerWidth < 380 ? 0.6 : 0.4), 320)
|
|
330
|
+
: 0
|
|
331
|
+
: 160);
|
|
332
|
+
return (_jsxs(View, { ...props, onLayout: (event) => {
|
|
333
|
+
if (illustrated)
|
|
334
|
+
setContainerWidth(event.nativeEvent.layout.width);
|
|
335
|
+
onLayout?.(event);
|
|
336
|
+
}, style: [
|
|
337
|
+
styles.empty,
|
|
338
|
+
{ padding: s.xxl, gap: s.md },
|
|
339
|
+
illustrated && { width: "100%", paddingHorizontal: 0 },
|
|
340
|
+
style,
|
|
341
|
+
], children: [illustration ??
|
|
342
|
+
(image && imageSize > 0 ? (_jsx(Image, { source: image, resizeMode: "contain", style: {
|
|
343
|
+
width: imageSize,
|
|
344
|
+
height: imageSize / illustrationAspectRatio,
|
|
345
|
+
} })) : null), title != null && (_jsx(UIText, { variant: "subtitle", color: "content2", style: [
|
|
346
|
+
styles.center,
|
|
347
|
+
illustrated && {
|
|
348
|
+
paddingTop: s.lg,
|
|
349
|
+
color: c.content1,
|
|
350
|
+
fontWeight: "600",
|
|
351
|
+
},
|
|
352
|
+
titleStyle,
|
|
353
|
+
], children: title })), description != null && (_jsx(UIText, { color: "content3", style: [styles.center, descriptionStyle], children: description })), action] }));
|
|
354
|
+
}
|
|
355
|
+
export function Card({ style, ...props }) {
|
|
356
|
+
const { colors: c, radius: r, spacing: s } = useUITheme();
|
|
357
|
+
return (_jsx(View, { ...props, style: [
|
|
358
|
+
{ backgroundColor: c.background, borderRadius: r.lg, padding: s.lg },
|
|
359
|
+
style,
|
|
360
|
+
] }));
|
|
361
|
+
}
|
|
362
|
+
export function CollapsibleSection({ variant = "default", title, children, expanded, defaultExpanded = true, onExpandedChange, trailing, style, headerStyle, testID, toggleTestID, contentTestID, }) {
|
|
363
|
+
const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);
|
|
364
|
+
const open = expanded ?? internalExpanded;
|
|
365
|
+
const { spacing: s, colors: c } = useUITheme();
|
|
366
|
+
const toggle = () => {
|
|
367
|
+
if (expanded === undefined)
|
|
368
|
+
setInternalExpanded(!open);
|
|
369
|
+
onExpandedChange?.(!open);
|
|
370
|
+
};
|
|
371
|
+
return (_jsxs(Card, { style: [
|
|
372
|
+
variant === "bordered" && {
|
|
373
|
+
borderWidth: 1,
|
|
374
|
+
borderColor: c.divider,
|
|
375
|
+
paddingVertical: s.md,
|
|
376
|
+
},
|
|
377
|
+
style,
|
|
378
|
+
], testID: testID, children: [_jsxs(Pressable, { testID: toggleTestID, onPress: toggle, accessibilityRole: "button", accessibilityState: { expanded: open }, style: [styles.sectionHeader, headerStyle], children: [typeof title === "string" ? (_jsx(UIText, { variant: "subtitle", weight: "600", style: styles.flex, children: title })) : (title), trailing, _jsx(View, { style: { transform: [{ rotate: open ? "180deg" : "0deg" }] }, children: _jsx(UIIcon, { name: "chevron", color: c.content2, size: 18 }) })] }), open && (_jsx(View, { testID: contentTestID, style: { paddingTop: s.md }, children: children }))] }));
|
|
379
|
+
}
|
|
380
|
+
export function Badge({ children, tone = "accent", color, backgroundColor, style, textStyle, }) {
|
|
381
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
382
|
+
const fg = color ?? (tone === "neutral" ? c.content2 : tone === "accent" ? c.primary500 : c[tone]);
|
|
383
|
+
return (_jsx(View, { style: [
|
|
384
|
+
{
|
|
385
|
+
alignSelf: "flex-start",
|
|
386
|
+
paddingVertical: s.xs,
|
|
387
|
+
paddingHorizontal: s.sm,
|
|
388
|
+
borderRadius: r.sm,
|
|
389
|
+
backgroundColor: backgroundColor ??
|
|
390
|
+
(tone === "accent" ? c.primary50 : c.gray50),
|
|
391
|
+
},
|
|
392
|
+
style,
|
|
393
|
+
], children: _jsx(UIText, { variant: "label", weight: "500", style: [{ color: fg }, textStyle], children: children }) }));
|
|
394
|
+
}
|
|
395
|
+
export function ActionBar({ children, safeArea = true, style, ...props }) {
|
|
396
|
+
const { colors: c, spacing: s } = useUITheme();
|
|
397
|
+
const insets = useSafeAreaInsets();
|
|
398
|
+
return (_jsx(View, { ...props, style: [
|
|
399
|
+
{
|
|
400
|
+
flexDirection: "row",
|
|
401
|
+
gap: s.md,
|
|
402
|
+
backgroundColor: c.background,
|
|
403
|
+
borderTopWidth: 1,
|
|
404
|
+
borderTopColor: c.divider,
|
|
405
|
+
paddingHorizontal: s.lg,
|
|
406
|
+
paddingTop: s.md,
|
|
407
|
+
paddingBottom: Math.max(s.md, safeArea ? insets.bottom : 0),
|
|
408
|
+
},
|
|
409
|
+
style,
|
|
410
|
+
], children: children }));
|
|
411
|
+
}
|
|
412
|
+
const styles = StyleSheet.create({
|
|
413
|
+
button: {
|
|
414
|
+
flexDirection: "row",
|
|
415
|
+
alignItems: "center",
|
|
416
|
+
justifyContent: "center",
|
|
417
|
+
},
|
|
418
|
+
header: { flexDirection: "row", alignItems: "center" },
|
|
419
|
+
headerSide: { flexDirection: "row", alignItems: "center", flexShrink: 1 },
|
|
420
|
+
headerActionRow: { flexDirection: "row", alignItems: "center", flexShrink: 0 },
|
|
421
|
+
headerActionsOverlay: { position: "absolute", bottom: 0, flexDirection: "row", alignItems: "center" },
|
|
422
|
+
headerAction: { flexDirection: "row", alignItems: "center", justifyContent: "center" },
|
|
423
|
+
headerActionIndicator: { position: "absolute" },
|
|
424
|
+
headerTitle: { flex: 1, minWidth: 0, textAlign: "center" },
|
|
425
|
+
headerSearch: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
|
|
426
|
+
headerSearchInput: { flex: 1, minWidth: 0, padding: 0 },
|
|
427
|
+
infoRow: { flexDirection: "row" },
|
|
428
|
+
empty: { alignItems: "center", justifyContent: "center" },
|
|
429
|
+
center: { textAlign: "center" },
|
|
430
|
+
flex: { flex: 1 },
|
|
431
|
+
sectionHeader: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
432
|
+
});
|