@arcblock/ux 2.6.8 → 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,396 @@
|
|
1
|
+
import { useState, useRef, useEffect, isValidElement } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { TableFilter, TableViewCol } from 'mui-datatables';
|
4
|
+
import ReactToPrint, { PrintContextConsumer } from 'react-to-print';
|
5
|
+
import IconButton from '@mui/material/IconButton';
|
6
|
+
import Tooltip from '@mui/material/Tooltip';
|
7
|
+
import DownloadIcon from '@mui/icons-material/CloudDownload';
|
8
|
+
import PrintIcon from '@mui/icons-material/Print';
|
9
|
+
import ViewColumnIcon from '@mui/icons-material/ViewColumn';
|
10
|
+
import FilterIcon from '@mui/icons-material/FilterList';
|
11
|
+
import Popover from '@mui/material/Popover';
|
12
|
+
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
13
|
+
import Menu from '@mui/material/Menu';
|
14
|
+
import MenuItem from '@mui/material/MenuItem';
|
15
|
+
import ListItemIcon from '@mui/material/ListItemIcon';
|
16
|
+
import ListItemText from '@mui/material/ListItemText';
|
17
|
+
import useMediaQuery from '@mui/material/useMediaQuery';
|
18
|
+
import LinearProgress from '@mui/material/LinearProgress';
|
19
|
+
import { handleCSVDownload } from './utils';
|
20
|
+
import TableSearch from './TableSearch';
|
21
|
+
import { useDatatableContext } from './DatatableContext';
|
22
|
+
import { styled, useTheme } from '../Theme';
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
25
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
26
|
+
function useMobile() {
|
27
|
+
const theme = useTheme();
|
28
|
+
return useMediaQuery(theme.breakpoints.down('sm'));
|
29
|
+
}
|
30
|
+
export default function CustomToolbar(props) {
|
31
|
+
const [menuIconEl, setMenuIconEl] = useState(null);
|
32
|
+
const moreBtn = useRef(null);
|
33
|
+
const isMobile = useMobile();
|
34
|
+
const toolbarId = useRef(Math.random().toString(32).slice(2));
|
35
|
+
const [searchOpened, setSearchOpened] = useState(false);
|
36
|
+
const {
|
37
|
+
customButtons,
|
38
|
+
loading,
|
39
|
+
disabled
|
40
|
+
} = useDatatableContext();
|
41
|
+
const {
|
42
|
+
data,
|
43
|
+
options,
|
44
|
+
components,
|
45
|
+
columns,
|
46
|
+
filterList,
|
47
|
+
filterData,
|
48
|
+
filterUpdate,
|
49
|
+
resetFilters,
|
50
|
+
updateFilterByType,
|
51
|
+
toggleViewColumn,
|
52
|
+
updateColumns,
|
53
|
+
title,
|
54
|
+
searchText,
|
55
|
+
searchTextUpdate,
|
56
|
+
searchClose
|
57
|
+
} = props;
|
58
|
+
const customToolbarEle = options.customToolbar ? options.customToolbar(props) : '';
|
59
|
+
const {
|
60
|
+
search,
|
61
|
+
downloadCsv,
|
62
|
+
print,
|
63
|
+
viewColumns,
|
64
|
+
filterTable
|
65
|
+
} = options.textLabels.toolbar;
|
66
|
+
const hideSearch = options.search === false || options.search === 'false';
|
67
|
+
const hidePrint = options.print === false || options.print === 'false';
|
68
|
+
const TableFilterComponent = components.TableFilter || TableFilter;
|
69
|
+
const TableViewColComponent = components.TableViewCol || TableViewCol;
|
70
|
+
useEffect(() => {
|
71
|
+
if (loading || disabled) {
|
72
|
+
setAllPopsEl({});
|
73
|
+
}
|
74
|
+
}, [loading, disabled]);
|
75
|
+
const printArea = func => {
|
76
|
+
return /*#__PURE__*/_jsx(ReactToPrint, {
|
77
|
+
content: () => props.tableRef(),
|
78
|
+
children: /*#__PURE__*/_jsx(PrintContextConsumer, {
|
79
|
+
children: func
|
80
|
+
})
|
81
|
+
});
|
82
|
+
};
|
83
|
+
const getPopId = key => `toolbar-pop-${toolbarId.current}-${key}`;
|
84
|
+
const defaultButtons = [];
|
85
|
+
|
86
|
+
// download/viewColumns/filter button behaviours, rendered using custom button logic
|
87
|
+
if (!(options.download === false || options.download === 'false')) {
|
88
|
+
defaultButtons.push({
|
89
|
+
icon: /*#__PURE__*/_jsx(DownloadIcon, {}),
|
90
|
+
title: downloadCsv,
|
91
|
+
onClick: () => {
|
92
|
+
handleCSVDownload(props);
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
96
|
+
if (!(options.viewColumns === false || options.viewColumns === 'false')) {
|
97
|
+
defaultButtons.push({
|
98
|
+
icon: /*#__PURE__*/_jsx(ViewColumnIcon, {}),
|
99
|
+
title: viewColumns,
|
100
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
101
|
+
popRender() {
|
102
|
+
return /*#__PURE__*/_jsx(TableViewColComponent, {
|
103
|
+
data: data,
|
104
|
+
columns: columns,
|
105
|
+
options: options,
|
106
|
+
onColumnUpdate: toggleViewColumn,
|
107
|
+
updateColumns: updateColumns,
|
108
|
+
components: components
|
109
|
+
});
|
110
|
+
}
|
111
|
+
});
|
112
|
+
}
|
113
|
+
if (!(options.filter === false || options.filter === 'false')) {
|
114
|
+
defaultButtons.push({
|
115
|
+
icon: /*#__PURE__*/_jsx(FilterIcon, {}),
|
116
|
+
title: filterTable,
|
117
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
118
|
+
popRender() {
|
119
|
+
return /*#__PURE__*/_jsx(TableFilterComponent, {
|
120
|
+
customFooter: options.customFilterDialogFooter,
|
121
|
+
columns: columns,
|
122
|
+
options: options,
|
123
|
+
filterList: filterList,
|
124
|
+
filterData: filterData,
|
125
|
+
onFilterUpdate: filterUpdate,
|
126
|
+
onFilterReset: resetFilters,
|
127
|
+
updateFilterByType: updateFilterByType,
|
128
|
+
components: components
|
129
|
+
});
|
130
|
+
}
|
131
|
+
});
|
132
|
+
}
|
133
|
+
const showMore = [!hidePrint, ...defaultButtons, ...customButtons].filter(e => !!e).length > 1 && isMobile;
|
134
|
+
const allPops = [];
|
135
|
+
const [allPopsEl, setAllPopsEl] = useState({});
|
136
|
+
|
137
|
+
// Large screens show the toolbar buttons directly, small screens show the drop-down menu style buttons
|
138
|
+
// The right-hand button of the form toolbar in desktop mode
|
139
|
+
const toolbarButtons = [...defaultButtons, ...customButtons].map((e, index) => {
|
140
|
+
if ( /*#__PURE__*/isValidElement(e)) {
|
141
|
+
return e;
|
142
|
+
}
|
143
|
+
const popId = getPopId(index);
|
144
|
+
if (e.icon) {
|
145
|
+
const {
|
146
|
+
popRender,
|
147
|
+
icon
|
148
|
+
} = e;
|
149
|
+
// When popRender is present, clicking the button will bubble up the content returned by the popRender
|
150
|
+
if (popRender) {
|
151
|
+
allPops.push( /*#__PURE__*/_jsx(Popover, {
|
152
|
+
open: !!allPopsEl[popId],
|
153
|
+
anchorEl: () => allPopsEl[popId],
|
154
|
+
onClose: () => {
|
155
|
+
setAllPopsEl({});
|
156
|
+
},
|
157
|
+
anchorOrigin: {
|
158
|
+
vertical: 'bottom',
|
159
|
+
horizontal: 'right'
|
160
|
+
},
|
161
|
+
children: /*#__PURE__*/_jsx("div", {
|
162
|
+
children: popRender()
|
163
|
+
})
|
164
|
+
}, popId));
|
165
|
+
}
|
166
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
167
|
+
title: e.title,
|
168
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
169
|
+
"data-testid": `${e.title}-iconButton`,
|
170
|
+
id: `btn-${popId}`,
|
171
|
+
"aria-label": e.title,
|
172
|
+
onClick: () => {
|
173
|
+
if (e.onClick) {
|
174
|
+
e.onClick();
|
175
|
+
}
|
176
|
+
if (popRender) {
|
177
|
+
// On the large screen, the bubble is positioned at the corresponding button
|
178
|
+
setAllPopsEl({
|
179
|
+
[popId]: document.getElementById(`btn-${popId}`)
|
180
|
+
});
|
181
|
+
}
|
182
|
+
},
|
183
|
+
children: /*#__PURE__*/_jsx("div", {
|
184
|
+
className: "custom-toolbar-icon",
|
185
|
+
children: icon
|
186
|
+
})
|
187
|
+
})
|
188
|
+
}, popId);
|
189
|
+
}
|
190
|
+
return e;
|
191
|
+
});
|
192
|
+
|
193
|
+
// The toolbar menu in the mobile to replace toolbarButtons
|
194
|
+
const menuItems = [...defaultButtons, ...customButtons].map((e, index) => {
|
195
|
+
const popId = getPopId(index);
|
196
|
+
let content;
|
197
|
+
if ( /*#__PURE__*/isValidElement(e)) {
|
198
|
+
content = e;
|
199
|
+
} else if (e.icon) {
|
200
|
+
const {
|
201
|
+
icon
|
202
|
+
} = e;
|
203
|
+
content = /*#__PURE__*/_jsxs(_Fragment, {
|
204
|
+
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
205
|
+
children: icon
|
206
|
+
}), /*#__PURE__*/_jsx(ListItemText, {
|
207
|
+
children: e.title
|
208
|
+
})]
|
209
|
+
});
|
210
|
+
}
|
211
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
212
|
+
onClick: () => {
|
213
|
+
setMenuIconEl(null);
|
214
|
+
if (e.onClick) {
|
215
|
+
e.onClick();
|
216
|
+
}
|
217
|
+
if (e.popRender) {
|
218
|
+
// On the small screen, the bubbles are positioned at the three dot buttons
|
219
|
+
setAllPopsEl({
|
220
|
+
[popId]: moreBtn.current
|
221
|
+
});
|
222
|
+
}
|
223
|
+
},
|
224
|
+
children: content
|
225
|
+
}, popId);
|
226
|
+
});
|
227
|
+
return /*#__PURE__*/_jsxs("div", {
|
228
|
+
children: [/*#__PURE__*/_jsxs(Container, {
|
229
|
+
children: [/*#__PURE__*/_jsx("div", {
|
230
|
+
className: `custom-toobar-title ${isMobile && searchOpened && /*#__PURE__*/isValidElement(title) ? 'toobar-title-hidden' : ''}`,
|
231
|
+
children: /*#__PURE__*/_jsx("div", {
|
232
|
+
className: "custom-toobar-title-inner",
|
233
|
+
children: /*#__PURE__*/_jsx("span", {
|
234
|
+
children: title
|
235
|
+
})
|
236
|
+
})
|
237
|
+
}), /*#__PURE__*/_jsxs("div", {
|
238
|
+
className: `custom-toobar-btns ${loading || disabled ? 'toobar-btns-disabled' : ''}`,
|
239
|
+
children: [!hideSearch && /*#__PURE__*/_jsx(TableSearch, {
|
240
|
+
search: search,
|
241
|
+
options: options,
|
242
|
+
searchText: searchText,
|
243
|
+
searchTextUpdate: searchTextUpdate,
|
244
|
+
searchClose: searchClose,
|
245
|
+
onSearchOpen: setSearchOpened
|
246
|
+
}), !showMore && /*#__PURE__*/_jsxs(_Fragment, {
|
247
|
+
children: [!hidePrint && printArea(({
|
248
|
+
handlePrint
|
249
|
+
}) => /*#__PURE__*/_jsx("span", {
|
250
|
+
children: /*#__PURE__*/_jsx(Tooltip, {
|
251
|
+
title: print,
|
252
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
253
|
+
"data-testid": `${print}-iconButton`,
|
254
|
+
"aria-label": print,
|
255
|
+
disabled: options.print === 'disabled',
|
256
|
+
onClick: handlePrint,
|
257
|
+
children: /*#__PURE__*/_jsx(PrintIcon, {})
|
258
|
+
})
|
259
|
+
})
|
260
|
+
})), toolbarButtons]
|
261
|
+
}), showMore && /*#__PURE__*/_jsx(IconButton, {
|
262
|
+
ref: moreBtn,
|
263
|
+
"aria-haspopup": "true",
|
264
|
+
"aria-expanded": menuIconEl ? 'true' : undefined,
|
265
|
+
onClick: event => setMenuIconEl(event.currentTarget),
|
266
|
+
style: {
|
267
|
+
flexShrink: 0
|
268
|
+
},
|
269
|
+
children: /*#__PURE__*/_jsx(MoreVertIcon, {})
|
270
|
+
})]
|
271
|
+
}), customToolbarEle]
|
272
|
+
}), /*#__PURE__*/_jsxs(Menu, {
|
273
|
+
anchorEl: menuIconEl,
|
274
|
+
open: !!menuIconEl,
|
275
|
+
onClose: () => setMenuIconEl(null),
|
276
|
+
MenuListProps: {
|
277
|
+
'aria-labelledby': 'more-button'
|
278
|
+
},
|
279
|
+
children: [!hidePrint && printArea(({
|
280
|
+
handlePrint
|
281
|
+
}) => /*#__PURE__*/_jsxs(MenuItem, {
|
282
|
+
onClick: () => {
|
283
|
+
setMenuIconEl(null);
|
284
|
+
handlePrint();
|
285
|
+
},
|
286
|
+
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
287
|
+
children: /*#__PURE__*/_jsx(PrintIcon, {
|
288
|
+
fontSize: "small"
|
289
|
+
})
|
290
|
+
}), /*#__PURE__*/_jsx(ListItemText, {
|
291
|
+
children: print
|
292
|
+
})]
|
293
|
+
})), menuItems]
|
294
|
+
}), allPops.map((e, index) => /*#__PURE__*/_jsx("div", {
|
295
|
+
children: e
|
296
|
+
}, getPopId(index))), /*#__PURE__*/_jsx(ProgressContainer, {
|
297
|
+
children: loading && /*#__PURE__*/_jsx(LinearProgress, {
|
298
|
+
className: "toolbar-progress"
|
299
|
+
})
|
300
|
+
})]
|
301
|
+
});
|
302
|
+
}
|
303
|
+
CustomToolbar.propTypes = {
|
304
|
+
data: PropTypes.array,
|
305
|
+
options: PropTypes.object.isRequired,
|
306
|
+
components: PropTypes.object,
|
307
|
+
columns: PropTypes.array.isRequired,
|
308
|
+
filterList: PropTypes.array,
|
309
|
+
filterData: PropTypes.array,
|
310
|
+
filterUpdate: PropTypes.func.isRequired,
|
311
|
+
resetFilters: PropTypes.func.isRequired,
|
312
|
+
updateFilterByType: PropTypes.func.isRequired,
|
313
|
+
toggleViewColumn: PropTypes.func.isRequired,
|
314
|
+
updateColumns: PropTypes.func.isRequired,
|
315
|
+
title: PropTypes.any,
|
316
|
+
searchText: PropTypes.any,
|
317
|
+
searchTextUpdate: PropTypes.func.isRequired,
|
318
|
+
searchClose: PropTypes.func.isRequired,
|
319
|
+
tableRef: PropTypes.func.isRequired
|
320
|
+
};
|
321
|
+
CustomToolbar.defaultProps = {
|
322
|
+
data: [],
|
323
|
+
components: {},
|
324
|
+
filterList: [],
|
325
|
+
filterData: [],
|
326
|
+
title: '',
|
327
|
+
searchText: null
|
328
|
+
};
|
329
|
+
const Container = styled('div')`
|
330
|
+
display: flex;
|
331
|
+
align-items: center;
|
332
|
+
height: 56px;
|
333
|
+
.custom-toobar-title {
|
334
|
+
position: relative;
|
335
|
+
flex: 1;
|
336
|
+
font-size: 18px;
|
337
|
+
font-weight: 800;
|
338
|
+
height: 56px;
|
339
|
+
transition: all ease 0.3s;
|
340
|
+
&-inner {
|
341
|
+
line-height: 56px;
|
342
|
+
width: 100%;
|
343
|
+
height: 56px;
|
344
|
+
position: absolute;
|
345
|
+
left: 0;
|
346
|
+
top: 0;
|
347
|
+
span {
|
348
|
+
display: inline-block;
|
349
|
+
max-width: 100%;
|
350
|
+
white-space: nowrap;
|
351
|
+
text-overflow: ellipsis;
|
352
|
+
overflow: hidden;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
.custom-toobar-btns {
|
357
|
+
display: flex;
|
358
|
+
justify-content: center;
|
359
|
+
align-items: center;
|
360
|
+
&.toobar-btns-disabled {
|
361
|
+
position: relative;
|
362
|
+
opacity: 0.5;
|
363
|
+
&:after {
|
364
|
+
position: absolute;
|
365
|
+
display: block;
|
366
|
+
z-index: 2;
|
367
|
+
width: 100%;
|
368
|
+
height: 100%;
|
369
|
+
left: 0;
|
370
|
+
top: 0;
|
371
|
+
content: '';
|
372
|
+
cursor: not-allowed;
|
373
|
+
}
|
374
|
+
}
|
375
|
+
.custom-toolbar-icon {
|
376
|
+
display: flex;
|
377
|
+
justify-content: center;
|
378
|
+
align-items: center;
|
379
|
+
width: 24px;
|
380
|
+
height: 24px;
|
381
|
+
font-size: 20px;
|
382
|
+
overflow: hidden;
|
383
|
+
}
|
384
|
+
}
|
385
|
+
.toobar-title-hidden {
|
386
|
+
opacity: 0;
|
387
|
+
cursor: none;
|
388
|
+
}
|
389
|
+
`;
|
390
|
+
const ProgressContainer = styled('div')`
|
391
|
+
width: 100%;
|
392
|
+
height: 2px;
|
393
|
+
.toolbar-progress {
|
394
|
+
height: 2px;
|
395
|
+
}
|
396
|
+
`;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { createContext, useContext, useState } from 'react';
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
3
|
+
const DatatableContext = /*#__PURE__*/createContext({});
|
4
|
+
const {
|
5
|
+
Provider
|
6
|
+
} = DatatableContext;
|
7
|
+
|
8
|
+
// eslint-disable-next-line react/prop-types
|
9
|
+
function DatatableProvider({
|
10
|
+
children
|
11
|
+
}) {
|
12
|
+
const [customButtons, setCustomButtons] = useState([]);
|
13
|
+
const [loading, setLoading] = useState(false);
|
14
|
+
const [disabled, setDisabled] = useState(false);
|
15
|
+
const [filterLabel, setFilterLabel] = useState('Filter');
|
16
|
+
const value = {
|
17
|
+
customButtons,
|
18
|
+
setCustomButtons,
|
19
|
+
filterLabel,
|
20
|
+
setFilterLabel,
|
21
|
+
loading,
|
22
|
+
setLoading,
|
23
|
+
disabled,
|
24
|
+
setDisabled
|
25
|
+
};
|
26
|
+
return /*#__PURE__*/_jsx(Provider, {
|
27
|
+
value: value,
|
28
|
+
children: children
|
29
|
+
});
|
30
|
+
}
|
31
|
+
function useDatatableContext() {
|
32
|
+
return useContext(DatatableContext);
|
33
|
+
}
|
34
|
+
export { DatatableProvider, useDatatableContext };
|
@@ -0,0 +1,165 @@
|
|
1
|
+
import { useState, useRef } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
4
|
+
import Tooltip from '@mui/material/Tooltip';
|
5
|
+
import SearchIcon from '@mui/icons-material/Search';
|
6
|
+
import TextField from '@mui/material/TextField';
|
7
|
+
import ClearIcon from '@mui/icons-material/Clear';
|
8
|
+
import clsx from 'clsx';
|
9
|
+
import { useDatatableContext } from './DatatableContext';
|
10
|
+
import { styled } from '../Theme';
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
export default function TableSearch({
|
14
|
+
search,
|
15
|
+
options,
|
16
|
+
searchText,
|
17
|
+
searchTextUpdate,
|
18
|
+
searchClose,
|
19
|
+
onSearchOpen
|
20
|
+
}) {
|
21
|
+
const {
|
22
|
+
searchOpen,
|
23
|
+
searchPlaceholder,
|
24
|
+
searchAlwaysOpen
|
25
|
+
} = options;
|
26
|
+
const [inputExpand, setInputExpand] = useState(!!searchText || searchOpen || false);
|
27
|
+
const [innerSearchText, setInnerSearchText] = useState(searchText);
|
28
|
+
const inputTimer = useRef(null);
|
29
|
+
const {
|
30
|
+
loading
|
31
|
+
} = useDatatableContext();
|
32
|
+
const {
|
33
|
+
searchDebounceTime
|
34
|
+
} = options;
|
35
|
+
const searchExpand = searchAlwaysOpen || inputExpand;
|
36
|
+
const clickSearchIcon = () => {
|
37
|
+
setInputExpand(true);
|
38
|
+
onSearchOpen(true);
|
39
|
+
};
|
40
|
+
const onChange = event => {
|
41
|
+
const {
|
42
|
+
value
|
43
|
+
} = event.currentTarget;
|
44
|
+
if (searchDebounceTime) {
|
45
|
+
clearTimeout(inputTimer.current);
|
46
|
+
setInnerSearchText(value);
|
47
|
+
inputTimer.current = setTimeout(() => {
|
48
|
+
searchTextUpdate(value);
|
49
|
+
}, searchDebounceTime);
|
50
|
+
} else {
|
51
|
+
searchTextUpdate(value);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
const clickClose = () => {
|
55
|
+
setInputExpand(false);
|
56
|
+
searchClose();
|
57
|
+
setInnerSearchText('');
|
58
|
+
onSearchOpen(false);
|
59
|
+
};
|
60
|
+
return /*#__PURE__*/_jsxs(Container, {
|
61
|
+
className: clsx({
|
62
|
+
'search-always-open': searchAlwaysOpen
|
63
|
+
}),
|
64
|
+
children: [searchExpand ? /*#__PURE__*/_jsx("div", {
|
65
|
+
className: "toolbar-search-icon-placeholder",
|
66
|
+
children: /*#__PURE__*/_jsx(SearchIcon, {})
|
67
|
+
}) : /*#__PURE__*/_jsx(Tooltip, {
|
68
|
+
title: search,
|
69
|
+
disableFocusListener: true,
|
70
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
71
|
+
"aria-label": search,
|
72
|
+
"data-testid": `${search}-iconButton`,
|
73
|
+
disabled: options.search === 'disabled',
|
74
|
+
onClick: clickSearchIcon,
|
75
|
+
children: /*#__PURE__*/_jsx(SearchIcon, {})
|
76
|
+
})
|
77
|
+
}), /*#__PURE__*/_jsxs("div", {
|
78
|
+
className: `toolbar-search-area ${searchExpand ? 'toolbar-btn-show' : ''}`,
|
79
|
+
children: [searchExpand && !loading && /*#__PURE__*/_jsx(TextField, {
|
80
|
+
variant: "standard",
|
81
|
+
spacing: 2,
|
82
|
+
onChange: onChange,
|
83
|
+
value: searchDebounceTime ? innerSearchText : searchText,
|
84
|
+
placeholder: searchPlaceholder || '',
|
85
|
+
autoFocus: !searchAlwaysOpen
|
86
|
+
}), loading && /*#__PURE__*/_jsx(TextField, {
|
87
|
+
disabled: true,
|
88
|
+
variant: "standard",
|
89
|
+
spacing: 2,
|
90
|
+
value: searchDebounceTime ? innerSearchText : searchText
|
91
|
+
})]
|
92
|
+
}), !searchAlwaysOpen && /*#__PURE__*/_jsx("div", {
|
93
|
+
className: `toolbar-search-close ${searchExpand ? 'toolbar-btn-show' : ''}`,
|
94
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
95
|
+
onClick: clickClose,
|
96
|
+
"aria-label": "click to close the search box",
|
97
|
+
children: /*#__PURE__*/_jsx(ClearIcon, {})
|
98
|
+
})
|
99
|
+
})]
|
100
|
+
});
|
101
|
+
}
|
102
|
+
TableSearch.propTypes = {
|
103
|
+
search: PropTypes.string,
|
104
|
+
searchText: PropTypes.string,
|
105
|
+
onSearchOpen: PropTypes.func,
|
106
|
+
options: PropTypes.object.isRequired,
|
107
|
+
searchTextUpdate: PropTypes.func.isRequired,
|
108
|
+
searchClose: PropTypes.func.isRequired
|
109
|
+
};
|
110
|
+
TableSearch.defaultProps = {
|
111
|
+
search: '',
|
112
|
+
searchText: '',
|
113
|
+
onSearchOpen: () => {}
|
114
|
+
};
|
115
|
+
const Container = styled('div')`
|
116
|
+
display: flex;
|
117
|
+
align-items: center;
|
118
|
+
.toolbar-search-area {
|
119
|
+
width: 0;
|
120
|
+
transition: all ease 0.3s;
|
121
|
+
overflow: hidden;
|
122
|
+
.MuiFormControl-root {
|
123
|
+
width: inherit;
|
124
|
+
margin: 0 12px;
|
125
|
+
}
|
126
|
+
&.toolbar-btn-show {
|
127
|
+
width: 260px;
|
128
|
+
padding-left: 8px;
|
129
|
+
|
130
|
+
${props => props.theme.breakpoints.down('md')} {
|
131
|
+
width: 200px;
|
132
|
+
}
|
133
|
+
|
134
|
+
${props => props.theme.breakpoints.down('sm')} {
|
135
|
+
width: 180px;
|
136
|
+
}
|
137
|
+
&.small-textfield {
|
138
|
+
width: 200px;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
.toolbar-search-close {
|
143
|
+
width: 0;
|
144
|
+
transition: all ease 0.3s;
|
145
|
+
overflow: hidden;
|
146
|
+
&.toolbar-btn-show {
|
147
|
+
width: 40px;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
.toolbar-search-icon-placeholder {
|
151
|
+
display: flex;
|
152
|
+
justify-content: center;
|
153
|
+
align-items: center;
|
154
|
+
width: 40px;
|
155
|
+
height: 40px;
|
156
|
+
}
|
157
|
+
&.search-always-open {
|
158
|
+
.MuiFormControl-root {
|
159
|
+
margin: 0 12px 0 0;
|
160
|
+
}
|
161
|
+
.toolbar-btn-show {
|
162
|
+
padding-left: 0;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
`;
|