es-grid-template 0.0.7 → 0.0.8

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,5 +1,5 @@
1
1
  import * as React from "react";
2
- import type { TableLocale } from "ui-rc/dist/table/interface";
2
+ import type { TableLocale } from "rc-master-ui/es/table/interface";
3
3
  type Props = {
4
4
  options: any[];
5
5
  filterSearch?: boolean;
@@ -1,14 +1,10 @@
1
1
  import * as React from "react";
2
2
  import classNames from "classnames";
3
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";
4
+ import { Checkbox, Menu, Radio, Empty } from "rc-master-ui";
5
+ import { Tree } from "antd";
6
+ import { flattenKeys } from "rc-master-ui/es/table/hooks/useFilter";
7
+ // import Tree from "rc-master-ui/es/tree";
12
8
 
13
9
  function searchValueMatched(searchValue, text) {
14
10
  if (typeof text === 'string' || typeof text === 'number') {
@@ -153,10 +149,11 @@ const CheckboxFilter = props => {
153
149
  children: node.children?.map(item => getFilterData(item)) || []
154
150
  });
155
151
  const onCheckAll = e => {
156
- console.log('e.target.checked', e.target.checked);
152
+ // console.log('e.target.checked', e.target.checked)
157
153
  if (e.target.checked) {
158
154
  const allFilterKeys = flattenKeys(options).map(key => String(key));
159
- console.log('allFilterKeys', allFilterKeys);
155
+
156
+ // console.log('allFilterKeys', allFilterKeys)
160
157
  // setFilteredKeysSync(allFilterKeys);
161
158
  onSelect?.(allFilterKeys);
162
159
  } else {
@@ -1,10 +1,9 @@
1
1
  import type { Dispatch, SetStateAction } from "react";
2
2
  import React from "react";
3
- import type { TableColumnsType } from "ui-rc";
4
- export declare const BoxInputFilterColumn: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
3
+ import type { ColumnsType } from "./type";
5
4
  export type IColumnsChoose<RecordType> = {
6
5
  columns: any[];
7
- setColumns: Dispatch<SetStateAction<TableColumnsType<RecordType>>>;
6
+ setColumns: Dispatch<SetStateAction<ColumnsType<RecordType>>>;
8
7
  t?: any;
9
8
  };
10
9
  export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;
@@ -1,91 +1,84 @@
1
- import React, { Fragment, useMemo, useState } from "react";
1
+ import React, { Fragment, useEffect, useMemo, useState } from "react";
2
2
  import styled from "styled-components";
3
- import { Button, Input, Popover, Tooltip, Tree } from "antd";
3
+ // import type { TreeDataNode} from "antd";
4
+ import { Button, Input, Popover, Tooltip } from "antd";
4
5
  import { SettingOutlined } from "@ant-design/icons";
5
6
  import { getVisibleColumnKeys, updateColumns } from "./hooks";
6
- const {
7
- Search
8
- } = Input;
7
+ import Tree from "rc-master-ui/es/tree";
8
+ import SearchOutlined from "@ant-design/icons/SearchOutlined";
9
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
- // `
10
+ // const { Search } = Input;
22
11
 
23
12
  const BoxAction = styled.div.withConfig({
24
13
  displayName: "BoxAction",
25
14
  componentId: "es-grid-template__sc-1k89i9w-0"
26
15
  })(["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
16
  export const ColumnsChoose = props => {
32
17
  const {
33
18
  columns: propsColumns,
34
19
  setColumns: changeHiddenColumn
35
20
  // t,
36
- // columnsGrouped,
37
- // onChangeDisplay
38
- // frozen
39
21
  } = props;
40
22
 
41
23
  // const dataList: { key: React.Key; title: string }[] = [];
42
24
 
43
- const defaultColumns = useMemo(() => {
44
- const rs = propsColumns.filter(it => it.key || it.dataIndex);
45
- return rs;
25
+ // const defaultColumns = useMemo(() => {
26
+ // return propsColumns.filter((it) => it.key || it.dataIndex && it.showColumnChoose !== false)
27
+ // }, [propsColumns])
28
+
29
+ // const columnsChooseRef: any = useRef()
30
+ // const searchRef: any = useRef()
31
+
32
+ const [columns, setColumns] = useState([]);
33
+ const [selectedKeys, setSelectedKeys] = useState([]);
34
+ useEffect(() => {
35
+ const defaultColumns = propsColumns.filter(it => it.key || it.dataIndex && it.showColumnChoose !== false);
36
+ const defaultSelectedKeys = getVisibleColumnKeys(propsColumns);
37
+ setSelectedKeys(defaultSelectedKeys);
38
+ setColumns(defaultColumns);
46
39
  }, [propsColumns]);
47
40
  const defaultSelectedKeys = useMemo(() => {
48
41
  return getVisibleColumnKeys(propsColumns);
49
42
  }, [propsColumns]);
50
43
 
51
- // const columnsChooseRef: any = useRef()
52
- // const searchRef: any = useRef()
44
+ // console.log('defaultSelectedKeys', defaultSelectedKeys)
53
45
 
54
- const [columns] = useState(defaultColumns);
55
46
  const [clicked, setClicked] = useState(false);
56
47
  const [autoExpandParent, setAutoExpandParent] = useState(true);
57
48
  // 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
- });
49
+ // const [searchValue, setSearchValue] = useState('');
50
+
51
+ // const treeData = useMemo(() => {
52
+ // const loop = (data: TreeDataNode[]): TreeDataNode[] =>
53
+ // data.map((item) => {
54
+ // const strTitle = item.title as string;
55
+ // const index = strTitle.indexOf(searchValue);
56
+ // const beforeStr = strTitle.substring(0, index);
57
+ // const afterStr = strTitle.slice(index + searchValue.length);
58
+ // const title =
59
+ // index > -1 ? (
60
+ // <span key={item.key}>
61
+ // {beforeStr}
62
+ // <span className="site-tree-search-value">{searchValue}</span>
63
+ // {afterStr}
64
+ // </span>
65
+ // ) : (
66
+ // <span key={item.key}>{strTitle}</span>
67
+ // );
68
+ // if (item.children) {
69
+ // return { title, key: item.key, children: loop(item.children) };
70
+ // }
71
+ //
72
+ // return {
73
+ // title,
74
+ // key: item.key,
75
+ // };
76
+ // });
77
+ //
78
+ // // return loop(defaultData);
79
+ // return loop(columns as any);
80
+ // }, [searchValue, columns]);
85
81
 
86
- // return loop(defaultData);
87
- return loop(columns);
88
- }, [searchValue]);
89
82
  const hide = () => {
90
83
  setClicked(false);
91
84
  };
@@ -112,10 +105,9 @@ export const ColumnsChoose = props => {
112
105
  // return parentKey!
113
106
  // }
114
107
 
115
- const onChange = e => {
116
- const {
117
- value
118
- } = e.target;
108
+ // const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
109
+ const onChange = () => {
110
+ // const { value } = e.target
119
111
  // const newExpandedKeys = dataList
120
112
  // .map((item) => {
121
113
  // if (item.title.indexOf(value) > -1) {
@@ -125,14 +117,15 @@ export const ColumnsChoose = props => {
125
117
  // })
126
118
  // .filter((item, i, self): item is React.Key => !!(item && self.indexOf(item) === i))
127
119
  // setExpandedKeys(newExpandedKeys)
128
- setSearchValue(value);
120
+
121
+ // setSearchValue(value)
129
122
  setAutoExpandParent(true);
130
123
  };
131
124
  const onCheck = keys => {
132
125
  setSelectedKeys(keys);
133
126
  };
134
127
  const handleAccept = () => {
135
- const rs1 = updateColumns(columns, selectedKeys);
128
+ const rs1 = updateColumns(propsColumns, selectedKeys);
136
129
  changeHiddenColumn(rs1);
137
130
  hide();
138
131
  };
@@ -146,18 +139,21 @@ export const ColumnsChoose = props => {
146
139
  style: {
147
140
  minWidth: 250
148
141
  }
149
- }, /*#__PURE__*/React.createElement(Search, {
142
+ }, /*#__PURE__*/React.createElement(Input, {
150
143
  style: {
151
144
  marginBottom: 8
152
145
  },
153
146
  placeholder: "Search",
147
+ prefix: /*#__PURE__*/React.createElement(SearchOutlined, null),
154
148
  onChange: onChange
155
149
  }), /*#__PURE__*/React.createElement(Tree, {
156
150
  onExpand: onExpand
157
151
  // expandedKeys={expandedKeys}
158
152
  ,
159
- autoExpandParent: autoExpandParent,
160
- treeData: treeData,
153
+ autoExpandParent: autoExpandParent
154
+ // treeData={treeData}
155
+ ,
156
+ treeData: columns,
161
157
  defaultExpandAll: true,
162
158
  checkable: true
163
159
  // onSelect={(keys, info) => {
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import SearchOutlined from '@ant-design/icons/SearchOutlined';
3
- import { Input } from 'ui-rc';
3
+ import { Input } from 'rc-master-ui';
4
4
  const FilterSearch = props => {
5
5
  const {
6
6
  value,
@@ -3,5 +3,5 @@ import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
4
  import './styles.scss';
5
5
  import type { GridTableProps } from "./type";
6
- declare const GridTable: <RecordType extends object>(props: GridTableProps<RecordType>) => React.JSX.Element;
7
- export default GridTable;
6
+ declare const InternalTable: <RecordType extends object>(props: GridTableProps<RecordType>) => React.JSX.Element;
7
+ export default InternalTable;
@@ -0,0 +1,185 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import React, { Fragment, useEffect, useState } from 'react';
3
+ import { Table } from "rc-master-ui";
4
+ import dayjs from "dayjs";
5
+ import 'dayjs/locale/es';
6
+ import 'dayjs/locale/vi';
7
+ import "./styles.scss";
8
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
9
+ import styled from "styled-components";
10
+ import TableGrid from "./TableGrid";
11
+ import { Resizable } from "react-resizable";
12
+ // import {ColumnsChoose} from "./ColumnsChoose";
13
+
14
+ dayjs.extend(customParseFormat);
15
+ const ResizableTitle = props => {
16
+ const {
17
+ onResize,
18
+ width,
19
+ ...restProps
20
+ } = props;
21
+ if (!width) {
22
+ return /*#__PURE__*/React.createElement("th", restProps);
23
+ }
24
+ return (
25
+ /*#__PURE__*/
26
+ // @ts-ignore
27
+ React.createElement(Resizable, {
28
+ width: width,
29
+ height: 0,
30
+ handle: /*#__PURE__*/React.createElement("span", {
31
+ className: "react-resizable-handle",
32
+ onClick: e => {
33
+ e.stopPropagation();
34
+ }
35
+ }),
36
+ onResize: onResize,
37
+ draggableOpts: {
38
+ enableUserSelectHack: false
39
+ }
40
+ }, /*#__PURE__*/React.createElement("th", restProps))
41
+ );
42
+ };
43
+ const GridStyle = styled.div.withConfig({
44
+ displayName: "GridStyle",
45
+ componentId: "es-grid-template__sc-1fs85vo-0"
46
+ })([".ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;visibility:visible;right:0;}}"], props => props.heightTable ? typeof props.heightTable === 'string' ? props.heightTable : `${props.heightTable}px` : undefined, props => props.heightTable ? `${props.heightTable}px` : undefined);
47
+ const InternalTable = props => {
48
+ const {
49
+ columns,
50
+ // title,
51
+ dataSource,
52
+ // toolbarItems,
53
+ // showColumnChoose,
54
+ ...rest
55
+ } = props;
56
+ const [tmpColumns, setColumns] = useState([]);
57
+ useEffect(() => {
58
+ const rs = columns ? [Table.SELECTION_COLUMN, ...columns] : [];
59
+ setColumns(rs);
60
+ }, [columns]);
61
+ const handleResize = indexPath => (e, {
62
+ size
63
+ }) => {
64
+ const updateColumns = (cols, path) => {
65
+ const [currentIndex, ...restPath] = path;
66
+ return cols.map((col, idx) => {
67
+ if (idx === currentIndex) {
68
+ if (restPath.length === 0) {
69
+ // Cập nhật width của cột cuối cùng trong path
70
+ // return { ...col, width: size.width }
71
+
72
+ // Kiểm tra minWidth trước khi cập nhật width
73
+ if (col.minWidth && size.width < col.minWidth) {
74
+ e.preventDefault();
75
+ return col; // Không cập nhật nếu nhỏ hơn minWidth
76
+ }
77
+
78
+ // Kiểm tra minWidth trước khi cập nhật width
79
+ if (col.maxWidth && size.width > col.maxWidth) {
80
+ e.preventDefault();
81
+ return col; // Không cập nhật nếu nhỏ hơn minWidth
82
+ }
83
+ return {
84
+ ...col,
85
+ width: size.width
86
+ };
87
+ } else if (col.children) {
88
+ // Tiếp tục cập nhật các cấp con
89
+ return {
90
+ ...col,
91
+ children: updateColumns(col.children, restPath)
92
+ };
93
+ }
94
+ }
95
+ // e.preventDefault()
96
+ return col;
97
+ });
98
+ };
99
+ setColumns(prevColumns => updateColumns(prevColumns, indexPath));
100
+ };
101
+ const addResizeHandlers = React.useCallback((cols, parentPath = []) => {
102
+ return cols.map((col, index) => {
103
+ const currentPath = [...parentPath, index];
104
+ if (!col?.dataIndex && !col.key) {
105
+ return col;
106
+ }
107
+ if (col.children) {
108
+ return {
109
+ ...col,
110
+ title: col.headerText ?? col.title,
111
+ ellipsis: col.ellipsis !== false,
112
+ children: addResizeHandlers(col.children, currentPath)
113
+ };
114
+ }
115
+ return {
116
+ ...col,
117
+ title: col.headerText ?? col.title,
118
+ ellipsis: col.ellipsis !== false,
119
+ onHeaderCell: () => ({
120
+ width: col.width,
121
+ onResize: handleResize(currentPath)
122
+ })
123
+ };
124
+ });
125
+ }, []);
126
+ const resizableColumns = React.useMemo(() => {
127
+ return addResizeHandlers(tmpColumns);
128
+ }, [addResizeHandlers, tmpColumns]);
129
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
130
+ heightTable: props.style?.minHeight,
131
+ style: {
132
+ position: 'relative'
133
+ }
134
+ }, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
135
+ dataSource: dataSource,
136
+ components: {
137
+ header: {
138
+ cell: ResizableTitle
139
+ }
140
+ },
141
+ columns: resizableColumns,
142
+ setColumns: setColumns,
143
+ showSorterTooltip: {
144
+ target: 'sorter-icon'
145
+ }
146
+
147
+ // title={() => {
148
+ // return (
149
+ // <Fragment>
150
+ // <div>
151
+ // {title?.(dataSource as any)}
152
+ // </div>
153
+ //
154
+ //
155
+ // {(toolbarItems || showColumnChoose !== false) && (
156
+ // <div style={{display: 'flex', justifyContent: 'space-between'}}>
157
+ //
158
+ // <Toolbar
159
+ // style={{width: '100%'}}
160
+ // items={toolbarItems ?? []}
161
+ // mode={'responsive'}
162
+ // // mode={'scroll'}
163
+ // onClick={(val: any) => {
164
+ // console.log(val)
165
+ // }}
166
+ // />
167
+ //
168
+ // {showColumnChoose && (
169
+ // <ColumnsChoose
170
+ // columns={resizableColumns}
171
+ // setColumns={setColumns}
172
+ // />
173
+ // )}
174
+ //
175
+ // <div />
176
+ // </div>
177
+ // )}
178
+ //
179
+ //
180
+ // </Fragment>
181
+ // )
182
+ // }}
183
+ }))));
184
+ };
185
+ export default InternalTable;
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ declare const ComponentSpinner: () => React.JSX.Element;
3
+ export default ComponentSpinner;
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import styled from "styled-components";
3
+ const SpinnerStyle = styled.div.withConfig({
4
+ displayName: "SpinnerStyle",
5
+ componentId: "es-grid-template__sc-180f2ml-0"
6
+ })(["width:1em;height:1em;font-size:20px;display:inline-block;transition:transform 0.3s ease,opacity 0.3s ease;transform-origin:50% 50%;line-height:1;.loading{position:absolute;top:50%;inset-inline-start:50%;margin:-10px;width:55px;height:55px;border-radius:50%;border:3px solid transparent;-webkit-box-sizing:border-box;box-sizing:border-box;.effect-1,.effect-2,.effect-3{width:36px;height:36px;border-radius:50%;border:3px solid transparent;border-left:3px solid #eb4619;-webkit-box-sizing:border-box;box-sizing:border-box;}.effect-1{position:absolute;animation:rotate 1s ease infinite;}.effect-2{position:absolute;animation:rotateOpacity 1s ease infinite 0.1s;}.effect-3{-webkit-animation:rotateOpacity 1s ease infinite 0.2s;animation:rotateOpacity 1s ease infinite 0.2s;}.loading .effects{transition:all 0.3s ease;}}@keyframes rotate{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg);}100%{-webkit-transform:rotate(1turn);transform:rotate(1turn);}}@keyframes rotateOpacity{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg);opacity:0.1;}100%{-webkit-transform:rotate(1turn);transform:rotate(1turn);opacity:1;}}"]);
7
+ const ComponentSpinner = () => {
8
+ return /*#__PURE__*/React.createElement(SpinnerStyle, {
9
+ className: "fallback-spinner"
10
+ }, /*#__PURE__*/React.createElement("div", {
11
+ className: "loading"
12
+ }, /*#__PURE__*/React.createElement("div", {
13
+ className: "effect-1 effects"
14
+ }), /*#__PURE__*/React.createElement("div", {
15
+ className: "effect-2 effects"
16
+ }), /*#__PURE__*/React.createElement("div", {
17
+ className: "effect-3 effects"
18
+ })));
19
+ };
20
+ export default ComponentSpinner;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import 'dayjs/locale/es';
3
+ import 'dayjs/locale/vi';
4
+ import './styles.scss';
5
+ import type { GridTableProps } from "./type";
6
+ type GridProps<T> = GridTableProps<T> & {
7
+ setColumns: any;
8
+ };
9
+ declare const TableGrid: <RecordType extends object>(props: GridProps<RecordType>) => React.JSX.Element;
10
+ export default TableGrid;