@pnkx-lib/ui 1.9.456 → 1.9.457

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/es/index.js CHANGED
@@ -48,7 +48,7 @@ export { Empty } from './ui/Empty.js';
48
48
  export { Image } from './ui/Image.js';
49
49
  export { ConfirmModal } from './ui/ConfirmModal.js';
50
50
  export { ErrorBoundary } from './ui/ErrorBoundary.js';
51
- export { CATEGORY_LIST_ENUM, CategoryStatus, badgeStatusCategoryAccount, badgeStatusCategoryConfig } from './ui/CategoryStatus.js';
51
+ export { CATEGORY_LIST_ENUM, CategoryStatus, badgeStatusCategoryConfig } from './ui/CategoryStatus.js';
52
52
  export { I as ID_TABLE_WRAPPER, a as MAX_TAG_COUNT, M as MAX_TAG_TEXT_LENGTH, T as TINY_API } from './chunks/common-BcURBmQ-.js';
53
53
  export { PAGE_NUMBER, PAGE_SIZE, SORT, START_PAGE, START_PAGE_SIZE, TypeActionRowTable, TypeBulkActions, TypeStatusTable } from './constants/index.js';
54
54
  export { BreadcrumbHeading } from './ui/BreadcrumbHeading.js';
@@ -1,5 +1,4 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { CategoryAccountStatus } from '@pnkx-lib/core';
3
2
  import { t as twMerge } from '../chunks/bundle-mjs-BME7zF0Z.js';
4
3
 
