@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,79 @@
|
|
|
1
|
+
/** Names and meaning follow the 360 guideline. Hex values belong to each app. */
|
|
2
|
+
export interface PaletteColors {
|
|
3
|
+
background: string;
|
|
4
|
+
base2: string;
|
|
5
|
+
base3: string;
|
|
6
|
+
divider: string;
|
|
7
|
+
focus: string;
|
|
8
|
+
content1: string;
|
|
9
|
+
content2: string;
|
|
10
|
+
content3: string;
|
|
11
|
+
content4: string;
|
|
12
|
+
textPrimary: string;
|
|
13
|
+
default: string;
|
|
14
|
+
primary: string;
|
|
15
|
+
secondary: string;
|
|
16
|
+
success: string;
|
|
17
|
+
warning: string;
|
|
18
|
+
danger: string;
|
|
19
|
+
gray50: string;
|
|
20
|
+
gray100: string;
|
|
21
|
+
gray200: string;
|
|
22
|
+
gray300: string;
|
|
23
|
+
gray400: string;
|
|
24
|
+
gray500: string;
|
|
25
|
+
gray600: string;
|
|
26
|
+
gray700: string;
|
|
27
|
+
gray800: string;
|
|
28
|
+
gray900: string;
|
|
29
|
+
primary50: string;
|
|
30
|
+
primary100: string;
|
|
31
|
+
primary200: string;
|
|
32
|
+
primary300: string;
|
|
33
|
+
primary400: string;
|
|
34
|
+
primary500: string;
|
|
35
|
+
primary600: string;
|
|
36
|
+
primary700: string;
|
|
37
|
+
primary800: string;
|
|
38
|
+
primary900: string;
|
|
39
|
+
secondary50: string;
|
|
40
|
+
secondary100: string;
|
|
41
|
+
secondary200: string;
|
|
42
|
+
secondary300: string;
|
|
43
|
+
secondary400: string;
|
|
44
|
+
secondary500: string;
|
|
45
|
+
secondary600: string;
|
|
46
|
+
secondary700: string;
|
|
47
|
+
secondary800: string;
|
|
48
|
+
secondary900: string;
|
|
49
|
+
success50: string;
|
|
50
|
+
success100: string;
|
|
51
|
+
success200: string;
|
|
52
|
+
success300: string;
|
|
53
|
+
success400: string;
|
|
54
|
+
success500: string;
|
|
55
|
+
success600: string;
|
|
56
|
+
success700: string;
|
|
57
|
+
success800: string;
|
|
58
|
+
success900: string;
|
|
59
|
+
warning50: string;
|
|
60
|
+
warning100: string;
|
|
61
|
+
warning200: string;
|
|
62
|
+
warning300: string;
|
|
63
|
+
warning400: string;
|
|
64
|
+
warning500: string;
|
|
65
|
+
warning600: string;
|
|
66
|
+
warning700: string;
|
|
67
|
+
warning800: string;
|
|
68
|
+
warning900: string;
|
|
69
|
+
danger50: string;
|
|
70
|
+
danger100: string;
|
|
71
|
+
danger200: string;
|
|
72
|
+
danger300: string;
|
|
73
|
+
danger400: string;
|
|
74
|
+
danger500: string;
|
|
75
|
+
danger600: string;
|
|
76
|
+
danger700: string;
|
|
77
|
+
danger800: string;
|
|
78
|
+
danger900: string;
|
|
79
|
+
}
|
package/dist/date.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ImageSourcePropType, StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
/** Validates date-only values without parsing through UTC or applying a timezone. */
|
|
4
|
+
export declare function isDateOnly(value: string): boolean;
|
|
5
|
+
export declare function isDateInRange(value: string, minDate?: string, maxDate?: string): boolean;
|
|
6
|
+
export declare function todayDateOnly(): string;
|
|
7
|
+
export declare function formatDateOnly(value: string): string;
|
|
8
|
+
export declare function addDateMonths(value: string, amount: number): string;
|
|
9
|
+
export interface DatePickerRenderProps {
|
|
10
|
+
selectedDate: string | null;
|
|
11
|
+
currentMonth: string;
|
|
12
|
+
onSelect: (date: string) => void;
|
|
13
|
+
onMonthChange: (date: string) => void;
|
|
14
|
+
minDate?: string;
|
|
15
|
+
maxDate?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DateFieldProps {
|
|
18
|
+
variant?: "default" | "form";
|
|
19
|
+
label?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
confirmText: string;
|
|
23
|
+
clearText?: string;
|
|
24
|
+
value: string | null;
|
|
25
|
+
minDate?: string;
|
|
26
|
+
maxDate?: string;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
error?: string;
|
|
29
|
+
onChange: (date: string) => void;
|
|
30
|
+
onClear?: () => void;
|
|
31
|
+
formatValue?: (date: string) => string;
|
|
32
|
+
formatMonth?: (date: string) => string;
|
|
33
|
+
renderPicker?: (props: DatePickerRenderProps) => React.ReactNode;
|
|
34
|
+
icon?: React.ReactNode;
|
|
35
|
+
iconSource?: ImageSourcePropType;
|
|
36
|
+
closeAccessibilityLabel?: string;
|
|
37
|
+
style?: StyleProp<ViewStyle>;
|
|
38
|
+
fieldStyle?: StyleProp<ViewStyle>;
|
|
39
|
+
}
|
|
40
|
+
export declare function DateField({ variant, label, required, placeholder, confirmText, clearText, value, minDate, maxDate, disabled, error, onChange, onClear, formatValue, formatMonth, renderPicker, icon, iconSource, closeAccessibilityLabel, style, fieldStyle, }: DateFieldProps): React.JSX.Element;
|
package/dist/date.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDateOnly = isDateOnly;
|
|
4
|
+
exports.isDateInRange = isDateInRange;
|
|
5
|
+
exports.todayDateOnly = todayDateOnly;
|
|
6
|
+
exports.formatDateOnly = formatDateOnly;
|
|
7
|
+
exports.addDateMonths = addDateMonths;
|
|
8
|
+
exports.DateField = DateField;
|
|
9
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const react_native_1 = require("react-native");
|
|
12
|
+
const react_native_calendars_1 = require("react-native-calendars");
|
|
13
|
+
const theme_1 = require("./theme");
|
|
14
|
+
const primitives_1 = require("./primitives");
|
|
15
|
+
const fields_1 = require("./fields");
|
|
16
|
+
const overlays_1 = require("./overlays");
|
|
17
|
+
const icons_1 = require("./icons");
|
|
18
|
+
/** Validates date-only values without parsing through UTC or applying a timezone. */
|
|
19
|
+
function isDateOnly(value) {
|
|
20
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
21
|
+
if (!match)
|
|
22
|
+
return false;
|
|
23
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
24
|
+
if (year < 1 || month < 1 || month > 12 || day < 1)
|
|
25
|
+
return false;
|
|
26
|
+
const days = month === 2
|
|
27
|
+
? year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
28
|
+
? 29
|
|
29
|
+
: 28
|
|
30
|
+
: [4, 6, 9, 11].includes(month)
|
|
31
|
+
? 30
|
|
32
|
+
: 31;
|
|
33
|
+
return day <= days;
|
|
34
|
+
}
|
|
35
|
+
function isDateInRange(value, minDate, maxDate) {
|
|
36
|
+
return (isDateOnly(value) &&
|
|
37
|
+
(!minDate || value >= minDate) &&
|
|
38
|
+
(!maxDate || value <= maxDate));
|
|
39
|
+
}
|
|
40
|
+
function todayDateOnly() {
|
|
41
|
+
const now = new Date();
|
|
42
|
+
return `${String(now.getFullYear()).padStart(4, "0")}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
43
|
+
}
|
|
44
|
+
function formatDateOnly(value) {
|
|
45
|
+
return isDateOnly(value) ? value.split("-").reverse().join("/") : value;
|
|
46
|
+
}
|
|
47
|
+
function addDateMonths(value, amount) {
|
|
48
|
+
const [year, month] = value.split("-").map(Number);
|
|
49
|
+
const index = year * 12 + month - 1 + amount;
|
|
50
|
+
return `${String(Math.floor(index / 12)).padStart(4, "0")}-${String((((index % 12) + 12) % 12) + 1).padStart(2, "0")}-01`;
|
|
51
|
+
}
|
|
52
|
+
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, }) {
|
|
53
|
+
const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
|
|
54
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
55
|
+
const [selectedDate, setSelectedDate] = (0, react_1.useState)(null);
|
|
56
|
+
const [currentMonth, setCurrentMonth] = (0, react_1.useState)(todayDateOnly);
|
|
57
|
+
const validSelection = !!selectedDate && isDateInRange(selectedDate, minDate, maxDate);
|
|
58
|
+
const open = () => {
|
|
59
|
+
const selected = value && isDateOnly(value) ? value : null;
|
|
60
|
+
let month = selected ?? todayDateOnly();
|
|
61
|
+
if (minDate && month < minDate)
|
|
62
|
+
month = minDate;
|
|
63
|
+
if (maxDate && month > maxDate)
|
|
64
|
+
month = maxDate;
|
|
65
|
+
setSelectedDate(selected);
|
|
66
|
+
setCurrentMonth(month);
|
|
67
|
+
setVisible(true);
|
|
68
|
+
};
|
|
69
|
+
const select = (date) => {
|
|
70
|
+
if (isDateInRange(date, minDate, maxDate))
|
|
71
|
+
setSelectedDate(date);
|
|
72
|
+
};
|
|
73
|
+
const confirm = () => {
|
|
74
|
+
if (validSelection && selectedDate) {
|
|
75
|
+
onChange(selectedDate);
|
|
76
|
+
setVisible(false);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const calendarTheme = (0, react_1.useMemo)(() => ({
|
|
80
|
+
backgroundColor: c.background,
|
|
81
|
+
calendarBackground: c.background,
|
|
82
|
+
dayTextColor: c.content1,
|
|
83
|
+
textDisabledColor: c.content4,
|
|
84
|
+
monthTextColor: c.content1,
|
|
85
|
+
textMonthFontWeight: "600",
|
|
86
|
+
todayTextColor: c.primary500,
|
|
87
|
+
arrowColor: c.primary500,
|
|
88
|
+
textSectionTitleColor: c.content2,
|
|
89
|
+
}), [c]);
|
|
90
|
+
// Calendar caches theme styles at mount, including weekday/disabled text.
|
|
91
|
+
const calendarPaletteKey = `${JSON.stringify(calendarTheme)}:${c.textPrimary}`;
|
|
92
|
+
const monthLabel = formatMonth?.(currentMonth) ??
|
|
93
|
+
`${currentMonth.slice(5, 7)}/${currentMonth.slice(0, 4)}`;
|
|
94
|
+
const calendarHeader = () => ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
|
|
95
|
+
styles.calendarHeader,
|
|
96
|
+
{ paddingHorizontal: s.sm, paddingVertical: s.sm },
|
|
97
|
+
], children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.arrows, { gap: s.lg }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -12)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u00AB" }) }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Previous month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, -1)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u2039" }) })] }), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { weight: "600", style: styles.monthLabel, children: monthLabel }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.arrows, { gap: s.lg }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Next month", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 1)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u203A" }) }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: "Next year", hitSlop: 8, onPress: () => setCurrentMonth((prev) => addDateMonths(prev, 12)), children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "title", color: "content3", children: "\u00BB" }) })] })] }));
|
|
98
|
+
return ((0, jsx_runtime_1.jsxs)(fields_1.Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { disabled: disabled, onPress: open, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: [
|
|
99
|
+
styles.field,
|
|
100
|
+
{
|
|
101
|
+
minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
|
|
102
|
+
...(variant === "form" ? { height: s.xxl * 2 } : {}),
|
|
103
|
+
gap: s.sm,
|
|
104
|
+
paddingHorizontal: variant === "form" ? s.lg : s.md,
|
|
105
|
+
borderColor: error ? c.danger : c.gray200,
|
|
106
|
+
borderRadius: variant === "form" ? r.lg : r.md,
|
|
107
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
108
|
+
opacity: disabled && variant === "form" ? 0.5 : 1,
|
|
109
|
+
},
|
|
110
|
+
fieldStyle,
|
|
111
|
+
], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: value ? "content1" : "content3", style: styles.flex, children: value ? formatValue(value) : placeholder }), icon ??
|
|
112
|
+
(iconSource ? ((0, jsx_runtime_1.jsx)(react_native_1.Image, { source: iconSource, resizeMode: "contain", style: { width: s.xl, height: s.xl, tintColor: c.content2 } })) : ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "calendar", size: 20, color: c.content2 })))] }), (0, jsx_runtime_1.jsxs)(overlays_1.Sheet, { visible: visible, onClose: () => setVisible(false), title: label, closeAccessibilityLabel: closeAccessibilityLabel, children: [visible &&
|
|
113
|
+
(renderPicker ? (renderPicker({
|
|
114
|
+
selectedDate,
|
|
115
|
+
currentMonth,
|
|
116
|
+
onSelect: select,
|
|
117
|
+
onMonthChange: setCurrentMonth,
|
|
118
|
+
minDate,
|
|
119
|
+
maxDate,
|
|
120
|
+
})) : ((0, jsx_runtime_1.jsx)(react_native_calendars_1.Calendar, { current: currentMonth, theme: calendarTheme, minDate: minDate, maxDate: maxDate, markedDates: selectedDate
|
|
121
|
+
? {
|
|
122
|
+
[selectedDate]: {
|
|
123
|
+
selected: true,
|
|
124
|
+
selectedColor: c.primary500,
|
|
125
|
+
selectedTextColor: c.textPrimary,
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
: {}, onDayPress: (day) => select(day.dateString), onMonthChange: (month) => setCurrentMonth(month.dateString), hideArrows: true, renderHeader: calendarHeader, enableSwipeMonths: true }, `${currentMonth}:${calendarPaletteKey}`))), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
|
|
129
|
+
styles.footer,
|
|
130
|
+
{ gap: s.md, paddingHorizontal: s.xl, paddingTop: s.lg },
|
|
131
|
+
], children: [onClear && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { label: clearText ?? "", variant: "outline", disabled: !selectedDate && !value, onPress: () => {
|
|
132
|
+
setSelectedDate(null);
|
|
133
|
+
onClear();
|
|
134
|
+
setVisible(false);
|
|
135
|
+
}, style: styles.flex })), (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: confirmText, disabled: !validSelection, onPress: confirm, style: styles.flex })] })] })] }));
|
|
136
|
+
}
|
|
137
|
+
const styles = react_native_1.StyleSheet.create({
|
|
138
|
+
field: {
|
|
139
|
+
borderWidth: 1,
|
|
140
|
+
flexDirection: "row",
|
|
141
|
+
alignItems: "center",
|
|
142
|
+
justifyContent: "space-between",
|
|
143
|
+
},
|
|
144
|
+
flex: { flex: 1 },
|
|
145
|
+
footer: { flexDirection: "row" },
|
|
146
|
+
calendarHeader: {
|
|
147
|
+
flexDirection: "row",
|
|
148
|
+
alignItems: "center",
|
|
149
|
+
justifyContent: "space-between",
|
|
150
|
+
},
|
|
151
|
+
arrows: { flexDirection: "row", alignItems: "center" },
|
|
152
|
+
monthLabel: { flex: 1, textAlign: "center" },
|
|
153
|
+
});
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { PressableProps, StyleProp, TextInputProps, TextStyle, ViewStyle } from "react-native";
|
|
3
|
+
export interface FieldProps {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
hint?: React.ReactNode;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
11
|
+
}
|
|
12
|
+
export declare function Field({ label, required, error, hint, children, style, labelStyle, }: FieldProps): React.JSX.Element;
|
|
13
|
+
export interface TextFieldProps extends TextInputProps {
|
|
14
|
+
label?: string;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
hint?: React.ReactNode;
|
|
18
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
19
|
+
showCount?: boolean;
|
|
20
|
+
countLabel?: string;
|
|
21
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
22
|
+
}
|
|
23
|
+
export declare function TextField({ label, required, error, hint, containerStyle, showCount, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }: TextFieldProps): React.JSX.Element;
|
|
24
|
+
/** Display-only trigger for an app-owned picker or modal. No picker state is stored here. */
|
|
25
|
+
export interface PressableFieldProps extends Omit<PressableProps, "children" | "style"> {
|
|
26
|
+
variant?: "default" | "form" | "filter";
|
|
27
|
+
label?: React.ReactNode;
|
|
28
|
+
value?: React.ReactNode;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
hint?: React.ReactNode;
|
|
33
|
+
loading?: boolean;
|
|
34
|
+
icon?: React.ReactNode;
|
|
35
|
+
trailing?: React.ReactNode;
|
|
36
|
+
style?: StyleProp<ViewStyle>;
|
|
37
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
38
|
+
fieldStyle?: StyleProp<ViewStyle>;
|
|
39
|
+
valueStyle?: StyleProp<TextStyle>;
|
|
40
|
+
placeholderStyle?: StyleProp<TextStyle>;
|
|
41
|
+
}
|
|
42
|
+
export declare function PressableField({ variant, label, value, placeholder, required, error, hint, loading, disabled, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }: PressableFieldProps): React.JSX.Element;
|
|
43
|
+
export interface TimePickerRenderProps {
|
|
44
|
+
visible: boolean;
|
|
45
|
+
value: string;
|
|
46
|
+
onClose: () => void;
|
|
47
|
+
onConfirm: (time: string) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface TimeFieldProps {
|
|
50
|
+
label?: string;
|
|
51
|
+
value: string;
|
|
52
|
+
onChange: (time: string) => void;
|
|
53
|
+
renderPicker: (props: TimePickerRenderProps) => React.ReactNode;
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
required?: boolean;
|
|
56
|
+
error?: string;
|
|
57
|
+
clearable?: boolean;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
clearAccessibilityLabel?: string;
|
|
60
|
+
icon?: React.ReactNode;
|
|
61
|
+
clearIcon?: React.ReactNode;
|
|
62
|
+
style?: StyleProp<ViewStyle>;
|
|
63
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
64
|
+
fieldStyle?: StyleProp<ViewStyle>;
|
|
65
|
+
valueStyle?: StyleProp<TextStyle>;
|
|
66
|
+
}
|
|
67
|
+
/** Complete time field UI; the app supplies its native picker implementation. */
|
|
68
|
+
export declare function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable, disabled, clearAccessibilityLabel, icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }: TimeFieldProps): React.JSX.Element;
|
|
69
|
+
export interface SelectOption<Value = unknown> {
|
|
70
|
+
label: string;
|
|
71
|
+
value: Value;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
export interface SelectFieldProps<T extends {
|
|
75
|
+
label: string;
|
|
76
|
+
value: unknown;
|
|
77
|
+
}> {
|
|
78
|
+
variant?: "default" | "form";
|
|
79
|
+
options: readonly T[];
|
|
80
|
+
value?: T | null;
|
|
81
|
+
onChange: (option: T) => void;
|
|
82
|
+
label?: string;
|
|
83
|
+
placeholder?: string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
error?: string;
|
|
86
|
+
disabled?: boolean;
|
|
87
|
+
loading?: boolean;
|
|
88
|
+
searchable?: boolean;
|
|
89
|
+
/** Size the sheet from the window and let the list fill the remaining space. */
|
|
90
|
+
fixedSheetHeight?: boolean;
|
|
91
|
+
/** Maximum fraction of the window occupied by the options sheet. */
|
|
92
|
+
sheetHeightRatio?: number;
|
|
93
|
+
keyboardAvoiding?: boolean;
|
|
94
|
+
localSearch?: boolean;
|
|
95
|
+
searchKey?: keyof T;
|
|
96
|
+
searchFilter?: (option: T, query: string) => boolean;
|
|
97
|
+
onSearch?: (query: string) => void;
|
|
98
|
+
searchDelay?: number;
|
|
99
|
+
searchPlaceholder?: string;
|
|
100
|
+
autoFocus?: boolean;
|
|
101
|
+
emptyText?: string;
|
|
102
|
+
noResultsText?: string;
|
|
103
|
+
renderSelected?: (option: T) => React.ReactNode;
|
|
104
|
+
icon?: React.ReactNode;
|
|
105
|
+
closeAccessibilityLabel?: string;
|
|
106
|
+
style?: StyleProp<ViewStyle>;
|
|
107
|
+
fieldStyle?: StyleProp<ViewStyle>;
|
|
108
|
+
}
|
|
109
|
+
export declare function SelectField<T extends {
|
|
110
|
+
label: string;
|
|
111
|
+
value: unknown;
|
|
112
|
+
}>({ variant, options, value, onChange, label, placeholder, required, error, disabled, loading, searchable, fixedSheetHeight, sheetHeightRatio, keyboardAvoiding, localSearch, searchKey, searchFilter, onSearch, searchDelay, searchPlaceholder, autoFocus, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }: SelectFieldProps<T>): React.JSX.Element;
|
|
113
|
+
export interface Attachment {
|
|
114
|
+
id?: string;
|
|
115
|
+
name: string;
|
|
116
|
+
[key: string]: unknown;
|
|
117
|
+
}
|
|
118
|
+
export interface AttachmentFieldProps<T extends {
|
|
119
|
+
name: string;
|
|
120
|
+
}> {
|
|
121
|
+
title?: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
buttonText: string;
|
|
124
|
+
files: readonly T[];
|
|
125
|
+
loading?: boolean;
|
|
126
|
+
disabled?: boolean;
|
|
127
|
+
openingId?: string | null;
|
|
128
|
+
getId?: (file: T, index: number) => string;
|
|
129
|
+
onPick: () => void;
|
|
130
|
+
onOpen?: (file: T, index: number) => void;
|
|
131
|
+
onRemove?: (file: T, index: number) => void;
|
|
132
|
+
illustration?: React.ReactNode;
|
|
133
|
+
pickIcon?: React.ReactNode;
|
|
134
|
+
removeIcon?: React.ReactNode;
|
|
135
|
+
removeAccessibilityLabel?: string;
|
|
136
|
+
style?: StyleProp<ViewStyle>;
|
|
137
|
+
}
|
|
138
|
+
export declare function AttachmentField<T extends {
|
|
139
|
+
name: string;
|
|
140
|
+
}>({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel, style, }: AttachmentFieldProps<T>): React.JSX.Element;
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = Field;
|
|
4
|
+
exports.TextField = TextField;
|
|
5
|
+
exports.PressableField = PressableField;
|
|
6
|
+
exports.TimeField = TimeField;
|
|
7
|
+
exports.SelectField = SelectField;
|
|
8
|
+
exports.AttachmentField = AttachmentField;
|
|
9
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const react_native_1 = require("react-native");
|
|
12
|
+
const theme_1 = require("./theme");
|
|
13
|
+
const primitives_1 = require("./primitives");
|
|
14
|
+
const icons_1 = require("./icons");
|
|
15
|
+
const overlays_1 = require("./overlays");
|
|
16
|
+
const list_picker_1 = require("./list-picker");
|
|
17
|
+
function Field({ label, required, error, hint, children, style, labelStyle, }) {
|
|
18
|
+
const { spacing: s } = (0, theme_1.useUITheme)();
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ gap: s.xs }, style], children: [label != null && ((0, jsx_runtime_1.jsxs)(primitives_1.UIText, { variant: "label", color: "content2", style: labelStyle, children: [label, required && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "danger", children: "*" }))] })), children, hint != null &&
|
|
20
|
+
(typeof hint === "string" ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "caption", color: "content2", children: hint })) : (hint)), !!error && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "caption", color: "danger", accessibilityLiveRegion: "polite", children: error }))] }));
|
|
21
|
+
}
|
|
22
|
+
function TextField({ label, required, error, hint, containerStyle, showCount = false, countLabel, labelStyle, style, multiline, editable, placeholderTextColor, ...props }) {
|
|
23
|
+
const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(Field, { label: label, required: required, error: error, hint: hint, style: containerStyle, labelStyle: labelStyle, children: [(0, jsx_runtime_1.jsx)(react_native_1.TextInput, { ...props, editable: editable, multiline: multiline, placeholderTextColor: placeholderTextColor ?? c.content3, textAlignVertical: multiline ? "top" : "center", accessibilityLabel: props.accessibilityLabel ?? label, style: [
|
|
25
|
+
{
|
|
26
|
+
minHeight: multiline ? s.xxl * 4 : s.xxl + s.xl,
|
|
27
|
+
borderWidth: 1,
|
|
28
|
+
borderColor: error ? c.danger : c.gray200,
|
|
29
|
+
borderRadius: r.md,
|
|
30
|
+
paddingHorizontal: s.md,
|
|
31
|
+
paddingVertical: multiline ? s.md : s.sm,
|
|
32
|
+
backgroundColor: editable === false ? c.gray50 : c.background,
|
|
33
|
+
color: c.content1,
|
|
34
|
+
fontSize: t.body,
|
|
35
|
+
fontFamily: t.fontFamily,
|
|
36
|
+
},
|
|
37
|
+
style,
|
|
38
|
+
] }), showCount && ((0, jsx_runtime_1.jsxs)(primitives_1.UIText, { variant: "caption", color: "content2", style: styles.count, children: [props.value?.length ?? 0, props.maxLength != null ? `/${props.maxLength}` : "", countLabel ? ` ${countLabel}` : ""] }))] }));
|
|
39
|
+
}
|
|
40
|
+
function PressableField({ variant = "default", label, value, placeholder, required, error, hint, loading = false, disabled = false, icon, trailing, style, labelStyle, fieldStyle, valueStyle, placeholderStyle, ...props }) {
|
|
41
|
+
const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
|
|
42
|
+
const filter = variant === "filter";
|
|
43
|
+
const largeField = variant !== "default";
|
|
44
|
+
const hasValue = value !== undefined && value !== null && value !== "";
|
|
45
|
+
const textValue = !hasValue || typeof value === "string" || typeof value === "number";
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(Field, { label: label, required: required, error: error, hint: hint, labelStyle: [
|
|
47
|
+
filter && { fontSize: t.body, fontWeight: "500", color: c.content1 },
|
|
48
|
+
labelStyle,
|
|
49
|
+
], style: [
|
|
50
|
+
variant === "form" && { marginBottom: s.lg, gap: s.sm },
|
|
51
|
+
filter && { gap: s.sm },
|
|
52
|
+
style,
|
|
53
|
+
], children: (0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { ...props, disabled: disabled || loading, accessibilityRole: props.accessibilityRole ?? "button", accessibilityLabel: props.accessibilityLabel ??
|
|
54
|
+
(typeof label === "string" ? label : placeholder), accessibilityState: {
|
|
55
|
+
...props.accessibilityState,
|
|
56
|
+
disabled: disabled || loading,
|
|
57
|
+
busy: loading,
|
|
58
|
+
}, style: [
|
|
59
|
+
styles.selector,
|
|
60
|
+
{
|
|
61
|
+
minHeight: largeField ? s.xxl * 2 : s.xxl + s.xl,
|
|
62
|
+
...(largeField ? { height: s.xxl * 2 } : {}),
|
|
63
|
+
gap: s.sm,
|
|
64
|
+
paddingHorizontal: filter
|
|
65
|
+
? (s.md + s.lg) / 2
|
|
66
|
+
: variant === "form"
|
|
67
|
+
? s.lg
|
|
68
|
+
: s.md,
|
|
69
|
+
borderColor: error ? c.danger : c.gray200,
|
|
70
|
+
borderRadius: largeField ? r.lg : r.md,
|
|
71
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
72
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
73
|
+
},
|
|
74
|
+
fieldStyle,
|
|
75
|
+
], children: [loading ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: c.primary500 })) : textValue ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: hasValue ? "content1" : filter ? "content2" : "content3", style: [styles.flex, hasValue ? valueStyle : placeholderStyle], children: hasValue ? value : placeholder })) : ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.flex, children: value })), trailing ?? icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }) }));
|
|
76
|
+
}
|
|
77
|
+
/** Complete time field UI; the app supplies its native picker implementation. */
|
|
78
|
+
function TimeField({ label, value, onChange, renderPicker, placeholder, required, error, clearable = false, disabled = false, clearAccessibilityLabel = "Clear time", icon, clearIcon, style, labelStyle, fieldStyle, valueStyle, }) {
|
|
79
|
+
const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
|
|
80
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
81
|
+
const hasValue = !!value;
|
|
82
|
+
const iconSize = s.lg + s.xs / 2;
|
|
83
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ flex: 1, marginBottom: s.lg }, style], children: [label != null && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { flexDirection: "row", marginBottom: s.sm }, children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: "content2", style: [{ fontSize: t.body }, labelStyle], children: label }), required && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "danger", style: { fontSize: t.body, marginLeft: s.xs / 2 }, children: "*" }))] })), (0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { disabled: disabled, onPress: () => setVisible(true), accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: { disabled, expanded: visible }, style: ({ pressed }) => [
|
|
84
|
+
styles.selector,
|
|
85
|
+
{
|
|
86
|
+
height: s.xxl * 2,
|
|
87
|
+
paddingHorizontal: s.lg,
|
|
88
|
+
borderColor: error ? c.danger : c.gray200,
|
|
89
|
+
borderRadius: r.lg,
|
|
90
|
+
backgroundColor: c.gray50,
|
|
91
|
+
opacity: disabled ? 0.5 : pressed ? 0.2 : 1,
|
|
92
|
+
},
|
|
93
|
+
fieldStyle,
|
|
94
|
+
], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: [
|
|
95
|
+
styles.flex,
|
|
96
|
+
{
|
|
97
|
+
fontSize: (t.body + t.subtitle) / 2,
|
|
98
|
+
color: hasValue ? c.content1 : c.content4,
|
|
99
|
+
},
|
|
100
|
+
valueStyle,
|
|
101
|
+
], children: hasValue ? value : placeholder }), clearable && hasValue ? ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { disabled: disabled, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, onPress: (event) => {
|
|
102
|
+
event.stopPropagation();
|
|
103
|
+
onChange("");
|
|
104
|
+
}, children: clearIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: iconSize, color: c.content3 })) })) : ((icon ?? (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "clock", size: iconSize, color: c.content3 })))] }), !!error && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "danger", accessibilityLiveRegion: "polite", style: { marginTop: s.xs }, children: error })), visible &&
|
|
105
|
+
renderPicker({
|
|
106
|
+
visible,
|
|
107
|
+
value,
|
|
108
|
+
onClose: () => setVisible(false),
|
|
109
|
+
onConfirm: (time) => {
|
|
110
|
+
onChange(time);
|
|
111
|
+
setVisible(false);
|
|
112
|
+
},
|
|
113
|
+
})] }));
|
|
114
|
+
}
|
|
115
|
+
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, }) {
|
|
116
|
+
const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
|
|
117
|
+
const { height } = (0, react_native_1.useWindowDimensions)();
|
|
118
|
+
const sheetHeight = height * sheetHeightRatio;
|
|
119
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
120
|
+
const [query, setQuery] = (0, react_1.useState)("");
|
|
121
|
+
const searchCallback = (0, react_1.useRef)(onSearch);
|
|
122
|
+
searchCallback.current = onSearch;
|
|
123
|
+
(0, react_1.useEffect)(() => {
|
|
124
|
+
if (!visible || !searchable || localSearch)
|
|
125
|
+
return;
|
|
126
|
+
const timer = setTimeout(() => searchCallback.current?.(query), searchDelay);
|
|
127
|
+
return () => clearTimeout(timer);
|
|
128
|
+
}, [query, searchDelay, visible, searchable, localSearch]);
|
|
129
|
+
const filtered = (0, react_1.useMemo)(() => {
|
|
130
|
+
if (!searchable || !localSearch || !query.trim())
|
|
131
|
+
return options;
|
|
132
|
+
const normalized = query.trim().toLocaleLowerCase();
|
|
133
|
+
return options.filter((option) => searchFilter
|
|
134
|
+
? searchFilter(option, query)
|
|
135
|
+
: String(searchKey ? (option[searchKey] ?? "") : option.label)
|
|
136
|
+
.toLocaleLowerCase()
|
|
137
|
+
.includes(normalized));
|
|
138
|
+
}, [options, searchable, localSearch, query, searchKey, searchFilter]);
|
|
139
|
+
const open = () => {
|
|
140
|
+
if (disabled || loading)
|
|
141
|
+
return;
|
|
142
|
+
if (keyboardAvoiding && searchable)
|
|
143
|
+
react_native_1.Keyboard.dismiss();
|
|
144
|
+
setQuery("");
|
|
145
|
+
setVisible(true);
|
|
146
|
+
};
|
|
147
|
+
return ((0, jsx_runtime_1.jsxs)(Field, { label: label, required: required, error: error, style: [variant === "form" && { marginBottom: s.lg, gap: s.sm }, style], children: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: open, disabled: disabled || loading, accessibilityRole: "button", accessibilityLabel: label ?? placeholder, accessibilityState: {
|
|
148
|
+
disabled: disabled || loading,
|
|
149
|
+
expanded: visible,
|
|
150
|
+
busy: loading,
|
|
151
|
+
}, style: [
|
|
152
|
+
styles.selector,
|
|
153
|
+
{
|
|
154
|
+
minHeight: variant === "form" ? s.xxl * 2 : s.xxl + s.xl,
|
|
155
|
+
...(variant === "form" ? { height: s.xxl * 2 } : {}),
|
|
156
|
+
gap: s.sm,
|
|
157
|
+
paddingHorizontal: variant === "form" ? s.lg : s.md,
|
|
158
|
+
borderColor: error ? c.danger : c.gray200,
|
|
159
|
+
borderRadius: variant === "form" ? r.lg : r.md,
|
|
160
|
+
backgroundColor: disabled ? c.gray50 : c.background,
|
|
161
|
+
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
162
|
+
},
|
|
163
|
+
fieldStyle,
|
|
164
|
+
], children: [loading ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: c.primary500 })) : value ? (renderSelected ? (renderSelected(value)) : ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: styles.flex, children: value.label }))) : ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: "content3", style: styles.flex, children: placeholder })), icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "chevron", size: 16, color: disabled ? c.content4 : c.content2 }))] }), (0, jsx_runtime_1.jsxs)(overlays_1.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 && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
|
|
165
|
+
styles.search,
|
|
166
|
+
{
|
|
167
|
+
marginHorizontal: s.lg,
|
|
168
|
+
marginBottom: s.md,
|
|
169
|
+
gap: s.sm,
|
|
170
|
+
paddingHorizontal: s.md,
|
|
171
|
+
minHeight: s.xl * 2,
|
|
172
|
+
borderRadius: r.md,
|
|
173
|
+
backgroundColor: c.gray50,
|
|
174
|
+
},
|
|
175
|
+
], children: [(0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "search", size: 16, color: c.content3 }), visible && ((0, jsx_runtime_1.jsx)(react_native_1.TextInput, { placeholder: searchPlaceholder, placeholderTextColor: c.content3, value: query, onChangeText: setQuery, autoFocus: autoFocus, autoCorrect: false, autoComplete: "off", importantForAutofill: "no", style: {
|
|
176
|
+
flex: 1,
|
|
177
|
+
color: c.content1,
|
|
178
|
+
fontSize: t.body,
|
|
179
|
+
fontFamily: t.fontFamily,
|
|
180
|
+
} }))] })), (0, jsx_runtime_1.jsx)(list_picker_1.ListPicker, { items: filtered, getKey: option => option.value, getLabel: option => option.label, value: value, onChange: option => {
|
|
181
|
+
onChange(option);
|
|
182
|
+
setVisible(false);
|
|
183
|
+
}, loading: loading, listStyle: fixedSheetHeight ? styles.fixedSheetList : undefined, emptyText: query ? (noResultsText ?? emptyText) : emptyText })] })] }));
|
|
184
|
+
}
|
|
185
|
+
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 } = (0, theme_1.useUITheme)();
|
|
187
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [{ gap: s.sm }, style], children: [title != null && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "content2", children: title })), (0, jsx_runtime_1.jsxs)(react_native_1.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 ?? (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "folder", color: c.primary500, size: 24 }), description != null && ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { variant: "label", color: "content3", style: styles.center, children: description })), (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: buttonText, size: "small", onPress: onPick, loading: loading, disabled: disabled, leading: pickIcon ?? (0, jsx_runtime_1.jsx)(icons_1.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 ((0, jsx_runtime_1.jsxs)(react_native_1.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: [(0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => onOpen?.(file, index), disabled: !onOpen || openingId === id, accessibilityRole: "button", accessibilityLabel: file.name, style: [styles.selectItem, styles.flex, { gap: s.sm }], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, style: {
|
|
209
|
+
flex: 1,
|
|
210
|
+
fontSize: 13,
|
|
211
|
+
textDecorationLine: onOpen ? "underline" : "none",
|
|
212
|
+
}, children: file.name }), openingId === id && ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.content2, size: "small" }))] }), onRemove && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { hitSlop: 8, disabled: disabled, onPress: () => onRemove(file, index), accessibilityRole: "button", accessibilityLabel: `${removeAccessibilityLabel}: ${file.name}`, children: removeIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", color: c.content2, size: 14 })) }))] }, id));
|
|
213
|
+
})] }));
|
|
214
|
+
}
|
|
215
|
+
const styles = react_native_1.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
|
+
fixedSheetList: { flex: 1, minHeight: 0 },
|
|
225
|
+
center: { textAlign: "center" },
|
|
226
|
+
search: { flexDirection: "row", alignItems: "center" },
|
|
227
|
+
selectItem: {
|
|
228
|
+
flexDirection: "row",
|
|
229
|
+
alignItems: "center",
|
|
230
|
+
justifyContent: "space-between",
|
|
231
|
+
},
|
|
232
|
+
attachment: { flexDirection: "row", alignItems: "center" },
|
|
233
|
+
});
|