@etsoo/materialui 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.json +38 -0
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/main.yml +48 -0
  5. package/.prettierignore +5 -0
  6. package/.prettierrc +6 -0
  7. package/LICENSE +21 -0
  8. package/README.md +16 -0
  9. package/__tests__/ComboBox.tsx +30 -0
  10. package/__tests__/MUGlobalTests.tsx +58 -0
  11. package/__tests__/NotifierMUTests.tsx +217 -0
  12. package/__tests__/SelectEx.tsx +26 -0
  13. package/__tests__/tsconfig.json +19 -0
  14. package/babel.config.json +11 -0
  15. package/lib/AuditDisplay.d.ts +33 -0
  16. package/lib/AuditDisplay.js +52 -0
  17. package/lib/AutocompleteExtendedProps.d.ts +64 -0
  18. package/lib/AutocompleteExtendedProps.js +1 -0
  19. package/lib/BackButton.d.ts +13 -0
  20. package/lib/BackButton.js +33 -0
  21. package/lib/BridgeCloseButton.d.ts +23 -0
  22. package/lib/BridgeCloseButton.js +32 -0
  23. package/lib/ButtonLink.d.ts +17 -0
  24. package/lib/ButtonLink.js +19 -0
  25. package/lib/ComboBox.d.ts +38 -0
  26. package/lib/ComboBox.js +108 -0
  27. package/lib/CountdownButton.d.ts +23 -0
  28. package/lib/CountdownButton.js +81 -0
  29. package/lib/CustomFabProps.d.ts +27 -0
  30. package/lib/CustomFabProps.js +1 -0
  31. package/lib/DataGridEx.d.ts +94 -0
  32. package/lib/DataGridEx.js +329 -0
  33. package/lib/DataGridRenderers.d.ts +22 -0
  34. package/lib/DataGridRenderers.js +99 -0
  35. package/lib/DialogButton.d.ts +54 -0
  36. package/lib/DialogButton.js +45 -0
  37. package/lib/DnDList.d.ts +87 -0
  38. package/lib/DnDList.js +153 -0
  39. package/lib/DraggablePaperComponent.d.ts +8 -0
  40. package/lib/DraggablePaperComponent.js +12 -0
  41. package/lib/EmailInput.d.ts +11 -0
  42. package/lib/EmailInput.js +15 -0
  43. package/lib/FabBox.d.ts +21 -0
  44. package/lib/FabBox.js +31 -0
  45. package/lib/FlexBox.d.ts +14 -0
  46. package/lib/FlexBox.js +18 -0
  47. package/lib/GridDataFormat.d.ts +10 -0
  48. package/lib/GridDataFormat.js +43 -0
  49. package/lib/IconButtonLink.d.ts +17 -0
  50. package/lib/IconButtonLink.js +16 -0
  51. package/lib/InputField.d.ts +21 -0
  52. package/lib/InputField.js +39 -0
  53. package/lib/ItemList.d.ts +56 -0
  54. package/lib/ItemList.js +69 -0
  55. package/lib/ListItemRightIcon.d.ts +4 -0
  56. package/lib/ListItemRightIcon.js +8 -0
  57. package/lib/ListMoreDisplay.d.ts +35 -0
  58. package/lib/ListMoreDisplay.js +99 -0
  59. package/lib/LoadingButton.d.ts +16 -0
  60. package/lib/LoadingButton.js +41 -0
  61. package/lib/MUGlobal.d.ts +102 -0
  62. package/lib/MUGlobal.js +184 -0
  63. package/lib/MaskInput.d.ts +34 -0
  64. package/lib/MaskInput.js +43 -0
  65. package/lib/MobileListItemRenderer.d.ts +17 -0
  66. package/lib/MobileListItemRenderer.js +35 -0
  67. package/lib/MoreFab.d.ts +45 -0
  68. package/lib/MoreFab.js +95 -0
  69. package/lib/NotifierMU.d.ts +47 -0
  70. package/lib/NotifierMU.js +387 -0
  71. package/lib/NotifierPromptProps.d.ts +22 -0
  72. package/lib/NotifierPromptProps.js +1 -0
  73. package/lib/OptionGroup.d.ts +58 -0
  74. package/lib/OptionGroup.js +81 -0
  75. package/lib/PList.d.ts +15 -0
  76. package/lib/PList.js +12 -0
  77. package/lib/ProgressCount.d.ts +44 -0
  78. package/lib/ProgressCount.js +79 -0
  79. package/lib/PullToRefreshUI.d.ts +9 -0
  80. package/lib/PullToRefreshUI.js +18 -0
  81. package/lib/RLink.d.ts +14 -0
  82. package/lib/RLink.js +37 -0
  83. package/lib/ResponsibleContainer.d.ts +87 -0
  84. package/lib/ResponsibleContainer.js +156 -0
  85. package/lib/ScrollTopFab.d.ts +7 -0
  86. package/lib/ScrollTopFab.js +25 -0
  87. package/lib/ScrollerListEx.d.ts +81 -0
  88. package/lib/ScrollerListEx.js +167 -0
  89. package/lib/SearchBar.d.ts +29 -0
  90. package/lib/SearchBar.js +260 -0
  91. package/lib/SearchField.d.ts +21 -0
  92. package/lib/SearchField.js +39 -0
  93. package/lib/SearchOptionGroup.d.ts +9 -0
  94. package/lib/SearchOptionGroup.js +14 -0
  95. package/lib/SelectBool.d.ts +13 -0
  96. package/lib/SelectBool.js +22 -0
  97. package/lib/SelectEx.d.ts +50 -0
  98. package/lib/SelectEx.js +156 -0
  99. package/lib/ShowDataComparison.d.ts +20 -0
  100. package/lib/ShowDataComparison.js +58 -0
  101. package/lib/Switch.d.ts +29 -0
  102. package/lib/Switch.js +34 -0
  103. package/lib/SwitchAnt.d.ts +25 -0
  104. package/lib/SwitchAnt.js +40 -0
  105. package/lib/TabBox.d.ts +54 -0
  106. package/lib/TabBox.js +31 -0
  107. package/lib/TableEx.d.ts +65 -0
  108. package/lib/TableEx.js +270 -0
  109. package/lib/TextFieldEx.d.ts +101 -0
  110. package/lib/TextFieldEx.js +126 -0
  111. package/lib/Tiplist.d.ts +18 -0
  112. package/lib/Tiplist.js +157 -0
  113. package/lib/TooltipClick.d.ts +15 -0
  114. package/lib/TooltipClick.js +40 -0
  115. package/lib/UserAvatar.d.ts +24 -0
  116. package/lib/UserAvatar.js +25 -0
  117. package/lib/UserAvatarEditor.d.ts +53 -0
  118. package/lib/UserAvatarEditor.js +129 -0
  119. package/lib/app/CommonApp.d.ts +38 -0
  120. package/lib/app/CommonApp.js +149 -0
  121. package/lib/app/IServiceAppSettings.d.ts +11 -0
  122. package/lib/app/IServiceAppSettings.js +1 -0
  123. package/lib/app/IServicePage.d.ts +6 -0
  124. package/lib/app/IServicePage.js +1 -0
  125. package/lib/app/IServiceUser.d.ts +14 -0
  126. package/lib/app/IServiceUser.js +1 -0
  127. package/lib/app/ISmartERPUser.d.ts +14 -0
  128. package/lib/app/ISmartERPUser.js +1 -0
  129. package/lib/app/Labels.d.ts +65 -0
  130. package/lib/app/Labels.js +62 -0
  131. package/lib/app/ReactApp.d.ts +195 -0
  132. package/lib/app/ReactApp.js +296 -0
  133. package/lib/app/ServiceApp.d.ts +78 -0
  134. package/lib/app/ServiceApp.js +244 -0
  135. package/lib/index.d.ts +74 -0
  136. package/lib/index.js +74 -0
  137. package/lib/pages/CommonPage.d.ts +11 -0
  138. package/lib/pages/CommonPage.js +60 -0
  139. package/lib/pages/CommonPageProps.d.ts +59 -0
  140. package/lib/pages/CommonPageProps.js +1 -0
  141. package/lib/pages/DataGridPage.d.ts +9 -0
  142. package/lib/pages/DataGridPage.js +79 -0
  143. package/lib/pages/DataGridPageProps.d.ts +17 -0
  144. package/lib/pages/DataGridPageProps.js +1 -0
  145. package/lib/pages/EditPage.d.ts +33 -0
  146. package/lib/pages/EditPage.js +29 -0
  147. package/lib/pages/FixedListPage.d.ts +15 -0
  148. package/lib/pages/FixedListPage.js +70 -0
  149. package/lib/pages/ListPage.d.ts +9 -0
  150. package/lib/pages/ListPage.js +50 -0
  151. package/lib/pages/ListPageProps.d.ts +7 -0
  152. package/lib/pages/ListPageProps.js +1 -0
  153. package/lib/pages/ResponsivePage.d.ts +9 -0
  154. package/lib/pages/ResponsivePage.js +45 -0
  155. package/lib/pages/ResponsivePageProps.d.ts +39 -0
  156. package/lib/pages/ResponsivePageProps.js +1 -0
  157. package/lib/pages/SearchPageProps.d.ts +30 -0
  158. package/lib/pages/SearchPageProps.js +1 -0
  159. package/lib/pages/TablePage.d.ts +9 -0
  160. package/lib/pages/TablePage.js +69 -0
  161. package/lib/pages/TablePageProps.d.ts +7 -0
  162. package/lib/pages/TablePageProps.js +1 -0
  163. package/lib/pages/ViewPage.d.ts +66 -0
  164. package/lib/pages/ViewPage.js +105 -0
  165. package/lib/texts/DateText.d.ts +34 -0
  166. package/lib/texts/DateText.js +25 -0
  167. package/lib/texts/MoneyText.d.ts +21 -0
  168. package/lib/texts/MoneyText.js +14 -0
  169. package/lib/texts/NumberText.d.ts +25 -0
  170. package/lib/texts/NumberText.js +14 -0
  171. package/package.json +97 -0
  172. package/src/AuditDisplay.tsx +114 -0
  173. package/src/AutocompleteExtendedProps.ts +83 -0
  174. package/src/BackButton.tsx +55 -0
  175. package/src/BridgeCloseButton.tsx +69 -0
  176. package/src/ButtonLink.tsx +32 -0
  177. package/src/ComboBox.tsx +251 -0
  178. package/src/CountdownButton.tsx +119 -0
  179. package/src/CustomFabProps.ts +32 -0
  180. package/src/DataGridEx.tsx +713 -0
  181. package/src/DataGridRenderers.tsx +140 -0
  182. package/src/DialogButton.tsx +163 -0
  183. package/src/DnDList.tsx +344 -0
  184. package/src/DraggablePaperComponent.tsx +19 -0
  185. package/src/EmailInput.tsx +24 -0
  186. package/src/FabBox.tsx +51 -0
  187. package/src/FlexBox.tsx +20 -0
  188. package/src/GridDataFormat.tsx +77 -0
  189. package/src/IconButtonLink.tsx +29 -0
  190. package/src/InputField.tsx +82 -0
  191. package/src/ItemList.tsx +204 -0
  192. package/src/ListItemRightIcon.tsx +9 -0
  193. package/src/ListMoreDisplay.tsx +205 -0
  194. package/src/LoadingButton.tsx +75 -0
  195. package/src/MUGlobal.ts +220 -0
  196. package/src/MaskInput.tsx +107 -0
  197. package/src/MobileListItemRenderer.tsx +79 -0
  198. package/src/MoreFab.tsx +211 -0
  199. package/src/NotifierMU.tsx +654 -0
  200. package/src/NotifierPromptProps.ts +24 -0
  201. package/src/OptionGroup.tsx +223 -0
  202. package/src/PList.tsx +27 -0
  203. package/src/ProgressCount.tsx +166 -0
  204. package/src/PullToRefreshUI.tsx +21 -0
  205. package/src/RLink.tsx +64 -0
  206. package/src/ResponsibleContainer.tsx +394 -0
  207. package/src/ScrollTopFab.tsx +34 -0
  208. package/src/ScrollerListEx.tsx +387 -0
  209. package/src/SearchBar.tsx +396 -0
  210. package/src/SearchField.tsx +82 -0
  211. package/src/SearchOptionGroup.tsx +31 -0
  212. package/src/SelectBool.tsx +33 -0
  213. package/src/SelectEx.tsx +290 -0
  214. package/src/ShowDataComparison.tsx +106 -0
  215. package/src/Switch.tsx +94 -0
  216. package/src/SwitchAnt.tsx +95 -0
  217. package/src/TabBox.tsx +118 -0
  218. package/src/TableEx.tsx +558 -0
  219. package/src/TextFieldEx.tsx +249 -0
  220. package/src/Tiplist.tsx +303 -0
  221. package/src/TooltipClick.tsx +84 -0
  222. package/src/UserAvatar.tsx +64 -0
  223. package/src/UserAvatarEditor.tsx +287 -0
  224. package/src/app/CommonApp.ts +223 -0
  225. package/src/app/IServiceAppSettings.ts +13 -0
  226. package/src/app/IServicePage.ts +6 -0
  227. package/src/app/IServiceUser.ts +17 -0
  228. package/src/app/ISmartERPUser.ts +16 -0
  229. package/src/app/Labels.ts +77 -0
  230. package/src/app/ReactApp.ts +504 -0
  231. package/src/app/ServiceApp.ts +352 -0
  232. package/src/index.ts +77 -0
  233. package/src/pages/CommonPage.tsx +128 -0
  234. package/src/pages/CommonPageProps.ts +70 -0
  235. package/src/pages/DataGridPage.tsx +140 -0
  236. package/src/pages/DataGridPageProps.ts +24 -0
  237. package/src/pages/EditPage.tsx +114 -0
  238. package/src/pages/FixedListPage.tsx +141 -0
  239. package/src/pages/ListPage.tsx +90 -0
  240. package/src/pages/ListPageProps.ts +12 -0
  241. package/src/pages/ResponsivePage.tsx +68 -0
  242. package/src/pages/ResponsivePageProps.ts +57 -0
  243. package/src/pages/SearchPageProps.ts +39 -0
  244. package/src/pages/TablePage.tsx +126 -0
  245. package/src/pages/TablePageProps.ts +12 -0
  246. package/src/pages/ViewPage.tsx +282 -0
  247. package/src/texts/DateText.tsx +74 -0
  248. package/src/texts/MoneyText.tsx +49 -0
  249. package/src/texts/NumberText.tsx +40 -0
  250. package/tsconfig.json +19 -0
