es-grid-template 0.0.4 → 0.0.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +19 -0
  3. package/README.md +1 -6
  4. package/{dist/components/GridTable → es}/CheckboxFilter.d.ts +1 -1
  5. package/es/CheckboxFilter.js +249 -0
  6. package/{dist/components/GridTable → es}/ColumnsChoose.d.ts +3 -2
  7. package/es/ColumnsChoose.js +213 -0
  8. package/{dist/components/GridTable → es}/ContextMenu.d.ts +1 -1
  9. package/es/ContextMenu.js +126 -0
  10. package/{dist/components/GridTable → es}/FilterSearch.d.ts +3 -3
  11. package/es/FilterSearch.js +33 -0
  12. package/es/GridTable.d.ts +7 -0
  13. package/es/GridTable.js +927 -0
  14. package/es/hooks/constant.js +214 -0
  15. package/es/hooks/index.js +5 -0
  16. package/{dist → es}/hooks/useColumns/index.d.ts +1 -1
  17. package/es/hooks/useColumns/index.js +25 -0
  18. package/{dist → es}/hooks/useIsOverflow.d.ts +1 -1
  19. package/es/hooks/useIsOverflow.js +17 -0
  20. package/es/hooks/useOnClickOutside.js +28 -0
  21. package/{dist → es}/hooks/utils.d.ts +7 -3
  22. package/es/hooks/utils.js +192 -0
  23. package/es/index.d.ts +2 -0
  24. package/es/index.js +2 -0
  25. package/es/styles.scss +30 -0
  26. package/es/type.d.ts +88 -0
  27. package/es/type.js +1 -0
  28. package/lib/CheckboxFilter.d.ts +19 -0
  29. package/lib/CheckboxFilter.js +257 -0
  30. package/lib/ColumnsChoose.d.ts +10 -0
  31. package/lib/ColumnsChoose.js +223 -0
  32. package/lib/ContextMenu.d.ts +20 -0
  33. package/lib/ContextMenu.js +135 -0
  34. package/lib/FilterSearch.d.ts +12 -0
  35. package/lib/FilterSearch.js +42 -0
  36. package/lib/GridTable.d.ts +7 -0
  37. package/lib/GridTable.js +936 -0
  38. package/lib/hooks/constant.d.ts +48 -0
  39. package/lib/hooks/constant.js +221 -0
  40. package/lib/hooks/index.d.ts +4 -0
  41. package/lib/hooks/index.js +49 -0
  42. package/lib/hooks/useColumns/index.d.ts +2 -0
  43. package/lib/hooks/useColumns/index.js +31 -0
  44. package/lib/hooks/useIsOverflow.d.ts +1 -0
  45. package/lib/hooks/useIsOverflow.js +26 -0
  46. package/lib/hooks/useOnClickOutside.d.ts +1 -0
  47. package/lib/hooks/useOnClickOutside.js +36 -0
  48. package/lib/hooks/utils.d.ts +18 -0
  49. package/lib/hooks/utils.js +215 -0
  50. package/lib/index.d.ts +2 -0
  51. package/lib/index.js +9 -0
  52. package/lib/styles.scss +30 -0
  53. package/lib/type.d.ts +88 -0
  54. package/lib/type.js +5 -0
  55. package/package.json +75 -94
  56. package/dist/components/GridTable/GridTable.d.ts +0 -6
  57. package/dist/components/GridTable/index.d.ts +0 -1
  58. package/dist/components/index.d.ts +0 -1
  59. package/dist/index.d.ts +0 -2
  60. package/dist/index.js +0 -53
  61. package/dist/type.d.ts +0 -45
  62. /package/{dist → es}/hooks/constant.d.ts +0 -0
  63. /package/{dist → es}/hooks/index.d.ts +0 -0
  64. /package/{dist → es}/hooks/useOnClickOutside.d.ts +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+
