@etsoo/react 1.5.80 → 1.5.83

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 (259) hide show
  1. package/README.md +7 -2
  2. package/__tests__/ReactUtils.ts +6 -0
  3. package/lib/{mu → components}/DnDList.d.ts +1 -14
  4. package/lib/{mu → components}/DnDList.js +1 -24
  5. package/lib/components/GridMethodRef.d.ts +11 -0
  6. package/lib/{mu → components}/GridMethodRef.js +0 -0
  7. package/lib/components/ScrollerGrid.d.ts +3 -3
  8. package/lib/components/ScrollerList.d.ts +3 -3
  9. package/lib/index.d.ts +2 -74
  10. package/lib/index.js +2 -75
  11. package/lib/notifier/Notifier.d.ts +2 -3
  12. package/lib/states/UserState.d.ts +1 -1
  13. package/lib/uses/useWindowScroll.d.ts +10 -0
  14. package/lib/uses/useWindowScroll.js +46 -0
  15. package/lib/uses/useWindowSize.js +11 -5
  16. package/package.json +4 -16
  17. package/src/{mu → components}/DnDList.tsx +11 -34
  18. package/src/components/GridMethodRef.ts +12 -0
  19. package/src/components/ScrollerGrid.tsx +3 -3
  20. package/src/components/ScrollerList.tsx +5 -3
  21. package/src/index.ts +2 -78
  22. package/src/notifier/Notifier.ts +2 -3
  23. package/src/states/UserState.ts +7 -2
  24. package/src/uses/useWindowScroll.ts +60 -0
  25. package/src/uses/useWindowSize.ts +14 -5
  26. package/__tests__/mu/ComboBox.tsx +0 -30
  27. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  28. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  29. package/__tests__/mu/SelectEx.tsx +0 -26
  30. package/lib/app/CommonApp.d.ts +0 -39
  31. package/lib/app/CommonApp.js +0 -149
  32. package/lib/app/IServiceAppSettings.d.ts +0 -11
  33. package/lib/app/IServiceAppSettings.js +0 -1
  34. package/lib/app/IServicePage.d.ts +0 -6
  35. package/lib/app/IServicePage.js +0 -1
  36. package/lib/app/IServiceUser.d.ts +0 -14
  37. package/lib/app/IServiceUser.js +0 -1
  38. package/lib/app/ISmartERPUser.d.ts +0 -14
  39. package/lib/app/ISmartERPUser.js +0 -1
  40. package/lib/app/Labels.d.ts +0 -65
  41. package/lib/app/Labels.js +0 -62
  42. package/lib/app/ReactApp.d.ts +0 -194
  43. package/lib/app/ReactApp.js +0 -298
  44. package/lib/app/ServiceApp.d.ts +0 -78
  45. package/lib/app/ServiceApp.js +0 -244
  46. package/lib/components/ShowDataComparison.d.ts +0 -20
  47. package/lib/components/ShowDataComparison.js +0 -60
  48. package/lib/mu/AuditDisplay.d.ts +0 -33
  49. package/lib/mu/AuditDisplay.js +0 -52
  50. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
  51. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  52. package/lib/mu/BackButton.d.ts +0 -13
  53. package/lib/mu/BackButton.js +0 -33
  54. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  55. package/lib/mu/BridgeCloseButton.js +0 -32
  56. package/lib/mu/ButtonLink.d.ts +0 -17
  57. package/lib/mu/ButtonLink.js +0 -19
  58. package/lib/mu/ComboBox.d.ts +0 -38
  59. package/lib/mu/ComboBox.js +0 -108
  60. package/lib/mu/CountdownButton.d.ts +0 -23
  61. package/lib/mu/CountdownButton.js +0 -81
  62. package/lib/mu/CustomFabProps.d.ts +0 -27
  63. package/lib/mu/CustomFabProps.js +0 -1
  64. package/lib/mu/DataGridEx.d.ts +0 -96
  65. package/lib/mu/DataGridEx.js +0 -331
  66. package/lib/mu/DataGridRenderers.d.ts +0 -22
  67. package/lib/mu/DataGridRenderers.js +0 -99
  68. package/lib/mu/DialogButton.d.ts +0 -54
  69. package/lib/mu/DialogButton.js +0 -45
  70. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  71. package/lib/mu/DraggablePaperComponent.js +0 -12
  72. package/lib/mu/EmailInput.d.ts +0 -11
  73. package/lib/mu/EmailInput.js +0 -15
  74. package/lib/mu/FabBox.d.ts +0 -21
  75. package/lib/mu/FabBox.js +0 -31
  76. package/lib/mu/FlexBox.d.ts +0 -14
  77. package/lib/mu/FlexBox.js +0 -18
  78. package/lib/mu/GridDataFormat.d.ts +0 -10
  79. package/lib/mu/GridDataFormat.js +0 -43
  80. package/lib/mu/GridMethodRef.d.ts +0 -11
  81. package/lib/mu/IconButtonLink.d.ts +0 -17
  82. package/lib/mu/IconButtonLink.js +0 -16
  83. package/lib/mu/InputField.d.ts +0 -21
  84. package/lib/mu/InputField.js +0 -39
  85. package/lib/mu/ItemList.d.ts +0 -56
  86. package/lib/mu/ItemList.js +0 -69
  87. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  88. package/lib/mu/ListItemRightIcon.js +0 -8
  89. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  90. package/lib/mu/ListMoreDisplay.js +0 -99
  91. package/lib/mu/LoadingButton.d.ts +0 -16
  92. package/lib/mu/LoadingButton.js +0 -41
  93. package/lib/mu/MUGlobal.d.ts +0 -102
  94. package/lib/mu/MUGlobal.js +0 -184
  95. package/lib/mu/MaskInput.d.ts +0 -34
  96. package/lib/mu/MaskInput.js +0 -43
  97. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  98. package/lib/mu/MobileListItemRenderer.js +0 -35
  99. package/lib/mu/MoreFab.d.ts +0 -45
  100. package/lib/mu/MoreFab.js +0 -95
  101. package/lib/mu/NotifierMU.d.ts +0 -47
  102. package/lib/mu/NotifierMU.js +0 -387
  103. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  104. package/lib/mu/NotifierPromptProps.js +0 -1
  105. package/lib/mu/OptionGroup.d.ts +0 -58
  106. package/lib/mu/OptionGroup.js +0 -81
  107. package/lib/mu/PList.d.ts +0 -15
  108. package/lib/mu/PList.js +0 -12
  109. package/lib/mu/ProgressCount.d.ts +0 -44
  110. package/lib/mu/ProgressCount.js +0 -79
  111. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  112. package/lib/mu/PullToRefreshUI.js +0 -18
  113. package/lib/mu/RLink.d.ts +0 -14
  114. package/lib/mu/RLink.js +0 -37
  115. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  116. package/lib/mu/ResponsibleContainer.js +0 -159
  117. package/lib/mu/ScrollTopFab.d.ts +0 -7
  118. package/lib/mu/ScrollTopFab.js +0 -25
  119. package/lib/mu/ScrollerListEx.d.ts +0 -81
  120. package/lib/mu/ScrollerListEx.js +0 -167
  121. package/lib/mu/SearchBar.d.ts +0 -29
  122. package/lib/mu/SearchBar.js +0 -262
  123. package/lib/mu/SearchField.d.ts +0 -21
  124. package/lib/mu/SearchField.js +0 -39
  125. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  126. package/lib/mu/SearchOptionGroup.js +0 -14
  127. package/lib/mu/SelectBool.d.ts +0 -13
  128. package/lib/mu/SelectBool.js +0 -22
  129. package/lib/mu/SelectEx.d.ts +0 -50
  130. package/lib/mu/SelectEx.js +0 -156
  131. package/lib/mu/Switch.d.ts +0 -29
  132. package/lib/mu/Switch.js +0 -34
  133. package/lib/mu/SwitchAnt.d.ts +0 -25
  134. package/lib/mu/SwitchAnt.js +0 -40
  135. package/lib/mu/TabBox.d.ts +0 -54
  136. package/lib/mu/TabBox.js +0 -31
  137. package/lib/mu/TableEx.d.ts +0 -66
  138. package/lib/mu/TableEx.js +0 -271
  139. package/lib/mu/TextFieldEx.d.ts +0 -101
  140. package/lib/mu/TextFieldEx.js +0 -127
  141. package/lib/mu/Tiplist.d.ts +0 -18
  142. package/lib/mu/Tiplist.js +0 -158
  143. package/lib/mu/TooltipClick.d.ts +0 -15
  144. package/lib/mu/TooltipClick.js +0 -40
  145. package/lib/mu/UserAvatar.d.ts +0 -24
  146. package/lib/mu/UserAvatar.js +0 -25
  147. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  148. package/lib/mu/UserAvatarEditor.js +0 -129
  149. package/lib/mu/pages/CommonPage.d.ts +0 -11
  150. package/lib/mu/pages/CommonPage.js +0 -60
  151. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  152. package/lib/mu/pages/CommonPageProps.js +0 -1
  153. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  154. package/lib/mu/pages/DataGridPage.js +0 -81
  155. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  156. package/lib/mu/pages/DataGridPageProps.js +0 -1
  157. package/lib/mu/pages/EditPage.d.ts +0 -33
  158. package/lib/mu/pages/EditPage.js +0 -29
  159. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  160. package/lib/mu/pages/FixedListPage.js +0 -72
  161. package/lib/mu/pages/ListPage.d.ts +0 -9
  162. package/lib/mu/pages/ListPage.js +0 -51
  163. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  164. package/lib/mu/pages/ListPageProps.js +0 -1
  165. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  166. package/lib/mu/pages/ResponsivePage.js +0 -45
  167. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  168. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  169. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  170. package/lib/mu/pages/SearchPageProps.js +0 -1
  171. package/lib/mu/pages/TablePage.d.ts +0 -9
  172. package/lib/mu/pages/TablePage.js +0 -71
  173. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  174. package/lib/mu/pages/TablePageProps.js +0 -1
  175. package/lib/mu/pages/ViewPage.d.ts +0 -66
  176. package/lib/mu/pages/ViewPage.js +0 -105
  177. package/lib/mu/texts/DateText.d.ts +0 -34
  178. package/lib/mu/texts/DateText.js +0 -25
  179. package/lib/mu/texts/MoneyText.d.ts +0 -21
  180. package/lib/mu/texts/MoneyText.js +0 -14
  181. package/lib/mu/texts/NumberText.d.ts +0 -25
  182. package/lib/mu/texts/NumberText.js +0 -14
  183. package/src/app/CommonApp.ts +0 -225
  184. package/src/app/IServiceAppSettings.ts +0 -13
  185. package/src/app/IServicePage.ts +0 -6
  186. package/src/app/IServiceUser.ts +0 -17
  187. package/src/app/ISmartERPUser.ts +0 -16
  188. package/src/app/Labels.ts +0 -77
  189. package/src/app/ReactApp.ts +0 -500
  190. package/src/app/ServiceApp.ts +0 -353
  191. package/src/components/ShowDataComparison.tsx +0 -108
  192. package/src/mu/AuditDisplay.tsx +0 -117
  193. package/src/mu/AutocompleteExtendedProps.ts +0 -83
  194. package/src/mu/BackButton.tsx +0 -55
  195. package/src/mu/BridgeCloseButton.tsx +0 -69
  196. package/src/mu/ButtonLink.tsx +0 -32
  197. package/src/mu/ComboBox.tsx +0 -251
  198. package/src/mu/CountdownButton.tsx +0 -119
  199. package/src/mu/CustomFabProps.ts +0 -32
  200. package/src/mu/DataGridEx.tsx +0 -712
  201. package/src/mu/DataGridRenderers.tsx +0 -140
  202. package/src/mu/DialogButton.tsx +0 -163
  203. package/src/mu/DraggablePaperComponent.tsx +0 -19
  204. package/src/mu/EmailInput.tsx +0 -24
  205. package/src/mu/FabBox.tsx +0 -51
  206. package/src/mu/FlexBox.tsx +0 -20
  207. package/src/mu/GridDataFormat.tsx +0 -77
  208. package/src/mu/GridMethodRef.ts +0 -12
  209. package/src/mu/IconButtonLink.tsx +0 -29
  210. package/src/mu/InputField.tsx +0 -82
  211. package/src/mu/ItemList.tsx +0 -204
  212. package/src/mu/ListItemRightIcon.tsx +0 -9
  213. package/src/mu/ListMoreDisplay.tsx +0 -205
  214. package/src/mu/LoadingButton.tsx +0 -75
  215. package/src/mu/MUGlobal.ts +0 -220
  216. package/src/mu/MaskInput.tsx +0 -107
  217. package/src/mu/MobileListItemRenderer.tsx +0 -79
  218. package/src/mu/MoreFab.tsx +0 -211
  219. package/src/mu/NotifierMU.tsx +0 -654
  220. package/src/mu/NotifierPromptProps.ts +0 -26
  221. package/src/mu/OptionGroup.tsx +0 -223
  222. package/src/mu/PList.tsx +0 -27
  223. package/src/mu/ProgressCount.tsx +0 -166
  224. package/src/mu/PullToRefreshUI.tsx +0 -21
  225. package/src/mu/RLink.tsx +0 -64
  226. package/src/mu/ResponsibleContainer.tsx +0 -394
  227. package/src/mu/ScrollTopFab.tsx +0 -34
  228. package/src/mu/ScrollerListEx.tsx +0 -387
  229. package/src/mu/SearchBar.tsx +0 -398
  230. package/src/mu/SearchField.tsx +0 -82
  231. package/src/mu/SearchOptionGroup.tsx +0 -31
  232. package/src/mu/SelectBool.tsx +0 -33
  233. package/src/mu/SelectEx.tsx +0 -290
  234. package/src/mu/Switch.tsx +0 -94
  235. package/src/mu/SwitchAnt.tsx +0 -95
  236. package/src/mu/TabBox.tsx +0 -118
  237. package/src/mu/TableEx.tsx +0 -560
  238. package/src/mu/TextFieldEx.tsx +0 -250
  239. package/src/mu/Tiplist.tsx +0 -304
  240. package/src/mu/TooltipClick.tsx +0 -84
  241. package/src/mu/UserAvatar.tsx +0 -64
  242. package/src/mu/UserAvatarEditor.tsx +0 -287
  243. package/src/mu/pages/CommonPage.tsx +0 -128
  244. package/src/mu/pages/CommonPageProps.ts +0 -71
  245. package/src/mu/pages/DataGridPage.tsx +0 -137
  246. package/src/mu/pages/DataGridPageProps.ts +0 -24
  247. package/src/mu/pages/EditPage.tsx +0 -114
  248. package/src/mu/pages/FixedListPage.tsx +0 -135
  249. package/src/mu/pages/ListPage.tsx +0 -87
  250. package/src/mu/pages/ListPageProps.ts +0 -12
  251. package/src/mu/pages/ResponsivePage.tsx +0 -68
  252. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  253. package/src/mu/pages/SearchPageProps.ts +0 -39
  254. package/src/mu/pages/TablePage.tsx +0 -120
  255. package/src/mu/pages/TablePageProps.ts +0 -12
  256. package/src/mu/pages/ViewPage.tsx +0 -285
  257. package/src/mu/texts/DateText.tsx +0 -74
  258. package/src/mu/texts/MoneyText.tsx +0 -49
  259. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,114 +0,0 @@
