@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,145 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { Image, Pressable, StyleSheet, View, } from "react-native";
|
|
4
|
+
import { Calendar } from "react-native-calendars";
|
|
5
|
+
import { useUITheme } from "./theme.js";
|
|
6
|
+
import { Button, UIText } from "./primitives.js";
|
|
7
|
+
import { Field } from "./fields.js";
|
|
8
|
+
import { Sheet } from "./overlays.js";
|
|
9
|
+
import { UIIcon } from "./icons.js";
|
|
10
|
+
/** Validates date-only values without parsing through UTC or applying a timezone. */
|
|
11
|
+
export function isDateOnly(value) {
|
|
12
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
13
|
+
if (!match)
|
|
14
|
+
return false;
|
|
15
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
16
|
+
if (year < 1 || month < 1 || month > 12 || day < 1)
|
|
17
|
+
return false;
|
|
18
|
+
const days = month === 2
|
|
19
|
+
? year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
20
|
+
? 29
|
|
21
|
+
: 28
|
|
22
|
+
: [4, 6, 9, 11].includes(month)
|
|
23
|
+
? 30
|
|
24
|
+
: 31;
|
|
25
|
+
return day <= days;
|
|
26
|
+
}
|
|
27
|
+
export function isDateInRange(value, minDate, maxDate) {
|
|
28
|
+
return (isDateOnly(value) &&
|
|
29
|
+
(!minDate || value >= minDate) &&
|
|
30
|
+
(!maxDate || value <= maxDate));
|
|
31
|
+
}
|
|
32
|
+
export function todayDateOnly() {
|
|
33
|
+
const now = new Date();
|
|
34
|
+
return `${String(now.getFullYear()).padStart(4, "0")}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
35
|
+
}
|
|
36
|
+
export function formatDateOnly(value) {
|
|
37
|
+
return isDateOnly(value) ? value.split("-").reverse().join("/") : value;
|
|
38
|
+
}
|
|
39
|
+
export function addDateMonths(value, amount) {
|
|
40
|
+
const [year, month] = value.split("-").map(Number);
|
|
41
|
+
const index = year * 12 + month - 1 + amount;
|
|
42
|
+
return `${String(Math.floor(index / 12)).padStart(4, "0")}-${String((((index % 12) + 12) % 12) + 1).padStart(2, "0")}-01`;
|
|
43
|
+
}
|
|
44
|
+
export function DateField({ variant = "default", label, required, placeholder, confirmText, clearText, value, minDate, maxDate, disabled = false, error, onChange, onClear, formatValue = formatDateOnly, formatMonth, renderPicker, icon, iconSource, closeAccessibilityLabel, style, fieldStyle, }) {
|
|
45
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
46
|
+
const [visible, setVisible] = useState(false);
|
|
47
|
+
const [selectedDate, setSelectedDate] = useState(null);
|
|
48
|
+
const [currentMonth, setCurrentMonth] = useState(todayDateOnly);
|
|
49
|
+
const validSelection = !!selectedDate && isDateInRange(selectedDate, minDate, maxDate);
|
|
50
|
+
const open = () => {
|
|
51
|
+
const selected = value && isDateOnly(value) ? value : null;
|
|
52
|
+
let month = selected ?? todayDateOnly();
|
|
53
|
+
if (minDate && month < minDate)
|
|
54
|
+
month = minDate;
|
|
55
|
+
if (maxDate && month > maxDate)
|
|
56
|
+
month = maxDate;
|
|
57
|
+
setSelectedDate(selected);
|
|
58
|
+
setCurrentMonth(month);
|
|
59
|
+
setVisible(true);
|
|
60
|
+
};
|
|
61
|
+
const select = (date) => {
|
|
62
|
+
if (isDateInRange(date, minDate, maxDate))
|
|
63
|
+
setSelectedDate(date);
|
|
64
|
+
};
|
|
65
|
+
const confirm = () => {
|
|
66
|
+
if (validSelection && selectedDate) {
|
|
67
|
+
onChange(selectedDate);
|
|
68
|
+
setVisible(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const calendarTheme = useMemo(() => ({
|
|
72
|
+
backgroundColor: c.background,
|
|
73
|
+
calendarBackground: c.background,
|
|
74
|
+
dayTextColor: c.content1,
|
|
75
|
+
textDisabledColor: c.content4,
|
|
76
|
+
monthTextColor: c.content1,
|
|
77
|
+
textMonthFontWeight: "600",
|
|
78
|
+
todayTextColor: c.primary500,
|
|
79
|
+
arrowColor: c.primary500,
|
|
80
|
+
textSectionTitleColor: c.content2,
|
|
81
|
+
}), [c]);
|
|
82
|
+
// Calendar caches theme styles at mount, including weekday/disabled text.
|
|
83
|
+
const calendarPaletteKey = `${JSON.stringify(calendarTheme)}:${c.textPrimary}`;
|
|
84
|
+
const monthLabel = formatMonth?.(currentMonth) ??
|
|
85
|
+
`${currentMonth.slice(5, 7)}/${currentMonth.slice(0, 4)}`;
|
|
86
|
+
const calendarHeader = () => (_jsxs(View, { style: [
|
|
87
|
+
styles.calendarHeader,
|
|
88
|
+
{ paddingHorizontal: s.sm, paddingVertical: s.sm },
|
|
89
|
+
], children: [_jsxs(View, { style: [styles.arrows, { gap: s.lg }], children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -12)), children: _jsx(UIText, { variant: "title", color: "content3", children: "\u00AB" }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -1)), children: _jsx(UIText, { variant: "title", color: "content3", children: "\u2039" }) })] }), _jsx(UIText, { weight: "600", style: styles.monthLabel, children: monthLabel }), _jsxs(View, { style: [styles.arrows, { gap: s.lg }], children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Next month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 1)), children: _jsx(UIText, { variant: "title", color: "content3", children: "\u203A" }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Next year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 12)), children: _jsx(UIText, { variant: "title", color: "content3", children: "\u00BB" }) })] })] }));
|
|
90
|
+
return (_jsxs(Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [_jsxs(Pressable, { disabled: disabled, onPress: open, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: [
|
|
91
|
+
styles.field,
|
|
92
|
+
{
|
|
93
|
+
minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
|
|
94
|
+
...(variant === "form" ? { height: s.xxl * 2 } : {}),
|
|
95
|
+
gap: s.sm,
|
|
96
|
+
paddingHorizontal: variant === "form" ? s.lg : s.md,
|
|
97
|
+
borderColor: error ? c.danger : c.gray200,
|
|
98
|
+
borderRadius: variant === "form" ? r.lg : r.md,
|
|
99
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
100
|
+
opacity: disabled && variant === "form" ? 0.5 : 1,
|
|
101
|
+
},
|
|
102
|
+
fieldStyle,
|
|
103
|
+
], children: [_jsx(UIText, { numberOfLines: 1, color: value ? "content1" : "content3", style: styles.flex, children: value ? formatValue(value) : placeholder }), icon ??
|
|
104
|
+
(iconSource ? (_jsx(Image, { source: iconSource, resizeMode: "contain", style: { width: s.xl, height: s.xl, tintColor: c.content2 } })) : (_jsx(UIIcon, { name: "calendar", size: 20, color: c.content2 })))] }), _jsxs(Sheet, { visible: visible, onClose: () => setVisible(false), title: label, closeAccessibilityLabel: closeAccessibilityLabel, children: [visible &&
|
|
105
|
+
(renderPicker ? (renderPicker({
|
|
106
|
+
selectedDate,
|
|
107
|
+
currentMonth,
|
|
108
|
+
onSelect: select,
|
|
109
|
+
onMonthChange: setCurrentMonth,
|
|
110
|
+
minDate,
|
|
111
|
+
maxDate,
|
|
112
|
+
})) : (_jsx(Calendar, { current: currentMonth, theme: calendarTheme, minDate: minDate, maxDate: maxDate, markedDates: selectedDate
|
|
113
|
+
? {
|
|
114
|
+
[selectedDate]: {
|
|
115
|
+
selected: true,
|
|
116
|
+
selectedColor: c.primary500,
|
|
117
|
+
selectedTextColor: c.textPrimary,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
: {}, onDayPress: (day) => select(day.dateString), onMonthChange: (month) => setCurrentMonth(month.dateString), hideArrows: true, renderHeader: calendarHeader, enableSwipeMonths: true }, `${currentMonth}:${calendarPaletteKey}`))), _jsxs(View, { style: [
|
|
121
|
+
styles.footer,
|
|
122
|
+
{ gap: s.md, paddingHorizontal: s.xl, paddingTop: s.lg },
|
|
123
|
+
], children: [onClear && (_jsx(Button, { label: clearText ?? "", variant: "outline", disabled: !selectedDate && !value, onPress: () => {
|
|
124
|
+
setSelectedDate(null);
|
|
125
|
+
onClear();
|
|
126
|
+
setVisible(false);
|
|
127
|
+
}, style: styles.flex })), _jsx(Button, { label: confirmText, disabled: !validSelection, onPress: confirm, style: styles.flex })] })] })] }));
|
|
128
|
+
}
|
|
129
|
+
const styles = StyleSheet.create({
|
|
130
|
+
field: {
|
|
131
|
+
borderWidth: 1,
|
|
132
|
+
flexDirection: "row",
|
|
133
|
+
alignItems: "center",
|
|
134
|
+
justifyContent: "space-between",
|
|
135
|
+
},
|
|
136
|
+
flex: { flex: 1 },
|
|
137
|
+
footer: { flexDirection: "row" },
|
|
138
|
+
calendarHeader: {
|
|
139
|
+
flexDirection: "row",
|
|
140
|
+
alignItems: "center",
|
|
141
|
+
justifyContent: "space-between",
|
|
142
|
+
},
|
|
143
|
+
arrows: { flexDirection: "row", alignItems: "center" },
|
|
144
|
+
monthLabel: { flex: 1, textAlign: "center" },
|
|
145
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ActivityIndicator, 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
|
+
import { ListPicker } from "./list-picker.js";
|
|
9
|
+
export function Field({ label, required, error, hint, children, style, labelStyle, }) {
|
|
10
|
+
const { spacing: s } = useUITheme();
|
|
11
|
+
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 &&
|
|
12
|
+
(typeof hint === "string" ? (_jsx(UIText, { variant: "caption", color: "content2", children: hint })) : (hint)), !!error && (_jsx(UIText, { variant: "caption", color: "danger", accessibilityLiveRegion: "polite", children: error }))] }));
|
|
13
|
+
}
|
|
14
|
+
export function TextField({ label, required, error, hint, containerStyle, showCount = false, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }) {
|
|
15
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
16
|
+
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: [
|
|
17
|
+
{
|
|
18
|
+
minHeight: multiline ? s.xxl * 4 : s.xxl + s.xl,
|
|
19
|
+
borderWidth: 1,
|
|
20
|
+
borderColor: error ? c.danger : c.gray200,
|
|
21
|
+
borderRadius: r.md,
|
|
22
|
+
paddingHorizontal: s.md,
|
|
23
|
+
paddingVertical: multiline ? s.md : s.sm,
|
|
24
|
+
backgroundColor: editable === false ? c.gray50 : c.background,
|
|
25
|
+
color: c.content1,
|
|
26
|
+
fontSize: t.body,
|
|
27
|
+
fontFamily: t.fontFamily,
|
|
28
|
+
},
|
|
29
|
+
style,
|
|
30
|
+
] }), showCount && (_jsxs(UIText, { variant: "caption", color: "content2", style: styles.count, children: [props.value?.length ?? 0, props.maxLength != null ? `/${props.maxLength}` : "", countLabel ? ` ${countLabel}` : ""] }))] }));
|
|
31
|
+
}
|
|
32
|
+
export function PressableField({ variant = "default", label, value, placeholder, required, error, hint, loading = false, disabled = false, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }) {
|
|
33
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
34
|
+
const filter = variant === "filter";
|
|
35
|
+
const largeField = variant !== "default";
|
|
36
|
+
const hasValue = value !== undefined && value !== null && value !== "";
|
|
37
|
+
const textValue = !hasValue || typeof value === "string" || typeof value === "number";
|
|
38
|
+
return (_jsx(Field, { label: label, required: required, error: error, hint: hint, labelStyle: [
|
|
39
|
+
filter && { fontSize: t.body, fontWeight: "500", color: c.content1 },
|
|
40
|
+
labelStyle,
|
|
41
|
+
], style: [
|
|
42
|
+
variant === "form" && { marginBottom: s.lg, gap: s.sm },
|
|
43
|
+
filter && { gap: s.sm },
|
|
44
|
+
style,
|
|
45
|
+
], children: _jsxs(Pressable, { ...props, disabled: disabled || loading, accessibilityRole: props.accessibilityRole ?? "button", accessibilityLabel: props.accessibilityLabel ??
|
|
46
|
+
(typeof label === "string" ? label : placeholder), accessibilityState: {
|
|
47
|
+
...props.accessibilityState,
|
|
48
|
+
disabled: disabled || loading,
|
|
49
|
+
busy: loading,
|
|
50
|
+
}, style: [
|
|
51
|
+
styles.selector,
|
|
52
|
+
{
|
|
53
|
+
minHeight: largeField ? s.xxl * 2 : s.xxl + s.xl,
|
|
54
|
+
...(largeField ? { height: s.xxl * 2 } : {}),
|
|
55
|
+
gap: s.sm,
|
|
56
|
+
paddingHorizontal: filter
|
|
57
|
+
? (s.md + s.lg) / 2
|
|
58
|
+
: variant === "form"
|
|
59
|
+
? s.lg
|
|
60
|
+
: s.md,
|
|
61
|
+
borderColor: error ? c.danger : c.gray200,
|
|
62
|
+
borderRadius: largeField ? r.lg : r.md,
|
|
63
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
64
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
65
|
+
},
|
|
66
|
+
fieldStyle,
|
|
67
|
+
], 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 }))] }) }));
|
|
68
|
+
}
|
|
69
|
+
/** Complete time field UI; the app supplies its native picker implementation. */
|
|
70
|
+
export function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable = false, disabled = false, clearAccessibilityLabel = "Clear time", icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }) {
|
|
71
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
72
|
+
const [visible, setVisible] = useState(false);
|
|
73
|
+
const hasValue = !!value;
|
|
74
|
+
const iconSize = s.lg + s.xs / 2;
|
|
75
|
+
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 }) => [
|
|
76
|
+
styles.selector,
|
|
77
|
+
{
|
|
78
|
+
height: s.xxl * 2,
|
|
79
|
+
paddingHorizontal: s.lg,
|
|
80
|
+
borderColor: error ? c.danger : c.gray200,
|
|
81
|
+
borderRadius: r.lg,
|
|
82
|
+
backgroundColor: c.gray50,
|
|
83
|
+
opacity: disabled ? 0.5 : pressed ? 0.2 : 1,
|
|
84
|
+
},
|
|
85
|
+
fieldStyle,
|
|
86
|
+
], children: [_jsx(UIText, { numberOfLines: 1, style: [
|
|
87
|
+
styles.flex,
|
|
88
|
+
{
|
|
89
|
+
fontSize: (t.body + t.subtitle) / 2,
|
|
90
|
+
color: hasValue ? c.content1 : c.content4,
|
|
91
|
+
},
|
|
92
|
+
valueStyle,
|
|
93
|
+
], children: hasValue ? value : placeholder }), clearable && hasValue ? (_jsx(Pressable, { disabled: disabled, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, onPress: (event) => {
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
onChange("");
|
|
96
|
+
}, 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 &&
|
|
97
|
+
renderPicker({
|
|
98
|
+
visible,
|
|
99
|
+
value,
|
|
100
|
+
onClose: () => setVisible(false),
|
|
101
|
+
onConfirm: (time) => {
|
|
102
|
+
onChange(time);
|
|
103
|
+
setVisible(false);
|
|
104
|
+
},
|
|
105
|
+
})] }));
|
|
106
|
+
}
|
|
107
|
+
export function SelectField({ variant = "default", options, value, onChange, label, placeholder, required, error, disabled = false, loading = false, searchable = true, fixedSheetHeight = false, sheetHeightRatio = 0.7, keyboardAvoiding = false, localSearch = true, searchKey, searchFilter, onSearch, searchDelay = 500, searchPlaceholder, autoFocus = false, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }) {
|
|
108
|
+
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
109
|
+
const { height } = useWindowDimensions();
|
|
110
|
+
const sheetHeight = height * sheetHeightRatio;
|
|
111
|
+
const [visible, setVisible] = useState(false);
|
|
112
|
+
const [query, setQuery] = useState("");
|
|
113
|
+
const searchCallback = useRef(onSearch);
|
|
114
|
+
searchCallback.current = onSearch;
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!visible || !searchable || localSearch)
|
|
117
|
+
return;
|
|
118
|
+
const timer = setTimeout(() => searchCallback.current?.(query), searchDelay);
|
|
119
|
+
return () => clearTimeout(timer);
|
|
120
|
+
}, [query, searchDelay, visible, searchable, localSearch]);
|
|
121
|
+
const filtered = useMemo(() => {
|
|
122
|
+
if (!searchable || !localSearch || !query.trim())
|
|
123
|
+
return options;
|
|
124
|
+
const normalized = query.trim().toLocaleLowerCase();
|
|
125
|
+
return options.filter((option) => searchFilter
|
|
126
|
+
? searchFilter(option, query)
|
|
127
|
+
: String(searchKey ? (option[searchKey] ?? "") : option.label)
|
|
128
|
+
.toLocaleLowerCase()
|
|
129
|
+
.includes(normalized));
|
|
130
|
+
}, [options, searchable, localSearch, query, searchKey, searchFilter]);
|
|
131
|
+
const open = () => {
|
|
132
|
+
if (disabled || loading)
|
|
133
|
+
return;
|
|
134
|
+
if (keyboardAvoiding && searchable)
|
|
135
|
+
Keyboard.dismiss();
|
|
136
|
+
setQuery("");
|
|
137
|
+
setVisible(true);
|
|
138
|
+
};
|
|
139
|
+
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: {
|
|
140
|
+
disabled: disabled || loading,
|
|
141
|
+
expanded: visible,
|
|
142
|
+
busy: loading,
|
|
143
|
+
}, style: [
|
|
144
|
+
styles.selector,
|
|
145
|
+
{
|
|
146
|
+
minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
|
|
147
|
+
...(variant === "form" ? { height: s.xxl * 2 } : {}),
|
|
148
|
+
gap: s.sm,
|
|
149
|
+
paddingHorizontal: variant === "form" ? s.lg : s.md,
|
|
150
|
+
borderColor: error ? c.danger : c.gray200,
|
|
151
|
+
borderRadius: variant === "form" ? r.lg : r.md,
|
|
152
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
153
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
154
|
+
},
|
|
155
|
+
fieldStyle,
|
|
156
|
+
], 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, heightRatio: fixedSheetHeight ? sheetHeightRatio : undefined, style: fixedSheetHeight ? undefined : { maxHeight: sheetHeight }, children: [searchable && (_jsxs(View, { style: [
|
|
157
|
+
styles.search,
|
|
158
|
+
{
|
|
159
|
+
marginHorizontal: s.lg,
|
|
160
|
+
marginBottom: s.md,
|
|
161
|
+
gap: s.sm,
|
|
162
|
+
paddingHorizontal: s.md,
|
|
163
|
+
minHeight: s.xl * 2,
|
|
164
|
+
borderRadius: r.md,
|
|
165
|
+
backgroundColor: c.gray50,
|
|
166
|
+
},
|
|
167
|
+
], 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: {
|
|
168
|
+
flex: 1,
|
|
169
|
+
color: c.content1,
|
|
170
|
+
fontSize: t.body,
|
|
171
|
+
fontFamily: t.fontFamily,
|
|
172
|
+
} }))] })), _jsx(ListPicker, { items: filtered, getKey: option => option.value, getLabel: option => option.label, value: value, onChange: option => {
|
|
173
|
+
onChange(option);
|
|
174
|
+
setVisible(false);
|
|
175
|
+
}, loading: loading, listStyle: fixedSheetHeight ? styles.fixedSheetList : undefined, emptyText: query ? (noResultsText ?? emptyText) : emptyText })] })] }));
|
|
176
|
+
}
|
|
177
|
+
export function AttachmentField({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel = "Remove file", style, }) {
|
|
178
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
179
|
+
return (_jsxs(View, { style: [{ gap: s.sm }, style], children: [title != null && (_jsx(UIText, { variant: "label", color: "content2", children: title })), _jsxs(View, { style: {
|
|
180
|
+
borderWidth: 1,
|
|
181
|
+
borderStyle: "dashed",
|
|
182
|
+
borderColor: c.gray200,
|
|
183
|
+
borderRadius: r.md,
|
|
184
|
+
paddingVertical: s.xl,
|
|
185
|
+
paddingHorizontal: s.lg,
|
|
186
|
+
alignItems: "center",
|
|
187
|
+
gap: s.sm,
|
|
188
|
+
}, 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) => {
|
|
189
|
+
const id = getId?.(file, index) ?? String(file.id ?? index);
|
|
190
|
+
return (_jsxs(View, { style: [
|
|
191
|
+
styles.attachment,
|
|
192
|
+
{
|
|
193
|
+
gap: s.sm,
|
|
194
|
+
paddingVertical: s.sm,
|
|
195
|
+
paddingHorizontal: s.md,
|
|
196
|
+
borderWidth: 1,
|
|
197
|
+
borderColor: c.gray200,
|
|
198
|
+
borderRadius: r.md,
|
|
199
|
+
},
|
|
200
|
+
], 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: {
|
|
201
|
+
flex: 1,
|
|
202
|
+
fontSize: 13,
|
|
203
|
+
textDecorationLine: onOpen ? "underline" : "none",
|
|
204
|
+
}, 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));
|
|
205
|
+
})] }));
|
|
206
|
+
}
|
|
207
|
+
const styles = StyleSheet.create({
|
|
208
|
+
count: { alignSelf: "flex-end" },
|
|
209
|
+
selector: {
|
|
210
|
+
borderWidth: 1,
|
|
211
|
+
flexDirection: "row",
|
|
212
|
+
alignItems: "center",
|
|
213
|
+
justifyContent: "space-between",
|
|
214
|
+
},
|
|
215
|
+
flex: { flex: 1 },
|
|
216
|
+
fixedSheetList: { flex: 1, minHeight: 0 },
|
|
217
|
+
center: { textAlign: "center" },
|
|
218
|
+
search: { flexDirection: "row", alignItems: "center" },
|
|
219
|
+
selectItem: {
|
|
220
|
+
flexDirection: "row",
|
|
221
|
+
alignItems: "center",
|
|
222
|
+
justifyContent: "space-between",
|
|
223
|
+
},
|
|
224
|
+
attachment: { flexDirection: "row", alignItems: "center" },
|
|
225
|
+
});
|
|
@@ -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,16 @@
|
|
|
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: "M21 11.5C21 16.7467 16.7467 21 11.5 21C6.25329 21 2 16.7467 2 11.5C2 6.25329 6.25329 2 11.5 2C16.7467 2 21 6.25329 21 11.5ZM22 22L20 20",
|
|
10
|
+
filter: "M3 7h18M6 12h12M10 17h4",
|
|
11
|
+
folder: "M3 7V5h7l2 2h9v13H3V7zm9 4v6m-3-3h6",
|
|
12
|
+
upload: "M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6",
|
|
13
|
+
file: "M14 3H5v18h14V8l-5-5zm0 0v5h5M8 12h8M8 16h6",
|
|
14
|
+
};
|
|
15
|
+
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" })] })) : (_jsx(Path, { d: paths[name], stroke: color, strokeWidth: name === "search" ? 1.5 : 1.7, strokeLinecap: "round", strokeLinejoin: "round" })) }));
|
|
16
|
+
}
|
|
@@ -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,13 @@
|
|
|
1
|
+
export * from "./theme.js";
|
|
2
|
+
export * from "./primitives.js";
|
|
3
|
+
export * from "./image.js";
|
|
4
|
+
export * from "./fields.js";
|
|
5
|
+
export * from "./search.js";
|
|
6
|
+
export * from "./date.js";
|
|
7
|
+
export * from "./overlays.js";
|
|
8
|
+
export * from "./ui-modal.js";
|
|
9
|
+
export * from "./choices.js";
|
|
10
|
+
export * from "./process-graph.js";
|
|
11
|
+
export { UIIcon } from "./icons.js";
|
|
12
|
+
export { ScreenHeader as Header, CollapsibleSection as CollapsibleCard, } from "./primitives.js";
|
|
13
|
+
export * from "./list-picker.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ActivityIndicator, FlatList, Pressable, RefreshControl, StyleSheet, View, } from "react-native";
|
|
4
|
+
import { UIIcon } from "./icons.js";
|
|
5
|
+
import { Button, UIText } from "./primitives.js";
|
|
6
|
+
import { SearchBar } from "./search.js";
|
|
7
|
+
import { useUITheme } from "./theme.js";
|
|
8
|
+
export function ListPicker(props) {
|
|
9
|
+
const { colors: c, spacing: s } = useUITheme();
|
|
10
|
+
const { items, getKey, getLabel, loading, loadingMore, refreshing, onRefresh, onLoadMore, onSearch, errorText, emptyText, onRetry, retryText = "Retry", confirmText = "Confirm", searchPlaceholder, clearSearchAccessibilityLabel, search, loadingContent, listStyle, contentContainerStyle, footerStyle, renderList, renderItem, } = props;
|
|
11
|
+
const [keyword, setKeyword] = React.useState("");
|
|
12
|
+
const [draft, setDraft] = React.useState(null);
|
|
13
|
+
const selected = props.multiple ? draft ?? props.value ?? [] : undefined;
|
|
14
|
+
const selectedKeys = React.useMemo(() => selected && new Set(selected.map(getKey)), [getKey, selected]);
|
|
15
|
+
const singleKey = !props.multiple && props.value != null ? getKey(props.value) : undefined;
|
|
16
|
+
const normalized = keyword.trim().toLocaleLowerCase();
|
|
17
|
+
const data = React.useMemo(() => searchPlaceholder && !onSearch && normalized
|
|
18
|
+
? items.filter((item) => getLabel(item).toLocaleLowerCase().includes(normalized))
|
|
19
|
+
: items, [getLabel, items, normalized, onSearch, searchPlaceholder]);
|
|
20
|
+
const select = (item) => {
|
|
21
|
+
if (!props.multiple) {
|
|
22
|
+
props.onChange(item);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const key = getKey(item);
|
|
26
|
+
setDraft((previous) => {
|
|
27
|
+
const current = previous ?? props.value ?? [];
|
|
28
|
+
return current.some((option) => Object.is(getKey(option), key))
|
|
29
|
+
? current.filter((option) => !Object.is(getKey(option), key))
|
|
30
|
+
: [...current, item];
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const listProps = {
|
|
34
|
+
style: listStyle,
|
|
35
|
+
data,
|
|
36
|
+
extraData: selectedKeys ?? singleKey,
|
|
37
|
+
renderItem: ({ item }) => {
|
|
38
|
+
const key = getKey(item);
|
|
39
|
+
const isSelected = props.multiple
|
|
40
|
+
? !!selectedKeys?.has(key)
|
|
41
|
+
: props.value != null && Object.is(singleKey, key);
|
|
42
|
+
return renderItem ? (renderItem(item, isSelected, () => select(item))) : (_jsxs(Pressable, { accessibilityRole: props.multiple ? "checkbox" : "radio", accessibilityState: props.multiple ? { checked: isSelected } : { selected: isSelected }, style: [styles.row, { paddingVertical: s.md + 2, gap: s.sm }], onPress: () => select(item), children: [_jsx(UIText, { numberOfLines: 1, color: isSelected ? "primary500" : "content1", weight: isSelected ? "600" : "400", style: styles.label, children: getLabel(item) }), isSelected && _jsx(UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
|
|
43
|
+
},
|
|
44
|
+
contentContainerStyle: contentContainerStyle ?? { paddingHorizontal: s.lg },
|
|
45
|
+
keyExtractor: (item, index) => `${String(getKey(item))}_${index}`,
|
|
46
|
+
keyboardShouldPersistTaps: "handled",
|
|
47
|
+
showsVerticalScrollIndicator: false,
|
|
48
|
+
onEndReached: loading || loadingMore ? undefined : onLoadMore,
|
|
49
|
+
onEndReachedThreshold: 0.3,
|
|
50
|
+
refreshControl: onRefresh && (_jsx(RefreshControl, { refreshing: !!refreshing, onRefresh: onRefresh, colors: [c.primary500], tintColor: c.primary500 })),
|
|
51
|
+
ItemSeparatorComponent: () => (_jsx(View, { style: { height: 1, backgroundColor: c.divider } })),
|
|
52
|
+
ListFooterComponent: loadingMore ? (_jsx(ActivityIndicator, { color: c.primary500 })) : null,
|
|
53
|
+
ListEmptyComponent: errorText || emptyText ? (_jsxs(View, { style: [styles.empty, { paddingVertical: s.xxl + s.sm }], children: [_jsx(UIText, { color: "content3", style: styles.emptyText, children: errorText || emptyText }), !!errorText && onRetry && (_jsx(Button, { variant: "ghost", label: retryText, onPress: onRetry }))] })) : null,
|
|
54
|
+
};
|
|
55
|
+
return (_jsxs(_Fragment, { children: [search ??
|
|
56
|
+
(searchPlaceholder && (_jsx(SearchBar, { style: { marginHorizontal: s.lg, marginBottom: s.xs }, placeholder: searchPlaceholder, clearAccessibilityLabel: clearSearchAccessibilityLabel, onChangeText: (text) => {
|
|
57
|
+
setKeyword(text);
|
|
58
|
+
onSearch?.(text.trim());
|
|
59
|
+
} }))), loading ? (loadingContent ?? _jsx(ActivityIndicator, { color: c.primary500 })) : renderList ? (renderList(listProps)) : (_jsx(FlatList, { ...listProps })), props.multiple && (_jsx(View, { style: [{ paddingHorizontal: s.lg, paddingTop: s.md }, footerStyle], children: _jsx(Button, { label: confirmText, onPress: () => props.onChange([...(selected ?? [])]) }) }))] }));
|
|
60
|
+
}
|
|
61
|
+
const styles = StyleSheet.create({
|
|
62
|
+
row: {
|
|
63
|
+
flexDirection: "row",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
justifyContent: "space-between",
|
|
66
|
+
},
|
|
67
|
+
label: { flex: 1 },
|
|
68
|
+
empty: { alignItems: "center" },
|
|
69
|
+
emptyText: { textAlign: "center" },
|
|
70
|
+
});
|