4
+ ## 0.0.1 / 20-02-2025
5
+
6
+ add package
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
17
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1 @@
1
- #
2
-
3
- ## Quick Features
4
-
5
-
6
- <!-- Force 1 -->
1
+ # es-grid-template
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { TableLocale } from "antd/es/table/interface";
2
+ import type { TableLocale } from "ui-rc/dist/table/interface";
3
3
  type Props = {
4
4
  options: any[];
5
5
  filterSearch?: boolean;
@@ -0,0 +1,249 @@
1
+ import * as React from "react";
2
+ import classNames from "classnames";
3
+ import FilterSearch from "./FilterSearch";
4
+ import { Checkbox, Menu, Radio } from "ui-rc";
5
+ import { Empty, Tree } from "antd";
6
+
7
+ // import {flattenKeys} from "ui-rc/dist/table/hooks/useFilter";
8
+
9
+ import { flattenKeys } from "antd/es/table/hooks/useFilter";
10
+ // import Empty from "ui-rc/dist/empty";
11
+ // import Tree from "ui-rc/dist/tree";
12
+
13
+ function searchValueMatched(searchValue, text) {
14
+ if (typeof text === 'string' || typeof text === 'number') {
15
+ return text?.toString().toLowerCase().includes(searchValue.trim().toLowerCase());
16
+ }
17
+ return false;
18
+ }
19
+ function renderFilterItems({
20
+ filters,
21
+ prefixCls,
22
+ filteredKeys,
23
+ filterMultiple,
24
+ searchValue,
25
+ filterSearch
26
+ }) {
27
+ return filters.map((filter, index) => {
28
+ const key = String(filter.value);
29
+ if (filter.children) {
30
+ return {
31
+ key: key || index,
32
+ label: filter.text,
33
+ popupClassName: `${prefixCls}-dropdown-submenu`,
34
+ children: renderFilterItems({
35
+ filters: filter.children,
36
+ prefixCls,
37
+ filteredKeys,
38
+ filterMultiple,
39
+ searchValue,
40
+ filterSearch
41
+ })
42
+ };
43
+ }
44
+ const Component = filterMultiple ? Checkbox : Radio;
45
+ const item = {
46
+ key: filter.value !== undefined ? key : index,
47
+ label: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Component, {
48
+ checked: filteredKeys.includes(key)
49
+ }), /*#__PURE__*/React.createElement("span", null, filter.text))
50
+ };
51
+ if (searchValue.trim()) {
52
+ if (typeof filterSearch === 'function') {
53
+ return filterSearch(searchValue, filter) ? item : null;
54
+ }
55
+ return searchValueMatched(searchValue, filter.text) ? item : null;
56
+ }
57
+ return item;
58
+ });
59
+ }
60
+ function hasSubMenu(filters) {
61
+ return filters.some(({
62
+ children
63
+ }) => children);
64
+ }
65
+ const CheckboxFilter = props => {
66
+ const {
67
+ // column,
68
+ filterSearch = true,
69
+ tablePrefixCls = 'ui-rc-table',
70
+ prefixCls = 'ui-rc-table-filter',
71
+ dropdownPrefixCls = 'ui-rc-dropdown',
72
+ filterMultiple,
73
+ selectedKeys,
74
+ locale,
75
+ options,
76
+ filterMode = 'tree',
77
+ // open,
78
+ searchValue,
79
+ setSearchValue,
80
+ onSelect
81
+ } = props;
82
+
83
+ // const [searchValue, setSearchValue] = React.useState('');
84
+
85
+ const [openKeys, setOpenKeys] = React.useState([]);
86
+
87
+ // clear search value after close filter dropdown
88
+ // React.useEffect(() => {
89
+ // // if (visible) {
90
+ // setSearchValue('');
91
+ // // }
92
+ // }, [open]);
93
+
94
+ const onOpenChange = keys => {
95
+ setOpenKeys(keys);
96
+ };
97
+ const items = renderFilterItems({
98
+ // filters: column.filters || [],
99
+ filters: options || [],
100
+ filterSearch,
101
+ prefixCls,
102
+ filteredKeys: selectedKeys ?? [],
103
+ filterMultiple,
104
+ searchValue
105
+ });
106
+ const dropdownMenuClass = classNames({
107
+ // [`${dropdownPrefixCls}-menu-without-submenu`]: !hasSubMenu(column.filters || []),
108
+ [`${dropdownPrefixCls}-menu-without-submenu`]: !hasSubMenu(options || [])
109
+ });
110
+ console.log('selectedKeys', selectedKeys);
111
+ const empty = /*#__PURE__*/React.createElement(Empty, {
112
+ image: Empty.PRESENTED_IMAGE_SIMPLE,
113
+ description: locale.filterEmptyText,
114
+ imageStyle: {
115
+ height: 24
116
+ },
117
+ style: {
118
+ margin: 0,
119
+ padding: '16px 0'
120
+ }
121
+ });
122
+ const isEmpty = items.every(item => item === null);
123
+ const onSearch = e => {
124
+ const {
125
+ value
126
+ } = e.target;
127
+ setSearchValue(value);
128
+ };
129
+
130
+ // if ((column.filters || []).length === 0) {
131
+ // return empty;
132
+ // }
133
+
134
+ const getTreeData = ({
135
+ filters
136
+ }) => (filters || []).map((filter, index) => {
137
+ const key = String(filter.value);
138
+ const item = {
139
+ title: filter.text,
140
+ key: filter.value !== undefined ? key : String(index)
141
+ };
142
+ if (filter.children) {
143
+ item.children = getTreeData({
144
+ filters: filter.children
145
+ });
146
+ }
147
+ return item;
148
+ });
149
+ const getFilterData = node => ({
150
+ ...node,
151
+ text: node.title,
152
+ value: node.key,
153
+ children: node.children?.map(item => getFilterData(item)) || []
154
+ });
155
+ const onCheckAll = e => {
156
+ console.log('e.target.checked', e.target.checked);
157
+ if (e.target.checked) {
158
+ const allFilterKeys = flattenKeys(options).map(key => String(key));
159
+ console.log('allFilterKeys', allFilterKeys);
160
+ // setFilteredKeysSync(allFilterKeys);
161
+ onSelect?.(allFilterKeys);
162
+ } else {
163
+ onSelect?.([]);
164
+ // setFilteredKeysSync([]);
165
+ }
166
+ };
167
+ const onCheck = (keys, {
168
+ node,
169
+ checked
170
+ }) => {
171
+ if (!filterMultiple) {
172
+ // onSelectKeys({ selectedKeys: checked && node.key ? [node.key] : [] });
173
+ onSelect?.(checked && node.key ? [node.key] : []);
174
+ } else {
175
+ // onSelectKeys({ selectedKeys: keys });
176
+ onSelect?.(keys);
177
+ }
178
+ };
179
+ if (filterMode === 'tree') {
180
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FilterSearch, {
181
+ filterSearch: filterSearch,
182
+ value: searchValue,
183
+ onChange: onSearch,
184
+ tablePrefixCls: tablePrefixCls,
185
+ locale: locale
186
+ }), /*#__PURE__*/React.createElement("div", {
187
+ className: `${tablePrefixCls}-filter-dropdown-tree`
188
+ }, filterMultiple ? /*#__PURE__*/React.createElement(Checkbox
189
+ // checked={selectedKeys.length === flattenKeys(column.filters).length}
190
+ , {
191
+ checked: selectedKeys.length === flattenKeys(options).length
192
+ // indeterminate={
193
+ // selectedKeys.length > 0 &&
194
+ // selectedKeys.length < flattenKeys(column.filters).length
195
+ // }
196
+ ,
197
+
198
+ indeterminate: selectedKeys.length > 0 && selectedKeys.length < flattenKeys(options).length,
199
+ className: `${tablePrefixCls}-filter-dropdown-checkall`,
200
+ onChange: onCheckAll
201
+ }, locale.filterCheckall) : null, /*#__PURE__*/React.createElement(Tree, {
202
+ checkable: true,
203
+ selectable: false,
204
+ blockNode: true,
205
+ multiple: filterMultiple,
206
+ checkStrictly: !filterMultiple,
207
+ className: `${dropdownPrefixCls}-menu`,
208
+ onCheck: onCheck,
209
+ checkedKeys: selectedKeys,
210
+ selectedKeys: selectedKeys,
211
+ showIcon: false
212
+ // treeData={getTreeData({ filters: column.filters })}
213
+ ,
214
+ treeData: getTreeData({
215
+ filters: options
216
+ }),
217
+ autoExpandParent: true,
218
+ defaultExpandAll: true,
219
+ filterTreeNode: searchValue.trim() ? node => {
220
+ if (typeof filterSearch === 'function') {
221
+ // @ts-ignore
222
+ return filterSearch(searchValue, getFilterData(node));
223
+ }
224
+ return searchValueMatched(searchValue, node.title);
225
+ } : undefined
226
+ })));
227
+ }
228
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FilterSearch, {
229
+ filterSearch: filterSearch,
230
+ value: searchValue,
231
+ onChange: onSearch,
232
+ tablePrefixCls: tablePrefixCls,
233
+ locale: locale
234
+ }), isEmpty ? empty : /*#__PURE__*/React.createElement(Menu, {
235
+ selectable: true,
236
+ multiple: filterMultiple,
237
+ prefixCls: `${dropdownPrefixCls}-menu`,
238
+ className: dropdownMenuClass,
239
+ onSelect: onSelect,
240
+ onDeselect: onSelect,
241
+ selectedKeys: selectedKeys
242
+ // getPopupContainer={getPopupContainer}
243
+ ,
244
+ openKeys: openKeys,
245
+ onOpenChange: onOpenChange,
246
+ items: items
247
+ }));
248
+ };
249
+ export default CheckboxFilter;
@@ -1,5 +1,6 @@
1
- import React, { Dispatch, SetStateAction } from "react";
2
- import { TableColumnsType } from "ui-rc";
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import React from "react";
3
+ import type { TableColumnsType } from "ui-rc";
3
4
  export declare const BoxInputFilterColumn: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