1
- import { Button, Grid } from '@mui/material';
2
- import React, { FormEventHandler } from 'react';
3
- import { Labels } from '../../app/Labels';
4
- import { MUGlobal } from '../MUGlobal';
5
- import { CommonPage, CommonPageScrollContainer } from './CommonPage';
6
- import { CommonPageProps } from './CommonPageProps';
7
- import SaveIcon from '@mui/icons-material/Save';
8
- import DeleteIcon from '@mui/icons-material/Delete';
9
- import { BackButton } from '../BackButton';
10
-
11
- /**
12
- * Add / Edit page props
13
- */
14
- export interface EditPageProps extends Omit<CommonPageProps, 'onSubmit'> {
15
- /**
16
- * Is editing
17
- */
18
- isEditing?: boolean;
19
-
20
- /**
21
- * On form submit
22
- */
23
- onSubmit?: FormEventHandler<HTMLFormElement>;
24
-
25
- /**
26
- * On delete callback
27
- */
28
- onDelete?: () => Promise<void> | void;
29
-
30
- /**
31
- * Submit button disabled or not
32
- */
33
- submitDisabled?: boolean;
34
-
35
- /**
36
- * Support back click
37
- * @default true
38
- */
39
- supportBack?: boolean;
40
- }
41
-
42
- /**
43
- * Add / Edit page
44
- * @param props Props
45
- */
46
- export function EditPage(props: EditPageProps) {
47
- // Destruct
48
- const {
49
- children,
50
- isEditing,
51
- onDelete,
52
- onSubmit,
53
- paddings = MUGlobal.pagePaddings,
54
- scrollContainer = CommonPageScrollContainer,
55
- supportBack = true,
56
- submitDisabled = false,
57
- ...rest
58
- } = props;
59
-
60
- // Labels
61
- const labels = Labels.CommonPage;
62
-
63
- return (
64
- <CommonPage
65
- paddings={paddings}
66
- scrollContainer={scrollContainer}
67
- {...rest}
68
- >
69
- <form onSubmit={onSubmit}>
70
- <Grid
71
- container
72
- justifyContent="left"
73
- spacing={paddings}
74
- paddingTop={1}
75
- >
76
- {children}
77
- </Grid>
78
- <Grid
79
- container
80
- position="sticky"
81
- display="flex"
82
- gap={paddings}
83
- sx={{
84
- top: 'auto',
85
- bottom: (theme) =>
86
- MUGlobal.updateWithTheme(paddings, theme.spacing),
87
- paddingTop: paddings
88
- }}
89
- >
90
- {isEditing && onDelete && (
91
- <Button
92
- color="primary"
93
- variant="outlined"
94
- onClick={() => onDelete()}
95
- startIcon={<DeleteIcon color="warning" />}
96
- >
97
- {labels.delete}
98
- </Button>
99
- )}
100
- <Button
101
- variant="contained"
102
- type="submit"
103
- startIcon={<SaveIcon />}
104
- sx={{ flexGrow: 1 }}
105
- disabled={submitDisabled}
106
- >
107
- {labels.save}
108
- </Button>
109
- {supportBack && <BackButton title={labels.back} />}
110
- </Grid>
111
- </form>
112
- </CommonPage>
113
- );
114
- }
@@ -1,135 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
5
- import { ScrollerListForwardRef } from '../../components/ScrollerList';
6
- import useCombinedRefs from '../../uses/useCombinedRefs';
7
- import { useDimensions } from '../../uses/useDimensions';
8
- import { MUGlobal } from '../MUGlobal';
9
- import { ScrollerListEx } from '../ScrollerListEx';
10
- import { SearchBar } from '../SearchBar';
11
- import { CommonPage } from './CommonPage';
12
- import { ListPageProps } from './ListPageProps';
13
-
14
- /**
15
- * Fixed height list page
16
- * @param props Props
17
- * @returns Component
18
- */
19
- export function FixedListPage<
20
- T extends object,
21
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
22
- D extends DataTypes.Keys<T> = IdDefaultType<T>
23
- >(
24
- props: ListPageProps<T, F, D> & {
25
- /**
26
- * Height will be deducted
27
- * @param height Current calcuated height
28
- */
29
- adjustHeight?: (height: number) => number;
30
- }
31
- ) {
32
- // Destruct
33
- const {
34
- adjustHeight,
35
- fields,
36
- fieldTemplate,
37
- loadData,
38
- mRef,
39
- sizeReadyMiliseconds = 0,
40
- pageProps = {},
41
- ...rest
42
- } = props;
43
-
44
- pageProps.paddings ??= MUGlobal.pagePaddings;
45
-
46
- // States
47
- const [states] = React.useState<{
48
- data?: FormData;
49
- ref?: ScrollerListForwardRef;
50
- }>({});
51
-
52
- // Scroll container
53
- const [scrollContainer, updateScrollContainer] = React.useState<
54
- HTMLElement | undefined
55
- >();
56
-
57
- const refs = useCombinedRefs(mRef, (ref: ScrollerListForwardRef) => {
58
- if (ref == null) return;
59
-
60
- const first = states.ref == null;
61
-
62
- states.ref = ref;
63
-
64
- if (first) reset();
65
- });
66
-
67
- const reset = () => {
68
- if (states.data == null || states.ref == null) return;
69
- states.ref.reset({ data: states.data });
70
- };
71
-
72
- // On submit callback
73
- const onSubmit = (data: FormData, _reset: boolean) => {
74
- states.data = data;
75
- reset();
76
- };
77
-
78
- const localLoadData = (props: GridLoadDataProps) => {
79
- const data = GridDataGet(props, fieldTemplate);
80
- return loadData(data);
81
- };
82
-
83
- // Watch container
84
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
85
- const rect = dimensions[0][2];
86
- const list = React.useMemo(() => {
87
- if (rect != null && rect.height > 50) {
88
- let height =
89
- document.documentElement.clientHeight -
90
- Math.round(rect.top + rect.height + 1);
91
-
92
- if (adjustHeight != null) {
93
- height -= adjustHeight(height);
94
- }
95
-
96
- return (
97
- <Box
98
- id="list-container"
99
- sx={{
100
- height: height + 'px'
101
- }}
102
- >
103
- <ScrollerListEx<T, D>
104
- autoLoad={false}
105
- height={height}
106
- loadData={localLoadData}
107
- mRef={refs}
108
- oRef={(element) => {
109
- if (element != null) updateScrollContainer(element);
110
- }}
111
- {...rest}
112
- />
113
- </Box>
114
- );
115
- }
116
- }, [rect]);
117
-
118
- const { paddings, ...pageRest } = pageProps;
119
-
120
- // Layout
121
- return (
122
- <CommonPage
123
- {...pageRest}
124
- paddings={{}}
125
- scrollContainer={scrollContainer}
126
- >
127
- <Stack>
128
- <Box ref={dimensions[0][0]} sx={{ padding: paddings }}>
129
- <SearchBar fields={fields} onSubmit={onSubmit} />
130
- </Box>
131
- {list}
132
- </Stack>
133
- </CommonPage>
134
- );
135
- }
@@ -1,87 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
5
- import { ScrollerListForwardRef } from '../../components/ScrollerList';
6
- import useCombinedRefs from '../../uses/useCombinedRefs';
7
- import { MUGlobal } from '../MUGlobal';
8
- import { ScrollerListEx } from '../ScrollerListEx';
9
- import { SearchBar } from '../SearchBar';
10
- import { CommonPage, CommonPageScrollContainer } from './CommonPage';
11
- import { ListPageProps } from './ListPageProps';
12
-
13
- /**
14
- * List page
15
- * @param props Props
16
- * @returns Component
17
- */
18
- export function ListPage<
19
- T extends object,
20
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
21
- D extends DataTypes.Keys<T> = IdDefaultType<T>
22
- >(props: ListPageProps<T, F, D>) {
23
- // Destruct
24
- const {
25
- fields,
26
- fieldTemplate,
27
- loadData,
28
- mRef,
29
- pageProps = {},
30
- ...rest
31
- } = props;
32
-
33
- pageProps.paddings ??= MUGlobal.pagePaddings;
34
-
35
- // States
36
- const [states] = React.useState<{
37
- data?: FormData;
38
- ref?: ScrollerListForwardRef;
39
- }>({});
40
-
41
- const refs = useCombinedRefs(mRef, (ref: ScrollerListForwardRef) => {
42
- if (ref == null) return;
43
-
44
- const first = states.ref == null;
45
-
46
- states.ref = ref;
47
-
48
- if (first) reset();
49
- });
50
-
51
- const reset = () => {
52
- if (states.data == null || states.ref == null) return;
53
- states.ref.reset({ data: states.data });
54
- };
55
-
56
- // On submit callback
57
- const onSubmit = (data: FormData, _reset: boolean) => {
58
- states.data = data;
59
- reset();
60
- };
61
-
62
- const localLoadData = (props: GridLoadDataProps) => {
63
- const data = GridDataGet(props, fieldTemplate);
64
- return loadData(data);
65
- };
66
-
67
- // Layout
68
- return (
69
- <CommonPage {...pageProps} scrollContainer={CommonPageScrollContainer}>
70
- <Stack>
71
- <Box
72
- sx={{
73
- paddingBottom: pageProps.paddings
74
- }}
75
- >
76
- <SearchBar fields={fields} onSubmit={onSubmit} />
77
- </Box>
78
- <ScrollerListEx<T, D>
79
- autoLoad={false}
80
- loadData={localLoadData}
81
- mRef={refs}
82
- {...rest}
83
- />
84
- </Stack>
85
- </CommonPage>
86
- );
87
- }
@@ -1,12 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import { ScrollerListExProps } from '../ScrollerListEx';
3
- import { SearchPageProps } from './SearchPageProps';
4
-
5
- /**
6
- * List page props
7
- */
8
- export type ListPageProps<
9
- T extends object,
10
- F extends DataTypes.BasicTemplate,
11
- D extends DataTypes.Keys<T>
12
- > = SearchPageProps<T, F> & Omit<ScrollerListExProps<T, D>, 'loadData'>;
@@ -1,68 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import React from 'react';
3
- import { MUGlobal } from '../MUGlobal';
4
- import { ResponsibleContainer } from '../ResponsibleContainer';
5
- import { CommonPage } from './CommonPage';
6
- import { ResponsePageProps } from './ResponsivePageProps';
7
-
8
- /**
9
- * Fixed height list page
10
- * @param props Props
11
- * @returns Component
12
- */
13
- export function ResponsivePage<
14
- T extends object,
15
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
16
- D extends DataTypes.Keys<T> = IdDefaultType<T>
17
- >(props: ResponsePageProps<T, F, D>) {
18
- // Destruct
19
- const { pageProps = {}, ...rest } = props;
20
-
21
- pageProps.paddings ??= MUGlobal.pagePaddings;
22
- const { paddings, fabColumnDirection, ...pageRest } = pageProps;
23
-
24
- // State
25
- const [scrollContainer, setScrollContainer] = React.useState<HTMLElement>();
26
- const [direction, setDirection] = React.useState(fabColumnDirection);
27
-
28
- // Layout
29
- return (
30
- <CommonPage
31
- {...pageRest}
32
- paddings={{}}
33
- scrollContainer={scrollContainer}
34
- fabColumnDirection={direction}
35
- >
36
- <ResponsibleContainer<T, F, D>
37
- paddings={paddings}
38
- containerBoxSx={(paddings, hasField, _dataGrid) => {
39
- // Half
40
- const half = MUGlobal.half(paddings);
41
-
42
- // .SearchBox keep the same to avoid flick when switching between DataGrid and List
43
- return {
44
- paddingTop: paddings,
45
- '& .SearchBox': {
46
- marginLeft: paddings,
47
- marginRight: paddings,
48
- marginBottom: hasField ? half : 0
49
- },
50
- '& .ListBox': {
51
- marginBottom: paddings
52
- },
53
- '& .DataGridBox': {
54
- marginLeft: paddings,
55
- marginRight: paddings,
56
- marginBottom: paddings
57
- }
58
- };
59
- }}
60
- elementReady={(element, isDataGrid) => {
61
- setDirection(!isDataGrid);
62
- setScrollContainer(element);
63
- }}
64
- {...rest}
65
- />
66
- </CommonPage>
67
- );
68
- }
@@ -1,57 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { ListChildComponentProps } from 'react-window';
3
- import { GridMethodRef } from '../GridMethodRef';
4
- import {
5
- ScrollerListExInnerItemRendererProps,
6
- ScrollerListExItemSize
7
- } from '../ScrollerListEx';
8
- import { DataGridPageProps } from './DataGridPageProps';
9
-
10
- /**
11
- * Response page props
12
- */
13
- export type ResponsePageProps<
14
- T extends object,
15
- F extends DataTypes.BasicTemplate,
16
- D extends DataTypes.Keys<T> = IdDefaultType<T>
17
- > = Omit<
18
- DataGridPageProps<T, F, D>,
19
- 'mRef' | 'itemKey' | 'onScroll' | 'onItemsRendered'
20
- > & {
21
- /**
22
- * Min width to show Datagrid
23
- */
24
- dataGridMinWidth?: number;
25
-
26
- /**
27
- * Inner item renderer
28
- */
29
- innerItemRenderer: (
30
- props: ScrollerListExInnerItemRendererProps<T>
31
- ) => React.ReactNode;
32
-
33
- /**
34
- * Item renderer
35
- */
36
- itemRenderer?: (props: ListChildComponentProps<T>) => React.ReactElement;
37
-
38
- /**
39
- * Item size, a function indicates its a variable size list
40
- */
41
- itemSize: ScrollerListExItemSize;
42
-
43
- /**
44
- * Methods
45
- */
46
- mRef?: React.MutableRefObject<GridMethodRef | undefined>;
47
-
48
- /**
49
- * Pull to refresh data
50
- */
51
- pullToRefresh?: boolean;
52
-
53
- /**
54
- * Quick action for double click or click under mobile
55
- */
56
- quickAction?: (data: T) => void;
57
- };
@@ -1,39 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import { GridJsonData, GridLoader } from '../../components/GridLoader';
3
- import { CommonPageProps } from './CommonPageProps';
4
-
5
- /**
6
- * Search page props
7
- */
8
- export type SearchPageProps<
9
- T extends object,
10
- F extends DataTypes.BasicTemplate
11
- > = Omit<GridLoader<T>, 'loadData'> & {
12
- /**
13
- * Search fields
14
- */
15
- fields: React.ReactElement[];
16
-
17
- /**
18
- * Search field template
19
- */
20
- fieldTemplate?: F;
21
-
22
- /**
23
- * Load data callback
24
- */
25
- loadData: (
26
- data: GridJsonData & DataTypes.BasicTemplateType<F>
27
- ) => PromiseLike<T[] | null | undefined>;
28
-
29
- /**
30
- * Page props
31
- */
32
- pageProps?: CommonPageProps;
33
-
34
- /**
35
- * Size ready to read miliseconds span
36
- * @default 100
37
- */
38
- sizeReadyMiliseconds?: number;
39
- };
@@ -1,120 +0,0 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
5
- import useCombinedRefs from '../../uses/useCombinedRefs';
6
- import { useDimensions } from '../../uses/useDimensions';
7
- import { MUGlobal } from '../MUGlobal';
8
- import { SearchBar } from '../SearchBar';
9
- import { TableEx, TableExMethodRef, TableExMinWidth } from '../TableEx';
10
- import { CommonPage, CommonPageScrollContainer } from './CommonPage';
11
- import { TablePageProps } from './TablePageProps';
12
-
13
- /**
14
- * Table page
15
- * @param props Props
16
- * @returns Component
17
- */
18
- export function TablePage<
19
- T extends object,
20
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
21
- D extends DataTypes.Keys<T> = IdDefaultType<T>
22
- >(props: TablePageProps<T, F, D>) {
23
- // Destruct
24
- const {
25
- columns,
26
- fields,
27
- fieldTemplate,
28
- loadData,
29
- mRef,
30
- sizeReadyMiliseconds = 0,
31
- pageProps = {},
32
- ...rest
33
- } = props;
34
-
35
- pageProps.paddings ??= MUGlobal.pagePaddings;
36
-
37
- // States
38
- const [states] = React.useState<{
39
- data?: FormData;
40
- ref?: TableExMethodRef;
41
- }>({});
42
-
43
- const refs = useCombinedRefs(mRef, (ref: TableExMethodRef) => {
44
- if (ref == null) return;
45
-
46
- const first = states.ref == null;
47
-
48
- states.ref = ref;
49
-
50
- if (first) reset();
51
- });
52
-
53
- const reset = () => {
54
- if (states.data == null || states.ref == null) return;
55
- states.ref.reset({ data: states.data });
56
- };
57
-
58
- // On submit callback
59
- const onSubmit = (data: FormData, _reset: boolean) => {
60
- states.data = data;
61
- reset();
62
- };
63
-
64
- const localLoadData = (props: GridLoadDataProps) => {
65
- const data = GridDataGet(props, fieldTemplate);
66
- return loadData(data);
67
- };
68
-
69
- // Total width
70
- const totalWidth = React.useMemo(
71
- () =>
72
- columns.reduce((previousValue, { width, minWidth }) => {
73
- return previousValue + (width ?? minWidth ?? TableExMinWidth);
74
- }, 0),
75
- [columns]
76
- );
77
-
78
- // Watch container
79
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
80
- const rect = dimensions[0][2];
81
- const list = React.useMemo(() => {
82
- if (rect != null && rect.height > 50 && rect.width >= totalWidth) {
83
- let maxHeight =
84
- document.documentElement.clientHeight -
85
- (rect.top + rect.height + 1);
86
-
87
- const style = window.getComputedStyle(dimensions[0][1]!);
88
- const paddingBottom = parseFloat(style.paddingBottom);
89
- if (!isNaN(paddingBottom)) maxHeight -= paddingBottom;
90
-
91
- return (
92
- <TableEx<T, D>
93
- autoLoad={false}
94
- columns={columns}
95
- loadData={localLoadData}
96
- maxHeight={maxHeight}
97
- mRef={refs}
98
- {...rest}
99
- />
100
- );
101
- }
102
- }, [rect]);
103
-
104
- // Layout
105
- return (
106
- <CommonPage {...pageProps} scrollContainer={CommonPageScrollContainer}>
107
- <Stack>
108
- <Box
109
- ref={dimensions[0][0]}
110
- sx={{
111
- paddingBottom: pageProps.paddings
112
- }}
113
- >
114
- <SearchBar fields={fields} onSubmit={onSubmit} />
115
- </Box>
116
- {list}
117
- </Stack>
118
- </CommonPage>
119
- );
120
- }
@@ -1,12 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import { TableExProps } from '../TableEx';
3
- import { SearchPageProps } from './SearchPageProps';
4
-
5
- /**
6
- * Table page props
7
- */
8
- export type TablePageProps<
9
- T extends object,
10
- F extends DataTypes.BasicTemplate,
11
- D extends DataTypes.Keys<T>
12
- > = SearchPageProps<T, F> & Omit<TableExProps<T, D>, 'loadData'>;