5
4
  var CATEGORY_LIST_ENUM = /* @__PURE__ */ ((CATEGORY_LIST_ENUM2) => {
@@ -31,20 +30,9 @@ const badgeStatusCategoryConfig = {
31
30
  text: "Đã xóa"
32
31
  }
33
32
  };
34
- const badgeStatusCategoryAccount = {
35
- [CategoryAccountStatus.ACTIVE]: { color: "bg-[#27CD7F]", text: "Hoạt động" },
36
- [CategoryAccountStatus.INACTIVE]: {
37
- color: "bg-[#DD4338]",
38
- text: "Ngừng hoạt động"
39
- },
40
- [CategoryAccountStatus.DELETED]: {
41
- color: "bg-[#B2B7C2]",
42
- text: "Đã xóa"
43
- }
44
- };
45
- const CategoryStatus = ({ status, mode }) => {
33
+ const CategoryStatus = ({ status }) => {
46
34
  //! State
47
- const bagde = mode === "categoryAccount" ? badgeStatusCategoryAccount[Number(status)] : badgeStatusCategoryConfig[Number(status)];
35
+ const bagde = badgeStatusCategoryConfig[Number(status)];
48
36
  //! Function
49
37
  const ItemStatus = ({
50
38
  color,
@@ -59,4 +47,4 @@ const CategoryStatus = ({ status, mode }) => {
59
47
  return /* @__PURE__ */ jsx(ItemStatus, { color: bagde?.color, statusName: bagde?.text });
60
48
  };
61
49
 
62
- export { CATEGORY_LIST_ENUM, CategoryStatus, badgeStatusCategoryAccount, badgeStatusCategoryConfig };
50
+ export { CATEGORY_LIST_ENUM, CategoryStatus, badgeStatusCategoryConfig };
@@ -1,7 +1,10 @@
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-BME7zF0Z.js';
5
+ import { get } from 'lodash';
6
+ import { ErrorMessage } from './ErrorMessage.js';
7
+ import { Label } from './Label.js';
5
8
 
6
9
  const SelectTable = ({
7
10
  columns,
@@ -21,6 +24,15 @@ const SelectTable = ({
21
24
  selectedRows = [],
22
25
  customeContentTable = "",
23
26
  customeContainerTable = "",
27
+ field,
28
+ formState,
29
+ label,
30
+ required,
31
+ isDisabledCheckbox,
32
+ classNameContainer,
33
+ classNameLabel,
34
+ isShowLabel = false,
35
+ isShowCheckboxAll = false,
24
36
  ...selectProps
25
37
  }) => {
26
38
  const [open, setOpen] = useState(false);
@@ -28,6 +40,22 @@ const SelectTable = ({
28
40
  const [internalLoading, setInternalLoading] = useState(false);
29
41
  const [searchValue, setSearchValue] = useState("");
30
42
  const [isClearing, setIsClearing] = useState(false);
43
+ const { name, value, onChange } = field || {};
44
+ const { touchedFields, errors, isSubmitted } = formState || {};
45
+ const isTouched = get(touchedFields, name);
46
+ const errorMessage = get(errors, name)?.message;
47
+ const currentSelectedKeys = (() => {
48
+ if (value && Array.isArray(value)) {
49
+ if (value.length > 0 && typeof value[0] === "object") {
50
+ return value.map((row) => {
51
+ const key = typeof rowKey === "function" ? rowKey(row) : row[rowKey];
52
+ return key;
53
+ });
54
+ }
55
+ return value;
56
+ }
57
+ return selectedKeys;
58
+ })();
31
59
  const currentDataSource = dataSource.length > 0 ? dataSource : internalDataSource;
32
60
  const loadMoreData = useCallback(async () => {
33
61
  if (internalLoading || loading || !hasMore || !onLoadMore) return;
@@ -40,6 +68,17 @@ const SelectTable = ({
40
68
  setInternalLoading(false);
41
69
  }
42
70
  }, [onLoadMore, internalLoading, loading, hasMore]);
71
+ const renderErrorMessage = () => {
72
+ if (!errorMessage) return null;
73
+ return /* @__PURE__ */ jsx(
74
+ ErrorMessage,
75
+ {
76
+ errorMessage,
77
+ isTouched,
78
+ isSubmitted
79
+ }
80
+ );
81
+ };
43
82
  const handleScroll = useCallback(
44
83
  (e) => {
45
84
  if (!infiniteScroll) return;
@@ -51,32 +90,49 @@ const SelectTable = ({
51
90
  [infiniteScroll, loadMoreThreshold, loadMoreData]
52
91
  );
53
92
  const onSelectChange = (newSelectedRowKeys, newSelectedRows) => {
93
+ onChange?.({
94
+ target: {
95
+ name,
96
+ value: newSelectedRows
97
+ }
98
+ });
54
99
  if (onSelectionChange) {
55
100
  onSelectionChange(newSelectedRowKeys, newSelectedRows);
56
101
  }
57
102
  };
58
103
  const rowSelection = {
59
- selectedRowKeys: selectedKeys,
104
+ selectedRowKeys: currentSelectedKeys,
60
105
  onChange: onSelectChange,
106
+ hideSelectAll: isShowCheckboxAll,
61
107
  getCheckboxProps: (record) => {
62
108
  return {
63
- disabled: selectedKeys.includes(record[rowKey])
109
+ disabled: isDisabledCheckbox ? currentSelectedKeys.includes(record[rowKey]) : false
64
110
  // Disable checkbox nếu đã được chọn
65
111
  };
66
112
  }
67
113
  };
68
114
  const getDisplayValue = useCallback(() => {
69
- if (!displayField) {
115
+ if (!isShowLabel) {
70
116
  return [];
117
+ } else {
118
+ if (value && Array.isArray(value)) {
119
+ if (value.length > 0 && typeof value[0] === "object") {
120
+ return value.map(
121
+ (row) => row[displayField]
122
+ );
123
+ }
124
+ if (selectedRows.length > 0) {
125
+ return selectedRows.map(
126
+ (row) => row[displayField]
127
+ );
128
+ }
129
+ }
71
130
  }
72
- return selectedRows.map(
73
- (row) => row[displayField]
74
- );
75
- }, [selectedRows, displayField]);
76
- const handleSearch = (value) => {
77
- setSearchValue(value);
131
+ }, [selectedRows, displayField, value, isShowLabel]);
132
+ const handleSearch = (value2) => {
133
+ setSearchValue(value2);
78
134
  if (onSearch) {
79
- onSearch(value);
135
+ onSearch(value2);
80
136
  }
81
137
  };
82
138
  const handleClear = () => {
@@ -85,6 +141,18 @@ const SelectTable = ({
85
141
  if (onSearch) {
86
142
  onSearch("");
87
143
  }
144
+ if (onSelectionChange) {
145
+ onSelectionChange([], []);
146
+ }
147
+ if (field && onChange) {
148
+ onChange({
149
+ target: {
150
+ name,
151
+ value: []
152
+ // Clear với empty array of objects
153
+ }
154
+ });
155
+ }
88
156
  setTimeout(() => {
89
157
  setOpen(true);
90
158
  setIsClearing(false);
@@ -100,6 +168,7 @@ const SelectTable = ({
100
168
  "div",
101
169
  {
102
170
  className: twMerge("overflow-x-hidden w-full", customeContainerTable),
171
+ onScroll: handleScroll,
103
172
  children: /* @__PURE__ */ jsx(
104
173
  Table,
105
174
  {
@@ -112,30 +181,47 @@ const SelectTable = ({
112
181
  pagination: false,
113
182
  scroll: tableProps.scrollTable,
114
183
  style: { overflowX: "hidden" },
115
- loading,
116
- onScroll: handleScroll,
184
+ loading: false,
117
185
  ...tableProps
118
186
  }
119
187
  )
120
188
  }
121
189
  ) });
122
- return /* @__PURE__ */ jsx(
123
- Select,
190
+ return /* @__PURE__ */ jsxs(
191
+ "div",
124
192
  {
125
- ...selectProps,
126
- open,
127
- onDropdownVisibleChange: handleDropdownVisibleChange,
128
- dropdownRender,
129
- value: getDisplayValue(),
130
- mode: "multiple",
131
- showSearch: true,
132
- onSearch: handleSearch,
133
- onClear: handleClear,
134
- placeholder: searchPlaceholder,
135
- maxTagCount: 3,
136
- showArrow: true,
137
- filterOption: false,
138
- searchValue
193
+ className: twMerge("pnkx-default-select-container", classNameContainer),
194
+ children: [
195
+ label && /* @__PURE__ */ jsx(
196
+ Label,
197
+ {
198
+ label,
199
+ required,
200
+ classNameLabel
201
+ }
202
+ ),
203
+ /* @__PURE__ */ jsx(
204
+ Select,
205
+ {
206
+ ...selectProps,
207
+ open,
208
+ onDropdownVisibleChange: handleDropdownVisibleChange,
209
+ dropdownRender,
210
+ value: getDisplayValue(),
211
+ mode: "multiple",
212
+ showSearch: true,
213
+ onSearch: handleSearch,
214
+ onClear: handleClear,
215
+ placeholder: searchPlaceholder,
216
+ maxTagCount: 3,
217
+ showArrow: true,
218
+ filterOption: false,
219
+ searchValue,
220
+ allowClear: true
221
+ }
222
+ ),
223
+ renderErrorMessage()
224
+ ]
139
225
  }
140
226
  );
141
227
  };
package/es/ui/index.js CHANGED
@@ -55,7 +55,7 @@ export { Image } from './Image.js';
55
55
  import { ConfirmModal } from './ConfirmModal.js';
56
56
  export { ErrorBoundary } from './ErrorBoundary.js';
57
57
  import { CATEGORY_LIST_ENUM } from './CategoryStatus.js';
58
- export { CategoryStatus, badgeStatusCategoryAccount, badgeStatusCategoryConfig } from './CategoryStatus.js';
58
+ export { CategoryStatus, badgeStatusCategoryConfig } from './CategoryStatus.js';
59
59
  import { useToggle } from '@pnkx-lib/core';
60
60
  import { isEmpty, isBoolean } from 'lodash';
61
61
  import { t as twMerge } from '../chunks/bundle-mjs-BME7zF0Z.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pnkx-lib/ui",
3
3
  "private": false,
4
- "version": "1.9.456",
4
+ "version": "1.9.457",
5
5
  "type": "module",
6
6
  "main": "./es/index.js",
7
7
  "module": "./es/index.js",
@@ -1,4 +1,3 @@
1
- import { CategoryAccountStatus } from '@pnkx-lib/core';
2
1
  import { TypeStatusTable } from '../../constants';
3
2
  export declare enum CATEGORY_LIST_ENUM {
4
3
  DRAFT = 0,// tạo mới
@@ -15,10 +14,8 @@ type BadgeConfig = {
15
14
  };
16
15
  };
17
16
  export declare const badgeStatusCategoryConfig: BadgeConfig;
18
- export declare const badgeStatusCategoryAccount: BadgeConfig;
19
17
  export interface CategoryStatusProps {
20
- status: TypeStatusTable | CategoryAccountStatus;
21
- mode?: string;
18
+ status: TypeStatusTable;
22
19
  }
23
- export declare const CategoryStatus: ({ status, mode }: CategoryStatusProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const CategoryStatus: ({ status }: CategoryStatusProps) => import("react/jsx-runtime").JSX.Element;
24
21
  export {};
@@ -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 SelectTableProps<T = Record<string, unknown>> extends Omit<SelectProps, "children" | "dropdownRender" | "mode" | "value"> {
4
5
  columns: ColumnsType<T>;
5
6
  dataSource?: T[];
@@ -25,5 +26,14 @@ export interface SelectTableProps<T = Record<string, unknown>> extends Omit<Sele
25
26
  selectedRows?: T[];
26
27
  customeContentTable?: string;
27
28
  customeContainerTable?: string;
29
+ field?: ControllerRenderProps<any, any>;
30
+ formState?: UseFormStateReturn<any>;
31
+ label?: string;
32
+ required?: boolean;
33
+ isDisabledCheckbox?: boolean;
34
+ classNameContainer?: string;
35
+ classNameLabel?: string;
36
+ isShowLabel?: boolean;
37
+ isShowCheckboxAll?: boolean;
28
38
  }
29
- export declare const SelectTable: <T>({ columns, dataSource, selectedKeys, onSelectionChange, onLoadMore, onSearch, hasMore, loading, rowKey, tableProps, infiniteScroll, loadMoreThreshold, searchPlaceholder, displayField, selectedRows, customeContentTable, customeContainerTable, ...selectProps }: SelectTableProps<T>) => import("react/jsx-runtime").JSX.Element;
39
+ export declare const SelectTable: <T>({ columns, dataSource, selectedKeys, onSelectionChange, onLoadMore, onSearch, hasMore, loading, rowKey, tableProps, infiniteScroll, loadMoreThreshold, searchPlaceholder, displayField, selectedRows, customeContentTable, customeContainerTable, field, formState, label, required, isDisabledCheckbox, classNameContainer, classNameLabel, isShowLabel, isShowCheckboxAll, ...selectProps }: SelectTableProps<T>) => import("react/jsx-runtime").JSX.Element;