@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,232 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ActivityIndicator, FlatList, Keyboard, Pressable, StyleSheet, TextInput, View, useWindowDimensions, } from "react-native";
|
|
4
|
+
import { useUITheme } from "./theme.js";
|
|
5
|
+
import { Button, UIText } from "./primitives.js";
|
|
6
|
+
import { UIIcon } from "./icons.js";
|
|
7
|
+
import { Sheet } from "./overlays.js";
|
|
8
|
+
export function Field({ label, required, error, hint, children, style, labelStyle, }) {
|
|
9
|
+
const { spacing: s } = useUITheme();
|
|
10
|
+
return (_jsxs(View, { style: [{ gap: s.xs }, style], children: [label != null && (_jsxs(UIText, { variant: "label", color: "content2", style: labelStyle, children: [label, required && (_jsx(UIText, { variant: "label", color: "danger", children: "*" }))] })), children, hint != null &&
|
|
11
|
+
(typeof hint === "string" ? (_jsx(UIText, { variant: "caption", color: "content2", children: hint })) : (hint)), !!error && (_jsx(UIText, { variant: "caption", color: "danger", accessibilityLiveRegion: "polite", children: error }))] }));
|
|
12
|
+
}
|
|
13
|
+
export function TextField({ label, required, error, hint, containerStyle, showCount = false, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }) {
|
|
14
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
15
|
+
return (_jsxs(Field, { label: label, required: required, error: error, hint: hint, style: containerStyle, labelStyle: labelStyle, children: [_jsx(TextInput, { ...props, editable: editable, multiline: multiline, placeholderTextColor: placeholderTextColor ?? c.content3, textAlignVertical: multiline ? "top" : "center", accessibilityLabel: props.accessibilityLabel ?? label, style: [
|
|
16
|
+
{
|
|
17
|
+
minHeight: multiline ? s.xxl * 4 : s.xxl + s.xl,
|
|
18
|
+
borderWidth: 1,
|
|
19
|
+
borderColor: error ? c.danger : c.gray200,
|
|
20
|
+
borderRadius: r.md,
|
|
21
|
+
paddingHorizontal: s.md,
|
|
22
|
+
paddingVertical: multiline ? s.md : s.sm,
|
|
23
|
+
backgroundColor: editable === false ? c.gray50 : c.background,
|
|
24
|
+
color: c.content1,
|
|
25
|
+
fontSize: t.body,
|
|
26
|
+
fontFamily: t.fontFamily,
|
|
27
|
+
},
|
|
28
|
+
style,
|
|
29
|
+
] }), showCount && (_jsxs(UIText, { variant: "caption", color: "content2", style: styles.count, children: [props.value?.length ?? 0, props.maxLength != null ? `/${props.maxLength}` : "", countLabel ? ` ${countLabel}` : ""] }))] }));
|
|
30
|
+
}
|
|
31
|
+
export function PressableField({ variant = "default", label, value, placeholder, required, error, hint, loading = false, disabled = false, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }) {
|
|
32
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
33
|
+
const filter = variant === "filter";
|
|
34
|
+
const largeField = variant !== "default";
|
|
35
|
+
const hasValue = value !== undefined && value !== null && value !== "";
|
|
36
|
+
const textValue = !hasValue || typeof value === "string" || typeof value === "number";
|
|
37
|
+
return (_jsx(Field, { label: label, required: required, error: error, hint: hint, labelStyle: [
|
|
38
|
+
filter && { fontSize: t.body, fontWeight: "500", color: c.content1 },
|
|
39
|
+
labelStyle,
|
|
40
|
+
], style: [
|
|
41
|
+
variant === "form" && { marginBottom: s.lg, gap: s.sm },
|
|
42
|
+
filter && { gap: s.sm },
|
|
43
|
+
style,
|
|
44
|
+
], children: _jsxs(Pressable, { ...props, disabled: disabled || loading, accessibilityRole: props.accessibilityRole ?? "button", accessibilityLabel: props.accessibilityLabel ??
|
|
45
|
+
(typeof label === "string" ? label : placeholder), accessibilityState: {
|
|
46
|
+
...props.accessibilityState,
|
|
47
|
+
disabled: disabled || loading,
|
|
48
|
+
busy: loading,
|
|
49
|
+
}, style: [
|
|
50
|
+
styles.selector,
|
|
51
|
+
{
|
|
52
|
+
minHeight: largeField ? s.xxl * 2 : s.xxl + s.xl,
|
|
53
|
+
...(largeField ? { height: s.xxl * 2 } : {}),
|
|
54
|
+
gap: s.sm,
|
|
55
|
+
paddingHorizontal: filter
|
|
56
|
+
? (s.md + s.lg) / 2
|
|
57
|
+
: variant === "form"
|
|
58
|
+
? s.lg
|
|
59
|
+
: s.md,
|
|
60
|
+
borderColor: error ? c.danger : c.gray200,
|
|
61
|
+
borderRadius: largeField ? r.lg : r.md,
|
|
62
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
63
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
64
|
+
},
|
|
65
|
+
fieldStyle,
|
|
66
|
+
], children: [loading ? (_jsx(ActivityIndicator, { size: "small", color: c.primary500 })) : textValue ? (_jsx(UIText, { numberOfLines: 1, color: hasValue ? "content1" : filter ? "content2" : "content3", style: [styles.flex, hasValue ? valueStyle : placeholderStyle], children: hasValue ? value : placeholder })) : (_jsx(View, { style: styles.flex, children: value })), trailing ?? icon ?? (_jsx(UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }) }));
|
|
67
|
+
}
|
|
68
|
+
/** Complete time field UI; the app supplies its native picker implementation. */
|
|
69
|
+
export function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable = false, disabled = false, clearAccessibilityLabel = "Clear time", icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }) {
|
|
70
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
71
|
+
const [visible, setVisible] = useState(false);
|
|
72
|
+
const hasValue = !!value;
|
|
73
|
+
const iconSize = s.lg + s.xs / 2;
|
|
74
|
+
return (_jsxs(View, { style: [{ flex: 1, marginBottom: s.lg }, style], children: [label != null && (_jsxs(View, { style: { flexDirection: "row", marginBottom: s.sm }, children: [_jsx(UIText, { numberOfLines: 1, color: "content2", style: [{ fontSize: t.body }, labelStyle], children: label }), required && (_jsx(UIText, { color: "danger", style: { fontSize: t.body, marginLeft: s.xs / 2 }, children: "*" }))] })), _jsxs(Pressable, { disabled: disabled, onPress: () => setVisible(true), accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: ({ pressed }) => [
|
|
75
|
+
styles.selector,
|
|
76
|
+
{
|
|
77
|
+
height: s.xxl * 2,
|
|
78
|
+
paddingHorizontal: s.lg,
|
|
79
|
+
borderColor: error ? c.danger : c.gray200,
|
|
80
|
+
borderRadius: r.lg,
|
|
81
|
+
backgroundColor: c.gray50,
|
|
82
|
+
opacity: disabled ? 0.5 : pressed ? 0.2 : 1,
|
|
83
|
+
},
|
|
84
|
+
fieldStyle,
|
|
85
|
+
], children: [_jsx(UIText, { numberOfLines: 1, style: [
|
|
86
|
+
styles.flex,
|
|
87
|
+
{
|
|
88
|
+
fontSize: (t.body + t.subtitle) / 2,
|
|
89
|
+
color: hasValue ? c.content1 : c.content4,
|
|
90
|
+
},
|
|
91
|
+
valueStyle,
|
|
92
|
+
], children: hasValue ? value : placeholder }), clearable && hasValue ? (_jsx(Pressable, { disabled: disabled, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, onPress: (event) => {
|
|
93
|
+
event.stopPropagation();
|
|
94
|
+
onChange("");
|
|
95
|
+
}, children: clearIcon ?? (_jsx(UIIcon, { name: "close", size: iconSize, color: c.content3 })) })) : ((icon ?? _jsx(UIIcon, { name: "clock", size: iconSize, color: c.content3 })))] }), !!error && (_jsx(UIText, { variant: "label", color: "danger", accessibilityLiveRegion: "polite", style: { marginTop: s.xs }, children: error })), visible &&
|
|
96
|
+
renderPicker({
|
|
97
|
+
visible,
|
|
98
|
+
value,
|
|
99
|
+
onClose: () => setVisible(false),
|
|
100
|
+
onConfirm: (time) => {
|
|
101
|
+
onChange(time);
|
|
102
|
+
setVisible(false);
|
|
103
|
+
},
|
|
104
|
+
})] }));
|
|
105
|
+
}
|
|
106
|
+
export function SelectField({ variant = "default", options, value, onChange, label, placeholder, required, error, disabled = false, loading = false, searchable = true, fixedSheetHeight = false, keyboardAvoiding = false, localSearch = true, searchKey, searchFilter, onSearch, searchDelay = 500, searchPlaceholder, autoFocus = false, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }) {
|
|
107
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
108
|
+
const { height } = useWindowDimensions();
|
|
109
|
+
const sheetHeight = height * 0.7;
|
|
110
|
+
const [visible, setVisible] = useState(false);
|
|
111
|
+
const [query, setQuery] = useState("");
|
|
112
|
+
const searchCallback = useRef(onSearch);
|
|
113
|
+
searchCallback.current = onSearch;
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!visible || !searchable || localSearch)
|
|
116
|
+
return;
|
|
117
|
+
const timer = setTimeout(() => searchCallback.current?.(query), searchDelay);
|
|
118
|
+
return () => clearTimeout(timer);
|
|
119
|
+
}, [query, searchDelay, visible, searchable, localSearch]);
|
|
120
|
+
const filtered = useMemo(() => {
|
|
121
|
+
if (!searchable || !localSearch || !query.trim())
|
|
122
|
+
return options;
|
|
123
|
+
const normalized = query.trim().toLocaleLowerCase();
|
|
124
|
+
return options.filter((option) => searchFilter
|
|
125
|
+
? searchFilter(option, query)
|
|
126
|
+
: String(searchKey ? (option[searchKey] ?? "") : option.label)
|
|
127
|
+
.toLocaleLowerCase()
|
|
128
|
+
.includes(normalized));
|
|
129
|
+
}, [options, searchable, localSearch, query, searchKey, searchFilter]);
|
|
130
|
+
const open = () => {
|
|
131
|
+
if (disabled || loading)
|
|
132
|
+
return;
|
|
133
|
+
if (keyboardAvoiding && searchable)
|
|
134
|
+
Keyboard.dismiss();
|
|
135
|
+
setQuery("");
|
|
136
|
+
setVisible(true);
|
|
137
|
+
};
|
|
138
|
+
return (_jsxs(Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [_jsxs(Pressable, { onPress: open, disabled: disabled || loading, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: {
|
|
139
|
+
disabled: disabled || loading,
|
|
140
|
+
expanded: visible,
|
|
141
|
+
busy: loading,
|
|
142
|
+
}, style: [
|
|
143
|
+
styles.selector,
|
|
144
|
+
{
|
|
145
|
+
minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
|
|
146
|
+
...(variant === "form" ? { height: s.xxl * 2 } : {}),
|
|
147
|
+
gap: s.sm,
|
|
148
|
+
paddingHorizontal: variant === "form" ? s.lg : s.md,
|
|
149
|
+
borderColor: error ? c.danger : c.gray200,
|
|
150
|
+
borderRadius: variant === "form" ? r.lg : r.md,
|
|
151
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
152
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
153
|
+
},
|
|
154
|
+
fieldStyle,
|
|
155
|
+
], children: [loading ? (_jsx(ActivityIndicator, { size: "small", color: c.primary500 })) : value ? (renderSelected ? (renderSelected(value)) : (_jsx(UIText, { numberOfLines: 1, style: styles.flex, children: value.label }))) : (_jsx(UIText, { numberOfLines: 1, color: "content3", style: styles.flex, children: placeholder })), icon ?? (_jsx(UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }), _jsxs(Sheet, { visible: visible, onClose: () => setVisible(false), keyboardAvoiding: keyboardAvoiding && searchable, title: label ?? placeholder, closeAccessibilityLabel: closeAccessibilityLabel, style: {
|
|
156
|
+
maxHeight: sheetHeight,
|
|
157
|
+
height: fixedSheetHeight ? sheetHeight : undefined,
|
|
158
|
+
}, children: [searchable && (_jsxs(View, { style: [
|
|
159
|
+
styles.search,
|
|
160
|
+
{
|
|
161
|
+
marginHorizontal: s.lg,
|
|
162
|
+
marginBottom: s.md,
|
|
163
|
+
gap: s.sm,
|
|
164
|
+
paddingHorizontal: s.md,
|
|
165
|
+
minHeight: s.xl * 2,
|
|
166
|
+
borderRadius: r.md,
|
|
167
|
+
backgroundColor: c.gray50,
|
|
168
|
+
},
|
|
169
|
+
], children: [_jsx(UIIcon, { name: "search", size: 16, color: c.content3 }), visible && (_jsx(TextInput, { placeholder: searchPlaceholder, placeholderTextColor: c.content3, value: query, onChangeText: setQuery, autoFocus: autoFocus, autoCorrect: false, autoComplete: "off", importantForAutofill: "no", style: {
|
|
170
|
+
flex: 1,
|
|
171
|
+
color: c.content1,
|
|
172
|
+
fontSize: t.body,
|
|
173
|
+
fontFamily: t.fontFamily,
|
|
174
|
+
} }))] })), loading && _jsx(ActivityIndicator, { color: c.primary500 }), _jsx(FlatList, { data: filtered, keyboardShouldPersistTaps: "handled", keyExtractor: (option, index) => `${String(option.value)}_${index}`, contentContainerStyle: { paddingHorizontal: s.lg }, ItemSeparatorComponent: () => (_jsx(View, { style: { height: 1, backgroundColor: c.divider } })), renderItem: ({ item }) => {
|
|
175
|
+
const selected = Object.is(item.value, value?.value);
|
|
176
|
+
return (_jsxs(Pressable, { accessibilityRole: "radio", accessibilityState: { selected }, onPress: () => {
|
|
177
|
+
onChange(item);
|
|
178
|
+
setVisible(false);
|
|
179
|
+
}, style: [
|
|
180
|
+
styles.selectItem,
|
|
181
|
+
{ paddingVertical: s.md + 2, gap: s.sm },
|
|
182
|
+
], children: [_jsx(UIText, { numberOfLines: 1, color: selected ? "primary500" : "content1", weight: selected ? "600" : "400", style: styles.flex, children: item.label }), selected && _jsx(UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
|
|
183
|
+
}, ListEmptyComponent: !loading ? (_jsx(View, { style: { paddingVertical: s.xxl + s.sm }, children: _jsx(UIText, { color: "content3", style: styles.center, children: query ? (noResultsText ?? emptyText) : emptyText }) })) : null })] })] }));
|
|
184
|
+
}
|
|
185
|
+
export function AttachmentField({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel = "Remove file", style, }) {
|
|
186
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
187
|
+
return (_jsxs(View, { style: [{ gap: s.sm }, style], children: [title != null && (_jsx(UIText, { variant: "label", color: "content2", children: title })), _jsxs(View, { style: {
|
|
188
|
+
borderWidth: 1,
|
|
189
|
+
borderStyle: "dashed",
|
|
190
|
+
borderColor: c.gray200,
|
|
191
|
+
borderRadius: r.md,
|
|
192
|
+
paddingVertical: s.xl,
|
|
193
|
+
paddingHorizontal: s.lg,
|
|
194
|
+
alignItems: "center",
|
|
195
|
+
gap: s.sm,
|
|
196
|
+
}, children: [illustration ?? _jsx(UIIcon, { name: "folder", color: c.primary500, size: 24 }), description != null && (_jsx(UIText, { variant: "label", color: "content3", style: styles.center, children: description })), _jsx(Button, { label: buttonText, size: "small", onPress: onPick, loading: loading, disabled: disabled, leading: pickIcon ?? _jsx(UIIcon, { name: "upload", color: c.textPrimary, size: 14 }), style: { borderRadius: r.md, marginTop: s.xs }, textStyle: { fontSize: 13 } })] }), files.map((file, index) => {
|
|
197
|
+
const id = getId?.(file, index) ?? String(file.id ?? index);
|
|
198
|
+
return (_jsxs(View, { style: [
|
|
199
|
+
styles.attachment,
|
|
200
|
+
{
|
|
201
|
+
gap: s.sm,
|
|
202
|
+
paddingVertical: s.sm,
|
|
203
|
+
paddingHorizontal: s.md,
|
|
204
|
+
borderWidth: 1,
|
|
205
|
+
borderColor: c.gray200,
|
|
206
|
+
borderRadius: r.md,
|
|
207
|
+
},
|
|
208
|
+
], children: [_jsxs(Pressable, { onPress: () => onOpen?.(file, index), disabled: !onOpen || openingId === id, accessibilityRole: "button", accessibilityLabel: file.name, style: [styles.selectItem, styles.flex, { gap: s.sm }], children: [_jsx(UIText, { numberOfLines: 1, style: {
|
|
209
|
+
flex: 1,
|
|
210
|
+
fontSize: 13,
|
|
211
|
+
textDecorationLine: onOpen ? "underline" : "none",
|
|
212
|
+
}, children: file.name }), openingId === id && (_jsx(ActivityIndicator, { color: c.content2, size: "small" }))] }), onRemove && (_jsx(Pressable, { hitSlop: 8, disabled: disabled, onPress: () => onRemove(file, index), accessibilityRole: "button", accessibilityLabel: `${removeAccessibilityLabel}: ${file.name}`, children: removeIcon ?? (_jsx(UIIcon, { name: "close", color: c.content2, size: 14 })) }))] }, id));
|
|
213
|
+
})] }));
|
|
214
|
+
}
|
|
215
|
+
const styles = StyleSheet.create({
|
|
216
|
+
count: { alignSelf: "flex-end" },
|
|
217
|
+
selector: {
|
|
218
|
+
borderWidth: 1,
|
|
219
|
+
flexDirection: "row",
|
|
220
|
+
alignItems: "center",
|
|
221
|
+
justifyContent: "space-between",
|
|
222
|
+
},
|
|
223
|
+
flex: { flex: 1 },
|
|
224
|
+
center: { textAlign: "center" },
|
|
225
|
+
search: { flexDirection: "row", alignItems: "center" },
|
|
226
|
+
selectItem: {
|
|
227
|
+
flexDirection: "row",
|
|
228
|
+
alignItems: "center",
|
|
229
|
+
justifyContent: "space-between",
|
|
230
|
+
},
|
|
231
|
+
attachment: { flexDirection: "row", alignItems: "center" },
|
|
232
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
import { KeyboardAwareScrollView, KeyboardController, KeyboardStickyView, } from 'react-native-keyboard-controller';
|
|
5
|
+
const FormErrorContext = createContext(null);
|
|
6
|
+
export const useScrollToFormError = () => {
|
|
7
|
+
const [validationAttempt, setValidationAttempt] = useState(0);
|
|
8
|
+
const onValidationError = useCallback(() => setValidationAttempt(count => count + 1), []);
|
|
9
|
+
return { validationAttempt, onValidationError };
|
|
10
|
+
};
|
|
11
|
+
export const FormScrollView = ({ validationAttempt, footer, style, keyboardShouldPersistTaps = 'handled', ...props }) => {
|
|
12
|
+
const scroll = useRef(null);
|
|
13
|
+
const content = useRef(null);
|
|
14
|
+
const invalidFields = useRef(new Set());
|
|
15
|
+
const [footerHeight, setFooterHeight] = useState(0);
|
|
16
|
+
const register = useCallback((field) => {
|
|
17
|
+
invalidFields.current.add(field);
|
|
18
|
+
return () => {
|
|
19
|
+
invalidFields.current.delete(field);
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!validationAttempt)
|
|
24
|
+
return;
|
|
25
|
+
let cancelled = false;
|
|
26
|
+
let frame;
|
|
27
|
+
// Let the keyboard and its scroll adjustments finish before measuring the errors.
|
|
28
|
+
void KeyboardController.dismiss().then(() => {
|
|
29
|
+
if (cancelled)
|
|
30
|
+
return;
|
|
31
|
+
frame = requestAnimationFrame(async () => {
|
|
32
|
+
const parent = content.current;
|
|
33
|
+
if (!parent)
|
|
34
|
+
return;
|
|
35
|
+
const positions = await Promise.all([...invalidFields.current].map(field => new Promise(resolve => {
|
|
36
|
+
field.measureLayout(parent, (_x, y) => resolve(y), () => resolve(Infinity));
|
|
37
|
+
})));
|
|
38
|
+
const first = Math.min(...positions.filter(Number.isFinite));
|
|
39
|
+
if (!cancelled && Number.isFinite(first)) {
|
|
40
|
+
scroll.current?.scrollTo({ y: Math.max(0, first - 16), animated: true });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
cancelled = true;
|
|
46
|
+
if (frame !== undefined)
|
|
47
|
+
cancelAnimationFrame(frame);
|
|
48
|
+
};
|
|
49
|
+
}, [validationAttempt]);
|
|
50
|
+
return (_jsx(FormErrorContext.Provider, { value: register, children: _jsxs(View, { style: [styles.fill, style], children: [_jsx(KeyboardAwareScrollView, { ...props, ref: scroll, style: styles.fill, innerViewRef: content, keyboardShouldPersistTaps: keyboardShouldPersistTaps, bottomOffset: (footer == null ? 0 : footerHeight) + 16 }), footer != null && (_jsx(KeyboardStickyView, { onLayout: event => setFooterHeight(event.nativeEvent.layout.height), children: footer }))] }) }));
|
|
51
|
+
};
|
|
52
|
+
export const FormErrorAnchor = ({ error, ...props }) => {
|
|
53
|
+
const register = useContext(FormErrorContext);
|
|
54
|
+
const field = useRef(null);
|
|
55
|
+
const invalid = !!error;
|
|
56
|
+
useLayoutEffect(() => {
|
|
57
|
+
if (invalid && field.current)
|
|
58
|
+
return register?.(field.current);
|
|
59
|
+
}, [invalid, register]);
|
|
60
|
+
return _jsx(View, { ...props, ref: field, collapsable: false });
|
|
61
|
+
};
|
|
62
|
+
const styles = StyleSheet.create({ fill: { flex: 1 } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Svg, { Circle, Path, Rect } from "react-native-svg";
|
|
3
|
+
export function UIIcon({ name, color, size = 20, }) {
|
|
4
|
+
const paths = {
|
|
5
|
+
back: "M15 5l-7 7 7 7",
|
|
6
|
+
close: "M6 6l12 12M18 6L6 18",
|
|
7
|
+
chevron: "M6 9l6 6 6-6",
|
|
8
|
+
check: "M5 12l4 4L19 6",
|
|
9
|
+
search: "M16 16l5 5",
|
|
10
|
+
folder: "M3 7V5h7l2 2h9v13H3V7zm9 4v6m-3-3h6",
|
|
11
|
+
upload: "M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6",
|
|
12
|
+
file: "M14 3H5v18h14V8l-5-5zm0 0v5h5M8 12h8M8 16h6",
|
|
13
|
+
};
|
|
14
|
+
return (_jsx(Svg, { width: size, height: size, viewBox: "0 0 24 24", fill: "none", children: name === "calendar" ? (_jsxs(_Fragment, { children: [_jsx(Rect, { x: 3, y: 5, width: 18, height: 16, rx: 2, stroke: color, strokeWidth: 1.7 }), _jsx(Path, { d: "M3 10h18M7 3v4M17 3v4M7 14h2M12 14h2M7 17h2M12 17h2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round" })] })) : name === "clock" ? (_jsxs(_Fragment, { children: [_jsx(Circle, { cx: 12, cy: 12, r: 9, stroke: color, strokeWidth: 1.7 }), _jsx(Path, { d: "M12 7v5l3 2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" })] })) : (_jsxs(_Fragment, { children: [name === "search" && (_jsx(Circle, { cx: 10.5, cy: 10.5, r: 6.5, stroke: color, strokeWidth: 1.7 })), _jsx(Path, { d: paths[name], stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" })] })) }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Image } from "expo-image";
|
|
4
|
+
import { StyleSheet, View } from "react-native";
|
|
5
|
+
import { Skeleton } from "./primitives.js";
|
|
6
|
+
function ImagePresentation({ source, fallbackSource, loading = false, waitForDisplay = false, style, imageStyle, contentFit = "cover", fallbackContentFit = "contain", skeletonProps, testID = "image", onLoad, onDisplay, onError, ...imageProps }) {
|
|
7
|
+
const [loaded, setLoaded] = useState(false);
|
|
8
|
+
const [displayed, setDisplayed] = useState(false);
|
|
9
|
+
const [failed, setFailed] = useState(false);
|
|
10
|
+
const ready = waitForDisplay ? displayed : loaded;
|
|
11
|
+
const showSkeleton = source ? !failed && !ready : loading;
|
|
12
|
+
const useFallback = failed || !source;
|
|
13
|
+
return (_jsxs(View, { style: [{ overflow: "hidden" }, style], testID: `${testID}-container`, children: [_jsx(Image, { ...imageProps, source: useFallback ? fallbackSource : source, contentFit: useFallback ? fallbackContentFit : contentFit, style: [StyleSheet.absoluteFill, imageStyle], testID: testID, onLoad: (event) => {
|
|
14
|
+
setLoaded(true);
|
|
15
|
+
onLoad?.(event);
|
|
16
|
+
}, onDisplay: () => {
|
|
17
|
+
setDisplayed(true);
|
|
18
|
+
onDisplay?.();
|
|
19
|
+
}, onError: (event) => {
|
|
20
|
+
setFailed(true);
|
|
21
|
+
onError?.(event);
|
|
22
|
+
} }), showSkeleton && (_jsx(Skeleton, { ...skeletonProps, style: [
|
|
23
|
+
StyleSheet.absoluteFill,
|
|
24
|
+
{ width: "100%", height: "100%" },
|
|
25
|
+
skeletonProps?.style,
|
|
26
|
+
], testID: `${testID}-skeleton` }))] }));
|
|
27
|
+
}
|
|
28
|
+
/** Image loading state is local; source resolution, credentials and fallbacks belong to the app. */
|
|
29
|
+
export function ImageWithSkeleton(props) {
|
|
30
|
+
return (_jsx(ImagePresentation, { ...props }, JSON.stringify(props.source ?? null)));
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./theme.js";
|
|
2
|
+
export * from "./primitives.js";
|
|
3
|
+
export * from "./image.js";
|
|
4
|
+
export * from "./fields.js";
|
|
5
|
+
export * from "./date.js";
|
|
6
|
+
export * from "./overlays.js";
|
|
7
|
+
export * from "./choices.js";
|
|
8
|
+
export * from "./process-graph.js";
|
|
9
|
+
export { UIIcon } from "./icons.js";
|
|
10
|
+
export { ScreenHeader as Header, CollapsibleSection as CollapsibleCard, } from "./primitives.js";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ActivityIndicator, KeyboardAvoidingView, Modal, Platform, Pressable, StyleSheet, View, } 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
|
+
/** Native Modal children retain the provider of the app that rendered them. */
|
|
8
|
+
export function Sheet({ visible, onClose, title, closeAccessibilityLabel = "Close", children, style, animationType = "slide", keyboardAvoiding = false, }) {
|
|
9
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
10
|
+
const insets = useSafeAreaInsets();
|
|
11
|
+
const Root = keyboardAvoiding ? KeyboardAvoidingView : View;
|
|
12
|
+
return (_jsx(Modal, { visible: visible, transparent: true, animationType: animationType, onRequestClose: onClose, statusBarTranslucent: true, children: _jsxs(Root, { behavior: keyboardAvoiding && Platform.OS === "ios" ? "padding" : undefined, style: [
|
|
13
|
+
styles.modalRoot,
|
|
14
|
+
{ backgroundColor: c.backdrop, paddingTop: insets.top },
|
|
15
|
+
], children: [_jsx(Pressable, { style: StyleSheet.absoluteFill, onPress: onClose, accessible: false }), _jsxs(View, { accessibilityViewIsModal: true, style: [
|
|
16
|
+
{
|
|
17
|
+
maxHeight: "90%",
|
|
18
|
+
// The panel must yield to the keyboard instead of moving its header off-screen.
|
|
19
|
+
flexShrink: keyboardAvoiding ? 1 : undefined,
|
|
20
|
+
backgroundColor: c.background,
|
|
21
|
+
borderTopLeftRadius: r.sheet,
|
|
22
|
+
borderTopRightRadius: r.sheet,
|
|
23
|
+
paddingBottom: Math.max(s.xxl, insets.bottom),
|
|
24
|
+
},
|
|
25
|
+
style,
|
|
26
|
+
], children: [_jsxs(View, { style: [
|
|
27
|
+
styles.sheetHeader,
|
|
28
|
+
{ paddingHorizontal: s.lg, paddingVertical: s.md },
|
|
29
|
+
], children: [_jsx(View, { style: styles.headerSide }), _jsx(UIText, { variant: "subtitle", weight: "600", numberOfLines: 1, style: styles.sheetTitle, children: title }), _jsx(Pressable, { onPress: onClose, hitSlop: 12, accessibilityRole: "button", accessibilityLabel: closeAccessibilityLabel, children: _jsx(UIIcon, { name: "close", size: 18, color: c.content2 }) })] }), children] })] }) }));
|
|
30
|
+
}
|
|
31
|
+
export function ActionSheet({ items, onSelect, cancelText, ...props }) {
|
|
32
|
+
const { colors: c, spacing: s } = useUITheme();
|
|
33
|
+
return (_jsx(Sheet, { ...props, children: _jsxs(View, { style: { paddingHorizontal: s.lg }, children: [items.map((item) => (_jsxs(Pressable, { disabled: item.disabled, onPress: () => {
|
|
34
|
+
onSelect(item);
|
|
35
|
+
props.onClose();
|
|
36
|
+
}, accessibilityRole: "button", accessibilityState: { disabled: !!item.disabled }, style: [
|
|
37
|
+
styles.actionItem,
|
|
38
|
+
{
|
|
39
|
+
paddingVertical: s.lg,
|
|
40
|
+
gap: s.md,
|
|
41
|
+
borderBottomColor: c.divider,
|
|
42
|
+
opacity: item.disabled ? 0.5 : 1,
|
|
43
|
+
},
|
|
44
|
+
], 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 } }))] }) }));
|
|
45
|
+
}
|
|
46
|
+
export function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }) {
|
|
47
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
48
|
+
return (_jsx(Modal, { visible: visible, transparent: true, animationType: "fade", onRequestClose: loading ? () => undefined : onClose, statusBarTranslucent: true, children: _jsxs(View, { style: [
|
|
49
|
+
styles.dialogRoot,
|
|
50
|
+
{ backgroundColor: c.backdrop, padding: s.xxl },
|
|
51
|
+
], children: [_jsx(Pressable, { style: StyleSheet.absoluteFill, onPress: loading ? undefined : onClose, accessible: false }), _jsxs(View, { accessibilityViewIsModal: true, style: [
|
|
52
|
+
styles.dialog,
|
|
53
|
+
{
|
|
54
|
+
padding: s.xl,
|
|
55
|
+
gap: s.lg,
|
|
56
|
+
backgroundColor: c.background,
|
|
57
|
+
borderRadius: r.lg,
|
|
58
|
+
},
|
|
59
|
+
], 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 })] })] })] }) }));
|
|
60
|
+
}
|
|
61
|
+
export function ResultDialog({ buttonText, ...props }) {
|
|
62
|
+
return (_jsx(ConfirmDialog, { ...props, confirmText: buttonText, onConfirm: props.onClose }));
|
|
63
|
+
}
|
|
64
|
+
export function LoadingOverlay({ visible, label, presentation = "modal", testID, }) {
|
|
65
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
66
|
+
if (!visible)
|
|
67
|
+
return null;
|
|
68
|
+
const content = (_jsx(View, { testID: testID, accessibilityViewIsModal: true, accessibilityLiveRegion: "polite", style: [
|
|
69
|
+
styles.dialogRoot,
|
|
70
|
+
{ backgroundColor: c.backdrop },
|
|
71
|
+
presentation === "inline" && {
|
|
72
|
+
...StyleSheet.absoluteFillObject,
|
|
73
|
+
zIndex: 10000,
|
|
74
|
+
elevation: 10000,
|
|
75
|
+
},
|
|
76
|
+
], children: _jsxs(View, { style: {
|
|
77
|
+
padding: s.xxl,
|
|
78
|
+
gap: s.md,
|
|
79
|
+
backgroundColor: c.background,
|
|
80
|
+
borderRadius: r.lg,
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
}, children: [_jsx(ActivityIndicator, { size: "large", color: c.primary500 }), label != null && _jsx(UIText, { children: label })] }) }));
|
|
83
|
+
if (presentation === "inline")
|
|
84
|
+
return content;
|
|
85
|
+
return (_jsx(Modal, { visible: true, transparent: true, animationType: "fade", onRequestClose: () => undefined, statusBarTranslucent: true, children: content }));
|
|
86
|
+
}
|
|
87
|
+
const styles = StyleSheet.create({
|
|
88
|
+
modalRoot: { flex: 1, justifyContent: "flex-end" },
|
|
89
|
+
sheetHeader: { flexDirection: "row", alignItems: "center" },
|
|
90
|
+
headerSide: { width: 18 },
|
|
91
|
+
sheetTitle: { flex: 1, textAlign: "center" },
|
|
92
|
+
actionItem: {
|
|
93
|
+
flexDirection: "row",
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
borderBottomWidth: 1,
|
|
96
|
+
},
|
|
97
|
+
dialogRoot: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
98
|
+
dialog: { width: "100%", maxWidth: 420, alignItems: "center" },
|
|
99
|
+
dialogActions: { flexDirection: "row", alignSelf: "stretch" },
|
|
100
|
+
center: { textAlign: "center" },
|
|
101
|
+
flex: { flex: 1 },
|
|
102
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|