@@ -0,0 +1,329 @@
1
+ import { css } from '@emotion/css';
2
+ import { GridAlignGet, ScrollerGrid, useCombinedRefs } from '@etsoo/react';
3
+ import { Utils } from '@etsoo/shared';
4
+ import { Box, Checkbox, Paper, TableSortLabel, useTheme } from '@mui/material';
5
+ import React from 'react';
6
+ import { DataGridRenderers } from './DataGridRenderers';
7
+ // Borders
8
+ const boldBorder = '2px solid rgba(224, 224, 224, 1)';
9
+ const thinBorder = '1px solid rgba(224, 224, 224, 1)';
10
+ // Scroll bar size
11
+ const scrollbarSize = 16;
12
+ // Minimum width
13
+ const minWidth = 120;
14
+ const createGridStyle = (alternatingColors, selectedColor, hoverColor) => {
15
+ return css({
16
+ '.DataGridEx-Selected': {
17
+ backgroundColor: selectedColor
18
+ },
19
+ '.DataGridEx-Hover:not(.DataGridEx-Selected)': {
20
+ backgroundColor: hoverColor
21
+ },
22
+ '& .DataGridEx-Cell0:not(.DataGridEx-Hover):not(.DataGridEx-Selected)': {
23
+ backgroundColor: alternatingColors[0]
24
+ },
25
+ '& .DataGridEx-Cell1:not(.DataGridEx-Hover):not(.DataGridEx-Selected)': {
26
+ backgroundColor: alternatingColors[1]
27
+ },
28
+ '& .DataGridEx-Cell-Border': {
29
+ borderBottom: thinBorder
30
+ }
31
+ });
32
+ };
33
+ const rowItems = (div, callback) => {
34
+ const row = div.dataset['row'];
35
+ if (div.parentElement == null || row == null)
36
+ return;
37
+ doRowItems(div.parentElement, parseFloat(row), callback);
38
+ };
39
+ const doRowItems = (parent, rowIndex, callback) => {
40
+ if (parent == null || rowIndex == null)
41
+ return;
42
+ parent === null || parent === void 0 ? void 0 : parent.querySelectorAll(`div[data-row="${rowIndex}"]`).forEach((rowItem) => {
43
+ callback(rowItem);
44
+ });
45
+ };
46
+ /**
47
+ * Extended datagrid columns calculation
48
+ * @param columns
49
+ * @returns Total width and unset items
50
+ */
51
+ export function DataGridExCalColumns(columns) {
52
+ return columns.reduce((previousValue, currentItem) => {
53
+ var _a, _b;
54
+ previousValue.total +=
55
+ (_b = (_a = currentItem.width) !== null && _a !== void 0 ? _a : currentItem.minWidth) !== null && _b !== void 0 ? _b : minWidth;
56
+ if (currentItem.width == null)
57
+ previousValue.unset++;
58
+ return previousValue;
59
+ }, {
60
+ total: 0,
61
+ unset: 0
62
+ });
63
+ }
64
+ /**
65
+ * Extended DataGrid with VariableSizeGrid
66
+ * @param props Props
67
+ * @returns Component
68
+ */
69
+ export function DataGridEx(props) {
70
+ // Theme
71
+ const theme = useTheme();
72
+ const defaultHeaderRenderer = (states) => {
73
+ const { orderBy } = states;
74
+ return (React.createElement(Box, { className: "DataGridEx-Header", display: "flex", alignItems: "center", borderBottom: boldBorder, fontWeight: 500, minWidth: widthCalculator.total, height: headerHeight }, columns.map((column, index) => {
75
+ // Destruct
76
+ const { align, field, header, headerCellRenderer, sortable, sortAsc = true, type } = column;
77
+ // Header text
78
+ const headerText = header !== null && header !== void 0 ? header : field;
79
+ // Cell props
80
+ const cellProps = {};
81
+ // Sortable
82
+ let sortLabel;
83
+ if (headerCellRenderer) {
84
+ sortLabel = headerCellRenderer({
85
+ cellProps,
86
+ column,
87
+ columnIndex: checkable ? index - 1 : index,
88
+ states
89
+ });
90
+ }
91
+ else if (sortable && field != null) {
92
+ const active = orderBy === field;
93
+ sortLabel = (React.createElement(TableSortLabel, { active: active, direction: sortAsc ? 'asc' : 'desc', onClick: (_event) => {
94
+ if (active)
95
+ column.sortAsc = !sortAsc;
96
+ handleSort(field, column.sortAsc);
97
+ } }, headerText));
98
+ }
99
+ else {
100
+ sortLabel = headerText;
101
+ }
102
+ return (React.createElement(Box, { key: field !== null && field !== void 0 ? field : index.toString(), textAlign: GridAlignGet(align, type), width: columnWidth(index) },
103
+ React.createElement(Box, { className: "DataGridEx-Cell", onMouseEnter: handleMouseEnter, ...cellProps }, sortLabel)));
104
+ })));
105
+ };
106
+ function defaultFooterRenderer(rows, states) {
107
+ return (React.createElement(Box, { className: "DataGridEx-Footer", display: "flex", alignItems: "center", borderTop: thinBorder, marginTop: "1px", minWidth: widthCalculator.total, height: bottomHeight - 1 }, columns.map((column, index) => {
108
+ // Destruct
109
+ const { align, field, type } = column;
110
+ // Cell props
111
+ const cellProps = {};
112
+ // Cell
113
+ const cell = footerItemRenderer
114
+ ? footerItemRenderer(rows, {
115
+ column,
116
+ index: checkable ? index - 1 : index,
117
+ states,
118
+ cellProps,
119
+ checkable
120
+ })
121
+ : undefined;
122
+ return (React.createElement(Box, { key: 'bottom-' + (field !== null && field !== void 0 ? field : index.toString()), textAlign: GridAlignGet(align, type), width: columnWidth(index) },
123
+ React.createElement(Box, { className: "DataGridEx-Cell", onMouseEnter: handleMouseEnter, ...cellProps }, cell)));
124
+ })));
125
+ }
126
+ // Destruct
127
+ const { alternatingColors = [theme.palette.grey[100], undefined], borderRowsCount, bottomHeight = 53, checkable = false, className, columns, defaultOrderBy, height, headerHeight = 56, headerRenderer = defaultHeaderRenderer, footerRenderer = defaultFooterRenderer, footerItemRenderer = DataGridRenderers.defaultFooterItemRenderer, hideFooter = false, hoverColor = '#f6f9fb', idField = 'id', mRef = React.createRef(), onClick, onDoubleClick, selectable = true, selectedColor = '#edf4fb', width, ...rest } = props;
128
+ if (checkable) {
129
+ const cbColumn = {
130
+ field: 'selected',
131
+ header: '',
132
+ sortable: false,
133
+ width: 50,
134
+ cellRenderer: ({ cellProps, data, selected }) => {
135
+ cellProps.sx = {
136
+ padding: '4px!important'
137
+ };
138
+ return (React.createElement(Checkbox, { color: "primary", checked: selected, onChange: (_event, checked) => {
139
+ var _a;
140
+ (_a = refs.current.ref) === null || _a === void 0 ? void 0 : _a.selectItem(data, checked);
141
+ } }));
142
+ },
143
+ headerCellRenderer: ({ cellProps, states }) => {
144
+ // 2 = border height
145
+ const hpad = (headerHeight - 42) / 2;
146
+ cellProps.sx = {
147
+ padding: `${hpad}px 4px ${hpad - 1}px 4px!important`
148
+ };
149
+ return (React.createElement(Checkbox, { color: "primary", indeterminate: states.selectedItems.length > 0 &&
150
+ states.selectedItems.length < states.loadedItems, checked: states.selectedItems.length > 0, onChange: (_event, checked) => { var _a; return (_a = refs.current.ref) === null || _a === void 0 ? void 0 : _a.selectAll(checked); } }));
151
+ }
152
+ };
153
+ // Update to the latest version
154
+ if (columns[0].field === 'selected') {
155
+ columns[0] = cbColumn;
156
+ }
157
+ else {
158
+ columns.unshift(cbColumn);
159
+ }
160
+ }
161
+ const refs = React.useRef({});
162
+ const mRefLocal = useCombinedRefs(mRef, (ref) => {
163
+ if (ref == null)
164
+ return;
165
+ refs.current.ref = ref;
166
+ });
167
+ // New sort
168
+ const handleSort = (field, asc) => {
169
+ reset({ orderBy: field, orderByAsc: asc });
170
+ };
171
+ // Reset
172
+ const reset = (add) => {
173
+ var _a;
174
+ (_a = refs.current.ref) === null || _a === void 0 ? void 0 : _a.reset(add);
175
+ };
176
+ // Show hover tooltip for trucated text
177
+ const handleMouseEnter = (event) => {
178
+ const div = event.currentTarget;
179
+ const { innerText, offsetWidth, scrollWidth } = div;
180
+ if (offsetWidth < scrollWidth) {
181
+ div.title = innerText;
182
+ }
183
+ else {
184
+ div.title = '';
185
+ }
186
+ };
187
+ // selectedRowIndex state
188
+ const selectedRowIndex = React.useRef(-1);
189
+ const handleMouseDown = (event) => {
190
+ const div = event.currentTarget;
191
+ const row = div.dataset['row'];
192
+ if (div.parentElement == null || row == null)
193
+ return;
194
+ const rowIndex = parseFloat(row);
195
+ // No change
196
+ if (isNaN(rowIndex) || rowIndex === selectedRowIndex.current)
197
+ return;
198
+ if (selectedRowIndex.current != -1) {
199
+ doRowItems(div.parentElement, selectedRowIndex.current, (preDiv) => {
200
+ preDiv.classList.remove('DataGridEx-Selected');
201
+ });
202
+ }
203
+ rowItems(div, (currentDiv) => {
204
+ currentDiv.classList.add('DataGridEx-Selected');
205
+ });
206
+ selectedRowIndex.current = rowIndex;
207
+ };
208
+ const handleMouseOver = (event) => {
209
+ rowItems(event.currentTarget, (div) => {
210
+ div.classList.add('DataGridEx-Hover');
211
+ });
212
+ };
213
+ const handleMouseOut = (event) => {
214
+ rowItems(event.currentTarget, (div) => {
215
+ div.classList.remove('DataGridEx-Hover');
216
+ });
217
+ };
218
+ /**
219
+ * Item renderer
220
+ */
221
+ const itemRenderer = ({ columnIndex, rowIndex, style, data, selectedItems }) => {
222
+ // Column
223
+ const { align, cellRenderer = DataGridRenderers.defaultCellRenderer, field, type, valueFormatter, renderProps } = columns[columnIndex];
224
+ // Props
225
+ const formatProps = {
226
+ data,
227
+ field,
228
+ rowIndex,
229
+ columnIndex
230
+ };
231
+ let rowClass = `DataGridEx-Cell${rowIndex % 2}`;
232
+ if (borderRowsCount != null &&
233
+ borderRowsCount > 0 &&
234
+ (rowIndex + 1) % borderRowsCount === 0) {
235
+ rowClass += ` DataGridEx-Cell-Border`;
236
+ }
237
+ // Selected
238
+ const selected = data != null &&
239
+ (selectedRowIndex.current === rowIndex ||
240
+ selectedItems.some((selectedItem) => selectedItem != null &&
241
+ selectedItem[idField] === data[idField]));
242
+ if (selected) {
243
+ rowClass += ` DataGridEx-Selected`;
244
+ }
245
+ const cellProps = {
246
+ className: 'DataGridEx-Cell',
247
+ textAlign: GridAlignGet(align, type)
248
+ };
249
+ const child = cellRenderer({
250
+ data,
251
+ field,
252
+ formattedValue: valueFormatter
253
+ ? valueFormatter(formatProps)
254
+ : undefined,
255
+ selected,
256
+ type,
257
+ rowIndex,
258
+ columnIndex,
259
+ cellProps,
260
+ renderProps
261
+ });
262
+ return (React.createElement("div", { className: rowClass, style: style, "data-row": rowIndex, "data-column": columnIndex, onMouseDown: selectable && !checkable ? handleMouseDown : undefined, onMouseOver: selectable ? handleMouseOver : undefined, onMouseOut: selectable ? handleMouseOut : undefined, onClick: (event) => onClick && data != null && onClick(event, data), onDoubleClick: (event) => onDoubleClick && data != null && onDoubleClick(event, data) },
263
+ React.createElement(Box, { ...cellProps, onMouseEnter: handleMouseEnter }, child)));
264
+ };
265
+ // Column width calculator
266
+ const widthCalculator = React.useMemo(() => DataGridExCalColumns(columns), [columns]);
267
+ // Column width
268
+ const columnWidth = React.useCallback((index) => {
269
+ // Ignore null case
270
+ if (width == null)
271
+ return 0;
272
+ // Column
273
+ const column = columns[index];
274
+ if (column.width != null)
275
+ return column.width;
276
+ // More space
277
+ const leftWidth = width -
278
+ widthCalculator.total -
279
+ (width < 800 ? 0 : scrollbarSize);
280
+ // Shared width
281
+ const sharedWidth = leftWidth > 0 ? leftWidth / widthCalculator.unset : 0;
282
+ return (column.minWidth || minWidth) + sharedWidth;
283
+ }, [columns, width]);
284
+ // Table
285
+ const table = React.useMemo(() => {
286
+ var _a;
287
+ const defaultOrderByAsc = defaultOrderBy
288
+ ? (_a = columns.find((column) => column.field === defaultOrderBy)) === null || _a === void 0 ? void 0 : _a.sortAsc
289
+ : undefined;
290
+ return (React.createElement(ScrollerGrid, { className: Utils.mergeClasses('DataGridEx-Body', 'DataGridEx-CustomBar', className, createGridStyle(alternatingColors, selectedColor, hoverColor)), columnCount: columns.length, columnWidth: columnWidth, defaultOrderBy: defaultOrderBy, defaultOrderByAsc: defaultOrderByAsc, height: height -
291
+ headerHeight -
292
+ (hideFooter ? 0 : bottomHeight + 1) -
293
+ scrollbarSize, headerRenderer: headerRenderer, idField: idField, itemRenderer: itemRenderer, footerRenderer: hideFooter ? undefined : footerRenderer, width: Math.max(width !== null && width !== void 0 ? width : 0, widthCalculator.total), mRef: mRefLocal, ...rest }));
294
+ }, [width]);
295
+ return (React.createElement(Paper, { sx: {
296
+ fontSize: '0.875rem',
297
+ height,
298
+ '& .DataGridEx-Cell': {
299
+ padding: 2,
300
+ whiteSpace: 'nowrap',
301
+ overflow: 'hidden',
302
+ textOverflow: 'ellipsis'
303
+ },
304
+ '& .DataGridEx-CustomBar': {
305
+ '@media (min-width: 800px)': {
306
+ '::-webkit-scrollbar': {
307
+ width: scrollbarSize,
308
+ height: scrollbarSize,
309
+ backgroundColor: '#f6f6f6'
310
+ },
311
+ '::-webkit-scrollbar-thumb': {
312
+ backgroundColor: 'rgba(0,0,0,0.4)',
313
+ borderRadius: '2px'
314
+ },
315
+ '::-webkit-scrollbar-track-piece:start': {
316
+ background: 'transparent'
317
+ },
318
+ '::-webkit-scrollbar-track-piece:end': {
319
+ background: 'transparent'
320
+ }
321
+ }
322
+ }
323
+ } },
324
+ React.createElement("div", { className: "DataGridEx-CustomBar", style: {
325
+ width,
326
+ overflowX: 'auto',
327
+ overflowY: 'hidden'
328
+ } }, table)));
329
+ }
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { DataGridExFooterItemRendererProps } from './DataGridEx';
3
+ import { GridCellRendererProps } from '@etsoo/react';
4
+ /**
5
+ * Data grid renderers
6
+ */
7
+ export declare namespace DataGridRenderers {
8
+ /**
9
+ * Default cell renderer
10
+ * @param param Props
11
+ * @returns Component
12
+ */
13
+ function defaultCellRenderer<T extends Record<string, any>>({ cellProps, data, field, formattedValue, columnIndex, type, renderProps }: GridCellRendererProps<T>): React.ReactNode;
14
+ /**
15
+ * Default footer item renderer
16
+ * @param rows Rows
17
+ * @param props Renderer props
18
+ * @param location Renderer location (column index)
19
+ * @returns Component
20
+ */
21
+ function defaultFooterItemRenderer<T extends object>(_rows: T[], { index, states, checkable }: DataGridExFooterItemRendererProps<T>, location?: number): string | undefined;
22
+ }
@@ -0,0 +1,99 @@
1
+ import React from 'react';
2
+ import { CircularProgress } from '@mui/material';
3
+ import { DateUtils, NumberUtils } from '@etsoo/shared';
4
+ import CheckIcon from '@mui/icons-material/Check';
5
+ import ClearIcon from '@mui/icons-material/Clear';
6
+ import { DateText } from './texts/DateText';
7
+ import { GridDataType } from '@etsoo/react';
8
+ /**
9
+ * Data grid renderers
10
+ */
11
+ export var DataGridRenderers;
12
+ (function (DataGridRenderers) {
13
+ /**
14
+ * Default cell renderer
15
+ * @param param Props
16
+ * @returns Component
17
+ */
18
+ function defaultCellRenderer({ cellProps, data, field, formattedValue, columnIndex, type, renderProps }) {
19
+ // Is loading
20
+ if (data == null) {
21
+ // First column, show loading indicator
22
+ if (columnIndex === 0)
23
+ return React.createElement(CircularProgress, { size: 15 });
24
+ // Others return undefined
25
+ return undefined;
26
+ }
27
+ // No formatted value and data field
28
+ if (formattedValue == null && field == null)
29
+ return undefined;
30
+ // Cell value
31
+ const value = formattedValue !== null && formattedValue !== void 0 ? formattedValue : data[field];
32
+ if (value == null)
33
+ return undefined;
34
+ // For date time
35
+ // Conversion if necessary
36
+ if (type === GridDataType.Date || type === GridDataType.DateTime) {
37
+ const dateValue = value instanceof Date ? value : new Date(value);
38
+ const option = type === GridDataType.DateTime ? 'ds' : 'd';
39
+ const nearDays = renderProps === null || renderProps === void 0 ? void 0 : renderProps.nearDays;
40
+ if (nearDays != null) {
41
+ return (React.createElement(DateText, { value: dateValue, locale: renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, timeZone: renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone, options: option, nearDays: nearDays }));
42
+ }
43
+ return DateUtils.format(dateValue, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, option, renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone);
44
+ }
45
+ // For numbers
46
+ if (typeof value === 'number') {
47
+ if (type === GridDataType.Money || type === GridDataType.IntMoney)
48
+ return NumberUtils.formatMoney(value, renderProps === null || renderProps === void 0 ? void 0 : renderProps.currency, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, type === GridDataType.IntMoney, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
49
+ else
50
+ return NumberUtils.format(value, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
51
+ }
52
+ // For boolean
53
+ if (typeof value === 'boolean') {
54
+ // Add style
55
+ if ('align' in cellProps) {
56
+ cellProps.sx = {
57
+ paddingTop: '12px!important',
58
+ paddingBottom: '6px!important'
59
+ };
60
+ }
61
+ else {
62
+ cellProps.sx = {
63
+ paddingTop: '16px!important',
64
+ paddingBottom: '8px!important'
65
+ };
66
+ }
67
+ if (value)
68
+ return React.createElement(CheckIcon, { fontSize: "small" });
69
+ else
70
+ return React.createElement(ClearIcon, { fontSize: "small", color: "warning" });
71
+ }
72
+ // To string
73
+ return new String(value);
74
+ }
75
+ DataGridRenderers.defaultCellRenderer = defaultCellRenderer;
76
+ /**
77
+ * Default footer item renderer
78
+ * @param rows Rows
79
+ * @param props Renderer props
80
+ * @param location Renderer location (column index)
81
+ * @returns Component
82
+ */
83
+ function defaultFooterItemRenderer(_rows, { index, states, checkable }, location = 0) {
84
+ const { selectedItems, loadedItems, hasNextPage } = states;
85
+ if (index === location) {
86
+ if (checkable) {
87
+ return [
88
+ selectedItems.length,
89
+ loadedItems.toLocaleString() + (hasNextPage ? '+' : '')
90
+ ].join(' / ');
91
+ }
92
+ else {
93
+ return loadedItems.toLocaleString() + (hasNextPage ? '+' : '');
94
+ }
95
+ }
96
+ return undefined;
97
+ }
98
+ DataGridRenderers.defaultFooterItemRenderer = defaultFooterItemRenderer;
99
+ })(DataGridRenderers || (DataGridRenderers = {}));
@@ -0,0 +1,54 @@
1
+ import { Breakpoint, ButtonProps } from '@mui/material';
2
+ import React from 'react';
3
+ export interface DialogButtonProps extends ButtonProps {
4
+ /**
5
+ * Button label
6
+ */
7
+ buttonLabel?: string;
8
+ /**
9
+ * Dialog content
10
+ */
11
+ content: string;
12
+ /**
13
+ * Show content in pre component
14
+ */
15
+ contentPre?: boolean;
16
+ /**
17
+ * Default is label
18
+ */
19
+ dialogTitle?: string;
20
+ /**
21
+ * Disable the scroll lock behavior.
22
+ * @default false
23
+ */
24
+ disableScrollLock?: boolean;
25
+ /**
26
+ * Show fullscreen dialog
27
+ */
28
+ fullScreen?: boolean;
29
+ /**
30
+ * If `true`, the dialog stretches to `maxWidth`.
31
+ *
32
+ * Notice that the dialog width grow is limited by the default margin.
33
+ * @default false
34
+ */
35
+ fullWidth?: boolean;
36
+ /**
37
+ * Other layouts
38
+ */
39
+ inputs?: React.ReactNode;
40
+ /**
41
+ * Max width of the dialog
42
+ */
43
+ maxWidth?: Breakpoint | false;
44
+ /**
45
+ * Icon button
46
+ */
47
+ icon?: React.ReactNode;
48
+ }
49
+ /**
50
+ * Dialog button
51
+ * @param props Props
52
+ * @returns Component
53
+ */
54
+ export declare function DialogButton(props: DialogButtonProps): JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton } from '@mui/material';
2
+ import React from 'react';
3
+ import { Labels } from './app/Labels';
4
+ /**
5
+ * Dialog button
6
+ * @param props Props
7
+ * @returns Component
8
+ */
9
+ export function DialogButton(props) {
10
+ var _a;
11
+ // Labels shared with NotificationMU
12
+ const labels = Labels.NotificationMU;
13
+ // Destruct
14
+ const { buttonLabel = labels.alertOK, children, content, contentPre, dialogTitle, disableScrollLock, fullScreen, fullWidth, icon, inputs, maxWidth, onClick, title, ...rest } = props;
15
+ // Open state
16
+ const [open, setOpen] = React.useState(false);
17
+ const handleClickOpen = () => {
18
+ setOpen(true);
19
+ };
20
+ // Onclick handler
21
+ const onClickLocal = (event) => {
22
+ // Stop propagation
23
+ event.stopPropagation();
24
+ event.preventDefault();
25
+ // Show dialog
26
+ handleClickOpen();
27
+ // Additional callback
28
+ if (onClick)
29
+ onClick(event);
30
+ };
31
+ // Layout
32
+ return (React.createElement(React.Fragment, null,
33
+ icon == null ? (React.createElement(Button, { ...rest, title: title, onClick: onClickLocal }, children)) : (React.createElement(IconButton, { ...rest, onClick: onClickLocal, title: title !== null && title !== void 0 ? title : children === null || children === void 0 ? void 0 : children.toString() }, icon)),
34
+ React.createElement(Dialog, { disableScrollLock: disableScrollLock, fullScreen: fullScreen, fullWidth: fullWidth, maxWidth: maxWidth, open: open, onClose: () => setOpen(false), onClick: (event) => {
35
+ // The dialog will be embeded and the click event will bubble up
36
+ // Stop propatation but will also cancel onClose and onBackdropClick event
37
+ event.stopPropagation();
38
+ } },
39
+ React.createElement(DialogTitle, null, (_a = dialogTitle !== null && dialogTitle !== void 0 ? dialogTitle : title) !== null && _a !== void 0 ? _a : children),
40
+ React.createElement(DialogContent, null,
41
+ React.createElement(DialogContentText, { component: contentPre ? 'pre' : 'span' }, content),
42
+ inputs),
43
+ React.createElement(DialogActions, null,
44
+ React.createElement(Button, { onClick: () => setOpen(false) }, buttonLabel)))));
45
+ }
@@ -0,0 +1,87 @@
1
+ import { UniqueIdentifier } from '@dnd-kit/core';
2
+ import { DataTypes } from '@etsoo/shared';
3
+ import { Theme } from '@mui/material';
4
+ import React, { CSSProperties } from 'react';
5
+ /**
6
+ * DnD item default style
7
+ * @param index Item index
8
+ * @param isDragging Is dragging
9
+ * @param theme Theme
10
+ * @returns Style
11
+ */
12
+ export declare const DnDItemStyle: (index: number, isDragging: boolean, theme: Theme) => {
13
+ padding: string;
14
+ zIndex: string | number;
15
+ background: string;
16
+ };
17
+ /**
18
+ * DnD list forward ref
19
+ */
20
+ export interface DnDListRef<D extends object> {
21
+ /**
22
+ * Add item
23
+ * @param item New item
24
+ */
25
+ addItem(item: D): void;
26
+ /**
27
+ * Add items
28
+ * @param items items
29
+ */
30
+ addItems(items: D[]): void;
31
+ /**
32
+ * Delete item
33
+ * @param index Item index
34
+ */
35
+ deleteItem(index: number): void;
36
+ /**
37
+ * Edit item
38
+ * @param newItem New item
39
+ * @param index Index
40
+ */
41
+ editItem(newItem: D, index: number): boolean;
42
+ }
43
+ /**
44
+ * DnD sortable list properties
45
+ */
46
+ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
47
+ /**
48
+ * Get list item style callback
49
+ */
50
+ getItemStyle?: (index: number, isDragging: boolean) => CSSProperties;
51
+ /**
52
+ * Item renderer
53
+ */
54
+ itemRenderer: (item: D, index: number, nodeRef: React.ComponentProps<any>, actionNodeRef: React.ComponentProps<any>) => React.ReactElement;
55
+ /**
56
+ * List items
57
+ */
58
+ items: D[];
59
+ /**
60
+ * Unique key field
61
+ */
62
+ keyField: K;
63
+ /**
64
+ * Label field
65
+ */
66
+ labelField: K;
67
+ /**
68
+ * Methods ref
69
+ */
70
+ mRef?: React.Ref<DnDListRef<D>>;
71
+ /**
72
+ * Data change handler
73
+ */
74
+ onChange?: (items: D[]) => void;
75
+ /**
76
+ * Drag end handler
77
+ */
78
+ onDragEnd?: (items: D[]) => void;
79
+ }
80
+ /**
81
+ * DnD (Drag and Drop) sortable list
82
+ * @param props Props
83
+ * @returns Component
84
+ */
85
+ export declare function DnDList<D extends {
86
+ id: UniqueIdentifier;
87
+ }, K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<D, UniqueIdentifier>>(props: DnDListPros<D, K>): JSX.Element;