@etsoo/react 1.5.80 → 1.5.81
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/README.md +7 -2
- package/__tests__/ReactUtils.ts +6 -0
- package/lib/{mu → components}/DnDList.d.ts +1 -14
- package/lib/{mu → components}/DnDList.js +1 -24
- package/lib/components/GridMethodRef.d.ts +11 -0
- package/lib/{mu → components}/GridMethodRef.js +0 -0
- package/lib/components/ScrollerGrid.d.ts +3 -3
- package/lib/components/ScrollerList.d.ts +3 -3
- package/lib/index.d.ts +2 -74
- package/lib/index.js +2 -75
- package/lib/notifier/Notifier.d.ts +2 -3
- package/lib/uses/useWindowScroll.d.ts +10 -0
- package/lib/uses/useWindowScroll.js +46 -0
- package/lib/uses/useWindowSize.js +11 -5
- package/package.json +3 -15
- package/src/{mu → components}/DnDList.tsx +11 -34
- package/src/components/GridMethodRef.ts +12 -0
- package/src/components/ScrollerGrid.tsx +3 -3
- package/src/components/ScrollerList.tsx +5 -3
- package/src/index.ts +2 -78
- package/src/notifier/Notifier.ts +2 -3
- package/src/uses/useWindowScroll.ts +60 -0
- package/src/uses/useWindowSize.ts +14 -5
- package/__tests__/mu/ComboBox.tsx +0 -30
- package/__tests__/mu/MUGlobalTests.tsx +0 -58
- package/__tests__/mu/NotifierMUTests.tsx +0 -213
- package/__tests__/mu/SelectEx.tsx +0 -26
- package/lib/app/CommonApp.d.ts +0 -39
- package/lib/app/CommonApp.js +0 -149
- package/lib/app/IServiceAppSettings.d.ts +0 -11
- package/lib/app/IServiceAppSettings.js +0 -1
- package/lib/app/IServicePage.d.ts +0 -6
- package/lib/app/IServicePage.js +0 -1
- package/lib/app/IServiceUser.d.ts +0 -14
- package/lib/app/IServiceUser.js +0 -1
- package/lib/app/ISmartERPUser.d.ts +0 -14
- package/lib/app/ISmartERPUser.js +0 -1
- package/lib/app/Labels.d.ts +0 -65
- package/lib/app/Labels.js +0 -62
- package/lib/app/ReactApp.d.ts +0 -194
- package/lib/app/ReactApp.js +0 -298
- package/lib/app/ServiceApp.d.ts +0 -78
- package/lib/app/ServiceApp.js +0 -244
- package/lib/components/ShowDataComparison.d.ts +0 -20
- package/lib/components/ShowDataComparison.js +0 -60
- package/lib/mu/AuditDisplay.d.ts +0 -33
- package/lib/mu/AuditDisplay.js +0 -52
- package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
- package/lib/mu/AutocompleteExtendedProps.js +0 -1
- package/lib/mu/BackButton.d.ts +0 -13
- package/lib/mu/BackButton.js +0 -33
- package/lib/mu/BridgeCloseButton.d.ts +0 -23
- package/lib/mu/BridgeCloseButton.js +0 -32
- package/lib/mu/ButtonLink.d.ts +0 -17
- package/lib/mu/ButtonLink.js +0 -19
- package/lib/mu/ComboBox.d.ts +0 -38
- package/lib/mu/ComboBox.js +0 -108
- package/lib/mu/CountdownButton.d.ts +0 -23
- package/lib/mu/CountdownButton.js +0 -81
- package/lib/mu/CustomFabProps.d.ts +0 -27
- package/lib/mu/CustomFabProps.js +0 -1
- package/lib/mu/DataGridEx.d.ts +0 -96
- package/lib/mu/DataGridEx.js +0 -331
- package/lib/mu/DataGridRenderers.d.ts +0 -22
- package/lib/mu/DataGridRenderers.js +0 -99
- package/lib/mu/DialogButton.d.ts +0 -54
- package/lib/mu/DialogButton.js +0 -45
- package/lib/mu/DraggablePaperComponent.d.ts +0 -8
- package/lib/mu/DraggablePaperComponent.js +0 -12
- package/lib/mu/EmailInput.d.ts +0 -11
- package/lib/mu/EmailInput.js +0 -15
- package/lib/mu/FabBox.d.ts +0 -21
- package/lib/mu/FabBox.js +0 -31
- package/lib/mu/FlexBox.d.ts +0 -14
- package/lib/mu/FlexBox.js +0 -18
- package/lib/mu/GridDataFormat.d.ts +0 -10
- package/lib/mu/GridDataFormat.js +0 -43
- package/lib/mu/GridMethodRef.d.ts +0 -11
- package/lib/mu/IconButtonLink.d.ts +0 -17
- package/lib/mu/IconButtonLink.js +0 -16
- package/lib/mu/InputField.d.ts +0 -21
- package/lib/mu/InputField.js +0 -39
- package/lib/mu/ItemList.d.ts +0 -56
- package/lib/mu/ItemList.js +0 -69
- package/lib/mu/ListItemRightIcon.d.ts +0 -4
- package/lib/mu/ListItemRightIcon.js +0 -8
- package/lib/mu/ListMoreDisplay.d.ts +0 -35
- package/lib/mu/ListMoreDisplay.js +0 -99
- package/lib/mu/LoadingButton.d.ts +0 -16
- package/lib/mu/LoadingButton.js +0 -41
- package/lib/mu/MUGlobal.d.ts +0 -102
- package/lib/mu/MUGlobal.js +0 -184
- package/lib/mu/MaskInput.d.ts +0 -34
- package/lib/mu/MaskInput.js +0 -43
- package/lib/mu/MobileListItemRenderer.d.ts +0 -17
- package/lib/mu/MobileListItemRenderer.js +0 -35
- package/lib/mu/MoreFab.d.ts +0 -45
- package/lib/mu/MoreFab.js +0 -95
- package/lib/mu/NotifierMU.d.ts +0 -47
- package/lib/mu/NotifierMU.js +0 -387
- package/lib/mu/NotifierPromptProps.d.ts +0 -22
- package/lib/mu/NotifierPromptProps.js +0 -1
- package/lib/mu/OptionGroup.d.ts +0 -58
- package/lib/mu/OptionGroup.js +0 -81
- package/lib/mu/PList.d.ts +0 -15
- package/lib/mu/PList.js +0 -12
- package/lib/mu/ProgressCount.d.ts +0 -44
- package/lib/mu/ProgressCount.js +0 -79
- package/lib/mu/PullToRefreshUI.d.ts +0 -9
- package/lib/mu/PullToRefreshUI.js +0 -18
- package/lib/mu/RLink.d.ts +0 -14
- package/lib/mu/RLink.js +0 -37
- package/lib/mu/ResponsibleContainer.d.ts +0 -89
- package/lib/mu/ResponsibleContainer.js +0 -159
- package/lib/mu/ScrollTopFab.d.ts +0 -7
- package/lib/mu/ScrollTopFab.js +0 -25
- package/lib/mu/ScrollerListEx.d.ts +0 -81
- package/lib/mu/ScrollerListEx.js +0 -167
- package/lib/mu/SearchBar.d.ts +0 -29
- package/lib/mu/SearchBar.js +0 -262
- package/lib/mu/SearchField.d.ts +0 -21
- package/lib/mu/SearchField.js +0 -39
- package/lib/mu/SearchOptionGroup.d.ts +0 -9
- package/lib/mu/SearchOptionGroup.js +0 -14
- package/lib/mu/SelectBool.d.ts +0 -13
- package/lib/mu/SelectBool.js +0 -22
- package/lib/mu/SelectEx.d.ts +0 -50
- package/lib/mu/SelectEx.js +0 -156
- package/lib/mu/Switch.d.ts +0 -29
- package/lib/mu/Switch.js +0 -34
- package/lib/mu/SwitchAnt.d.ts +0 -25
- package/lib/mu/SwitchAnt.js +0 -40
- package/lib/mu/TabBox.d.ts +0 -54
- package/lib/mu/TabBox.js +0 -31
- package/lib/mu/TableEx.d.ts +0 -66
- package/lib/mu/TableEx.js +0 -271
- package/lib/mu/TextFieldEx.d.ts +0 -101
- package/lib/mu/TextFieldEx.js +0 -127
- package/lib/mu/Tiplist.d.ts +0 -18
- package/lib/mu/Tiplist.js +0 -158
- package/lib/mu/TooltipClick.d.ts +0 -15
- package/lib/mu/TooltipClick.js +0 -40
- package/lib/mu/UserAvatar.d.ts +0 -24
- package/lib/mu/UserAvatar.js +0 -25
- package/lib/mu/UserAvatarEditor.d.ts +0 -53
- package/lib/mu/UserAvatarEditor.js +0 -129
- package/lib/mu/pages/CommonPage.d.ts +0 -11
- package/lib/mu/pages/CommonPage.js +0 -60
- package/lib/mu/pages/CommonPageProps.d.ts +0 -60
- package/lib/mu/pages/CommonPageProps.js +0 -1
- package/lib/mu/pages/DataGridPage.d.ts +0 -9
- package/lib/mu/pages/DataGridPage.js +0 -81
- package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
- package/lib/mu/pages/DataGridPageProps.js +0 -1
- package/lib/mu/pages/EditPage.d.ts +0 -33
- package/lib/mu/pages/EditPage.js +0 -29
- package/lib/mu/pages/FixedListPage.d.ts +0 -15
- package/lib/mu/pages/FixedListPage.js +0 -72
- package/lib/mu/pages/ListPage.d.ts +0 -9
- package/lib/mu/pages/ListPage.js +0 -51
- package/lib/mu/pages/ListPageProps.d.ts +0 -7
- package/lib/mu/pages/ListPageProps.js +0 -1
- package/lib/mu/pages/ResponsivePage.d.ts +0 -9
- package/lib/mu/pages/ResponsivePage.js +0 -45
- package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
- package/lib/mu/pages/ResponsivePageProps.js +0 -1
- package/lib/mu/pages/SearchPageProps.d.ts +0 -30
- package/lib/mu/pages/SearchPageProps.js +0 -1
- package/lib/mu/pages/TablePage.d.ts +0 -9
- package/lib/mu/pages/TablePage.js +0 -71
- package/lib/mu/pages/TablePageProps.d.ts +0 -7
- package/lib/mu/pages/TablePageProps.js +0 -1
- package/lib/mu/pages/ViewPage.d.ts +0 -66
- package/lib/mu/pages/ViewPage.js +0 -105
- package/lib/mu/texts/DateText.d.ts +0 -34
- package/lib/mu/texts/DateText.js +0 -25
- package/lib/mu/texts/MoneyText.d.ts +0 -21
- package/lib/mu/texts/MoneyText.js +0 -14
- package/lib/mu/texts/NumberText.d.ts +0 -25
- package/lib/mu/texts/NumberText.js +0 -14
- package/src/app/CommonApp.ts +0 -225
- package/src/app/IServiceAppSettings.ts +0 -13
- package/src/app/IServicePage.ts +0 -6
- package/src/app/IServiceUser.ts +0 -17
- package/src/app/ISmartERPUser.ts +0 -16
- package/src/app/Labels.ts +0 -77
- package/src/app/ReactApp.ts +0 -500
- package/src/app/ServiceApp.ts +0 -353
- package/src/components/ShowDataComparison.tsx +0 -108
- package/src/mu/AuditDisplay.tsx +0 -117
- package/src/mu/AutocompleteExtendedProps.ts +0 -83
- package/src/mu/BackButton.tsx +0 -55
- package/src/mu/BridgeCloseButton.tsx +0 -69
- package/src/mu/ButtonLink.tsx +0 -32
- package/src/mu/ComboBox.tsx +0 -251
- package/src/mu/CountdownButton.tsx +0 -119
- package/src/mu/CustomFabProps.ts +0 -32
- package/src/mu/DataGridEx.tsx +0 -712
- package/src/mu/DataGridRenderers.tsx +0 -140
- package/src/mu/DialogButton.tsx +0 -163
- package/src/mu/DraggablePaperComponent.tsx +0 -19
- package/src/mu/EmailInput.tsx +0 -24
- package/src/mu/FabBox.tsx +0 -51
- package/src/mu/FlexBox.tsx +0 -20
- package/src/mu/GridDataFormat.tsx +0 -77
- package/src/mu/GridMethodRef.ts +0 -12
- package/src/mu/IconButtonLink.tsx +0 -29
- package/src/mu/InputField.tsx +0 -82
- package/src/mu/ItemList.tsx +0 -204
- package/src/mu/ListItemRightIcon.tsx +0 -9
- package/src/mu/ListMoreDisplay.tsx +0 -205
- package/src/mu/LoadingButton.tsx +0 -75
- package/src/mu/MUGlobal.ts +0 -220
- package/src/mu/MaskInput.tsx +0 -107
- package/src/mu/MobileListItemRenderer.tsx +0 -79
- package/src/mu/MoreFab.tsx +0 -211
- package/src/mu/NotifierMU.tsx +0 -654
- package/src/mu/NotifierPromptProps.ts +0 -26
- package/src/mu/OptionGroup.tsx +0 -223
- package/src/mu/PList.tsx +0 -27
- package/src/mu/ProgressCount.tsx +0 -166
- package/src/mu/PullToRefreshUI.tsx +0 -21
- package/src/mu/RLink.tsx +0 -64
- package/src/mu/ResponsibleContainer.tsx +0 -394
- package/src/mu/ScrollTopFab.tsx +0 -34
- package/src/mu/ScrollerListEx.tsx +0 -387
- package/src/mu/SearchBar.tsx +0 -398
- package/src/mu/SearchField.tsx +0 -82
- package/src/mu/SearchOptionGroup.tsx +0 -31
- package/src/mu/SelectBool.tsx +0 -33
- package/src/mu/SelectEx.tsx +0 -290
- package/src/mu/Switch.tsx +0 -94
- package/src/mu/SwitchAnt.tsx +0 -95
- package/src/mu/TabBox.tsx +0 -118
- package/src/mu/TableEx.tsx +0 -560
- package/src/mu/TextFieldEx.tsx +0 -250
- package/src/mu/Tiplist.tsx +0 -304
- package/src/mu/TooltipClick.tsx +0 -84
- package/src/mu/UserAvatar.tsx +0 -64
- package/src/mu/UserAvatarEditor.tsx +0 -287
- package/src/mu/pages/CommonPage.tsx +0 -128
- package/src/mu/pages/CommonPageProps.ts +0 -71
- package/src/mu/pages/DataGridPage.tsx +0 -137
- package/src/mu/pages/DataGridPageProps.ts +0 -24
- package/src/mu/pages/EditPage.tsx +0 -114
- package/src/mu/pages/FixedListPage.tsx +0 -135
- package/src/mu/pages/ListPage.tsx +0 -87
- package/src/mu/pages/ListPageProps.ts +0 -12
- package/src/mu/pages/ResponsivePage.tsx +0 -68
- package/src/mu/pages/ResponsivePageProps.ts +0 -57
- package/src/mu/pages/SearchPageProps.ts +0 -39
- package/src/mu/pages/TablePage.tsx +0 -120
- package/src/mu/pages/TablePageProps.ts +0 -12
- package/src/mu/pages/ViewPage.tsx +0 -285
- package/src/mu/texts/DateText.tsx +0 -74
- package/src/mu/texts/MoneyText.tsx +0 -49
- package/src/mu/texts/NumberText.tsx +0 -40
package/src/mu/DataGridEx.tsx
DELETED
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
import { css } from '@emotion/css';
|
|
2
|
-
import { DataTypes, IdDefaultType, Utils } from '@etsoo/shared';
|
|
3
|
-
import {
|
|
4
|
-
Box,
|
|
5
|
-
BoxProps,
|
|
6
|
-
Checkbox,
|
|
7
|
-
Paper,
|
|
8
|
-
TableSortLabel,
|
|
9
|
-
useTheme
|
|
10
|
-
} from '@mui/material';
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import {
|
|
13
|
-
GridAlignGet,
|
|
14
|
-
GridCellFormatterProps,
|
|
15
|
-
GridCellRendererProps,
|
|
16
|
-
GridColumn,
|
|
17
|
-
GridHeaderCellRendererProps
|
|
18
|
-
} from '../components/GridColumn';
|
|
19
|
-
import { GridLoaderStates } from '../components/GridLoader';
|
|
20
|
-
import {
|
|
21
|
-
ScrollerGrid,
|
|
22
|
-
ScrollerGridForwardRef,
|
|
23
|
-
ScrollerGridItemRendererProps,
|
|
24
|
-
ScrollerGridProps
|
|
25
|
-
} from '../components/ScrollerGrid';
|
|
26
|
-
import useCombinedRefs from '../uses/useCombinedRefs';
|
|
27
|
-
import { DataGridRenderers } from './DataGridRenderers';
|
|
28
|
-
import { MouseEventWithDataHandler } from './MUGlobal';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Footer item renderer props
|
|
32
|
-
*/
|
|
33
|
-
export type DataGridExFooterItemRendererProps<T extends object> = {
|
|
34
|
-
column: GridColumn<T>;
|
|
35
|
-
index: number;
|
|
36
|
-
states: GridLoaderStates<T>;
|
|
37
|
-
cellProps: any;
|
|
38
|
-
checkable: boolean;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Extended DataGrid with VariableSizeGrid props
|
|
43
|
-
*/
|
|
44
|
-
export type DataGridExProps<
|
|
45
|
-
T extends object,
|
|
46
|
-
D extends DataTypes.Keys<T>
|
|
47
|
-
> = Omit<
|
|
48
|
-
ScrollerGridProps<T, D>,
|
|
49
|
-
'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'
|
|
50
|
-
> & {
|
|
51
|
-
/**
|
|
52
|
-
* Alternating colors for odd/even rows
|
|
53
|
-
*/
|
|
54
|
-
alternatingColors?: [string?, string?];
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Checkable to choose multiple items
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
checkable?: boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Rows count to have the bottom border
|
|
64
|
-
*/
|
|
65
|
-
borderRowsCount?: number;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Bottom height
|
|
69
|
-
*/
|
|
70
|
-
bottomHeight?: number;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Columns
|
|
74
|
-
*/
|
|
75
|
-
columns: GridColumn<T>[];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Footer item renderer
|
|
79
|
-
*/
|
|
80
|
-
footerItemRenderer?: (
|
|
81
|
-
rows: T[],
|
|
82
|
-
props: DataGridExFooterItemRendererProps<T>
|
|
83
|
-
) => React.ReactNode;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Header height
|
|
87
|
-
* @default 56
|
|
88
|
-
*/
|
|
89
|
-
headerHeight?: number;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Hide the footer
|
|
93
|
-
* @default false
|
|
94
|
-
*/
|
|
95
|
-
hideFooter?: boolean;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Hover color
|
|
99
|
-
*/
|
|
100
|
-
hoverColor?: string;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Double click handler
|
|
104
|
-
*/
|
|
105
|
-
onDoubleClick?: MouseEventWithDataHandler<T>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Click handler
|
|
109
|
-
*/
|
|
110
|
-
onClick?: MouseEventWithDataHandler<T>;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Selectable to support hover over and out effect and row clickable
|
|
114
|
-
* @default true
|
|
115
|
-
*/
|
|
116
|
-
selectable?: boolean;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Selected color
|
|
120
|
-
*/
|
|
121
|
-
selectedColor?: string;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Width
|
|
125
|
-
*/
|
|
126
|
-
width?: number;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// Borders
|
|
130
|
-
const boldBorder = '2px solid rgba(224, 224, 224, 1)';
|
|
131
|
-
const thinBorder = '1px solid rgba(224, 224, 224, 1)';
|
|
132
|
-
|
|
133
|
-
// Scroll bar size
|
|
134
|
-
const scrollbarSize = 16;
|
|
135
|
-
|
|
136
|
-
// Minimum width
|
|
137
|
-
const minWidth = 120;
|
|
138
|
-
|
|
139
|
-
const createGridStyle = (
|
|
140
|
-
alternatingColors: [string?, string?],
|
|
141
|
-
selectedColor: string,
|
|
142
|
-
hoverColor: string
|
|
143
|
-
) => {
|
|
144
|
-
return css({
|
|
145
|
-
'.DataGridEx-Selected': {
|
|
146
|
-
backgroundColor: selectedColor
|
|
147
|
-
},
|
|
148
|
-
'.DataGridEx-Hover:not(.DataGridEx-Selected)': {
|
|
149
|
-
backgroundColor: hoverColor
|
|
150
|
-
},
|
|
151
|
-
'& .DataGridEx-Cell0:not(.DataGridEx-Hover):not(.DataGridEx-Selected)':
|
|
152
|
-
{
|
|
153
|
-
backgroundColor: alternatingColors[0]
|
|
154
|
-
},
|
|
155
|
-
'& .DataGridEx-Cell1:not(.DataGridEx-Hover):not(.DataGridEx-Selected)':
|
|
156
|
-
{
|
|
157
|
-
backgroundColor: alternatingColors[1]
|
|
158
|
-
},
|
|
159
|
-
'& .DataGridEx-Cell-Border': {
|
|
160
|
-
borderBottom: thinBorder
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const rowItems = (
|
|
166
|
-
div: HTMLDivElement,
|
|
167
|
-
callback: (div: HTMLDivElement) => void
|
|
168
|
-
) => {
|
|
169
|
-
const row = div.dataset['row'];
|
|
170
|
-
if (div.parentElement == null || row == null) return;
|
|
171
|
-
doRowItems(div.parentElement, parseFloat(row), callback);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const doRowItems = (
|
|
175
|
-
parent: HTMLElement,
|
|
176
|
-
rowIndex: number,
|
|
177
|
-
callback: (div: HTMLDivElement) => void
|
|
178
|
-
) => {
|
|
179
|
-
if (parent == null || rowIndex == null) return;
|
|
180
|
-
|
|
181
|
-
parent
|
|
182
|
-
?.querySelectorAll<HTMLDivElement>(`div[data-row="${rowIndex}"]`)
|
|
183
|
-
.forEach((rowItem) => {
|
|
184
|
-
callback(rowItem);
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Extended datagrid columns calculation
|
|
190
|
-
* @param columns
|
|
191
|
-
* @returns Total width and unset items
|
|
192
|
-
*/
|
|
193
|
-
export function DataGridExCalColumns<T>(columns: GridColumn<T>[]) {
|
|
194
|
-
return columns.reduce<{ total: number; unset: number }>(
|
|
195
|
-
(previousValue, currentItem) => {
|
|
196
|
-
previousValue.total +=
|
|
197
|
-
currentItem.width ?? currentItem.minWidth ?? minWidth;
|
|
198
|
-
if (currentItem.width == null) previousValue.unset++;
|
|
199
|
-
return previousValue;
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
total: 0,
|
|
203
|
-
unset: 0
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Extended DataGrid with VariableSizeGrid
|
|
210
|
-
* @param props Props
|
|
211
|
-
* @returns Component
|
|
212
|
-
*/
|
|
213
|
-
export function DataGridEx<
|
|
214
|
-
T extends object,
|
|
215
|
-
D extends DataTypes.Keys<T> = IdDefaultType<T>
|
|
216
|
-
>(props: DataGridExProps<T, D>) {
|
|
217
|
-
// Theme
|
|
218
|
-
const theme = useTheme();
|
|
219
|
-
|
|
220
|
-
const defaultHeaderRenderer = (states: GridLoaderStates<T>) => {
|
|
221
|
-
const { orderBy } = states;
|
|
222
|
-
return (
|
|
223
|
-
<Box
|
|
224
|
-
className="DataGridEx-Header"
|
|
225
|
-
display="flex"
|
|
226
|
-
alignItems="center"
|
|
227
|
-
borderBottom={boldBorder}
|
|
228
|
-
fontWeight={500}
|
|
229
|
-
minWidth={widthCalculator.total}
|
|
230
|
-
height={headerHeight}
|
|
231
|
-
>
|
|
232
|
-
{columns.map((column, index) => {
|
|
233
|
-
// Destruct
|
|
234
|
-
const {
|
|
235
|
-
align,
|
|
236
|
-
field,
|
|
237
|
-
header,
|
|
238
|
-
headerCellRenderer,
|
|
239
|
-
sortable,
|
|
240
|
-
sortAsc = true,
|
|
241
|
-
type
|
|
242
|
-
} = column;
|
|
243
|
-
|
|
244
|
-
// Header text
|
|
245
|
-
const headerText = header ?? field;
|
|
246
|
-
|
|
247
|
-
// Cell props
|
|
248
|
-
const cellProps: BoxProps = {};
|
|
249
|
-
|
|
250
|
-
// Sortable
|
|
251
|
-
let sortLabel: React.ReactNode;
|
|
252
|
-
if (headerCellRenderer) {
|
|
253
|
-
sortLabel = headerCellRenderer({
|
|
254
|
-
cellProps,
|
|
255
|
-
column,
|
|
256
|
-
columnIndex: checkable ? index - 1 : index, // Ignore the checkbox case,
|
|
257
|
-
states
|
|
258
|
-
});
|
|
259
|
-
} else if (sortable && field != null) {
|
|
260
|
-
const active = orderBy === field;
|
|
261
|
-
|
|
262
|
-
sortLabel = (
|
|
263
|
-
<TableSortLabel
|
|
264
|
-
active={active}
|
|
265
|
-
direction={sortAsc ? 'asc' : 'desc'}
|
|
266
|
-
onClick={(_event) => {
|
|
267
|
-
if (active) column.sortAsc = !sortAsc;
|
|
268
|
-
|
|
269
|
-
handleSort(field, column.sortAsc);
|
|
270
|
-
}}
|
|
271
|
-
>
|
|
272
|
-
{headerText}
|
|
273
|
-
</TableSortLabel>
|
|
274
|
-
);
|
|
275
|
-
} else {
|
|
276
|
-
sortLabel = headerText;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return (
|
|
280
|
-
<Box
|
|
281
|
-
key={field ?? index.toString()}
|
|
282
|
-
textAlign={GridAlignGet(align, type)}
|
|
283
|
-
width={columnWidth(index)}
|
|
284
|
-
>
|
|
285
|
-
<Box
|
|
286
|
-
className="DataGridEx-Cell"
|
|
287
|
-
onMouseEnter={handleMouseEnter}
|
|
288
|
-
{...cellProps}
|
|
289
|
-
>
|
|
290
|
-
{sortLabel}
|
|
291
|
-
</Box>
|
|
292
|
-
</Box>
|
|
293
|
-
);
|
|
294
|
-
})}
|
|
295
|
-
</Box>
|
|
296
|
-
);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
function defaultFooterRenderer(rows: T[], states: GridLoaderStates<T>) {
|
|
300
|
-
return (
|
|
301
|
-
<Box
|
|
302
|
-
className="DataGridEx-Footer"
|
|
303
|
-
display="flex"
|
|
304
|
-
alignItems="center"
|
|
305
|
-
borderTop={thinBorder}
|
|
306
|
-
marginTop="1px"
|
|
307
|
-
minWidth={widthCalculator.total}
|
|
308
|
-
height={bottomHeight - 1}
|
|
309
|
-
>
|
|
310
|
-
{columns.map((column, index) => {
|
|
311
|
-
// Destruct
|
|
312
|
-
const { align, field, type } = column;
|
|
313
|
-
|
|
314
|
-
// Cell props
|
|
315
|
-
const cellProps: BoxProps = {};
|
|
316
|
-
|
|
317
|
-
// Cell
|
|
318
|
-
const cell = footerItemRenderer
|
|
319
|
-
? footerItemRenderer(rows, {
|
|
320
|
-
column,
|
|
321
|
-
index: checkable ? index - 1 : index, // Ignore the checkbox case
|
|
322
|
-
states,
|
|
323
|
-
cellProps,
|
|
324
|
-
checkable
|
|
325
|
-
})
|
|
326
|
-
: undefined;
|
|
327
|
-
|
|
328
|
-
return (
|
|
329
|
-
<Box
|
|
330
|
-
key={'bottom-' + (field ?? index.toString())}
|
|
331
|
-
textAlign={GridAlignGet(align, type)}
|
|
332
|
-
width={columnWidth(index)}
|
|
333
|
-
>
|
|
334
|
-
<Box
|
|
335
|
-
className="DataGridEx-Cell"
|
|
336
|
-
onMouseEnter={handleMouseEnter}
|
|
337
|
-
{...cellProps}
|
|
338
|
-
>
|
|
339
|
-
{cell}
|
|
340
|
-
</Box>
|
|
341
|
-
</Box>
|
|
342
|
-
);
|
|
343
|
-
})}
|
|
344
|
-
</Box>
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Destruct
|
|
349
|
-
const {
|
|
350
|
-
alternatingColors = [theme.palette.grey[100], undefined],
|
|
351
|
-
borderRowsCount,
|
|
352
|
-
bottomHeight = 53,
|
|
353
|
-
checkable = false,
|
|
354
|
-
className,
|
|
355
|
-
columns,
|
|
356
|
-
defaultOrderBy,
|
|
357
|
-
height,
|
|
358
|
-
headerHeight = 56,
|
|
359
|
-
headerRenderer = defaultHeaderRenderer,
|
|
360
|
-
footerRenderer = defaultFooterRenderer,
|
|
361
|
-
footerItemRenderer = DataGridRenderers.defaultFooterItemRenderer,
|
|
362
|
-
hideFooter = false,
|
|
363
|
-
hoverColor = '#f6f9fb',
|
|
364
|
-
idField = 'id' as D,
|
|
365
|
-
mRef = React.createRef(),
|
|
366
|
-
onClick,
|
|
367
|
-
onDoubleClick,
|
|
368
|
-
selectable = true,
|
|
369
|
-
selectedColor = '#edf4fb',
|
|
370
|
-
width,
|
|
371
|
-
...rest
|
|
372
|
-
} = props;
|
|
373
|
-
|
|
374
|
-
if (checkable) {
|
|
375
|
-
const cbColumn: GridColumn<T> = {
|
|
376
|
-
field: 'selected' as any, // Avoid validation from data model
|
|
377
|
-
header: '',
|
|
378
|
-
sortable: false,
|
|
379
|
-
width: 50,
|
|
380
|
-
cellRenderer: ({
|
|
381
|
-
cellProps,
|
|
382
|
-
data,
|
|
383
|
-
selected
|
|
384
|
-
}: GridCellRendererProps<T, BoxProps>) => {
|
|
385
|
-
cellProps.sx = {
|
|
386
|
-
padding: '4px!important'
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
return (
|
|
390
|
-
<Checkbox
|
|
391
|
-
color="primary"
|
|
392
|
-
checked={selected}
|
|
393
|
-
onChange={(_event, checked) => {
|
|
394
|
-
refs.current.ref?.selectItem(data, checked);
|
|
395
|
-
}}
|
|
396
|
-
/>
|
|
397
|
-
);
|
|
398
|
-
},
|
|
399
|
-
headerCellRenderer: ({
|
|
400
|
-
cellProps,
|
|
401
|
-
states
|
|
402
|
-
}: GridHeaderCellRendererProps<T, BoxProps>) => {
|
|
403
|
-
// 2 = border height
|
|
404
|
-
const hpad = (headerHeight - 42) / 2;
|
|
405
|
-
cellProps.sx = {
|
|
406
|
-
padding: `${hpad}px 4px ${hpad - 1}px 4px!important`
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
return (
|
|
410
|
-
<Checkbox
|
|
411
|
-
color="primary"
|
|
412
|
-
indeterminate={
|
|
413
|
-
states.selectedItems.length > 0 &&
|
|
414
|
-
states.selectedItems.length < states.loadedItems
|
|
415
|
-
}
|
|
416
|
-
checked={states.selectedItems.length > 0}
|
|
417
|
-
onChange={(_event, checked) =>
|
|
418
|
-
refs.current.ref?.selectAll(checked)
|
|
419
|
-
}
|
|
420
|
-
/>
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
// Update to the latest version
|
|
426
|
-
if (columns[0].field === 'selected') {
|
|
427
|
-
columns[0] = cbColumn;
|
|
428
|
-
} else {
|
|
429
|
-
columns.unshift(cbColumn);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const refs = React.useRef<{ ref?: ScrollerGridForwardRef }>({});
|
|
434
|
-
|
|
435
|
-
const mRefLocal = useCombinedRefs(mRef, (ref: ScrollerGridForwardRef) => {
|
|
436
|
-
if (ref == null) return;
|
|
437
|
-
refs.current.ref = ref;
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
// New sort
|
|
441
|
-
const handleSort = (field: string, asc?: boolean) => {
|
|
442
|
-
reset({ orderBy: field, orderByAsc: asc });
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
// Reset
|
|
446
|
-
const reset = (add: object) => {
|
|
447
|
-
refs.current.ref?.reset(add);
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
// Show hover tooltip for trucated text
|
|
451
|
-
const handleMouseEnter = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
452
|
-
const div = event.currentTarget;
|
|
453
|
-
const { innerText, offsetWidth, scrollWidth } = div;
|
|
454
|
-
if (offsetWidth < scrollWidth) {
|
|
455
|
-
div.title = innerText;
|
|
456
|
-
} else {
|
|
457
|
-
div.title = '';
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// selectedRowIndex state
|
|
462
|
-
const selectedRowIndex = React.useRef(-1);
|
|
463
|
-
|
|
464
|
-
const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
465
|
-
const div = event.currentTarget;
|
|
466
|
-
const row = div.dataset['row'];
|
|
467
|
-
if (div.parentElement == null || row == null) return;
|
|
468
|
-
|
|
469
|
-
const rowIndex = parseFloat(row);
|
|
470
|
-
|
|
471
|
-
// No change
|
|
472
|
-
if (isNaN(rowIndex) || rowIndex === selectedRowIndex.current) return;
|
|
473
|
-
|
|
474
|
-
if (selectedRowIndex.current != -1) {
|
|
475
|
-
doRowItems(
|
|
476
|
-
div.parentElement,
|
|
477
|
-
selectedRowIndex.current,
|
|
478
|
-
(preDiv) => {
|
|
479
|
-
preDiv.classList.remove('DataGridEx-Selected');
|
|
480
|
-
}
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
rowItems(div, (currentDiv) => {
|
|
485
|
-
currentDiv.classList.add('DataGridEx-Selected');
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
selectedRowIndex.current = rowIndex;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
const handleMouseOver = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
492
|
-
rowItems(event.currentTarget, (div) => {
|
|
493
|
-
div.classList.add('DataGridEx-Hover');
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
const handleMouseOut = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
498
|
-
rowItems(event.currentTarget, (div) => {
|
|
499
|
-
div.classList.remove('DataGridEx-Hover');
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Item renderer
|
|
505
|
-
*/
|
|
506
|
-
const itemRenderer = ({
|
|
507
|
-
columnIndex,
|
|
508
|
-
rowIndex,
|
|
509
|
-
style,
|
|
510
|
-
data,
|
|
511
|
-
selectedItems
|
|
512
|
-
}: ScrollerGridItemRendererProps<T>) => {
|
|
513
|
-
// Column
|
|
514
|
-
const {
|
|
515
|
-
align,
|
|
516
|
-
cellRenderer = DataGridRenderers.defaultCellRenderer,
|
|
517
|
-
field,
|
|
518
|
-
type,
|
|
519
|
-
valueFormatter,
|
|
520
|
-
renderProps
|
|
521
|
-
} = columns[columnIndex];
|
|
522
|
-
|
|
523
|
-
// Props
|
|
524
|
-
const formatProps: GridCellFormatterProps<T> = {
|
|
525
|
-
data,
|
|
526
|
-
field,
|
|
527
|
-
rowIndex,
|
|
528
|
-
columnIndex
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
let rowClass = `DataGridEx-Cell${rowIndex % 2}`;
|
|
532
|
-
if (
|
|
533
|
-
borderRowsCount != null &&
|
|
534
|
-
borderRowsCount > 0 &&
|
|
535
|
-
(rowIndex + 1) % borderRowsCount === 0
|
|
536
|
-
) {
|
|
537
|
-
rowClass += ` DataGridEx-Cell-Border`;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// Selected
|
|
541
|
-
const selected =
|
|
542
|
-
data != null &&
|
|
543
|
-
(selectedRowIndex.current === rowIndex ||
|
|
544
|
-
selectedItems.some(
|
|
545
|
-
(selectedItem) =>
|
|
546
|
-
selectedItem != null &&
|
|
547
|
-
selectedItem[idField] === data[idField]
|
|
548
|
-
));
|
|
549
|
-
|
|
550
|
-
if (selected) {
|
|
551
|
-
rowClass += ` DataGridEx-Selected`;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
const cellProps: BoxProps = {
|
|
555
|
-
className: 'DataGridEx-Cell',
|
|
556
|
-
textAlign: GridAlignGet(align, type)
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
const child = cellRenderer({
|
|
560
|
-
data,
|
|
561
|
-
field,
|
|
562
|
-
formattedValue: valueFormatter
|
|
563
|
-
? valueFormatter(formatProps)
|
|
564
|
-
: undefined,
|
|
565
|
-
selected,
|
|
566
|
-
type,
|
|
567
|
-
rowIndex,
|
|
568
|
-
columnIndex,
|
|
569
|
-
cellProps,
|
|
570
|
-
renderProps
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return (
|
|
574
|
-
<div
|
|
575
|
-
className={rowClass}
|
|
576
|
-
style={style}
|
|
577
|
-
data-row={rowIndex}
|
|
578
|
-
data-column={columnIndex}
|
|
579
|
-
onMouseDown={
|
|
580
|
-
selectable && !checkable ? handleMouseDown : undefined
|
|
581
|
-
}
|
|
582
|
-
onMouseOver={selectable ? handleMouseOver : undefined}
|
|
583
|
-
onMouseOut={selectable ? handleMouseOut : undefined}
|
|
584
|
-
onClick={(event) =>
|
|
585
|
-
onClick && data != null && onClick(event, data)
|
|
586
|
-
}
|
|
587
|
-
onDoubleClick={(event) =>
|
|
588
|
-
onDoubleClick && data != null && onDoubleClick(event, data)
|
|
589
|
-
}
|
|
590
|
-
>
|
|
591
|
-
<Box {...cellProps} onMouseEnter={handleMouseEnter}>
|
|
592
|
-
{child}
|
|
593
|
-
</Box>
|
|
594
|
-
</div>
|
|
595
|
-
);
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
// Column width calculator
|
|
599
|
-
const widthCalculator = React.useMemo(
|
|
600
|
-
() => DataGridExCalColumns(columns),
|
|
601
|
-
[columns]
|
|
602
|
-
);
|
|
603
|
-
|
|
604
|
-
// Column width
|
|
605
|
-
const columnWidth = React.useCallback(
|
|
606
|
-
(index: number) => {
|
|
607
|
-
// Ignore null case
|
|
608
|
-
if (width == null) return 0;
|
|
609
|
-
|
|
610
|
-
// Column
|
|
611
|
-
const column = columns[index];
|
|
612
|
-
if (column.width != null) return column.width;
|
|
613
|
-
|
|
614
|
-
// More space
|
|
615
|
-
const leftWidth =
|
|
616
|
-
width -
|
|
617
|
-
widthCalculator.total -
|
|
618
|
-
(width < 800 ? 0 : scrollbarSize);
|
|
619
|
-
|
|
620
|
-
// Shared width
|
|
621
|
-
const sharedWidth =
|
|
622
|
-
leftWidth > 0 ? leftWidth / widthCalculator.unset : 0;
|
|
623
|
-
|
|
624
|
-
return (column.minWidth || minWidth) + sharedWidth;
|
|
625
|
-
},
|
|
626
|
-
[columns, width]
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
// Table
|
|
630
|
-
const table = React.useMemo(() => {
|
|
631
|
-
const defaultOrderByAsc = defaultOrderBy
|
|
632
|
-
? columns.find((column) => column.field === defaultOrderBy)?.sortAsc
|
|
633
|
-
: undefined;
|
|
634
|
-
|
|
635
|
-
return (
|
|
636
|
-
<ScrollerGrid<T, D>
|
|
637
|
-
className={Utils.mergeClasses(
|
|
638
|
-
'DataGridEx-Body',
|
|
639
|
-
'DataGridEx-CustomBar',
|
|
640
|
-
className,
|
|
641
|
-
createGridStyle(
|
|
642
|
-
alternatingColors,
|
|
643
|
-
selectedColor,
|
|
644
|
-
hoverColor
|
|
645
|
-
)
|
|
646
|
-
)}
|
|
647
|
-
columnCount={columns.length}
|
|
648
|
-
columnWidth={columnWidth}
|
|
649
|
-
defaultOrderBy={defaultOrderBy}
|
|
650
|
-
defaultOrderByAsc={defaultOrderByAsc}
|
|
651
|
-
height={
|
|
652
|
-
height -
|
|
653
|
-
headerHeight -
|
|
654
|
-
(hideFooter ? 0 : bottomHeight + 1) -
|
|
655
|
-
scrollbarSize
|
|
656
|
-
}
|
|
657
|
-
headerRenderer={headerRenderer}
|
|
658
|
-
idField={idField}
|
|
659
|
-
itemRenderer={itemRenderer}
|
|
660
|
-
footerRenderer={hideFooter ? undefined : footerRenderer}
|
|
661
|
-
width={Math.max(width ?? 0, widthCalculator.total)}
|
|
662
|
-
mRef={mRefLocal}
|
|
663
|
-
{...rest}
|
|
664
|
-
/>
|
|
665
|
-
);
|
|
666
|
-
}, [width]);
|
|
667
|
-
|
|
668
|
-
return (
|
|
669
|
-
<Paper
|
|
670
|
-
sx={{
|
|
671
|
-
fontSize: '0.875rem',
|
|
672
|
-
height,
|
|
673
|
-
'& .DataGridEx-Cell': {
|
|
674
|
-
padding: 2,
|
|
675
|
-
whiteSpace: 'nowrap',
|
|
676
|
-
overflow: 'hidden',
|
|
677
|
-
textOverflow: 'ellipsis'
|
|
678
|
-
},
|
|
679
|
-
'& .DataGridEx-CustomBar': {
|
|
680
|
-
'@media (min-width: 800px)': {
|
|
681
|
-
'::-webkit-scrollbar': {
|
|
682
|
-
width: scrollbarSize,
|
|
683
|
-
height: scrollbarSize,
|
|
684
|
-
backgroundColor: '#f6f6f6'
|
|
685
|
-
},
|
|
686
|
-
'::-webkit-scrollbar-thumb': {
|
|
687
|
-
backgroundColor: 'rgba(0,0,0,0.4)',
|
|
688
|
-
borderRadius: '2px'
|
|
689
|
-
},
|
|
690
|
-
'::-webkit-scrollbar-track-piece:start': {
|
|
691
|
-
background: 'transparent'
|
|
692
|
-
},
|
|
693
|
-
'::-webkit-scrollbar-track-piece:end': {
|
|
694
|
-
background: 'transparent'
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
}}
|
|
699
|
-
>
|
|
700
|
-
<div
|
|
701
|
-
className="DataGridEx-CustomBar"
|
|
702
|
-
style={{
|
|
703
|
-
width,
|
|
704
|
-
overflowX: 'auto',
|
|
705
|
-
overflowY: 'hidden'
|
|
706
|
-
}}
|
|
707
|
-
>
|
|
708
|
-
{table}
|
|
709
|
-
</div>
|
|
710
|
-
</Paper>
|
|
711
|
-
);
|
|
712
|
-
}
|