musae 1.3.1-beta.20 → 1.3.1-beta.22
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/dist/components/form/item.cjs +2 -1
- package/dist/components/form/item.mjs +2 -1
- package/dist/components/pagination/pagination.cjs +9 -4
- package/dist/components/pagination/pagination.mjs +9 -4
- package/dist/components/table/hooks/use-pagination.hook.cjs +62 -0
- package/dist/components/table/hooks/use-pagination.hook.d.ts +10 -0
- package/dist/components/table/hooks/use-pagination.hook.mjs +60 -0
- package/dist/components/table/styles.cjs +9 -0
- package/dist/components/table/styles.d.ts +7 -0
- package/dist/components/table/styles.mjs +9 -0
- package/dist/components/table/table.cjs +46 -12
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.mjs +48 -14
- package/dist/styles.css +4 -0
- package/dist/types/table.d.ts +6 -0
- package/package.json +1 -1
|
@@ -42,8 +42,6 @@ var Pagination = function Pagination(_ref) {
|
|
|
42
42
|
onPageSizeChange: _onPageSizeChange
|
|
43
43
|
}),
|
|
44
44
|
paginationItems = _usePagiantion.paginationItems,
|
|
45
|
-
add = _usePagiantion.add,
|
|
46
|
-
subtract = _usePagiantion.subtract,
|
|
47
45
|
onChange = _usePagiantion.onChange,
|
|
48
46
|
at = _usePagiantion.at,
|
|
49
47
|
hasNext = _usePagiantion.hasNext,
|
|
@@ -54,6 +52,7 @@ var Pagination = function Pagination(_ref) {
|
|
|
54
52
|
pagination: stylex.props(styles.default.pagination.base),
|
|
55
53
|
sizer: stylex.props(styles.default.pagination.sizer)
|
|
56
54
|
};
|
|
55
|
+
var pages = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
57
56
|
var sizeOptions = React.useMemo(function () {
|
|
58
57
|
return relax.unique(pageSizes).map(function (size) {
|
|
59
58
|
return {
|
|
@@ -73,8 +72,14 @@ var Pagination = function Pagination(_ref) {
|
|
|
73
72
|
key: item$1
|
|
74
73
|
}, /*#__PURE__*/React.createElement(item.default, {
|
|
75
74
|
value: item$1,
|
|
76
|
-
add: add
|
|
77
|
-
|
|
75
|
+
add: function add() {
|
|
76
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
77
|
+
return onChange(Math.min(pages, at + step));
|
|
78
|
+
},
|
|
79
|
+
subtract: function subtract() {
|
|
80
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
81
|
+
return onChange(Math.max(1, at - step));
|
|
82
|
+
},
|
|
78
83
|
onClick: onChange,
|
|
79
84
|
checked: at === item$1,
|
|
80
85
|
hasNext: hasNext,
|
|
@@ -38,8 +38,6 @@ var Pagination = function Pagination(_ref) {
|
|
|
38
38
|
onPageSizeChange: _onPageSizeChange
|
|
39
39
|
}),
|
|
40
40
|
paginationItems = _usePagiantion.paginationItems,
|
|
41
|
-
add = _usePagiantion.add,
|
|
42
|
-
subtract = _usePagiantion.subtract,
|
|
43
41
|
onChange = _usePagiantion.onChange,
|
|
44
42
|
at = _usePagiantion.at,
|
|
45
43
|
hasNext = _usePagiantion.hasNext,
|
|
@@ -50,6 +48,7 @@ var Pagination = function Pagination(_ref) {
|
|
|
50
48
|
pagination: props(styles.pagination.base),
|
|
51
49
|
sizer: props(styles.pagination.sizer)
|
|
52
50
|
};
|
|
51
|
+
var pages = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
53
52
|
var sizeOptions = useMemo(function () {
|
|
54
53
|
return unique(pageSizes).map(function (size) {
|
|
55
54
|
return {
|
|
@@ -69,8 +68,14 @@ var Pagination = function Pagination(_ref) {
|
|
|
69
68
|
key: item
|
|
70
69
|
}, /*#__PURE__*/React.createElement(Item, {
|
|
71
70
|
value: item,
|
|
72
|
-
add: add
|
|
73
|
-
|
|
71
|
+
add: function add() {
|
|
72
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
73
|
+
return onChange(Math.min(pages, at + step));
|
|
74
|
+
},
|
|
75
|
+
subtract: function subtract() {
|
|
76
|
+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
77
|
+
return onChange(Math.max(1, at - step));
|
|
78
|
+
},
|
|
74
79
|
onClick: onChange,
|
|
75
80
|
checked: at === item,
|
|
76
81
|
hasNext: hasNext,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var relax = require('@aiszlab/relax');
|
|
6
|
+
|
|
7
|
+
var usePagination = function usePagination(_ref) {
|
|
8
|
+
var pagination = _ref.pagination;
|
|
9
|
+
var _pagination = React.useMemo(function () {
|
|
10
|
+
if (pagination === false) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (relax.isNull(pagination)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return pagination !== null && pagination !== void 0 ? pagination : {};
|
|
17
|
+
}, []);
|
|
18
|
+
var isPaginationHidden = !_pagination;
|
|
19
|
+
var _useControlledState = relax.useControlledState(_pagination === null || _pagination === void 0 ? void 0 : _pagination.at, {
|
|
20
|
+
defaultState: 1
|
|
21
|
+
}),
|
|
22
|
+
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
23
|
+
at = _useControlledState2[0],
|
|
24
|
+
setAt = _useControlledState2[1];
|
|
25
|
+
var _useControlledState3 = relax.useControlledState(_pagination === null || _pagination === void 0 ? void 0 : _pagination.pageSize, {
|
|
26
|
+
defaultState: 10
|
|
27
|
+
}),
|
|
28
|
+
_useControlledState4 = _slicedToArray(_useControlledState3, 2),
|
|
29
|
+
pageSize = _useControlledState4[0],
|
|
30
|
+
setPageSize = _useControlledState4[1];
|
|
31
|
+
var paginationState = React.useMemo(function () {
|
|
32
|
+
return {
|
|
33
|
+
pageIndex: at,
|
|
34
|
+
pageSize: pageSize
|
|
35
|
+
};
|
|
36
|
+
}, [at, pageSize]);
|
|
37
|
+
var changeAt = relax.useEvent(function (_at) {
|
|
38
|
+
var _pagination$onChange;
|
|
39
|
+
setAt(_at);
|
|
40
|
+
if (_at === at) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
_pagination === null || _pagination === void 0 || (_pagination$onChange = _pagination.onChange) === null || _pagination$onChange === void 0 || _pagination$onChange.call(_pagination, _at);
|
|
44
|
+
});
|
|
45
|
+
var changePageSize = relax.useEvent(function (_pageSize) {
|
|
46
|
+
var _pagination$onPageSiz;
|
|
47
|
+
setPageSize(_pageSize);
|
|
48
|
+
console.log("_pageSize=======", _pageSize);
|
|
49
|
+
if (_pageSize === pageSize) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
_pagination === null || _pagination === void 0 || (_pagination$onPageSiz = _pagination.onPageSizeChange) === null || _pagination$onPageSiz === void 0 || _pagination$onPageSiz.call(_pagination, _pageSize);
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
pagination: paginationState,
|
|
56
|
+
changeAt: changeAt,
|
|
57
|
+
changePageSize: changePageSize,
|
|
58
|
+
isPaginationHidden: isPaginationHidden
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.usePagination = usePagination;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableProps } from "../../../types/table";
|
|
2
|
+
import type { PaginationState } from "@tanstack/react-table";
|
|
3
|
+
type UsingPagination = Pick<TableProps<unknown>, "pagination">;
|
|
4
|
+
declare const usePagination: ({ pagination }: UsingPagination) => {
|
|
5
|
+
pagination: PaginationState;
|
|
6
|
+
changeAt: (_at: number) => void;
|
|
7
|
+
changePageSize: (_pageSize: number) => void;
|
|
8
|
+
isPaginationHidden: boolean;
|
|
9
|
+
};
|
|
10
|
+
export { usePagination };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { isNull, useControlledState, useEvent } from '@aiszlab/relax';
|
|
4
|
+
|
|
5
|
+
var usePagination = function usePagination(_ref) {
|
|
6
|
+
var pagination = _ref.pagination;
|
|
7
|
+
var _pagination = useMemo(function () {
|
|
8
|
+
if (pagination === false) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (isNull(pagination)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return pagination !== null && pagination !== void 0 ? pagination : {};
|
|
15
|
+
}, []);
|
|
16
|
+
var isPaginationHidden = !_pagination;
|
|
17
|
+
var _useControlledState = useControlledState(_pagination === null || _pagination === void 0 ? void 0 : _pagination.at, {
|
|
18
|
+
defaultState: 1
|
|
19
|
+
}),
|
|
20
|
+
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
21
|
+
at = _useControlledState2[0],
|
|
22
|
+
setAt = _useControlledState2[1];
|
|
23
|
+
var _useControlledState3 = useControlledState(_pagination === null || _pagination === void 0 ? void 0 : _pagination.pageSize, {
|
|
24
|
+
defaultState: 10
|
|
25
|
+
}),
|
|
26
|
+
_useControlledState4 = _slicedToArray(_useControlledState3, 2),
|
|
27
|
+
pageSize = _useControlledState4[0],
|
|
28
|
+
setPageSize = _useControlledState4[1];
|
|
29
|
+
var paginationState = useMemo(function () {
|
|
30
|
+
return {
|
|
31
|
+
pageIndex: at,
|
|
32
|
+
pageSize: pageSize
|
|
33
|
+
};
|
|
34
|
+
}, [at, pageSize]);
|
|
35
|
+
var changeAt = useEvent(function (_at) {
|
|
36
|
+
var _pagination$onChange;
|
|
37
|
+
setAt(_at);
|
|
38
|
+
if (_at === at) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
_pagination === null || _pagination === void 0 || (_pagination$onChange = _pagination.onChange) === null || _pagination$onChange === void 0 || _pagination$onChange.call(_pagination, _at);
|
|
42
|
+
});
|
|
43
|
+
var changePageSize = useEvent(function (_pageSize) {
|
|
44
|
+
var _pagination$onPageSiz;
|
|
45
|
+
setPageSize(_pageSize);
|
|
46
|
+
console.log("_pageSize=======", _pageSize);
|
|
47
|
+
if (_pageSize === pageSize) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
_pagination === null || _pagination === void 0 || (_pagination$onPageSiz = _pagination.onPageSizeChange) === null || _pagination$onPageSiz === void 0 || _pagination$onPageSiz.call(_pagination, _pageSize);
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
pagination: paginationState,
|
|
54
|
+
changeAt: changeAt,
|
|
55
|
+
changePageSize: changePageSize,
|
|
56
|
+
isPaginationHidden: isPaginationHidden
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { usePagination };
|
|
@@ -9,6 +9,14 @@ var table = {
|
|
|
9
9
|
$$css: true
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
+
var pagination = {
|
|
13
|
+
base: {
|
|
14
|
+
k1xSpc: "musaex-78zum5",
|
|
15
|
+
kjj79g: "musaex-13a6bvl",
|
|
16
|
+
keoZOQ: "musaex-1jjqrzr",
|
|
17
|
+
$$css: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
12
20
|
var body = {
|
|
13
21
|
cell: {
|
|
14
22
|
kjGldf: "musaex-aafj1c",
|
|
@@ -95,6 +103,7 @@ var header = {
|
|
|
95
103
|
};
|
|
96
104
|
var styles = {
|
|
97
105
|
table: table,
|
|
106
|
+
pagination: pagination,
|
|
98
107
|
body: body,
|
|
99
108
|
cell: cell,
|
|
100
109
|
sort: sort,
|
|
@@ -5,6 +5,13 @@ declare const styles: {
|
|
|
5
5
|
readonly borderCollapse: import("@stylexjs/stylex").StyleXClassNameFor<"borderCollapse", "collapse">;
|
|
6
6
|
}>;
|
|
7
7
|
}>;
|
|
8
|
+
pagination: Readonly<{
|
|
9
|
+
readonly base: Readonly<{
|
|
10
|
+
readonly display: import("@stylexjs/stylex").StyleXClassNameFor<"display", "flex">;
|
|
11
|
+
readonly justifyContent: import("@stylexjs/stylex").StyleXClassNameFor<"justifyContent", "flex-end">;
|
|
12
|
+
readonly marginBlockStart: import("@stylexjs/stylex").StyleXClassNameFor<"marginBlockStart", string>;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
8
15
|
body: Readonly<{
|
|
9
16
|
readonly cell: Readonly<{
|
|
10
17
|
readonly borderInlineWidth: import("@stylexjs/stylex").StyleXClassNameFor<"borderInlineWidth", string>;
|
|
@@ -5,6 +5,14 @@ var table = {
|
|
|
5
5
|
$$css: true
|
|
6
6
|
}
|
|
7
7
|
};
|
|
8
|
+
var pagination = {
|
|
9
|
+
base: {
|
|
10
|
+
k1xSpc: "musaex-78zum5",
|
|
11
|
+
kjj79g: "musaex-13a6bvl",
|
|
12
|
+
keoZOQ: "musaex-1jjqrzr",
|
|
13
|
+
$$css: true
|
|
14
|
+
}
|
|
15
|
+
};
|
|
8
16
|
var body = {
|
|
9
17
|
cell: {
|
|
10
18
|
kjGldf: "musaex-aafj1c",
|
|
@@ -91,6 +99,7 @@ var header = {
|
|
|
91
99
|
};
|
|
92
100
|
var styles = {
|
|
93
101
|
table: table,
|
|
102
|
+
pagination: pagination,
|
|
94
103
|
body: body,
|
|
95
104
|
cell: cell,
|
|
96
105
|
sort: sort,
|
|
@@ -16,6 +16,8 @@ var className = require('@aiszlab/relax/class-name');
|
|
|
16
16
|
var useClassNames = require('../../hooks/use-class-names.cjs');
|
|
17
17
|
var loading = require('../loading/loading.cjs');
|
|
18
18
|
var relax = require('@aiszlab/relax');
|
|
19
|
+
var pagination = require('../pagination/pagination.cjs');
|
|
20
|
+
var usePagination_hook = require('./hooks/use-pagination.hook.cjs');
|
|
19
21
|
|
|
20
22
|
var Table = function Table(_ref) {
|
|
21
23
|
var _ref$bordered = _ref.bordered,
|
|
@@ -36,7 +38,8 @@ var Table = function Table(_ref) {
|
|
|
36
38
|
_ref$defaultExpandedK = _ref.defaultExpandedKeys,
|
|
37
39
|
defaultExpandedKeys = _ref$defaultExpandedK === void 0 ? [] : _ref$defaultExpandedK,
|
|
38
40
|
onExpandedKeysChange = _ref.onExpandedKeysChange,
|
|
39
|
-
rowKey = _ref.rowKey
|
|
41
|
+
rowKey = _ref.rowKey,
|
|
42
|
+
_pagination = _ref.pagination;
|
|
40
43
|
var classNames = useClassNames.useClassNames(context.CLASS_NAMES);
|
|
41
44
|
var columns = hooks.useColumns({
|
|
42
45
|
columns: _columns,
|
|
@@ -50,23 +53,42 @@ var Table = function Table(_ref) {
|
|
|
50
53
|
_useState2 = _slicedToArray(_useState, 2),
|
|
51
54
|
uncontrolledExpanded = _useState2[0],
|
|
52
55
|
setUncontrolledExpanded = _useState2[1];
|
|
56
|
+
var _usePagination = usePagination_hook.usePagination({
|
|
57
|
+
pagination: _pagination
|
|
58
|
+
}),
|
|
59
|
+
pagination$1 = _usePagination.pagination,
|
|
60
|
+
isPaginationHidden = _usePagination.isPaginationHidden,
|
|
61
|
+
changeAt = _usePagination.changeAt,
|
|
62
|
+
changePageSize = _usePagination.changePageSize;
|
|
53
63
|
var expanded = React.useMemo(function () {
|
|
54
64
|
return relax.isUndefined(expandedKeys) ? uncontrolledExpanded : Object.fromEntries(expandedKeys.map(function (key) {
|
|
55
65
|
return [String(key), true];
|
|
56
66
|
}));
|
|
57
67
|
}, [expandedKeys, uncontrolledExpanded]);
|
|
58
|
-
var table = reactTable.useReactTable(_objectSpread(_objectSpread({
|
|
68
|
+
var table = reactTable.useReactTable(_objectSpread(_objectSpread(_objectSpread({
|
|
59
69
|
columns: columns,
|
|
60
70
|
data: dataSource,
|
|
61
|
-
getCoreRowModel: reactTable.getCoreRowModel()
|
|
62
|
-
|
|
71
|
+
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
72
|
+
state: _objectSpread(_objectSpread({}, expandable && {
|
|
73
|
+
expanded: expanded
|
|
74
|
+
}), !isPaginationHidden && {
|
|
75
|
+
pagination: {
|
|
76
|
+
pageIndex: pagination$1.pageIndex - 1,
|
|
77
|
+
pageSize: pagination$1.pageSize
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}, !isPaginationHidden && {
|
|
81
|
+
getPaginationRowModel: reactTable.getPaginationRowModel(),
|
|
82
|
+
onPaginationChange: function onPaginationChange(updater) {
|
|
83
|
+
var next = relax.isFunction(updater) ? updater(pagination$1) : updater;
|
|
84
|
+
changeAt(next.pageIndex + 1);
|
|
85
|
+
changePageSize(next.pageSize);
|
|
86
|
+
}
|
|
87
|
+
}), expandable && {
|
|
63
88
|
getSubRows: function getSubRows(record) {
|
|
64
89
|
return record.children;
|
|
65
90
|
},
|
|
66
91
|
getExpandedRowModel: reactTable.getExpandedRowModel(),
|
|
67
|
-
state: {
|
|
68
|
-
expanded: expanded
|
|
69
|
-
},
|
|
70
92
|
onExpandedChange: function onExpandedChange(updater) {
|
|
71
93
|
var next = relax.isFunction(updater) ? updater(expanded) : updater;
|
|
72
94
|
if (relax.isUndefined(expandedKeys)) setUncontrolledExpanded(next);
|
|
@@ -76,7 +98,7 @@ var Table = function Table(_ref) {
|
|
|
76
98
|
}
|
|
77
99
|
}), rowKey && {
|
|
78
100
|
getRowId: function getRowId(record, index, parent) {
|
|
79
|
-
return String(relax.isFunction(rowKey) ? rowKey(record, index, parent === null || parent === void 0 ? void 0 : parent.original) : record
|
|
101
|
+
return String(relax.isFunction(rowKey) ? rowKey(record, index, parent === null || parent === void 0 ? void 0 : parent.original) : relax.get(record, rowKey));
|
|
80
102
|
}
|
|
81
103
|
}));
|
|
82
104
|
var contextValue = hooks.useContextValue({
|
|
@@ -86,15 +108,27 @@ var Table = function Table(_ref) {
|
|
|
86
108
|
onSortChange: onSortChange,
|
|
87
109
|
classNames: classNames
|
|
88
110
|
});
|
|
89
|
-
var styled =
|
|
111
|
+
var styled = {
|
|
112
|
+
table: stylex.props(styles.default.table.base),
|
|
113
|
+
pagination: stylex.props(styles.default.pagination.base)
|
|
114
|
+
};
|
|
90
115
|
return /*#__PURE__*/React.createElement(context.Context.Provider, {
|
|
91
116
|
value: contextValue
|
|
92
117
|
}, /*#__PURE__*/React.createElement(loading.default, {
|
|
93
118
|
loading: loading$1
|
|
94
119
|
}, /*#__PURE__*/React.createElement("table", {
|
|
95
|
-
className: className.stringify(classNames.table, className$1, styled.className),
|
|
96
|
-
style: _objectSpread(_objectSpread({}, styled.style), style)
|
|
97
|
-
}, /*#__PURE__*/React.createElement(header.default, null), /*#__PURE__*/React.createElement(body.default, null))
|
|
120
|
+
className: className.stringify(classNames.table, className$1, styled.table.className),
|
|
121
|
+
style: _objectSpread(_objectSpread({}, styled.table.style), style)
|
|
122
|
+
}, /*#__PURE__*/React.createElement(header.default, null), /*#__PURE__*/React.createElement(body.default, null)), pagination$1 && (/*#__PURE__*/React.createElement("div", {
|
|
123
|
+
className: styled.pagination.className,
|
|
124
|
+
style: styled.pagination.style
|
|
125
|
+
}, /*#__PURE__*/React.createElement(pagination.default, {
|
|
126
|
+
total: dataSource.length,
|
|
127
|
+
at: pagination$1.pageIndex - 1,
|
|
128
|
+
pageSize: pagination$1.pageSize,
|
|
129
|
+
onChange: changeAt,
|
|
130
|
+
onPageSizeChange: changePageSize
|
|
131
|
+
})))));
|
|
98
132
|
};
|
|
99
133
|
|
|
100
134
|
exports.default = Table;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { TableProps } from "../../types/table";
|
|
3
|
-
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, className, style, loading, expandable, expandedKeys, defaultExpandedKeys, onExpandedKeysChange, rowKey, }: TableProps<T>) => React.JSX.Element;
|
|
3
|
+
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, className, style, loading, expandable, expandedKeys, defaultExpandedKeys, onExpandedKeysChange, rowKey, pagination: _pagination, }: TableProps<T>) => React.JSX.Element;
|
|
4
4
|
export default Table;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
3
|
import styles from './styles.mjs';
|
|
4
|
-
import { useReactTable, getCoreRowModel, getExpandedRowModel } from '@tanstack/react-table';
|
|
4
|
+
import { useReactTable, getCoreRowModel, getPaginationRowModel, getExpandedRowModel } from '@tanstack/react-table';
|
|
5
5
|
import React, { useState, useMemo } from 'react';
|
|
6
6
|
import { useColumns, useContextValue } from './hooks.mjs';
|
|
7
7
|
import Header from './header/header.mjs';
|
|
@@ -11,7 +11,9 @@ import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.19.0/node_mod
|
|
|
11
11
|
import { stringify } from '@aiszlab/relax/class-name';
|
|
12
12
|
import { useClassNames } from '../../hooks/use-class-names.mjs';
|
|
13
13
|
import Loading from '../loading/loading.mjs';
|
|
14
|
-
import { isUndefined, isFunction } from '@aiszlab/relax';
|
|
14
|
+
import { isUndefined, isFunction, get } from '@aiszlab/relax';
|
|
15
|
+
import Pagination from '../pagination/pagination.mjs';
|
|
16
|
+
import { usePagination } from './hooks/use-pagination.hook.mjs';
|
|
15
17
|
|
|
16
18
|
var Table = function Table(_ref) {
|
|
17
19
|
var _ref$bordered = _ref.bordered,
|
|
@@ -32,7 +34,8 @@ var Table = function Table(_ref) {
|
|
|
32
34
|
_ref$defaultExpandedK = _ref.defaultExpandedKeys,
|
|
33
35
|
defaultExpandedKeys = _ref$defaultExpandedK === void 0 ? [] : _ref$defaultExpandedK,
|
|
34
36
|
onExpandedKeysChange = _ref.onExpandedKeysChange,
|
|
35
|
-
rowKey = _ref.rowKey
|
|
37
|
+
rowKey = _ref.rowKey,
|
|
38
|
+
_pagination = _ref.pagination;
|
|
36
39
|
var classNames = useClassNames(CLASS_NAMES);
|
|
37
40
|
var columns = useColumns({
|
|
38
41
|
columns: _columns,
|
|
@@ -46,23 +49,42 @@ var Table = function Table(_ref) {
|
|
|
46
49
|
_useState2 = _slicedToArray(_useState, 2),
|
|
47
50
|
uncontrolledExpanded = _useState2[0],
|
|
48
51
|
setUncontrolledExpanded = _useState2[1];
|
|
52
|
+
var _usePagination = usePagination({
|
|
53
|
+
pagination: _pagination
|
|
54
|
+
}),
|
|
55
|
+
pagination = _usePagination.pagination,
|
|
56
|
+
isPaginationHidden = _usePagination.isPaginationHidden,
|
|
57
|
+
changeAt = _usePagination.changeAt,
|
|
58
|
+
changePageSize = _usePagination.changePageSize;
|
|
49
59
|
var expanded = useMemo(function () {
|
|
50
60
|
return isUndefined(expandedKeys) ? uncontrolledExpanded : Object.fromEntries(expandedKeys.map(function (key) {
|
|
51
61
|
return [String(key), true];
|
|
52
62
|
}));
|
|
53
63
|
}, [expandedKeys, uncontrolledExpanded]);
|
|
54
|
-
var table = useReactTable(_objectSpread(_objectSpread({
|
|
64
|
+
var table = useReactTable(_objectSpread(_objectSpread(_objectSpread({
|
|
55
65
|
columns: columns,
|
|
56
66
|
data: dataSource,
|
|
57
|
-
getCoreRowModel: getCoreRowModel()
|
|
58
|
-
|
|
67
|
+
getCoreRowModel: getCoreRowModel(),
|
|
68
|
+
state: _objectSpread(_objectSpread({}, expandable && {
|
|
69
|
+
expanded: expanded
|
|
70
|
+
}), !isPaginationHidden && {
|
|
71
|
+
pagination: {
|
|
72
|
+
pageIndex: pagination.pageIndex - 1,
|
|
73
|
+
pageSize: pagination.pageSize
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}, !isPaginationHidden && {
|
|
77
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
78
|
+
onPaginationChange: function onPaginationChange(updater) {
|
|
79
|
+
var next = isFunction(updater) ? updater(pagination) : updater;
|
|
80
|
+
changeAt(next.pageIndex + 1);
|
|
81
|
+
changePageSize(next.pageSize);
|
|
82
|
+
}
|
|
83
|
+
}), expandable && {
|
|
59
84
|
getSubRows: function getSubRows(record) {
|
|
60
85
|
return record.children;
|
|
61
86
|
},
|
|
62
87
|
getExpandedRowModel: getExpandedRowModel(),
|
|
63
|
-
state: {
|
|
64
|
-
expanded: expanded
|
|
65
|
-
},
|
|
66
88
|
onExpandedChange: function onExpandedChange(updater) {
|
|
67
89
|
var next = isFunction(updater) ? updater(expanded) : updater;
|
|
68
90
|
if (isUndefined(expandedKeys)) setUncontrolledExpanded(next);
|
|
@@ -72,7 +94,7 @@ var Table = function Table(_ref) {
|
|
|
72
94
|
}
|
|
73
95
|
}), rowKey && {
|
|
74
96
|
getRowId: function getRowId(record, index, parent) {
|
|
75
|
-
return String(isFunction(rowKey) ? rowKey(record, index, parent === null || parent === void 0 ? void 0 : parent.original) : record
|
|
97
|
+
return String(isFunction(rowKey) ? rowKey(record, index, parent === null || parent === void 0 ? void 0 : parent.original) : get(record, rowKey));
|
|
76
98
|
}
|
|
77
99
|
}));
|
|
78
100
|
var contextValue = useContextValue({
|
|
@@ -82,15 +104,27 @@ var Table = function Table(_ref) {
|
|
|
82
104
|
onSortChange: onSortChange,
|
|
83
105
|
classNames: classNames
|
|
84
106
|
});
|
|
85
|
-
var styled =
|
|
107
|
+
var styled = {
|
|
108
|
+
table: props(styles.table.base),
|
|
109
|
+
pagination: props(styles.pagination.base)
|
|
110
|
+
};
|
|
86
111
|
return /*#__PURE__*/React.createElement(Context.Provider, {
|
|
87
112
|
value: contextValue
|
|
88
113
|
}, /*#__PURE__*/React.createElement(Loading, {
|
|
89
114
|
loading: loading
|
|
90
115
|
}, /*#__PURE__*/React.createElement("table", {
|
|
91
|
-
className: stringify(classNames.table, className, styled.className),
|
|
92
|
-
style: _objectSpread(_objectSpread({}, styled.style), style)
|
|
93
|
-
}, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(Body, null))
|
|
116
|
+
className: stringify(classNames.table, className, styled.table.className),
|
|
117
|
+
style: _objectSpread(_objectSpread({}, styled.table.style), style)
|
|
118
|
+
}, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(Body, null)), pagination && (/*#__PURE__*/React.createElement("div", {
|
|
119
|
+
className: styled.pagination.className,
|
|
120
|
+
style: styled.pagination.style
|
|
121
|
+
}, /*#__PURE__*/React.createElement(Pagination, {
|
|
122
|
+
total: dataSource.length,
|
|
123
|
+
at: pagination.pageIndex - 1,
|
|
124
|
+
pageSize: pagination.pageSize,
|
|
125
|
+
onChange: changeAt,
|
|
126
|
+
onPageSizeChange: changePageSize
|
|
127
|
+
})))));
|
|
94
128
|
};
|
|
95
129
|
|
|
96
130
|
export { Table as default };
|
package/dist/styles.css
CHANGED
package/dist/types/table.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DeepKeys } from "@tanstack/react-table";
|
|
|
2
2
|
import type { Table } from "@tanstack/react-table";
|
|
3
3
|
import type { ComponentProps } from "./element";
|
|
4
4
|
import type { Key, ReactNode } from "react";
|
|
5
|
+
import type { PagiantionProps } from "./pagination";
|
|
5
6
|
export type SortDirection = "ascending" | "descending" | null;
|
|
6
7
|
export type SortDescriptor = {
|
|
7
8
|
key: Key;
|
|
@@ -98,6 +99,11 @@ export type TableProps<T> = ComponentProps & {
|
|
|
98
99
|
* TanStack Table's positional row ids.
|
|
99
100
|
*/
|
|
100
101
|
rowKey?: DeepKeys<T> | ((record: T, index: number, parent?: T) => Key);
|
|
102
|
+
/**
|
|
103
|
+
* @zh 配置内置分页;设置为 `false` 或省略时不显示分页。
|
|
104
|
+
* @en Configure built-in pagination. Set to `false` or omit to hide it.
|
|
105
|
+
*/
|
|
106
|
+
pagination?: false | PagiantionProps;
|
|
101
107
|
};
|
|
102
108
|
/** Recursive record shape used by the built-in hierarchical-row reader. */
|
|
103
109
|
export type ExpandableRecord<T> = T & {
|