@arcblock/ux 2.6.9 → 2.7.0
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/babel.config.es.js +12 -0
- package/es/ActionButton/index.js +99 -0
- package/es/ActivityIndicator/index.js +180 -0
- package/es/Address/compact-text.js +105 -0
- package/es/Address/did-address.js +211 -0
- package/es/Address/index.js +23 -0
- package/es/Address/responsive-did-address.js +88 -0
- package/es/Alert/index.js +134 -0
- package/es/AnimationWaiter/default-animation.json +1 -0
- package/es/AnimationWaiter/index.js +239 -0
- package/es/Async/index.js +38 -0
- package/es/Avatar/did-motif.js +64 -0
- package/es/Avatar/etherscan-blockies.js +83 -0
- package/es/Avatar/index.js +176 -0
- package/es/Badge/index.js +98 -0
- package/es/Blocklet/blocklet.js +298 -0
- package/es/Blocklet/index.js +4 -0
- package/es/Blocklet/utils.js +52 -0
- package/es/BlockletNFT/index.js +412 -0
- package/es/Button/index.js +8 -0
- package/es/Button/wrap.js +140 -0
- package/es/ButtonGroup/index.js +6 -0
- package/es/CardSelector/index.js +131 -0
- package/es/Center/index.js +41 -0
- package/es/ClickToCopy/copy-button.js +72 -0
- package/es/ClickToCopy/hook.js +39 -0
- package/es/ClickToCopy/index.js +93 -0
- package/es/CodeBlock/LightBox.js +85 -0
- package/es/CodeBlock/index.js +226 -0
- package/es/Colors/index.js +2 -0
- package/es/Colors/themes/default.js +78 -0
- package/es/ContactForm/index.js +230 -0
- package/es/CookieConsent/index.js +113 -0
- package/es/CountDown/index.js +178 -0
- package/es/DID/index.js +105 -0
- package/es/Datatable/CustomToolbar.js +396 -0
- package/es/Datatable/DatatableContext.js +34 -0
- package/es/Datatable/TableSearch.js +165 -0
- package/es/Datatable/index.js +627 -0
- package/es/Datatable/utils.js +132 -0
- package/es/Dialog/confirm.js +90 -0
- package/es/Dialog/dialog.js +192 -0
- package/es/Dialog/index.js +3 -0
- package/es/DidLogo/index.js +31 -0
- package/es/DriftBot/index.js +70 -0
- package/es/Earth/countries.json +8057 -0
- package/es/Earth/index.js +521 -0
- package/es/Earth/util.js +51 -0
- package/es/Empty/index.js +64 -0
- package/es/ErrorBoundary/fallback.js +73 -0
- package/es/ErrorBoundary/index.js +1 -0
- package/es/Footer/index.js +172 -0
- package/es/Header/auto-hidden.js +35 -0
- package/es/Header/header.js +211 -0
- package/es/Header/index.js +2 -0
- package/es/Header/responsive-header.js +111 -0
- package/es/Icon/image.js +65 -0
- package/es/Icon/index.js +84 -0
- package/es/Img/index.js +217 -0
- package/es/InfoRow/index.js +87 -0
- package/es/Layout/dashboard/external-link.js +58 -0
- package/es/Layout/dashboard/full-page.js +53 -0
- package/es/Layout/dashboard/index.js +275 -0
- package/es/Layout/dashboard/sidebar.js +209 -0
- package/es/Layout/dashboard-legacy/header.js +174 -0
- package/es/Layout/dashboard-legacy/index.js +149 -0
- package/es/Layout/dashboard-legacy/sidebar.js +129 -0
- package/es/Layout/index.js +335 -0
- package/es/Locale/browser-lang.js +52 -0
- package/es/Locale/context.js +114 -0
- package/es/Locale/languages.js +60 -0
- package/es/Locale/selector.js +180 -0
- package/es/Locale/util.js +13 -0
- package/es/Logo/images/logo-dark-text.svg +3 -0
- package/es/Logo/images/logo-dark-top.svg +6 -0
- package/es/Logo/images/logo-light-text.svg +3 -0
- package/es/Logo/images/logo-light-top.svg +6 -0
- package/es/Logo/index.js +136 -0
- package/es/Metric/index.js +132 -0
- package/es/NFTDisplay/README.md +59 -0
- package/es/NFTDisplay/aspect-ratio-container.js +39 -0
- package/es/NFTDisplay/broken.js +18 -0
- package/es/NFTDisplay/demo/data/asset-state-display-url.json +7 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-1-1.json +10 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-374-130.json +10 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-with-foreign-object.json +20 -0
- package/es/NFTDisplay/demo/data/asset-state-svg.json +29 -0
- package/es/NFTDisplay/demo/data/asset-state-url.json +10 -0
- package/es/NFTDisplay/index.js +323 -0
- package/es/NFTDisplay/loading.js +18 -0
- package/es/NFTDisplay/svg-embedder/img.js +45 -0
- package/es/NFTDisplay/svg-embedder/inline-svg.js +39 -0
- package/es/NavMenu/index.js +2 -0
- package/es/NavMenu/nav-menu.js +286 -0
- package/es/NavMenu/style.js +176 -0
- package/es/PageScroller/index.js +286 -0
- package/es/PageScroller/story/FifthComponent.js +9 -0
- package/es/PageScroller/story/FirstComponent.js +9 -0
- package/es/PageScroller/story/FourthComponent.js +12 -0
- package/es/PageScroller/story/FullPage.js +47 -0
- package/es/PageScroller/story/PageContain.js +59 -0
- package/es/PageScroller/story/SecondComponent.js +9 -0
- package/es/PageScroller/story/ThirdComponent.js +9 -0
- package/es/PageScroller/story/index.css +115 -0
- package/es/PageScroller/usePrevValue.js +9 -0
- package/es/PricingTable/PricingPlan.js +124 -0
- package/es/PricingTable/index.js +53 -0
- package/es/QRCode/index.js +72 -0
- package/es/RelativeTime/index.js +98 -0
- package/es/Result/common.js +140 -0
- package/es/Result/demo/fixtures/result-image-404.svg +1 -0
- package/es/Result/index.js +33 -0
- package/es/Result/result.js +59 -0
- package/es/Result/translations.js +54 -0
- package/es/Screenshot/BaseScreenshot/index.js +91 -0
- package/es/Screenshot/BaseScreenshot/shells/Macbook.js +51 -0
- package/es/Screenshot/BaseScreenshot/shells/Phone.js +36 -0
- package/es/Screenshot/demo/images/bg-00.jpg +0 -0
- package/es/Screenshot/demo/images/bg-01.jpg +0 -0
- package/es/Screenshot/demo/images/bg-02.jpg +0 -0
- package/es/Screenshot/demo/images/bg-03.jpg +0 -0
- package/es/Screenshot/demo/images/bg-04.jpg +0 -0
- package/es/Screenshot/demo/images/bg-05.jpg +0 -0
- package/es/Screenshot/demo/images/bg-06.jpg +0 -0
- package/es/Screenshot/demo/images/bg-07.jpg +0 -0
- package/es/Screenshot/demo/images/bg-08.jpg +0 -0
- package/es/Screenshot/demo/images/bg-09.jpg +0 -0
- package/es/Screenshot/devices.css +1366 -0
- package/es/Screenshot/index.js +299 -0
- package/es/SessionManager/federated-login-detecter.js +166 -0
- package/es/SessionManager/index.js +468 -0
- package/es/SessionManager/user-popper.js +132 -0
- package/es/Sparkline/index.js +193 -0
- package/es/Spinner/index.js +28 -0
- package/es/SplitButton/index.js +144 -0
- package/es/Switch/index.js +96 -0
- package/es/Tabs/index.js +48 -0
- package/es/Tag/index.js +108 -0
- package/es/TextCollapse/index.js +92 -0
- package/es/Theme/index.js +16 -0
- package/es/Theme/theme-provider.js +39 -0
- package/es/Theme/theme.js +133 -0
- package/es/Toast/index.js +95 -0
- package/es/Util/deprecate.js +28 -0
- package/es/Util/index.js +298 -0
- package/es/Util/wallet.js +32 -0
- package/es/Video/index.js +89 -0
- package/es/Wallet/Action.js +119 -0
- package/es/Wallet/Download.js +331 -0
- package/es/Wallet/Open.js +45 -0
- package/es/Wallet/images/abtwallet.png +0 -0
- package/es/Wallet/images/android_download.svg +23 -0
- package/es/Wallet/images/app-store.svg +20 -0
- package/es/Wallet/images/google-play.svg +70 -0
- package/es/WebWalletSWKeeper/index.js +115 -0
- package/es/WechatPrompt/images/android.png +0 -0
- package/es/WechatPrompt/images/ios.png +0 -0
- package/es/WechatPrompt/index.js +88 -0
- package/es/index.js +38 -0
- package/es/withTheme/index.js +69 -0
- package/es/withTracker/README.md +34 -0
- package/es/withTracker/error_boundary.js +34 -0
- package/es/withTracker/index.js +56 -0
- package/package.json +272 -5
@@ -0,0 +1,627 @@
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
2
|
+
import { useEffect, useRef, isValidElement } from 'react';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
import MUIDataTable, { TableFilterList, TableFooter } from 'mui-datatables';
|
5
|
+
import { css } from '@emotion/react';
|
6
|
+
import isObject from 'lodash/isObject';
|
7
|
+
import cloneDeep from 'lodash/cloneDeep';
|
8
|
+
import get from 'lodash/get';
|
9
|
+
import clsx from 'clsx';
|
10
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
11
|
+
import Empty from '../Empty';
|
12
|
+
import CustomToolbar from './CustomToolbar';
|
13
|
+
import { DatatableProvider as DataTableProvider, useDatatableContext } from './DatatableContext';
|
14
|
+
import { styled } from '../Theme';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @typedef {{
|
18
|
+
* icon: import('react').ReactElement,
|
19
|
+
* title: string,
|
20
|
+
* }} DataTableCustomButton
|
21
|
+
*/
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @typedef {{
|
25
|
+
* name: string,
|
26
|
+
* label: string,
|
27
|
+
* width?: number,
|
28
|
+
* options?: {
|
29
|
+
* filter?: boolean,
|
30
|
+
* sort?: boolean,
|
31
|
+
* customBodyRender?: (value: any) => import('react').ReactElement,
|
32
|
+
* customBodyRenderLite?: (index: number) => import('react').ReactElement
|
33
|
+
* } & import('mui-datatables').MUIDataTableColumnOptions
|
34
|
+
* } & import('mui-datatables').MUIDataTableColumnDef} DataTableColumn
|
35
|
+
*/
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @typedef {Pick<import('mui-datatables').MUIDataTableState, 'count' | 'page' | 'rowsPerPage' | 'searchText' | 'sortOrder' | 'filterList'>} DataTableState
|
39
|
+
*/
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @typedef {{
|
43
|
+
* data: Array<object | number[] | string[]>,
|
44
|
+
* columns: Array<DataTableColumn>,
|
45
|
+
* locale?: string,
|
46
|
+
* options?: import('mui-datatables').MUIDataTableOptions,
|
47
|
+
* style?: import('react').CSSProperties,
|
48
|
+
* customButtons?: Array<DataTableCustomButton>,
|
49
|
+
* onChange?: (state: DataTableState, action: string) => void | Promise<void>,
|
50
|
+
* loading?: boolean,
|
51
|
+
* disabled?: boolean,
|
52
|
+
* stripped?: boolean,
|
53
|
+
* verticalKeyWidth?: number | string,
|
54
|
+
* hideTableHeader?: boolean,
|
55
|
+
* components?: import('react').ReactElement,
|
56
|
+
* emptyNode?: import('react').ReactElement,
|
57
|
+
* durable?: string,
|
58
|
+
* durableKeys?: 'page' | 'rowsPerPage' | 'searchText' | 'sortOrder'
|
59
|
+
* } & import('mui-datatables').MUIDataTableProps} DataTableProps
|
60
|
+
*/
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @description
|
64
|
+
* @export
|
65
|
+
* @param {DataTableProps} props
|
66
|
+
* @return {import('react').ReactComponentElement}
|
67
|
+
*/
|
68
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
69
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
70
|
+
export default function DataTable(props) {
|
71
|
+
return /*#__PURE__*/_jsx(DataTableProvider, {
|
72
|
+
children: /*#__PURE__*/_jsx(ReDataTable, {
|
73
|
+
...props
|
74
|
+
})
|
75
|
+
});
|
76
|
+
}
|
77
|
+
const fixCellProp = (tempObj, cellProps) => {
|
78
|
+
const cellStyle = {};
|
79
|
+
if (tempObj.align) {
|
80
|
+
cellProps.className = clsx(cellProps.className, `pc-align-${tempObj.align}`);
|
81
|
+
}
|
82
|
+
if (tempObj.verticalKeyAlign) {
|
83
|
+
cellProps.className = clsx(cellProps.className, `vertical-align-${tempObj.verticalKeyAlign}`);
|
84
|
+
}
|
85
|
+
if (tempObj.minWidth) {
|
86
|
+
cellStyle.minWidth = tempObj.minWidth;
|
87
|
+
}
|
88
|
+
cellProps.style = Object.assign({}, cellProps.style, cellStyle);
|
89
|
+
};
|
90
|
+
|
91
|
+
/**
|
92
|
+
* @param {Object} props.options The options of mui-datatable,detail see https://github.com/gregnb/mui-datatables/tree/b8d2eee6af4589d254b40918e5d7e70b1ee4baca
|
93
|
+
* @param {Array} props.customButtons Custom buttons for toolbar
|
94
|
+
* @param {Function} props.onChange When onChange is present, serverSide mode is activated by default https://github.com/gregnb/mui-datatables/tree/b8d2eee6af4589d254b40918e5d7e70b1ee4baca#remote-data
|
95
|
+
* @param {Boolean} props.loading For dynamic data, usually used with onChange
|
96
|
+
* @returns
|
97
|
+
*/
|
98
|
+
function ReDataTable({
|
99
|
+
data: originData,
|
100
|
+
columns: originColumns,
|
101
|
+
locale,
|
102
|
+
options,
|
103
|
+
// The options object is usually a property supported by mui-datatable
|
104
|
+
style,
|
105
|
+
customButtons,
|
106
|
+
onChange,
|
107
|
+
loading,
|
108
|
+
disabled,
|
109
|
+
stripped,
|
110
|
+
verticalKeyWidth,
|
111
|
+
hideTableHeader,
|
112
|
+
components,
|
113
|
+
emptyNode,
|
114
|
+
durable,
|
115
|
+
durableKeys,
|
116
|
+
...rest
|
117
|
+
}) {
|
118
|
+
const oldState = useRef(null);
|
119
|
+
const {
|
120
|
+
setCustomButtons,
|
121
|
+
setFilterLabel,
|
122
|
+
setLoading,
|
123
|
+
setDisabled
|
124
|
+
} = useDatatableContext();
|
125
|
+
const disabledCellStyle = {
|
126
|
+
cursor: 'not-allowed',
|
127
|
+
pointerEvents: 'none'
|
128
|
+
};
|
129
|
+
const keys = [];
|
130
|
+
|
131
|
+
// Convert Columns fields to object sets to support the width function
|
132
|
+
const columns = originColumns.map(e => {
|
133
|
+
let tempObj;
|
134
|
+
if (!isObject(e)) {
|
135
|
+
tempObj = {
|
136
|
+
label: e,
|
137
|
+
name: e
|
138
|
+
};
|
139
|
+
} else {
|
140
|
+
tempObj = cloneDeep(e);
|
141
|
+
}
|
142
|
+
keys.push(tempObj.name);
|
143
|
+
if (!tempObj.align) {
|
144
|
+
// There must be an align default for setCellRender to take effect, this is a bug in mui-datatable
|
145
|
+
tempObj.align = 'left';
|
146
|
+
}
|
147
|
+
if (!tempObj.options) {
|
148
|
+
tempObj.options = {};
|
149
|
+
}
|
150
|
+
const {
|
151
|
+
setCellHeaderProps,
|
152
|
+
setCellProps
|
153
|
+
} = tempObj.options;
|
154
|
+
tempObj.options.setCellHeaderProps = (...args) => {
|
155
|
+
let cellProps = {
|
156
|
+
className: ''
|
157
|
+
};
|
158
|
+
|
159
|
+
// Complementing width while inheriting old setCellHeaderProps
|
160
|
+
if (setCellHeaderProps && !setCellHeaderProps.__innerFunc) {
|
161
|
+
cellProps = {
|
162
|
+
...cellProps,
|
163
|
+
...(setCellHeaderProps(...args) || {})
|
164
|
+
};
|
165
|
+
}
|
166
|
+
if (loading || disabled) {
|
167
|
+
cellProps = {
|
168
|
+
...cellProps,
|
169
|
+
style: disabledCellStyle
|
170
|
+
};
|
171
|
+
}
|
172
|
+
if (tempObj.width) {
|
173
|
+
cellProps.width = tempObj.width;
|
174
|
+
}
|
175
|
+
fixCellProp(tempObj, cellProps);
|
176
|
+
return cellProps;
|
177
|
+
};
|
178
|
+
|
179
|
+
// Prevent memory xie caused by recursive forwarding of setCellHeaderProps functions
|
180
|
+
tempObj.options.setCellHeaderProps.__innerFunc = 1;
|
181
|
+
if (tempObj.align || tempObj.style) {
|
182
|
+
tempObj.options.setCellProps = (...args) => {
|
183
|
+
let cellProps = {
|
184
|
+
className: ''
|
185
|
+
};
|
186
|
+
|
187
|
+
// Complementing width while inheriting old setCellHeaderProps
|
188
|
+
if (setCellProps && !setCellProps.__innerFunc) {
|
189
|
+
cellProps = {
|
190
|
+
...cellProps,
|
191
|
+
...(setCellProps(...args) || {})
|
192
|
+
};
|
193
|
+
}
|
194
|
+
fixCellProp(tempObj, cellProps);
|
195
|
+
return cellProps;
|
196
|
+
};
|
197
|
+
tempObj.options.setCellProps.__innerFunc = 1;
|
198
|
+
}
|
199
|
+
return tempObj;
|
200
|
+
});
|
201
|
+
|
202
|
+
// Fixing object-type structures
|
203
|
+
const data = originData.map(e => {
|
204
|
+
if (!Array.isArray(e) && isObject(e)) {
|
205
|
+
return keys.map(key => get(e, key));
|
206
|
+
}
|
207
|
+
return e;
|
208
|
+
});
|
209
|
+
useEffect(() => setCustomButtons(customButtons || []), [customButtons]);
|
210
|
+
useEffect(() => setLoading(loading), [loading]);
|
211
|
+
useEffect(() => setDisabled(disabled), [disabled]);
|
212
|
+
let emptyEl;
|
213
|
+
if (loading) {
|
214
|
+
emptyEl = /*#__PURE__*/_jsx(CircularProgress, {});
|
215
|
+
} else if ( /*#__PURE__*/isValidElement(emptyNode)) {
|
216
|
+
emptyEl = emptyNode;
|
217
|
+
} else if (locale === 'zh') {
|
218
|
+
emptyEl = /*#__PURE__*/_jsx(Empty, {
|
219
|
+
children: emptyNode || '没有找到匹配的记录'
|
220
|
+
});
|
221
|
+
} else {
|
222
|
+
emptyEl = /*#__PURE__*/_jsx(Empty, {
|
223
|
+
children: emptyNode || 'No matching records found'
|
224
|
+
});
|
225
|
+
}
|
226
|
+
let textLabels = {
|
227
|
+
body: {
|
228
|
+
noMatch: emptyEl,
|
229
|
+
toolTip: 'Sort'
|
230
|
+
},
|
231
|
+
pagination: {
|
232
|
+
next: 'Next Page',
|
233
|
+
previous: 'Previous Page',
|
234
|
+
rowsPerPage: 'Per page:',
|
235
|
+
displayRows: 'of',
|
236
|
+
jumpToPage: 'Jump to Page:'
|
237
|
+
},
|
238
|
+
toolbar: {
|
239
|
+
search: 'Search',
|
240
|
+
downloadCsv: 'Download CSV',
|
241
|
+
print: 'Print',
|
242
|
+
viewColumns: 'View Columns',
|
243
|
+
filterTable: 'Filter Table'
|
244
|
+
},
|
245
|
+
filter: {
|
246
|
+
all: 'All',
|
247
|
+
title: 'FILTERS',
|
248
|
+
reset: 'RESET'
|
249
|
+
},
|
250
|
+
viewColumns: {
|
251
|
+
title: 'Show Columns',
|
252
|
+
titleAria: 'Show/Hide Table Columns'
|
253
|
+
},
|
254
|
+
selectedRows: {
|
255
|
+
text: 'row(s) selected',
|
256
|
+
delete: 'Delete',
|
257
|
+
deleteAria: 'Delete Selected Rows'
|
258
|
+
}
|
259
|
+
};
|
260
|
+
if (locale === 'zh') {
|
261
|
+
textLabels = {
|
262
|
+
body: {
|
263
|
+
noMatch: emptyEl,
|
264
|
+
toolTip: '排序'
|
265
|
+
},
|
266
|
+
pagination: {
|
267
|
+
next: '下一页',
|
268
|
+
previous: '上一页',
|
269
|
+
rowsPerPage: '每页行数',
|
270
|
+
displayRows: '/',
|
271
|
+
jumpToPage: '跳转到页面:'
|
272
|
+
},
|
273
|
+
toolbar: {
|
274
|
+
search: '搜索',
|
275
|
+
downloadCsv: '下载CSV',
|
276
|
+
print: '打印',
|
277
|
+
viewColumns: '查看列',
|
278
|
+
filterTable: '筛选表格'
|
279
|
+
},
|
280
|
+
filter: {
|
281
|
+
all: '全部',
|
282
|
+
title: '筛选器',
|
283
|
+
reset: '重置'
|
284
|
+
},
|
285
|
+
viewColumns: {
|
286
|
+
title: '显示的列',
|
287
|
+
titleAria: '显示/隐藏 表格的列'
|
288
|
+
},
|
289
|
+
selectedRows: {
|
290
|
+
text: '个已选项目',
|
291
|
+
delete: '删除',
|
292
|
+
deleteAria: '删除所选项目'
|
293
|
+
}
|
294
|
+
};
|
295
|
+
}
|
296
|
+
useEffect(() => setFilterLabel(textLabels.filter.title), [textLabels.filter.title]);
|
297
|
+
const durableData = getDurableData(durable);
|
298
|
+
const opts = {
|
299
|
+
selectableRows: 'none',
|
300
|
+
textLabels,
|
301
|
+
rowsPerPage: 10,
|
302
|
+
rowsPerPageOptions: [10, 20, 50],
|
303
|
+
...durableData,
|
304
|
+
...options,
|
305
|
+
// Wrap the more friendly onChange callback by listening to onTableChange,
|
306
|
+
// which will only be triggered when the table key state changes
|
307
|
+
onTableChange: (action, tableState) => {
|
308
|
+
if (action === 'propsUpdate') {
|
309
|
+
return;
|
310
|
+
}
|
311
|
+
const state = {
|
312
|
+
count: tableState.count,
|
313
|
+
page: tableState.page,
|
314
|
+
rowsPerPage: tableState.rowsPerPage,
|
315
|
+
searchText: tableState.searchText,
|
316
|
+
sortOrder: tableState.sortOrder,
|
317
|
+
//
|
318
|
+
filterList: tableState.filterList
|
319
|
+
};
|
320
|
+
if (durable) {
|
321
|
+
const needSaveState = {};
|
322
|
+
durableKeys.forEach(key => {
|
323
|
+
needSaveState[key] = state[key];
|
324
|
+
});
|
325
|
+
localStorage.setItem(`datatable-durable-${durable}`, JSON.stringify(needSaveState));
|
326
|
+
}
|
327
|
+
const stateStr = JSON.stringify(state);
|
328
|
+
if (stateStr === oldState.current) {
|
329
|
+
return;
|
330
|
+
}
|
331
|
+
oldState.current = stateStr;
|
332
|
+
if (onChange) {
|
333
|
+
onChange(state, action);
|
334
|
+
}
|
335
|
+
}
|
336
|
+
};
|
337
|
+
if (onChange) {
|
338
|
+
opts.serverSide = true;
|
339
|
+
}
|
340
|
+
const props = {
|
341
|
+
options: opts,
|
342
|
+
...rest,
|
343
|
+
components: {
|
344
|
+
...components,
|
345
|
+
TableToolbar: CustomToolbar,
|
346
|
+
TableFooter: WrapTableFooter,
|
347
|
+
TableFilterList: WrapFilterList
|
348
|
+
}
|
349
|
+
};
|
350
|
+
return /*#__PURE__*/_jsx(TableContainer, {
|
351
|
+
verticalKeyWidth: verticalKeyWidth,
|
352
|
+
className: clsx({
|
353
|
+
'datatable-stripped': stripped,
|
354
|
+
'datatable-hide-header': hideTableHeader
|
355
|
+
}),
|
356
|
+
style: style,
|
357
|
+
children: /*#__PURE__*/_jsx(MUIDataTable, {
|
358
|
+
data: data,
|
359
|
+
columns: columns,
|
360
|
+
...props
|
361
|
+
})
|
362
|
+
});
|
363
|
+
}
|
364
|
+
ReDataTable.propTypes = {
|
365
|
+
data: PropTypes.array.isRequired,
|
366
|
+
columns: PropTypes.array.isRequired,
|
367
|
+
options: PropTypes.object,
|
368
|
+
style: PropTypes.object,
|
369
|
+
locale: PropTypes.string,
|
370
|
+
loading: PropTypes.bool,
|
371
|
+
disabled: PropTypes.bool,
|
372
|
+
customButtons: PropTypes.array,
|
373
|
+
onChange: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
374
|
+
stripped: PropTypes.bool,
|
375
|
+
verticalKeyWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
376
|
+
hideTableHeader: PropTypes.bool,
|
377
|
+
components: PropTypes.object,
|
378
|
+
emptyNode: PropTypes.node,
|
379
|
+
durable: PropTypes.string,
|
380
|
+
durableKeys: PropTypes.array
|
381
|
+
};
|
382
|
+
ReDataTable.defaultProps = {
|
383
|
+
options: {},
|
384
|
+
style: {},
|
385
|
+
locale: 'en',
|
386
|
+
loading: false,
|
387
|
+
disabled: false,
|
388
|
+
customButtons: [],
|
389
|
+
onChange: '',
|
390
|
+
stripped: false,
|
391
|
+
verticalKeyWidth: '',
|
392
|
+
hideTableHeader: false,
|
393
|
+
components: {},
|
394
|
+
emptyNode: '',
|
395
|
+
durable: '',
|
396
|
+
durableKeys: ['page', 'rowsPerPage', 'searchText', 'sortOrder']
|
397
|
+
};
|
398
|
+
export const getDurableData = key => {
|
399
|
+
const durableKey = `datatable-durable-${key}`;
|
400
|
+
let localData = localStorage[durableKey];
|
401
|
+
if (localData) {
|
402
|
+
try {
|
403
|
+
localData = JSON.parse(localData);
|
404
|
+
} catch (err) {
|
405
|
+
console.error(`parse durable data error (key:${key}) => `, err);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
return localData || {};
|
409
|
+
};
|
410
|
+
const alignCss = css`
|
411
|
+
.MuiTableCell-head {
|
412
|
+
[class*='MUIDataTableHeadCell-toolButton'] {
|
413
|
+
width: 100%;
|
414
|
+
> [class*='MUIDataTableHeadCell-sortAction'] {
|
415
|
+
width: 100%;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
&.pc-align-center {
|
419
|
+
text-align: center;
|
420
|
+
[class*='MUIDataTableHeadCell-toolButton'] > [class*='MUIDataTableHeadCell-sortAction'] {
|
421
|
+
justify-content: center;
|
422
|
+
}
|
423
|
+
}
|
424
|
+
&.pc-align-right {
|
425
|
+
text-align: right;
|
426
|
+
[class*='MUIDataTableHeadCell-toolButton'] {
|
427
|
+
margin-right: 0;
|
428
|
+
padding-right: 0;
|
429
|
+
& > [class*='MUIDataTableHeadCell-sortAction'] {
|
430
|
+
justify-content: flex-end;
|
431
|
+
}
|
432
|
+
}
|
433
|
+
}
|
434
|
+
}
|
435
|
+
.MuiTableCell-body {
|
436
|
+
&.pc-align-center {
|
437
|
+
text-align: center;
|
438
|
+
}
|
439
|
+
&.pc-align-right {
|
440
|
+
text-align: right;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
`;
|
444
|
+
const TableContainer = styled('div', {
|
445
|
+
shouldForwardProp: prop => prop !== 'verticalKeyWidth'
|
446
|
+
})`
|
447
|
+
&.datatable-hide-header {
|
448
|
+
thead.MuiTableHead-root {
|
449
|
+
display: none;
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
td {
|
454
|
+
&.vertical-align-top {
|
455
|
+
align-items: flex-start;
|
456
|
+
}
|
457
|
+
&.vertical-align-center {
|
458
|
+
align-items: center;
|
459
|
+
}
|
460
|
+
&.vertical-align-bottom {
|
461
|
+
align-items: flex-end;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
height: 100%;
|
466
|
+
> .MuiPaper-root {
|
467
|
+
display: flex;
|
468
|
+
flex-direction: column;
|
469
|
+
height: 100%;
|
470
|
+
box-shadow: none;
|
471
|
+
}
|
472
|
+
${props => props.theme.breakpoints.down('md')} {
|
473
|
+
td.MuiTableCell-body {
|
474
|
+
padding-right: 0;
|
475
|
+
}
|
476
|
+
[class*='MUIDataTable-responsiveBase'] {
|
477
|
+
tr:not([class*='responsiveSimple']) {
|
478
|
+
td.MuiTableCell-body {
|
479
|
+
display: flex;
|
480
|
+
> div {
|
481
|
+
width: auto;
|
482
|
+
flex: 1;
|
483
|
+
&:first-of-type {
|
484
|
+
font-weight: bold;
|
485
|
+
font-size: 14px;
|
486
|
+
width: auto;
|
487
|
+
flex: 0 0 auto;
|
488
|
+
padding-right: 16px;
|
489
|
+
&:empty {
|
490
|
+
padding-right: 0;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
}
|
494
|
+
}
|
495
|
+
}
|
496
|
+
}
|
497
|
+
}
|
498
|
+
${props => props.theme.breakpoints.up('md')} {
|
499
|
+
${alignCss}
|
500
|
+
}
|
501
|
+
${props => props.theme.breakpoints.up('sm')} {
|
502
|
+
[class*='responsiveSimple'] {
|
503
|
+
${alignCss}
|
504
|
+
}
|
505
|
+
}
|
506
|
+
|
507
|
+
${inProps => {
|
508
|
+
if (inProps.verticalKeyWidth) {
|
509
|
+
return `
|
510
|
+
${inProps.theme.breakpoints.down('md')} {
|
511
|
+
[class*='MUIDataTable-responsiveBase'] {
|
512
|
+
tr:not([class*='responsiveSimple']) {
|
513
|
+
td.MuiTableCell-body {
|
514
|
+
> div {
|
515
|
+
&:first-of-type {
|
516
|
+
width: ${inProps.verticalKeyWidth + (!/\D/.test(inProps.verticalKeyWidth) ? 'px' : '')};
|
517
|
+
}
|
518
|
+
}
|
519
|
+
}
|
520
|
+
}
|
521
|
+
}
|
522
|
+
}
|
523
|
+
`;
|
524
|
+
}
|
525
|
+
return '';
|
526
|
+
}}
|
527
|
+
|
528
|
+
&.datatable-stripped {
|
529
|
+
.MuiTableBody-root {
|
530
|
+
tr:nth-of-type(odd) {
|
531
|
+
background-color: ${props => props.theme.palette.action.hover};
|
532
|
+
}
|
533
|
+
}
|
534
|
+
}
|
535
|
+
`;
|
536
|
+
const FilterLine = styled('div')`
|
537
|
+
display: flex;
|
538
|
+
align-items: center;
|
539
|
+
.toolbar-filter-content {
|
540
|
+
margin-bottom: 8px;
|
541
|
+
}
|
542
|
+
.toolbar-filter-title {
|
543
|
+
font-weight: 700;
|
544
|
+
font-size: 14px;
|
545
|
+
}
|
546
|
+
`;
|
547
|
+
function WrapFilterList(props) {
|
548
|
+
const {
|
549
|
+
filterLabel
|
550
|
+
} = useDatatableContext();
|
551
|
+
const hasFilter = !!props.filterList.filter(e => e.length).length;
|
552
|
+
if (hasFilter) {
|
553
|
+
return /*#__PURE__*/_jsxs(FilterLine, {
|
554
|
+
children: [hasFilter && /*#__PURE__*/_jsx("div", {
|
555
|
+
className: "toolbar-filter-title",
|
556
|
+
children: filterLabel
|
557
|
+
}), /*#__PURE__*/_jsx("div", {
|
558
|
+
className: "toolbar-filter-content",
|
559
|
+
children: /*#__PURE__*/_jsx(TableFilterList, {
|
560
|
+
...props
|
561
|
+
})
|
562
|
+
})]
|
563
|
+
});
|
564
|
+
}
|
565
|
+
return '';
|
566
|
+
}
|
567
|
+
WrapFilterList.propTypes = {
|
568
|
+
filterList: PropTypes.array
|
569
|
+
};
|
570
|
+
WrapFilterList.defaultProps = {
|
571
|
+
filterList: []
|
572
|
+
};
|
573
|
+
function WrapTableFooter(props) {
|
574
|
+
const {
|
575
|
+
loading,
|
576
|
+
disabled
|
577
|
+
} = useDatatableContext();
|
578
|
+
return /*#__PURE__*/_jsx(FooterContainer, {
|
579
|
+
children: /*#__PURE__*/_jsx("div", {
|
580
|
+
className: `datatable-footer ${loading || disabled ? 'datatable-footer-disabled' : ''}`,
|
581
|
+
children: /*#__PURE__*/_jsx(TableFooter, {
|
582
|
+
...props
|
583
|
+
})
|
584
|
+
})
|
585
|
+
});
|
586
|
+
}
|
587
|
+
const FooterContainer = styled('div')`
|
588
|
+
display: flex;
|
589
|
+
align-items: center;
|
590
|
+
.datatable-footer {
|
591
|
+
position: relative;
|
592
|
+
margin-left: auto;
|
593
|
+
&.datatable-footer-disabled {
|
594
|
+
position: relative;
|
595
|
+
.MuiTablePagination-root {
|
596
|
+
opacity: 0.6;
|
597
|
+
}
|
598
|
+
&:after {
|
599
|
+
position: absolute;
|
600
|
+
display: block;
|
601
|
+
z-index: 2;
|
602
|
+
width: 100%;
|
603
|
+
height: 100%;
|
604
|
+
left: 0;
|
605
|
+
top: 0;
|
606
|
+
content: '';
|
607
|
+
cursor: not-allowed;
|
608
|
+
}
|
609
|
+
}
|
610
|
+
}
|
611
|
+
|
612
|
+
${props => props.theme.breakpoints.down('sm')} {
|
613
|
+
.MuiTableCell-footer,
|
614
|
+
.MuiToolbar-gutters {
|
615
|
+
padding: 0;
|
616
|
+
}
|
617
|
+
|
618
|
+
div[variant='standard'] {
|
619
|
+
margin-left: 4px;
|
620
|
+
margin-right: 16px;
|
621
|
+
}
|
622
|
+
|
623
|
+
.MuiTablePagination-actions {
|
624
|
+
margin-left: 10px;
|
625
|
+
}
|
626
|
+
}
|
627
|
+
`;
|