@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,223 @@
1
+ import {
2
+ DataTypes,
3
+ IdDefaultType,
4
+ LabelDefaultType,
5
+ ListType,
6
+ Utils
7
+ } from '@etsoo/shared';
8
+ import {
9
+ Checkbox,
10
+ FormControl,
11
+ FormControlLabel,
12
+ FormControlProps,
13
+ FormGroup,
14
+ FormLabel,
15
+ Radio,
16
+ RadioGroup
17
+ } from '@mui/material';
18
+ import React from 'react';
19
+
20
+ /**
21
+ * OptionGroup props
22
+ */
23
+ export type OptionGroupProps<
24
+ T extends object,
25
+ D extends DataTypes.Keys<T>,
26
+ L extends DataTypes.Keys<T, string>
27
+ > = Omit<FormControlProps<'fieldset'>, 'defaultValue'> & {
28
+ /**
29
+ * Default value
30
+ */
31
+ defaultValue?: T[D] | T[D][];
32
+
33
+ /**
34
+ * Get option label function
35
+ */
36
+ getOptionLabel?: (option: T) => string;
37
+
38
+ /**
39
+ * Id field
40
+ */
41
+ idField?: D;
42
+
43
+ /**
44
+ * Label
45
+ */
46
+ label?: string;
47
+
48
+ /**
49
+ * Label field
50
+ */
51
+ labelField?: L;
52
+
53
+ /**
54
+ * Multiple choose item
55
+ */
56
+ multiple?: boolean;
57
+
58
+ /**
59
+ * Field name
60
+ */
61
+ name: string;
62
+
63
+ /**
64
+ * On value change handler
65
+ */
66
+ onValueChange?: (value: T[D] | T[D][] | undefined) => void;
67
+
68
+ /**
69
+ * Array of options.
70
+ */
71
+ options: ReadonlyArray<T>;
72
+
73
+ /**
74
+ * Is the field read only?
75
+ */
76
+ readOnly?: boolean;
77
+
78
+ /**
79
+ * Display group of elements in a compact row
80
+ */
81
+ row?: boolean;
82
+ };
83
+
84
+ /**
85
+ * OptionGroup
86
+ * @param props Props
87
+ * @returns Component
88
+ */
89
+ export function OptionGroup<
90
+ T extends object = ListType,
91
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
92
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
93
+ >(props: OptionGroupProps<T, D, L>) {
94
+ // Destruct
95
+ const {
96
+ getOptionLabel,
97
+ defaultValue,
98
+ idField = 'id' as D,
99
+ label,
100
+ labelField = 'label' as L,
101
+ multiple = false,
102
+ name,
103
+ onValueChange,
104
+ options,
105
+ readOnly,
106
+ row,
107
+ size,
108
+ ...rest
109
+ } = props;
110
+
111
+ // Get option value
112
+ // D type should be the source id type
113
+ const getOptionValue = (option: T): T[D] | null => {
114
+ const value = DataTypes.getValue(option, idField);
115
+ if (value == null) return null;
116
+ return value as T[D];
117
+ };
118
+
119
+ // Checkbox values
120
+ const [values, setValues] = React.useState(
121
+ defaultValue == null
122
+ ? []
123
+ : Array.isArray(defaultValue)
124
+ ? defaultValue
125
+ : [defaultValue]
126
+ );
127
+
128
+ // Item checked
129
+ const itemChecked = (option: T) => {
130
+ // Value
131
+ const value = getOptionValue(option);
132
+ if (value == null) return false;
133
+
134
+ return values.includes(value);
135
+ };
136
+
137
+ // First item value
138
+ const firstOptionValue = getOptionValue(options[0]);
139
+
140
+ // Items
141
+ const list = options.map((option) => {
142
+ // Control
143
+ const control = multiple ? (
144
+ <Checkbox
145
+ name={name}
146
+ readOnly={readOnly}
147
+ size={size}
148
+ checked={itemChecked(option)}
149
+ onChange={(event) => {
150
+ if (firstOptionValue == null) return;
151
+
152
+ const typeValue = Utils.parseString(
153
+ event.target.value,
154
+ firstOptionValue
155
+ );
156
+
157
+ const changedValues = [...values];
158
+ if (event.target.checked) {
159
+ if (changedValues.includes(typeValue)) return;
160
+ changedValues.push(typeValue);
161
+ } else {
162
+ const index = changedValues.findIndex(
163
+ (v) => v === typeValue
164
+ );
165
+ if (index === -1) return;
166
+ changedValues.splice(index, 1);
167
+ }
168
+
169
+ if (onValueChange) onValueChange(changedValues);
170
+ setValues(changedValues);
171
+ }}
172
+ />
173
+ ) : (
174
+ <Radio size={size} readOnly={readOnly} />
175
+ );
176
+
177
+ // Label
178
+ const label =
179
+ getOptionLabel == null
180
+ ? `${option[labelField]}`
181
+ : getOptionLabel(option);
182
+
183
+ // Value, convert to string
184
+ // Will fail when type is number
185
+ const value = getOptionValue(option) as unknown as React.Key;
186
+
187
+ return (
188
+ <FormControlLabel
189
+ key={value}
190
+ control={control}
191
+ value={value}
192
+ label={label}
193
+ />
194
+ );
195
+ });
196
+
197
+ // Group
198
+ const group = multiple ? (
199
+ <FormGroup row={row}>{list}</FormGroup>
200
+ ) : (
201
+ <RadioGroup
202
+ row={row}
203
+ name={name}
204
+ value={values[0]}
205
+ onChange={(_event, value) => {
206
+ if (firstOptionValue == null) return;
207
+ const typeValue = Utils.parseString(value, firstOptionValue);
208
+ if (onValueChange) onValueChange(typeValue);
209
+ setValues([typeValue]);
210
+ }}
211
+ >
212
+ {list}
213
+ </RadioGroup>
214
+ );
215
+
216
+ // Layout
217
+ return (
218
+ <FormControl component="fieldset" {...rest}>
219
+ {label && <FormLabel component="legend">{label}</FormLabel>}
220
+ {group}
221
+ </FormControl>
222
+ );
223
+ }
package/src/PList.tsx ADDED
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Paragraph items list props
5
+ */
6
+ export interface PListProps {
7
+ /**
8
+ * List items
9
+ */
10
+ items?: string[];
11
+ }
12
+
13
+ /**
14
+ * Paragraph items list
15
+ * @param items Items
16
+ */
17
+ export function PList(props: PListProps) {
18
+ const { items } = props;
19
+ return (
20
+ <React.Fragment>
21
+ {items != null &&
22
+ items.map((item, index) => {
23
+ return <p key={index}>{item}</p>;
24
+ })}
25
+ </React.Fragment>
26
+ );
27
+ }
@@ -0,0 +1,166 @@
1
+ import {
2
+ Box,
3
+ CircularProgress,
4
+ LinearProgress,
5
+ Typography
6
+ } from '@mui/material';
7
+ import React from 'react';
8
+
9
+ /**
10
+ * Process count props
11
+ */
12
+ export interface ProgressCountProps {
13
+ /**
14
+ * Is countdown or opposite
15
+ * @default 'true'
16
+ */
17
+ countdown?: boolean;
18
+
19
+ /**
20
+ * Is linear or circular
21
+ * @default 'true'
22
+ */
23
+ linear?: boolean;
24
+
25
+ /**
26
+ * Min width
27
+ * @default 36
28
+ */
29
+ minWidth?: number;
30
+
31
+ /**
32
+ * On complete callback, return false will stop it
33
+ */
34
+ onComplete?: () => boolean;
35
+
36
+ /**
37
+ * On progress callback
38
+ */
39
+ onProgress?: (value: number) => void;
40
+
41
+ /**
42
+ * Seconds for count
43
+ */
44
+ seconds: number;
45
+
46
+ /**
47
+ * Value unit, like 's' or '%'
48
+ * @default ''
49
+ */
50
+ valueUnit?: string;
51
+ }
52
+
53
+ /**
54
+ * Progress count
55
+ * @param props Props
56
+ * @returns Component
57
+ */
58
+ export function ProgressCount(props: ProgressCountProps) {
59
+ // Destruct
60
+ const {
61
+ countdown = true,
62
+ linear = true,
63
+ minWidth = 36,
64
+ onComplete,
65
+ onProgress,
66
+ seconds,
67
+ valueUnit = ''
68
+ } = props;
69
+
70
+ // Progress value
71
+ const [value, setValue] = React.useState(countdown ? seconds : 0);
72
+
73
+ // Variant
74
+ const [variant, setVariant] = React.useState<
75
+ 'determinate' | 'indeterminate'
76
+ >('determinate');
77
+
78
+ // Progress value
79
+ const progressValue = (100.0 * value) / seconds;
80
+
81
+ React.useEffect(() => {
82
+ const timer = setInterval(() => {
83
+ setValue((prev) => {
84
+ const newValue = countdown
85
+ ? prev === 0
86
+ ? seconds
87
+ : prev - 1
88
+ : prev === seconds
89
+ ? 0
90
+ : prev + 1;
91
+
92
+ if (countdown) {
93
+ if (newValue === 0) {
94
+ if (onComplete) {
95
+ const result = onComplete();
96
+ // Finish
97
+ if (result === false) {
98
+ clearInterval(timer);
99
+ setVariant('indeterminate');
100
+ }
101
+ }
102
+ }
103
+ } else {
104
+ if (newValue === seconds) {
105
+ if (onComplete) {
106
+ const result = onComplete();
107
+ // Finish
108
+ if (result === false) {
109
+ clearInterval(timer);
110
+ setVariant('indeterminate');
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ if (onProgress) onProgress(newValue);
117
+
118
+ return newValue;
119
+ });
120
+ }, 1000);
121
+ return () => {
122
+ clearInterval(timer);
123
+ };
124
+ }, []);
125
+
126
+ if (linear)
127
+ return (
128
+ <Box sx={{ display: 'flex', alignItems: 'center', width: '100%' }}>
129
+ <Box sx={{ width: '100%', mr: 1 }}>
130
+ <LinearProgress variant={variant} value={progressValue} />
131
+ </Box>
132
+ <Box sx={{ minWidth }}>
133
+ <Typography
134
+ variant="body2"
135
+ color="text.secondary"
136
+ >{`${value}${valueUnit}`}</Typography>
137
+ </Box>
138
+ </Box>
139
+ );
140
+
141
+ return (
142
+ <Box sx={{ position: 'relative', display: 'inline-flex' }}>
143
+ <CircularProgress variant={variant} value={progressValue} />
144
+ <Box
145
+ sx={{
146
+ top: 0,
147
+ left: 0,
148
+ bottom: 0,
149
+ right: 0,
150
+ position: 'absolute',
151
+ display: 'flex',
152
+ alignItems: 'center',
153
+ justifyContent: 'center'
154
+ }}
155
+ >
156
+ <Typography
157
+ variant="caption"
158
+ component="div"
159
+ color="text.secondary"
160
+ >
161
+ {`${value}${valueUnit}`}
162
+ </Typography>
163
+ </Box>
164
+ </Box>
165
+ );
166
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import PullToRefresh, { Options } from 'pulltorefreshjs';
3
+
4
+ /**
5
+ * PullToRefresh UI
6
+ * Use hammerjs or touchemulator to simulate browser as mobile device
7
+ * @param props Props
8
+ * @returns Component
9
+ */
10
+ export function PullToRefreshUI(props: Options) {
11
+ // Ready
12
+ React.useEffect(() => {
13
+ PullToRefresh.init(props);
14
+
15
+ return () => {
16
+ PullToRefresh.destroyAll();
17
+ };
18
+ }, [props]);
19
+
20
+ return <React.Fragment />;
21
+ }
package/src/RLink.tsx ADDED
@@ -0,0 +1,64 @@
1
+ import { useDelayedExecutor } from '@etsoo/react';
2
+ import { Link, LinkProps } from '@mui/material';
3
+ import React from 'react';
4
+ import { globalApp } from './app/ReactApp';
5
+
6
+ /**
7
+ * Router Link properties
8
+ */
9
+ export type RLinkProps = LinkProps & {
10
+ delay?: number;
11
+ };
12
+
13
+ /**
14
+ * Router Link
15
+ * @param props Props
16
+ * @returns Component
17
+ */
18
+ export const RLink = React.forwardRef<HTMLAnchorElement, RLinkProps>(
19
+ (props, ref) => {
20
+ // Destruct
21
+ const { delay = 0, href, target, onClick, ...rest } = props;
22
+
23
+ const delayed = useDelayedExecutor((href: string) => {
24
+ // Router push
25
+ globalApp.history.push(href);
26
+ }, delay);
27
+
28
+ // Click handler
29
+ const onClickLocl = (
30
+ event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
31
+ ) => {
32
+ if (onClick) onClick(event);
33
+
34
+ if (
35
+ !event.isDefaultPrevented() &&
36
+ href &&
37
+ (!target || target === '_self') && // Let browser handle "target=_blank" etc
38
+ globalApp
39
+ ) {
40
+ // Prevent href action
41
+ event.preventDefault();
42
+
43
+ // Delayed excution
44
+ delayed.call(undefined, href);
45
+ }
46
+ };
47
+
48
+ // Clear when exit
49
+ React.useEffect(() => {
50
+ return () => delayed.clear();
51
+ }, [delayed]);
52
+
53
+ // Component
54
+ return (
55
+ <Link
56
+ {...rest}
57
+ onClick={onClickLocl}
58
+ href={href}
59
+ target={target}
60
+ ref={ref}
61
+ />
62
+ );
63
+ }
64
+ );