@thanhphi/unistyles-ui 0.0.0-stage → 0.2.6
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 +374 -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 +138 -0
- package/dist/fields.js +240 -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 +51 -0
- package/dist/image.d.ts +20 -0
- package/dist/image.js +34 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +30 -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 +232 -0
- package/dist/module/form/index.js +62 -0
- package/dist/module/form/package.json +1 -0
- package/dist/module/icons.js +15 -0
- package/dist/module/image.js +31 -0
- package/dist/module/index.js +10 -0
- package/dist/module/overlays.js +102 -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/theme.js +62 -0
- package/dist/module/toast.js +30 -0
- package/dist/overlays.d.ts +52 -0
- package/dist/overlays.js +109 -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/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/package.json +35 -4
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import Svg, { Circle, Defs, Pattern, Rect } from "react-native-svg";
|
|
5
|
+
import { UIText } from "./primitives.js";
|
|
6
|
+
import { useUITheme } from "./theme.js";
|
|
7
|
+
/** Pure presentation: apps own loading, workflow permissions, statuses and people. */
|
|
8
|
+
export function ProcessGraph({ nodes, startAdornment, connector, tones, style, accessibilityLabel, }) {
|
|
9
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
10
|
+
const patternId = `process-dots-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
11
|
+
const palette = {
|
|
12
|
+
success: {
|
|
13
|
+
dot: c.success500,
|
|
14
|
+
background: c.success50,
|
|
15
|
+
border: c.success300,
|
|
16
|
+
text: c.success700,
|
|
17
|
+
},
|
|
18
|
+
warning: {
|
|
19
|
+
dot: c.warning500,
|
|
20
|
+
background: c.warning50,
|
|
21
|
+
border: c.warning300,
|
|
22
|
+
text: c.warning700,
|
|
23
|
+
},
|
|
24
|
+
danger: {
|
|
25
|
+
dot: c.danger500,
|
|
26
|
+
background: c.danger50,
|
|
27
|
+
border: c.danger300,
|
|
28
|
+
text: c.danger700,
|
|
29
|
+
},
|
|
30
|
+
accent: {
|
|
31
|
+
dot: c.secondary500,
|
|
32
|
+
background: c.secondary50,
|
|
33
|
+
border: c.secondary300,
|
|
34
|
+
text: c.secondary700,
|
|
35
|
+
},
|
|
36
|
+
neutral: {
|
|
37
|
+
dot: c.gray400,
|
|
38
|
+
background: c.gray50,
|
|
39
|
+
border: c.gray300,
|
|
40
|
+
text: c.content2,
|
|
41
|
+
},
|
|
42
|
+
...tones,
|
|
43
|
+
};
|
|
44
|
+
return (_jsxs(View, { accessibilityLabel: accessibilityLabel, style: [
|
|
45
|
+
{
|
|
46
|
+
backgroundColor: c.background,
|
|
47
|
+
padding: s.lg,
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
overflow: "hidden",
|
|
50
|
+
},
|
|
51
|
+
style,
|
|
52
|
+
], children: [_jsx(View, { pointerEvents: "none", accessible: false, style: StyleSheet.absoluteFill, children: _jsxs(Svg, { width: "100%", height: "100%", children: [_jsx(Defs, { children: _jsx(Pattern, { id: patternId, width: s.xl, height: s.xl, patternUnits: "userSpaceOnUse", children: _jsx(Circle, { cx: s.xl / 2, cy: s.xl / 2, r: 0.8, fill: c.content4 }) }) }), _jsx(Rect, { width: "100%", height: "100%", fill: `url(#${patternId})` })] }) }), startAdornment, nodes.map((node) => {
|
|
53
|
+
const colors = palette[node.tone];
|
|
54
|
+
return (_jsxs(View, { style: { width: "100%", maxWidth: 448, alignItems: "center" }, children: [_jsx(View, { accessible: false, style: {
|
|
55
|
+
minHeight: s.xxl + s.lg,
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
}, children: connector ?? (_jsx(View, { style: {
|
|
59
|
+
width: 1,
|
|
60
|
+
height: s.xxl,
|
|
61
|
+
backgroundColor: palette.success.dot,
|
|
62
|
+
} })) }), _jsxs(View, { style: {
|
|
63
|
+
width: "100%",
|
|
64
|
+
minHeight: 110,
|
|
65
|
+
borderWidth: 1,
|
|
66
|
+
borderColor: colors.border,
|
|
67
|
+
borderRadius: r.lg + s.xs,
|
|
68
|
+
padding: s.lg,
|
|
69
|
+
backgroundColor: colors.background,
|
|
70
|
+
gap: s.md,
|
|
71
|
+
}, children: [_jsxs(View, { style: {
|
|
72
|
+
flexDirection: "row",
|
|
73
|
+
alignItems: "flex-start",
|
|
74
|
+
gap: s.sm,
|
|
75
|
+
}, children: [_jsxs(View, { style: {
|
|
76
|
+
flexDirection: "row",
|
|
77
|
+
flex: 1,
|
|
78
|
+
minWidth: 0,
|
|
79
|
+
alignItems: "center",
|
|
80
|
+
gap: s.sm,
|
|
81
|
+
}, children: [_jsx(View, { style: {
|
|
82
|
+
width: 9,
|
|
83
|
+
height: 9,
|
|
84
|
+
borderRadius: r.full,
|
|
85
|
+
backgroundColor: colors.dot,
|
|
86
|
+
} }), _jsx(UIText, { weight: "600", style: {
|
|
87
|
+
flex: 1,
|
|
88
|
+
fontSize: t.body,
|
|
89
|
+
lineHeight: t.body * 1.45,
|
|
90
|
+
}, children: node.title })] }), _jsx(UIText, { style: {
|
|
91
|
+
maxWidth: "43%",
|
|
92
|
+
fontSize: t.label,
|
|
93
|
+
lineHeight: t.body * 1.45,
|
|
94
|
+
color: c.content2,
|
|
95
|
+
textAlign: "right",
|
|
96
|
+
}, children: node.statusLabel })] }), _jsx(View, { style: { gap: s.xs }, children: node.people.map((person) => {
|
|
97
|
+
const personColors = palette[person.tone ?? node.tone];
|
|
98
|
+
return (_jsxs(View, { style: {
|
|
99
|
+
flexDirection: "row",
|
|
100
|
+
alignItems: "center",
|
|
101
|
+
gap: s.sm,
|
|
102
|
+
backgroundColor: c.background,
|
|
103
|
+
borderRadius: r.lg,
|
|
104
|
+
paddingHorizontal: s.md,
|
|
105
|
+
paddingVertical: s.sm,
|
|
106
|
+
minHeight: 38,
|
|
107
|
+
}, children: [_jsx(UIText, { selectable: true, numberOfLines: 1, accessibilityLabel: person.label, style: {
|
|
108
|
+
flex: 1,
|
|
109
|
+
minWidth: 0,
|
|
110
|
+
fontSize: t.body,
|
|
111
|
+
lineHeight: t.body * 1.45,
|
|
112
|
+
}, children: person.label }), !!person.statusLabel && (_jsx(View, { style: {
|
|
113
|
+
maxWidth: "47%",
|
|
114
|
+
borderRadius: r.full,
|
|
115
|
+
paddingHorizontal: s.sm,
|
|
116
|
+
paddingVertical: s.xs / 2,
|
|
117
|
+
backgroundColor: personColors.background,
|
|
118
|
+
}, children: _jsx(UIText, { weight: "500", style: {
|
|
119
|
+
fontSize: t.label,
|
|
120
|
+
lineHeight: t.label * 1.4,
|
|
121
|
+
color: personColors.text,
|
|
122
|
+
}, children: person.statusLabel }) }))] }, person.id));
|
|
123
|
+
}) })] })] }, node.id));
|
|
124
|
+
})] }));
|
|
125
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Dimensions, PixelRatio, Platform } from "react-native";
|
|
2
|
+
const BASE_WIDTH = 375;
|
|
3
|
+
const BASE_HEIGHT = 812;
|
|
4
|
+
const { width, height } = Dimensions.get("window");
|
|
5
|
+
export const scale = (size) => {
|
|
6
|
+
const scaleFactor = Math.min(width / BASE_WIDTH, height / BASE_HEIGHT);
|
|
7
|
+
// return Math.round(size * scaleFactor); // if not considering pixelRatio
|
|
8
|
+
const newSize = size * scaleFactor;
|
|
9
|
+
return Math.round(PixelRatio.roundToNearestPixel(newSize));
|
|
10
|
+
};
|
|
11
|
+
export function safeLineHeight(lineHeight) {
|
|
12
|
+
if (Platform.OS !== "ios" || lineHeight === 0)
|
|
13
|
+
return lineHeight;
|
|
14
|
+
// Give Yoga enough rounding room to keep the last line visible on iOS.
|
|
15
|
+
// https://github.com/react/react-native/issues/58970
|
|
16
|
+
const ratio = PixelRatio.get();
|
|
17
|
+
return Math.ceil(lineHeight * ratio - 1e-6) / ratio + 0.001;
|
|
18
|
+
}
|
|
19
|
+
export function richHtmlTextSize(size) {
|
|
20
|
+
const fontSize = scale(size);
|
|
21
|
+
return { fontSize, lineHeight: safeLineHeight(fontSize * 1.5) };
|
|
22
|
+
}
|
|
23
|
+
export function mergeRichHtmlStyle(defaults, override) {
|
|
24
|
+
if (!override)
|
|
25
|
+
return defaults;
|
|
26
|
+
const style = { ...defaults, ...override };
|
|
27
|
+
const { fontSize, lineHeight } = override;
|
|
28
|
+
if (typeof lineHeight === "number" && Number.isFinite(lineHeight)) {
|
|
29
|
+
style.lineHeight = safeLineHeight(lineHeight);
|
|
30
|
+
}
|
|
31
|
+
else if (lineHeight === undefined &&
|
|
32
|
+
typeof fontSize === "number" &&
|
|
33
|
+
Number.isFinite(fontSize) &&
|
|
34
|
+
fontSize > 0) {
|
|
35
|
+
style.lineHeight = safeLineHeight(fontSize * 1.5);
|
|
36
|
+
}
|
|
37
|
+
return style;
|
|
38
|
+
}
|
|
39
|
+
export function mergeRichHtmlStyleRecord(defaults, overrides) {
|
|
40
|
+
if (!overrides)
|
|
41
|
+
return defaults;
|
|
42
|
+
const styles = { ...defaults };
|
|
43
|
+
for (const name of Object.keys(overrides)) {
|
|
44
|
+
styles[name] = mergeRichHtmlStyle(styles[name] ?? {}, overrides[name]);
|
|
45
|
+
}
|
|
46
|
+
return styles;
|
|
47
|
+
}
|
|
48
|
+
// Quill stores font sizes as class names instead of inline font-size values.
|
|
49
|
+
// react-native-render-html does not include Quill's stylesheet, so these
|
|
50
|
+
// classes must be translated to native text styles explicitly.
|
|
51
|
+
export const quillClassesStyles = {
|
|
52
|
+
"ql-size-small": richHtmlTextSize(14 * 0.75),
|
|
53
|
+
"ql-size-large": richHtmlTextSize(14 * 1.5),
|
|
54
|
+
"ql-size-huge": richHtmlTextSize(14 * 2.5),
|
|
55
|
+
};
|