4
5
  export type IColumnsChoose<RecordType> = {
5
6
  columns: any[];
@@ -0,0 +1,213 @@
1
+ import React, { Fragment, useMemo, useState } from "react";
2
+ import styled from "styled-components";
3
+ import { Button, Input, Popover, Tooltip, Tree } from "antd";
4
+ import { SettingOutlined } from "@ant-design/icons";
5
+ import { getVisibleColumnKeys, updateColumns } from "./hooks";
6
+ const {
7
+ Search
8
+ } = Input;
9
+
10
+ // const RowStyle = styled.div`
11
+ // padding: 6px 0;
12
+ //
13
+ // height: 35px;
14
+ //
15
+ // .ellipsis {
16
+ // overflow: hidden;
17
+ // white-space: nowrap;
18
+ // text-overflow: ellipsis;
19
+ // word-break: keep-all;
20
+ // }
21
+ // `
22
+
23
+ const BoxAction = styled.div.withConfig({
24
+ displayName: "BoxAction",
25
+ componentId: "es-grid-template__sc-1k89i9w-0"
26
+ })(["border-top:1px solid #c4c4c4;padding-top:.75rem;display:flex;justify-content:end;gap:10px;.btn-action{background:none !important;border:none !important;&.btn-action-submit{color:#df4318;&:disabled{background-color:#f0f0f0 !important;}&:hover{color:#df4318 !important;}}&:hover{background-color:#f0f0f0 !important;}}"]);
27
+ export const BoxInputFilterColumn = styled.div.withConfig({
28
+ displayName: "BoxInputFilterColumn",
29
+ componentId: "es-grid-template__sc-1k89i9w-1"
30
+ })(["display:flex;position:relative;align-items:center;.input__value{z-index:1;border-radius:0;border-top:0;border-left:0;border-right:0;&:focus{box-shadow:none !important;}&.is-clearable{padding-right:25px !important;}}.input__clear-icon{cursor:pointer;position:absolute;right:5px;z-index:10;}"]);
31
+ export const ColumnsChoose = props => {
32
+ const {
33
+ columns: propsColumns,
34
+ setColumns: changeHiddenColumn
35
+ // t,
36
+ // columnsGrouped,
37
+ // onChangeDisplay
38
+ // frozen
39
+ } = props;
40
+
41
+ // const dataList: { key: React.Key; title: string }[] = [];
42
+
43
+ const defaultColumns = useMemo(() => {
44
+ const rs = propsColumns.filter(it => it.key || it.dataIndex);
45
+ return rs;
46
+ }, [propsColumns]);
47
+ const defaultSelectedKeys = useMemo(() => {
48
+ return getVisibleColumnKeys(propsColumns);
49
+ }, [propsColumns]);
50
+
51
+ // const columnsChooseRef: any = useRef()
52
+ // const searchRef: any = useRef()
53
+
54
+ const [columns] = useState(defaultColumns);
55
+ const [clicked, setClicked] = useState(false);
56
+ const [autoExpandParent, setAutoExpandParent] = useState(true);
57
+ // const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]);
58
+ const [searchValue, setSearchValue] = useState('');
59
+ const [selectedKeys, setSelectedKeys] = useState(defaultSelectedKeys);
60
+ const treeData = useMemo(() => {
61
+ const loop = data => data.map(item => {
62
+ const strTitle = item.title;
63
+ const index = strTitle.indexOf(searchValue);
64
+ const beforeStr = strTitle.substring(0, index);
65
+ const afterStr = strTitle.slice(index + searchValue.length);
66
+ const title = index > -1 ? /*#__PURE__*/React.createElement("span", {
67
+ key: item.key
68
+ }, beforeStr, /*#__PURE__*/React.createElement("span", {
69
+ className: "site-tree-search-value"
70
+ }, searchValue), afterStr) : /*#__PURE__*/React.createElement("span", {
71
+ key: item.key
72
+ }, strTitle);
73
+ if (item.children) {
74
+ return {
75
+ title,
76
+ key: item.key,
77
+ children: loop(item.children)
78
+ };
79
+ }
80
+ return {
81
+ title,
82
+ key: item.key
83
+ };
84
+ });
85
+
86
+ // return loop(defaultData);
87
+ return loop(columns);
88
+ }, [searchValue]);
89
+ const hide = () => {
90
+ setClicked(false);
91
+ };
92
+ const handleClickChange = open => {
93
+ setClicked(open);
94
+ };
95
+ const onExpand = () => {
96
+ // setExpandedKeys(newExpandedKeys)
97
+ setAutoExpandParent(false);
98
+ };
99
+
100
+ // const getParentKey = (key: React.Key, tree: TreeDataNode[]): React.Key => {
101
+ // let parentKey: React.Key
102
+ // for (let i = 0; i < tree.length; i++) {
103
+ // const node = tree[i]
104
+ // if (node.children) {
105
+ // if (node.children.some((item) => item.key === key)) {
106
+ // parentKey = node.key
107
+ // } else if (getParentKey(key, node.children)) {
108
+ // parentKey = getParentKey(key, node.children)
109
+ // }
110
+ // }
111
+ // }
112
+ // return parentKey!
113
+ // }
114
+
115
+ const onChange = e => {
116
+ const {
117
+ value
118
+ } = e.target;
119
+ // const newExpandedKeys = dataList
120
+ // .map((item) => {
121
+ // if (item.title.indexOf(value) > -1) {
122
+ // return getParentKey(item.key, defaultData)
123
+ // }
124
+ // return null
125
+ // })
126
+ // .filter((item, i, self): item is React.Key => !!(item && self.indexOf(item) === i))
127
+ // setExpandedKeys(newExpandedKeys)
128
+ setSearchValue(value);
129
+ setAutoExpandParent(true);
130
+ };
131
+ const onCheck = keys => {
132
+ setSelectedKeys(keys);
133
+ };
134
+ const handleAccept = () => {
135
+ const rs1 = updateColumns(columns, selectedKeys);
136
+ changeHiddenColumn(rs1);
137
+ hide();
138
+ };
139
+ const handleCancel = () => {
140
+ setSelectedKeys(defaultSelectedKeys);
141
+ hide();
142
+ };
143
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Popover, {
144
+ placement: 'bottomLeft',
145
+ content: /*#__PURE__*/React.createElement("div", {
146
+ style: {
147
+ minWidth: 250
148
+ }
149
+ }, /*#__PURE__*/React.createElement(Search, {
150
+ style: {
151
+ marginBottom: 8
152
+ },
153
+ placeholder: "Search",
154
+ onChange: onChange
155
+ }), /*#__PURE__*/React.createElement(Tree, {
156
+ onExpand: onExpand
157
+ // expandedKeys={expandedKeys}
158
+ ,
159
+ autoExpandParent: autoExpandParent,
160
+ treeData: treeData,
161
+ defaultExpandAll: true,
162
+ checkable: true
163
+ // onSelect={(keys, info) => {
164
+ // const key = info.node.key
165
+ // console.log('selectedKeys', keys)
166
+ // console.log('info', info)
167
+ //
168
+ // const find = findItemByKey(columns, 'key', key)
169
+ //
170
+ // // const tmpColumn
171
+ //
172
+ // // if (selectedKeys.includes(key as string)) {
173
+ // // const rssss = findKeyPath(columns, key as string)
174
+ // // const rs = selectedKeys.filter(item => !rssss.includes(item));
175
+ // //
176
+ // // setSelectedKeys(rs)
177
+ // // } else {
178
+ //
179
+ // // const rs = [...selectedKeys, keys[0]]
180
+ //
181
+ // // console.log('rs', rs)
182
+ // // setSelectedKeys(keys)
183
+ // // }
184
+ // }}
185
+ ,
186
+ onCheck: keys => onCheck(keys),
187
+ multiple: true,
188
+ checkedKeys: selectedKeys,
189
+ defaultCheckedKeys: selectedKeys,
190
+ selectedKeys: [],
191
+ height: window.innerHeight - 200
192
+ }), /*#__PURE__*/React.createElement(BoxAction, {
193
+ className: 'px-1'
194
+ }, /*#__PURE__*/React.createElement(Button
195
+ // className={classnames('btn-action btn-action-submit', {
196
+ // // disable: !columns.find((item) => item.visible !== false || item.visible)
197
+ // })}
198
+ , {
199
+ onClick: handleAccept
200
+ // disabled={!columns.find((item) => item.visible !== false || item.visible)}
201
+ }, 'OK'), /*#__PURE__*/React.createElement(Button, {
202
+ className: 'btn-action btn-action-cancel',
203
+ onClick: handleCancel
204
+ }, 'Cancel'))),
205
+ trigger: "click",
206
+ open: clicked,
207
+ onOpenChange: handleClickChange,
208
+ arrow: false
209
+ }, /*#__PURE__*/React.createElement(Tooltip, {
210
+ arrow: false,
211
+ title: 'Cài đặt'
212
+ }, /*#__PURE__*/React.createElement(SettingOutlined, null))));
213
+ };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import type { MenuProps } from "antd";
3
- import { ContextInfo } from "../../type";
3
+ import type { ContextInfo } from "./type";
4
4
  export declare const findItemByKey: (array: any[], key: string, value: any) => any;
