@pnkx-lib/ui 1.9.407 → 1.9.408
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { Select, Table } from 'antd';
|
|
3
3
|
import { useState, useCallback } from 'react';
|
|
4
4
|
import { t as twMerge } from '../chunks/bundle-mjs-BBFHkixS.js';
|
|
5
|
+
import { get, isEmpty } from 'lodash';
|
|
6
|
+
import { ErrorMessage } from './ErrorMessage.js';
|
|
5
7
|
|
|
6
8
|
const SelectSingleTable = ({
|
|
7
9
|
columns,
|
|
@@ -21,6 +23,9 @@ const SelectSingleTable = ({
|
|
|
21
23
|
displayField,
|
|
22
24
|
customeContentTable = "",
|
|
23
25
|
customeContainerTable = "",
|
|
26
|
+
field,
|
|
27
|
+
formState,
|
|
28
|
+
classNameContainer,
|
|
24
29
|
...selectProps
|
|
25
30
|
}) => {
|
|
26
31
|
const [open, setOpen] = useState(false);
|
|
@@ -28,6 +33,10 @@ const SelectSingleTable = ({
|
|
|
28
33
|
const [internalLoading, setInternalLoading] = useState(false);
|
|
29
34
|
const [searchValue, setSearchValue] = useState("");
|
|
30
35
|
const [isClearing, setIsClearing] = useState(false);
|
|
36
|
+
const { name, value, onChange } = field || {};
|
|
37
|
+
const { touchedFields, errors, isSubmitted } = formState || {};
|
|
38
|
+
const isTouched = get(touchedFields, name);
|
|
39
|
+
const errorMessage = get(errors, name)?.message;
|
|
31
40
|
const currentDataSource = dataSource.length > 0 ? dataSource : internalDataSource;
|
|
32
41
|
const loadMoreData = useCallback(async () => {
|
|
33
42
|
if (internalLoading || loading || !hasMore || !onLoadMore) return;
|
|
@@ -40,6 +49,17 @@ const SelectSingleTable = ({
|
|
|
40
49
|
setInternalLoading(false);
|
|
41
50
|
}
|
|
42
51
|
}, [onLoadMore, internalLoading, loading, hasMore]);
|
|
52
|
+
const renderErrorMessage = () => {
|
|
53
|
+
if (!errorMessage) return null;
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
ErrorMessage,
|
|
56
|
+
{
|
|
57
|
+
errorMessage,
|
|
58
|
+
isTouched,
|
|
59
|
+
isSubmitted
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
};
|
|
43
63
|
const handleScroll = useCallback(
|
|
44
64
|
(e) => {
|
|
45
65
|
if (!infiniteScroll) return;
|
|
@@ -51,6 +71,12 @@ const SelectSingleTable = ({
|
|
|
51
71
|
[infiniteScroll, loadMoreThreshold, loadMoreData]
|
|
52
72
|
);
|
|
53
73
|
const handleRowClick = (record) => {
|
|
74
|
+
onChange?.({
|
|
75
|
+
target: {
|
|
76
|
+
name,
|
|
77
|
+
value: record
|
|
78
|
+
}
|
|
79
|
+
});
|
|
54
80
|
const key = typeof rowKey === "function" ? rowKey(record) : record[rowKey];
|
|
55
81
|
if (selectedKey === key) {
|
|
56
82
|
if (onSelectionChange) {
|
|
@@ -64,15 +90,17 @@ const SelectSingleTable = ({
|
|
|
64
90
|
setOpen(false);
|
|
65
91
|
};
|
|
66
92
|
const getDisplayValue = useCallback(() => {
|
|
67
|
-
if (!selectedRow) {
|
|
68
|
-
return
|
|
93
|
+
if (isEmpty(value) && !selectedRow) {
|
|
94
|
+
return null;
|
|
69
95
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
if (!value)
|
|
97
|
+
return selectedRow[displayField];
|
|
98
|
+
return value[displayField];
|
|
99
|
+
}, [selectedRow, displayField, value]);
|
|
100
|
+
const handleSearch = (value2) => {
|
|
101
|
+
setSearchValue(value2);
|
|
74
102
|
if (onSearch) {
|
|
75
|
-
onSearch(
|
|
103
|
+
onSearch(value2);
|
|
76
104
|
}
|
|
77
105
|
};
|
|
78
106
|
const handleClear = () => {
|
|
@@ -119,21 +147,30 @@ const SelectSingleTable = ({
|
|
|
119
147
|
)
|
|
120
148
|
}
|
|
121
149
|
) });
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
|
|
150
|
+
return /* @__PURE__ */ jsxs(
|
|
151
|
+
"div",
|
|
124
152
|
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
className: twMerge("pnkx-default-select-container", classNameContainer),
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
Select,
|
|
157
|
+
{
|
|
158
|
+
...selectProps,
|
|
159
|
+
open,
|
|
160
|
+
onDropdownVisibleChange: handleDropdownVisibleChange,
|
|
161
|
+
dropdownRender,
|
|
162
|
+
value: getDisplayValue(),
|
|
163
|
+
showSearch: true,
|
|
164
|
+
onSearch: handleSearch,
|
|
165
|
+
onClear: handleClear,
|
|
166
|
+
placeholder: searchPlaceholder,
|
|
167
|
+
filterOption: false,
|
|
168
|
+
searchValue,
|
|
169
|
+
allowClear: true
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
renderErrorMessage()
|
|
173
|
+
]
|
|
137
174
|
}
|
|
138
175
|
);
|
|
139
176
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SelectProps } from 'antd/lib/select';
|
|
2
2
|
import { ColumnsType } from 'antd/es/table';
|
|
3
|
+
import { ControllerRenderProps, UseFormStateReturn } from 'react-hook-form';
|
|
3
4
|
export interface SelectSingleTableProps<T = Record<string, unknown>> extends Omit<SelectProps, "children" | "dropdownRender" | "mode" | "value"> {
|
|
4
5
|
columns: ColumnsType<T>;
|
|
5
6
|
dataSource?: T[];
|
|
@@ -21,5 +22,10 @@ export interface SelectSingleTableProps<T = Record<string, unknown>> extends Omi
|
|
|
21
22
|
displayField: string;
|
|
22
23
|
customeContentTable?: string;
|
|
23
24
|
customeContainerTable?: string;
|
|
25
|
+
field?: ControllerRenderProps<any, any>;
|
|
26
|
+
formState?: UseFormStateReturn<any>;
|
|
27
|
+
label?: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
classNameContainer?: string;
|
|
24
30
|
}
|
|
25
|
-
export declare const SelectSingleTable: <T>({ columns, dataSource, selectedKey, selectedRow, onSelectionChange, onLoadMore, onSearch, hasMore, loading, rowKey, tableProps, infiniteScroll, loadMoreThreshold, searchPlaceholder, displayField, customeContentTable, customeContainerTable, ...selectProps }: SelectSingleTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare const SelectSingleTable: <T>({ columns, dataSource, selectedKey, selectedRow, onSelectionChange, onLoadMore, onSearch, hasMore, loading, rowKey, tableProps, infiniteScroll, loadMoreThreshold, searchPlaceholder, displayField, customeContentTable, customeContainerTable, field, formState, classNameContainer, ...selectProps }: SelectSingleTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|