@thanhphi/unistyles-ui 0.2.6 → 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/README.md +10 -0
- package/dist/fields.d.ts +4 -2
- package/dist/fields.js +9 -16
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +3 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/list-picker.d.ts +45 -0
- package/dist/list-picker.js +76 -0
- package/dist/module/fields.js +10 -17
- package/dist/module/icons.js +3 -2
- package/dist/module/index.js +3 -0
- package/dist/module/list-picker.js +70 -0
- package/dist/module/overlays.js +71 -35
- package/dist/module/search.js +88 -0
- package/dist/module/ui-modal.js +145 -0
- package/dist/overlays.d.ts +21 -1
- package/dist/overlays.js +71 -34
- package/dist/search.d.ts +27 -0
- package/dist/search.js +91 -0
- package/dist/ui-modal.d.ts +17 -0
- package/dist/ui-modal.js +151 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,16 @@ import { Button, CollapsibleSection, DateField, InfoRow } from '@thanhphi/unisty
|
|
|
203
203
|
|
|
204
204
|
`AttachmentField` nhận danh sách file và callback pick/open/remove; app tự thực hiện picker/upload/preview. Dialog/sheet controlled visibility, không lưu ref/global callback trong package. Thư viện không chứa API, refresh token, upload, validation nghiệp vụ hoặc thư viện dịch.
|
|
205
205
|
|
|
206
|
+
`Sheet` nhận `heightRatio` để đặt chiều cao theo cửa sổ và `keyboardAvoiding` để dành chỗ cho bàn phím. Dùng `showHandle`, `description`, `headerStart`, `headerEnd`, `headerStyle` và `titleNumberOfLines` để tùy chỉnh header. `headerEnd` mặc định hiển thị nút đóng. Với danh sách tìm kiếm, đặt phần danh sách `flex: 1` để giữ vùng hiển thị kể cả khi kết quả rỗng. `SelectField` đã làm việc này khi bật `fixedSheetHeight` và nhận `sheetHeightRatio` để tùy chỉnh tỷ lệ mặc định 70%.
|
|
207
|
+
|
|
208
|
+
Dùng `onOpened` để dựng nội dung sau khi hiệu ứng mở kết thúc và `onClosed` để xử lý lựa chọn sau khi sheet đóng. `onClose` nhận yêu cầu đóng từ nút X, nền mờ hoặc nút Back trên Android.
|
|
209
|
+
|
|
210
|
+
`UIModal` dùng cùng vòng đời với `Sheet` và hỗ trợ `position="center"`, `"bottom"` hoặc `"fullScreen"`. Trong `Sheet`, nút X mặc định nằm ở góc trên bên phải. Các hành động truyền qua `headerStart` và `headerEnd` nằm trong hàng tiêu đề. Truyền `showHandle={false}` để ẩn thanh ngang.
|
|
211
|
+
|
|
212
|
+
`ListPicker` có thể đặt bên trong `Sheet` hoặc `UIModal`. Truyền `items`, `getKey`, `getLabel`, `value` và `onChange`. Với `multiple`, `onChange` nhận mảng sau khi người dùng xác nhận. Dùng `searchPlaceholder` cho tìm kiếm local. Khi có `onSearch`, picker chuyển từ khóa sang hook của ứng dụng. Với React Query hoặc API phân trang, hook truyền kết quả, trạng thái tải, `onRetry` và `onLoadMore` vào picker.
|
|
213
|
+
|
|
214
|
+
`SearchBar` nhận `value`, `onChangeText`, `onSubmit` và `onClear` để app quản lý tìm kiếm. Truyền `onPress` để mở màn tìm kiếm khi chạm vào ô. Dùng `fieldStyle` và `textStyle` để tùy chỉnh bố cục và chữ theo màn. Thêm `filter={{ onPress, count, accessibilityLabel }}` để hiện nút lọc. Khi có bộ lọc đang bật, badge số lượng nằm trên mép trên bên phải của nút và được đọc qua trợ năng.
|
|
215
|
+
|
|
206
216
|
Props và type được export từ package root. Khi chia sẻ package qua Module Federation, cấu hình singleton cho `@thanhphi/unistyles-ui` và đặt provider ở root host app. Khi đóng gói UI riêng trong mini app, đặt provider của bản UI đó tại root mini app và đưa các overlay, portal vào cùng subtree. Host app cung cấp native dependencies và các token Unistyles mà mini app sử dụng.
|
|
207
217
|
|
|
208
218
|
## Form
|
package/dist/fields.d.ts
CHANGED
|
@@ -86,8 +86,10 @@ export interface SelectFieldProps<T extends {
|
|
|
86
86
|
disabled?: boolean;
|
|
87
87
|
loading?: boolean;
|
|
88
88
|
searchable?: boolean;
|
|
89
|
-
/**
|
|
89
|
+
/** Size the sheet from the window and let the list fill the remaining space. */
|
|
90
90
|
fixedSheetHeight?: boolean;
|
|
91
|
+
/** Maximum fraction of the window occupied by the options sheet. */
|
|
92
|
+
sheetHeightRatio?: number;
|
|
91
93
|
keyboardAvoiding?: boolean;
|
|
92
94
|
localSearch?: boolean;
|
|
93
95
|
searchKey?: keyof T;
|
|
@@ -107,7 +109,7 @@ export interface SelectFieldProps<T extends {
|
|
|
107
109
|
export declare function SelectField<T extends {
|
|
108
110
|
label: string;
|
|
109
111
|
value: unknown;
|
|
110
|
-
}>({ variant, options, value, onChange, label, placeholder, required, error, disabled, loading, searchable, fixedSheetHeight, keyboardAvoiding, localSearch, searchKey, searchFilter, onSearch, searchDelay, searchPlaceholder, autoFocus, emptyText, noResultsText, renderSelected, icon, closeAccessibilityLabel, style, fieldStyle, }: SelectFieldProps<T>): React.JSX.Element;
|
|
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;
|
|
111
113
|
export interface Attachment {
|
|
112
114
|
id?: string;
|
|
113
115
|
name: string;
|
package/dist/fields.js
CHANGED
|
@@ -13,6 +13,7 @@ const theme_1 = require("./theme");
|
|
|
13
13
|
const primitives_1 = require("./primitives");
|
|
14
14
|
const icons_1 = require("./icons");
|
|
15
15
|
const overlays_1 = require("./overlays");
|
|
16
|
+
const list_picker_1 = require("./list-picker");
|
|
16
17
|
function Field({ label, required, error, hint, children, style, labelStyle, }) {
|
|
17
18
|
const { spacing: s } = (0, theme_1.useUITheme)();
|
|
18
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 &&
|
|
@@ -111,10 +112,10 @@ function TimeField({ label, value, onChange, renderPicker, placeholder, required
|
|
|
111
112
|
},
|
|
112
113
|
})] }));
|
|
113
114
|
}
|
|
114
|
-
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, }) {
|
|
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, }) {
|
|
115
116
|
const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
|
|
116
117
|
const { height } = (0, react_native_1.useWindowDimensions)();
|
|
117
|
-
const sheetHeight = height *
|
|
118
|
+
const sheetHeight = height * sheetHeightRatio;
|
|
118
119
|
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
119
120
|
const [query, setQuery] = (0, react_1.useState)("");
|
|
120
121
|
const searchCallback = (0, react_1.useRef)(onSearch);
|
|
@@ -160,10 +161,7 @@ function SelectField({ variant = "default", options, value, onChange, label, pla
|
|
|
160
161
|
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
161
162
|
},
|
|
162
163
|
fieldStyle,
|
|
163
|
-
], 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, style: {
|
|
164
|
-
maxHeight: sheetHeight,
|
|
165
|
-
height: fixedSheetHeight ? sheetHeight : undefined,
|
|
166
|
-
}, children: [searchable && ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
|
|
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: [
|
|
167
165
|
styles.search,
|
|
168
166
|
{
|
|
169
167
|
marginHorizontal: s.lg,
|
|
@@ -179,16 +177,10 @@ function SelectField({ variant = "default", options, value, onChange, label, pla
|
|
|
179
177
|
color: c.content1,
|
|
180
178
|
fontSize: t.body,
|
|
181
179
|
fontFamily: t.fontFamily,
|
|
182
|
-
} }))] })),
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
setVisible(false);
|
|
187
|
-
}, style: [
|
|
188
|
-
styles.selectItem,
|
|
189
|
-
{ paddingVertical: s.md + 2, gap: s.sm },
|
|
190
|
-
], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: selected ? "primary500" : "content1", weight: selected ? "600" : "400", style: styles.flex, children: item.label }), selected && (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
|
|
191
|
-
}, ListEmptyComponent: !loading ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { paddingVertical: s.xxl + s.sm }, children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content3", style: styles.center, children: query ? (noResultsText ?? emptyText) : emptyText }) })) : null })] })] }));
|
|
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 })] })] }));
|
|
192
184
|
}
|
|
193
185
|
function AttachmentField({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel = "Remove file", style, }) {
|
|
194
186
|
const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
|
|
@@ -229,6 +221,7 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
229
221
|
justifyContent: "space-between",
|
|
230
222
|
},
|
|
231
223
|
flex: { flex: 1 },
|
|
224
|
+
fixedSheetList: { flex: 1, minHeight: 0 },
|
|
232
225
|
center: { textAlign: "center" },
|
|
233
226
|
search: { flexDirection: "row", alignItems: "center" },
|
|
234
227
|
selectItem: {
|
package/dist/icons.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface UIIconProps {
|
|
|
3
3
|
color: string;
|
|
4
4
|
size?: number;
|
|
5
5
|
}
|
|
6
|
-
type Name = "back" | "close" | "chevron" | "check" | "calendar" | "clock" | "search" | "folder" | "upload" | "file";
|
|
6
|
+
type Name = "back" | "close" | "chevron" | "check" | "calendar" | "clock" | "search" | "filter" | "folder" | "upload" | "file";
|
|
7
7
|
export declare function UIIcon({ name, color, size, }: UIIconProps & {
|
|
8
8
|
name: Name;
|
|
9
9
|
}): React.JSX.Element;
|
package/dist/icons.js
CHANGED
|
@@ -42,10 +42,11 @@ function UIIcon({ name, color, size = 20, }) {
|
|
|
42
42
|
close: "M6 6l12 12M18 6L6 18",
|
|
43
43
|
chevron: "M6 9l6 6 6-6",
|
|
44
44
|
check: "M5 12l4 4L19 6",
|
|
45
|
-
search: "
|
|
45
|
+
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",
|
|
46
|
+
filter: "M3 7h18M6 12h12M10 17h4",
|
|
46
47
|
folder: "M3 7V5h7l2 2h9v13H3V7zm9 4v6m-3-3h6",
|
|
47
48
|
upload: "M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6",
|
|
48
49
|
file: "M14 3H5v18h14V8l-5-5zm0 0v5h5M8 12h8M8 16h6",
|
|
49
50
|
};
|
|
50
|
-
return ((0, jsx_runtime_1.jsx)(react_native_svg_1.default, { width: size, height: size, viewBox: "0 0 24 24", fill: "none", children: name === "calendar" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Rect, { x: 3, y: 5, width: 18, height: 16, rx: 2, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M3 10h18M7 3v4M17 3v4M7 14h2M12 14h2M7 17h2M12 17h2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round" })] })) : name === "clock" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Circle, { cx: 12, cy: 12, r: 9, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M12 7v5l3 2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" })] })) : ((0, jsx_runtime_1.
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(react_native_svg_1.default, { width: size, height: size, viewBox: "0 0 24 24", fill: "none", children: name === "calendar" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Rect, { x: 3, y: 5, width: 18, height: 16, rx: 2, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M3 10h18M7 3v4M17 3v4M7 14h2M12 14h2M7 17h2M12 17h2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round" })] })) : name === "clock" ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Circle, { cx: 12, cy: 12, r: 9, stroke: color, strokeWidth: 1.7 }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: "M12 7v5l3 2", stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" })] })) : ((0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { d: paths[name], stroke: color, strokeWidth: name === "search" ? 1.5 : 1.7, strokeLinecap: "round", strokeLinejoin: "round" })) }));
|
|
51
52
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,13 @@ export * from "./theme";
|
|
|
3
3
|
export * from "./primitives";
|
|
4
4
|
export * from "./image";
|
|
5
5
|
export * from "./fields";
|
|
6
|
+
export * from "./search";
|
|
6
7
|
export * from "./date";
|
|
7
8
|
export * from "./overlays";
|
|
9
|
+
export * from "./ui-modal";
|
|
8
10
|
export * from "./choices";
|
|
9
11
|
export * from "./process-graph";
|
|
10
12
|
export { UIIcon } from "./icons";
|
|
11
13
|
export type { UIIconProps } from "./icons";
|
|
12
14
|
export { ScreenHeader as Header, CollapsibleSection as CollapsibleCard, } from "./primitives";
|
|
15
|
+
export * from "./list-picker";
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,10 @@ __exportStar(require("./theme"), exports);
|
|
|
19
19
|
__exportStar(require("./primitives"), exports);
|
|
20
20
|
__exportStar(require("./image"), exports);
|
|
21
21
|
__exportStar(require("./fields"), exports);
|
|
22
|
+
__exportStar(require("./search"), exports);
|
|
22
23
|
__exportStar(require("./date"), exports);
|
|
23
24
|
__exportStar(require("./overlays"), exports);
|
|
25
|
+
__exportStar(require("./ui-modal"), exports);
|
|
24
26
|
__exportStar(require("./choices"), exports);
|
|
25
27
|
__exportStar(require("./process-graph"), exports);
|
|
26
28
|
var icons_1 = require("./icons");
|
|
@@ -28,3 +30,4 @@ Object.defineProperty(exports, "UIIcon", { enumerable: true, get: function () {
|
|
|
28
30
|
var primitives_1 = require("./primitives");
|
|
29
31
|
Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return primitives_1.ScreenHeader; } });
|
|
30
32
|
Object.defineProperty(exports, "CollapsibleCard", { enumerable: true, get: function () { return primitives_1.CollapsibleSection; } });
|
|
33
|
+
__exportStar(require("./list-picker"), exports);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type FlatListProps, type StyleProp, type ViewStyle } from "react-native";
|
|
3
|
+
export type ListPickerListProps<T> = Pick<FlatListProps<T>, "style" | "keyExtractor" | "extraData" | "contentContainerStyle" | "ListEmptyComponent" | "ListFooterComponent" | "onEndReached" | "onEndReachedThreshold" | "refreshControl" | "showsVerticalScrollIndicator" | "keyboardShouldPersistTaps"> & {
|
|
4
|
+
data: readonly T[];
|
|
5
|
+
renderItem: (info: {
|
|
6
|
+
item: T;
|
|
7
|
+
}) => React.ReactElement | null;
|
|
8
|
+
ItemSeparatorComponent: React.ComponentType;
|
|
9
|
+
};
|
|
10
|
+
type Selection<T> = {
|
|
11
|
+
multiple?: false;
|
|
12
|
+
value?: T | null;
|
|
13
|
+
onChange: (value: T) => void;
|
|
14
|
+
} | {
|
|
15
|
+
multiple: true;
|
|
16
|
+
value?: readonly T[] | null;
|
|
17
|
+
onChange: (value: T[]) => void;
|
|
18
|
+
};
|
|
19
|
+
export type ListPickerProps<T> = Selection<T> & {
|
|
20
|
+
items: readonly T[];
|
|
21
|
+
getKey: (item: T) => unknown;
|
|
22
|
+
getLabel: (item: T) => string;
|
|
23
|
+
loading?: boolean;
|
|
24
|
+
loadingMore?: boolean;
|
|
25
|
+
refreshing?: boolean;
|
|
26
|
+
onRefresh?: () => void;
|
|
27
|
+
onLoadMore?: () => void;
|
|
28
|
+
onSearch?: (keyword: string) => void;
|
|
29
|
+
errorText?: string;
|
|
30
|
+
emptyText?: string;
|
|
31
|
+
onRetry?: () => void;
|
|
32
|
+
retryText?: string;
|
|
33
|
+
confirmText?: string;
|
|
34
|
+
searchPlaceholder?: string;
|
|
35
|
+
clearSearchAccessibilityLabel?: string;
|
|
36
|
+
search?: React.ReactNode;
|
|
37
|
+
loadingContent?: React.ReactNode;
|
|
38
|
+
listStyle?: StyleProp<ViewStyle>;
|
|
39
|
+
contentContainerStyle?: StyleProp<ViewStyle>;
|
|
40
|
+
footerStyle?: StyleProp<ViewStyle>;
|
|
41
|
+
renderList?: (props: ListPickerListProps<T>) => React.ReactNode;
|
|
42
|
+
renderItem?: (item: T, selected: boolean, onSelect: () => void) => React.ReactElement;
|
|
43
|
+
};
|
|
44
|
+
export declare function ListPicker<T>(props: ListPickerProps<T>): React.JSX.Element;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ListPicker = ListPicker;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const icons_1 = require("./icons");
|
|
11
|
+
const primitives_1 = require("./primitives");
|
|
12
|
+
const search_1 = require("./search");
|
|
13
|
+
const theme_1 = require("./theme");
|
|
14
|
+
function ListPicker(props) {
|
|
15
|
+
const { colors: c, spacing: s } = (0, theme_1.useUITheme)();
|
|
16
|
+
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;
|
|
17
|
+
const [keyword, setKeyword] = react_1.default.useState("");
|
|
18
|
+
const [draft, setDraft] = react_1.default.useState(null);
|
|
19
|
+
const selected = props.multiple ? draft ?? props.value ?? [] : undefined;
|
|
20
|
+
const selectedKeys = react_1.default.useMemo(() => selected && new Set(selected.map(getKey)), [getKey, selected]);
|
|
21
|
+
const singleKey = !props.multiple && props.value != null ? getKey(props.value) : undefined;
|
|
22
|
+
const normalized = keyword.trim().toLocaleLowerCase();
|
|
23
|
+
const data = react_1.default.useMemo(() => searchPlaceholder && !onSearch && normalized
|
|
24
|
+
? items.filter((item) => getLabel(item).toLocaleLowerCase().includes(normalized))
|
|
25
|
+
: items, [getLabel, items, normalized, onSearch, searchPlaceholder]);
|
|
26
|
+
const select = (item) => {
|
|
27
|
+
if (!props.multiple) {
|
|
28
|
+
props.onChange(item);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const key = getKey(item);
|
|
32
|
+
setDraft((previous) => {
|
|
33
|
+
const current = previous ?? props.value ?? [];
|
|
34
|
+
return current.some((option) => Object.is(getKey(option), key))
|
|
35
|
+
? current.filter((option) => !Object.is(getKey(option), key))
|
|
36
|
+
: [...current, item];
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const listProps = {
|
|
40
|
+
style: listStyle,
|
|
41
|
+
data,
|
|
42
|
+
extraData: selectedKeys ?? singleKey,
|
|
43
|
+
renderItem: ({ item }) => {
|
|
44
|
+
const key = getKey(item);
|
|
45
|
+
const isSelected = props.multiple
|
|
46
|
+
? !!selectedKeys?.has(key)
|
|
47
|
+
: props.value != null && Object.is(singleKey, key);
|
|
48
|
+
return renderItem ? (renderItem(item, isSelected, () => select(item))) : ((0, jsx_runtime_1.jsxs)(react_native_1.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: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { numberOfLines: 1, color: isSelected ? "primary500" : "content1", weight: isSelected ? "600" : "400", style: styles.label, children: getLabel(item) }), isSelected && (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "check", size: 18, color: c.primary500 })] }));
|
|
49
|
+
},
|
|
50
|
+
contentContainerStyle: contentContainerStyle ?? { paddingHorizontal: s.lg },
|
|
51
|
+
keyExtractor: (item, index) => `${String(getKey(item))}_${index}`,
|
|
52
|
+
keyboardShouldPersistTaps: "handled",
|
|
53
|
+
showsVerticalScrollIndicator: false,
|
|
54
|
+
onEndReached: loading || loadingMore ? undefined : onLoadMore,
|
|
55
|
+
onEndReachedThreshold: 0.3,
|
|
56
|
+
refreshControl: onRefresh && ((0, jsx_runtime_1.jsx)(react_native_1.RefreshControl, { refreshing: !!refreshing, onRefresh: onRefresh, colors: [c.primary500], tintColor: c.primary500 })),
|
|
57
|
+
ItemSeparatorComponent: () => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { height: 1, backgroundColor: c.divider } })),
|
|
58
|
+
ListFooterComponent: loadingMore ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.primary500 })) : null,
|
|
59
|
+
ListEmptyComponent: errorText || emptyText ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.empty, { paddingVertical: s.xxl + s.sm }], children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content3", style: styles.emptyText, children: errorText || emptyText }), !!errorText && onRetry && ((0, jsx_runtime_1.jsx)(primitives_1.Button, { variant: "ghost", label: retryText, onPress: onRetry }))] })) : null,
|
|
60
|
+
};
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [search ??
|
|
62
|
+
(searchPlaceholder && ((0, jsx_runtime_1.jsx)(search_1.SearchBar, { style: { marginHorizontal: s.lg, marginBottom: s.xs }, placeholder: searchPlaceholder, clearAccessibilityLabel: clearSearchAccessibilityLabel, onChangeText: (text) => {
|
|
63
|
+
setKeyword(text);
|
|
64
|
+
onSearch?.(text.trim());
|
|
65
|
+
} }))), loading ? (loadingContent ?? (0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { color: c.primary500 })) : renderList ? (renderList(listProps)) : ((0, jsx_runtime_1.jsx)(react_native_1.FlatList, { ...listProps })), props.multiple && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [{ paddingHorizontal: s.lg, paddingTop: s.md }, footerStyle], children: (0, jsx_runtime_1.jsx)(primitives_1.Button, { label: confirmText, onPress: () => props.onChange([...(selected ?? [])]) }) }))] }));
|
|
66
|
+
}
|
|
67
|
+
const styles = react_native_1.StyleSheet.create({
|
|
68
|
+
row: {
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
justifyContent: "space-between",
|
|
72
|
+
},
|
|
73
|
+
label: { flex: 1 },
|
|
74
|
+
empty: { alignItems: "center" },
|
|
75
|
+
emptyText: { textAlign: "center" },
|
|
76
|
+
});
|
package/dist/module/fields.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { ActivityIndicator,
|
|
3
|
+
import { ActivityIndicator, Keyboard, Pressable, StyleSheet, TextInput, View, useWindowDimensions, } from "react-native";
|
|
4
4
|
import { useUITheme } from "./theme.js";
|
|
5
5
|
import { Button, UIText } from "./primitives.js";
|
|
6
6
|
import { UIIcon } from "./icons.js";
|
|
7
7
|
import { Sheet } from "./overlays.js";
|
|
8
|
+
import { ListPicker } from "./list-picker.js";
|
|
8
9
|
export function Field({ label, required, error, hint, children, style, labelStyle, }) {
|
|
9
10
|
const { spacing: s } = useUITheme();
|
|
10
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 &&
|
|
@@ -103,10 +104,10 @@ export function TimeField({ label, value, onChange, renderPicker, placeholder, r
|
|
|
103
104
|
},
|
|
104
105
|
})] }));
|
|
105
106
|
}
|
|
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
|
+
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, }) {
|
|
107
108
|
const { colors: c, spacing: s, radius: r, typography: t } = useUITheme();
|
|
108
109
|
const { height } = useWindowDimensions();
|
|
109
|
-
const sheetHeight = height *
|
|
110
|
+
const sheetHeight = height * sheetHeightRatio;
|
|
110
111
|
const [visible, setVisible] = useState(false);
|
|
111
112
|
const [query, setQuery] = useState("");
|
|
112
113
|
const searchCallback = useRef(onSearch);
|
|
@@ -152,10 +153,7 @@ export function SelectField({ variant = "default", options, value, onChange, lab
|
|
|
152
153
|
opacity: disabled ? (variant === "form" ? 0.5 : 0.6) : 1,
|
|
153
154
|
},
|
|
154
155
|
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: [
|
|
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: [
|
|
159
157
|
styles.search,
|
|
160
158
|
{
|
|
161
159
|
marginHorizontal: s.lg,
|
|
@@ -171,16 +169,10 @@ export function SelectField({ variant = "default", options, value, onChange, lab
|
|
|
171
169
|
color: c.content1,
|
|
172
170
|
fontSize: t.body,
|
|
173
171
|
fontFamily: t.fontFamily,
|
|
174
|
-
} }))] })),
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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 })] })] }));
|
|
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 })] })] }));
|
|
184
176
|
}
|
|
185
177
|
export function AttachmentField({ title, description, buttonText, files, loading, disabled, openingId, getId, onPick, onOpen, onRemove, illustration, pickIcon, removeIcon, removeAccessibilityLabel = "Remove file", style, }) {
|
|
186
178
|
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
@@ -221,6 +213,7 @@ const styles = StyleSheet.create({
|
|
|
221
213
|
justifyContent: "space-between",
|
|
222
214
|
},
|
|
223
215
|
flex: { flex: 1 },
|
|
216
|
+
fixedSheetList: { flex: 1, minHeight: 0 },
|
|
224
217
|
center: { textAlign: "center" },
|
|
225
218
|
search: { flexDirection: "row", alignItems: "center" },
|
|
226
219
|
selectItem: {
|
package/dist/module/icons.js
CHANGED
|
@@ -6,10 +6,11 @@ export function UIIcon({ name, color, size = 20, }) {
|
|
|
6
6
|
close: "M6 6l12 12M18 6L6 18",
|
|
7
7
|
chevron: "M6 9l6 6 6-6",
|
|
8
8
|
check: "M5 12l4 4L19 6",
|
|
9
|
-
search: "
|
|
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",
|
|
10
11
|
folder: "M3 7V5h7l2 2h9v13H3V7zm9 4v6m-3-3h6",
|
|
11
12
|
upload: "M12 16V3m-5 5 5-5 5 5M4 15v6h16v-6",
|
|
12
13
|
file: "M14 3H5v18h14V8l-5-5zm0 0v5h5M8 12h8M8 16h6",
|
|
13
14
|
};
|
|
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" })] })) : (
|
|
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" })) }));
|
|
15
16
|
}
|
package/dist/module/index.js
CHANGED
|
@@ -2,9 +2,12 @@ export * from "./theme.js";
|
|
|
2
2
|
export * from "./primitives.js";
|
|
3
3
|
export * from "./image.js";
|
|
4
4
|
export * from "./fields.js";
|
|
5
|
+
export * from "./search.js";
|
|
5
6
|
export * from "./date.js";
|
|
6
7
|
export * from "./overlays.js";
|
|
8
|
+
export * from "./ui-modal.js";
|
|
7
9
|
export * from "./choices.js";
|
|
8
10
|
export * from "./process-graph.js";
|
|
9
11
|
export { UIIcon } from "./icons.js";
|
|
10
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
|
+
});
|
package/dist/module/overlays.js
CHANGED
|
@@ -1,32 +1,63 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ActivityIndicator,
|
|
2
|
+
import { ActivityIndicator, Pressable, StyleSheet, View, useWindowDimensions, } from "react-native";
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
4
|
import { useUITheme } from "./theme.js";
|
|
5
5
|
import { Button, UIText } from "./primitives.js";
|
|
6
6
|
import { UIIcon } from "./icons.js";
|
|
7
|
+
import { UIModal } from "./ui-modal.js";
|
|
8
|
+
export function SheetHeader({ title, titleNumberOfLines = 1, headerStart, headerEnd, headerStyle, showHandle = false, closeAccessibilityLabel = "Close", onClose, closeDisabled, closeTestID, titleStyle, }) {
|
|
9
|
+
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
10
|
+
const showClose = headerEnd === undefined && !!onClose;
|
|
11
|
+
return (_jsxs(View, { children: [showHandle && (_jsx(View, { accessible: false, pointerEvents: "none", style: [
|
|
12
|
+
styles.handle,
|
|
13
|
+
{
|
|
14
|
+
width: s.xxl + s.md,
|
|
15
|
+
height: s.xs,
|
|
16
|
+
marginTop: s.md,
|
|
17
|
+
borderRadius: r.full,
|
|
18
|
+
backgroundColor: c.content3,
|
|
19
|
+
},
|
|
20
|
+
] })), (title != null ||
|
|
21
|
+
showClose ||
|
|
22
|
+
headerStart != null ||
|
|
23
|
+
headerEnd != null) && (_jsxs(View, { style: [
|
|
24
|
+
styles.sheetHeader,
|
|
25
|
+
{ paddingHorizontal: s.lg, paddingVertical: s.md },
|
|
26
|
+
showClose && {
|
|
27
|
+
paddingHorizontal: s.xxl * 2,
|
|
28
|
+
paddingTop: showHandle ? s.md : s.xxl + s.xs,
|
|
29
|
+
},
|
|
30
|
+
headerStyle,
|
|
31
|
+
], children: [headerStart === undefined && !showClose ? (_jsx(View, { style: styles.headerSide })) : (headerStart), _jsx(UIText, { accessibilityRole: "header", variant: "subtitle", weight: "600", numberOfLines: titleNumberOfLines, style: [styles.sheetTitle, titleStyle], children: title }), headerEnd === undefined && !showClose ? (_jsx(View, { style: styles.headerSide })) : (headerEnd)] })), showClose && (_jsx(Pressable, { testID: closeTestID, onPress: onClose, disabled: closeDisabled, accessibilityState: { disabled: !!closeDisabled }, hitSlop: s.sm, accessibilityRole: "button", accessibilityLabel: closeAccessibilityLabel, style: [
|
|
32
|
+
styles.closeCorner,
|
|
33
|
+
{ top: s.xs, right: s.md, opacity: closeDisabled ? 0.5 : 1 },
|
|
34
|
+
], children: _jsx(UIIcon, { name: "close", size: 22, color: c.content1 }) }))] }));
|
|
35
|
+
}
|
|
7
36
|
/** Native Modal children retain the provider of the app that rendered them. */
|
|
8
|
-
export function Sheet({ visible, onClose, title,
|
|
37
|
+
export function Sheet({ visible, onClose, onOpened, onClosed, title, description, titleNumberOfLines, closeAccessibilityLabel, children, style, headerStyle, headerStart, headerEnd, showHandle = true, heightRatio, animationType = "slide", keyboardAvoiding = false, }) {
|
|
9
38
|
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
10
39
|
const insets = useSafeAreaInsets();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const { height } = useWindowDimensions();
|
|
41
|
+
const panelHeight = heightRatio == null
|
|
42
|
+
? undefined
|
|
43
|
+
: Math.max(0, Math.min(height * heightRatio, height - insets.top));
|
|
44
|
+
return (_jsxs(UIModal, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, position: "bottom", animationType: animationType, keyboardAvoiding: keyboardAvoiding, statusBarTranslucent: true, containerStyle: { paddingTop: insets.top }, contentStyle: [
|
|
45
|
+
{
|
|
46
|
+
height: panelHeight,
|
|
47
|
+
maxHeight: panelHeight ?? "90%",
|
|
48
|
+
flexShrink: keyboardAvoiding || panelHeight != null ? 1 : undefined,
|
|
49
|
+
overflow: panelHeight != null ? "hidden" : undefined,
|
|
50
|
+
backgroundColor: c.background,
|
|
51
|
+
borderTopLeftRadius: r.sheet,
|
|
52
|
+
borderTopRightRadius: r.sheet,
|
|
53
|
+
paddingBottom: Math.max(s.xxl, insets.bottom),
|
|
54
|
+
},
|
|
55
|
+
style,
|
|
56
|
+
], children: [_jsx(SheetHeader, { title: title, titleNumberOfLines: titleNumberOfLines, closeAccessibilityLabel: closeAccessibilityLabel, headerStart: headerStart, headerEnd: headerEnd, headerStyle: headerStyle, showHandle: showHandle, onClose: onClose }), !!description && (_jsx(UIText, { variant: "caption", color: "content3", style: {
|
|
57
|
+
textAlign: "center",
|
|
58
|
+
paddingHorizontal: s.lg,
|
|
59
|
+
marginBottom: s.md,
|
|
60
|
+
}, children: description })), children] }));
|
|
30
61
|
}
|
|
31
62
|
export function ActionSheet({ items, onSelect, cancelText, ...props }) {
|
|
32
63
|
const { colors: c, spacing: s } = useUITheme();
|
|
@@ -45,18 +76,15 @@ export function ActionSheet({ items, onSelect, cancelText, ...props }) {
|
|
|
45
76
|
}
|
|
46
77
|
export function ConfirmDialog({ visible, title, message, confirmText, cancelText, destructive, loading, onConfirm, onClose, illustration, }) {
|
|
47
78
|
const { colors: c, spacing: s, radius: r } = useUITheme();
|
|
48
|
-
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 })] })] })] }) }));
|
|
79
|
+
return (_jsxs(UIModal, { visible: visible, animationType: "fade", onClose: loading ? undefined : onClose, statusBarTranslucent: true, containerStyle: { padding: s.xxl }, contentStyle: [
|
|
80
|
+
styles.dialog,
|
|
81
|
+
{
|
|
82
|
+
padding: s.xl,
|
|
83
|
+
gap: s.lg,
|
|
84
|
+
backgroundColor: c.background,
|
|
85
|
+
borderRadius: r.lg,
|
|
86
|
+
},
|
|
87
|
+
], children: [illustration, title != null && (_jsx(UIText, { variant: "subtitle", weight: "600", style: styles.center, children: title })), typeof message === "string" ? (_jsx(UIText, { color: "content2", style: styles.center, children: message })) : (message), _jsxs(View, { style: [styles.dialogActions, { gap: s.md }], children: [cancelText != null && (_jsx(Button, { label: cancelText, variant: "outline", disabled: loading, onPress: onClose, style: styles.flex })), _jsx(Button, { label: confirmText, variant: destructive ? "danger" : "primary", loading: loading, onPress: onConfirm, style: styles.flex })] })] }));
|
|
60
88
|
}
|
|
61
89
|
export function ResultDialog({ buttonText, ...props }) {
|
|
62
90
|
return (_jsx(ConfirmDialog, { ...props, confirmText: buttonText, onConfirm: props.onClose }));
|
|
@@ -82,10 +110,18 @@ export function LoadingOverlay({ visible, label, presentation = "modal", testID,
|
|
|
82
110
|
}, children: [_jsx(ActivityIndicator, { size: "large", color: c.primary500 }), label != null && _jsx(UIText, { children: label })] }) }));
|
|
83
111
|
if (presentation === "inline")
|
|
84
112
|
return content;
|
|
85
|
-
return (_jsx(
|
|
113
|
+
return (_jsx(UIModal, { visible: true, position: "fullScreen", animationType: "fade", backdropColor: "transparent", statusBarTranslucent: true, children: content }));
|
|
86
114
|
}
|
|
87
115
|
const styles = StyleSheet.create({
|
|
88
|
-
|
|
116
|
+
handle: { alignSelf: "center" },
|
|
117
|
+
closeCorner: {
|
|
118
|
+
position: "absolute",
|
|
119
|
+
width: 32,
|
|
120
|
+
height: 32,
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
justifyContent: "center",
|
|
123
|
+
zIndex: 1,
|
|
124
|
+
},
|
|
89
125
|
sheetHeader: { flexDirection: "row", alignItems: "center" },
|
|
90
126
|
headerSide: { width: 18 },
|
|
91
127
|
sheetTitle: { flex: 1, textAlign: "center" },
|