5
5
  type Props<RecordType> = {
6
6
  rowData: RecordType | null;
@@ -0,0 +1,126 @@
1
+ import * as React from "react";
2
+ import { Dropdown, Menu } from "antd";
3
+ export const findItemByKey = (array, key, value) => {
4
+ for (let i = 0; i < array.length; i++) {
5
+ const item = array[i];
6
+ if (item[key] === value) {
7
+ return item;
8
+ }
9
+ if (item.children && item.children.length > 0) {
10
+ const foundInChildren = findItemByKey(item.children, key, value);
11
+ if (foundInChildren) {
12
+ return foundInChildren;
13
+ }
14
+ }
15
+ }
16
+ return null;
17
+ };
18
+ const ContextMenu = props => {
19
+ const {
20
+ menuRef,
21
+ open,
22
+ setOpen,
23
+ pos,
24
+ contextMenuClick,
25
+ contextMenuItems,
26
+ rowData
27
+ } = props;
28
+
29
+ // const addPopupOffset = (items: MenuProps["items"]) : any => {
30
+ // return items?.map(item =>
31
+ // item && "children" in item
32
+ // ? {
33
+ // ...item,
34
+ // // popupOffset: [0, 30],
35
+ // children: addPopupOffset(item.children) }
36
+ // : item
37
+ // );
38
+ // };
39
+
40
+ // const newItems = React.useMemo(() => {
41
+ // return addPopupOffset(items)
42
+ // }, [items])
43
+
44
+ return (
45
+ /*#__PURE__*/
46
+ // <div>
47
+ // {open && (
48
+ // <div
49
+ // ref={menuRef}
50
+ // style={{
51
+ // position: "absolute",
52
+ // top: pos.y,
53
+ // left: pos.x,
54
+ // zIndex: 1000,
55
+ // background: "white",
56
+ // border: "1px solid #ddd",
57
+ // boxShadow: "2px 2px 5px rgba(0,0,0,0.2)",
58
+ // }}
59
+ // // onClick={() => setOpen(false)}
60
+ // >
61
+ // <Menu
62
+ // items={contextMenuItems}
63
+ // style={{ minWidth: 200, maxWidth: 400, maxHeight: pos.viewportHeight - 20 , width: 200 }}
64
+ // rootClassName={'popup-context-menu'}
65
+ //
66
+ // onClick={(e) => {
67
+ // contextMenuClick?.({
68
+ // rowInfo: {
69
+ // rowData
70
+ // },
71
+ // event: e.domEvent,
72
+ // item: {
73
+ // ...findItemByKey(contextMenuItems as any[], 'key', e.key ),
74
+ // id: e.key
75
+ // }
76
+ // })
77
+ // }} >
78
+ // </Menu>
79
+ // </div>
80
+ // )}
81
+ // </div>
82
+ React.createElement(Dropdown, {
83
+ placement: 'topRight',
84
+ open: open,
85
+ overlayStyle: {
86
+ left: `${pos.x}px`,
87
+ top: `${pos.y}px`
88
+ },
89
+ dropdownRender: () => {
90
+ return /*#__PURE__*/React.createElement("div", {
91
+ ref: menuRef
92
+ }, /*#__PURE__*/React.createElement(Menu, {
93
+ items: contextMenuItems,
94
+ style: {
95
+ minWidth: 200,
96
+ maxWidth: 400,
97
+ maxHeight: pos.viewportHeight - 20,
98
+ width: 200
99
+ },
100
+ rootClassName: 'popup-context-menu',
101
+ onClick: e => {
102
+ setOpen(false);
103
+ contextMenuClick?.({
104
+ rowInfo: {
105
+ rowData
106
+ },
107
+ event: e.domEvent,
108
+ item: {
109
+ ...findItemByKey(contextMenuItems, 'key', e.key),
110
+ id: e.key
111
+ }
112
+ });
113
+
114
+ // if (!open) {
115
+ // document.addEventListener(`click`, function onClickOutside() {
116
+ // setOpen(false);
117
+ // document.removeEventListener(`click`, onClickOutside);
118
+ // });
119
+ // }
120
+ }
121
+ }));
122
+ }
123
+ }, /*#__PURE__*/React.createElement(React.Fragment, null))
124
+ );
125
+ };
126
+ export default ContextMenu;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { AnyObject } from "../../type";
3
- import { FilterSearchType, TableLocale } from "antd/es/table/interface";
2
+ import type { FilterSearchType, TableLocale } from "antd/es/table/interface";
3
+ import type { AnyObject } from "./type";
4
4
  interface FilterSearchProps<RecordType = AnyObject> {
5
5
  value: string;
6
6
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
@@ -8,5 +8,5 @@ interface FilterSearchProps<RecordType = AnyObject> {
8
8
  tablePrefixCls: string;
9
9
  locale: TableLocale;
10
10
  }
11
- declare const FilterSearch: <RecordType extends AnyObject = AnyObject>(props: FilterSearchProps<RecordType>) => React.JSX.Element | null;
11
+ declare const FilterSearch: <RecordType extends AnyObject = AnyObject>(props: FilterSearchProps<RecordType>) => React.JSX.Element;
12
12
  export default FilterSearch;