@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,50 @@
1
+ import { SelectProps } from '@mui/material';
2
+ import React from 'react';
3
+ import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
4
+ /**
5
+ * Extended select component props
6
+ */
7
+ export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>> = Omit<SelectProps, 'labelId' | 'input' | 'native'> & {
8
+ /**
9
+ * Auto add blank item
10
+ */
11
+ autoAddBlankItem?: boolean;
12
+ /**
13
+ * Id field
14
+ */
15
+ idField?: D;
16
+ /**
17
+ * Item icon renderer
18
+ */
19
+ itemIconRenderer?: (id: T[D]) => React.ReactNode;
20
+ /**
21
+ * Label field
22
+ */
23
+ labelField?: L | ((option: T) => string);
24
+ /**
25
+ * Load data callback
26
+ */
27
+ loadData?: () => PromiseLike<T[] | null | undefined>;
28
+ /**
29
+ * Item click handler
30
+ */
31
+ onItemClick?: (event: React.MouseEvent, option: T) => void;
32
+ /**
33
+ * On load data handler
34
+ */
35
+ onLoadData?: (options: T[]) => void;
36
+ /**
37
+ * Array of options.
38
+ */
39
+ options?: ReadonlyArray<T>;
40
+ /**
41
+ * Is search case?
42
+ */
43
+ search?: boolean;
44
+ };
45
+ /**
46
+ * Extended select component
47
+ * @param props Props
48
+ * @returns Component
49
+ */
50
+ export declare function SelectEx<T extends object = ListType, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>>(props: SelectExProps<T, D, L>): JSX.Element;
@@ -0,0 +1,156 @@
1
+ import { Checkbox, FormControl, InputLabel, ListItemText, MenuItem, OutlinedInput, Select } from '@mui/material';
2
+ import React from 'react';
3
+ import { MUGlobal } from './MUGlobal';
4
+ import { ListItemRightIcon } from './ListItemRightIcon';
5
+ import { Utils } from '@etsoo/shared';
6
+ import { ReactUtils } from '@etsoo/react';
7
+ /**
8
+ * Extended select component
9
+ * @param props Props
10
+ * @returns Component
11
+ */
12
+ export function SelectEx(props) {
13
+ var _a;
14
+ // Destruct
15
+ const { defaultValue, idField = 'id', itemIconRenderer, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
16
+ // Options state
17
+ const [localOptions, setOptions] = React.useState(options);
18
+ const isMounted = React.useRef(true);
19
+ // When options change
20
+ // [options] will cause infinite loop
21
+ const propertyWay = loadData == null;
22
+ React.useEffect(() => {
23
+ if (propertyWay && options != null)
24
+ setOptions(options);
25
+ }, [JSON.stringify(options), propertyWay]);
26
+ // Local value
27
+ const valueSource = (_a = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value) !== null && _a !== void 0 ? _a : '';
28
+ let localValue;
29
+ if (multiple) {
30
+ if (Array.isArray(valueSource))
31
+ localValue = valueSource;
32
+ else
33
+ localValue = [valueSource];
34
+ }
35
+ else {
36
+ localValue = valueSource;
37
+ }
38
+ // Value state
39
+ const [valueState, setValueState] = React.useState();
40
+ React.useEffect(() => {
41
+ if (localValue != null)
42
+ setValueState(localValue);
43
+ }, [localValue]);
44
+ // Label id
45
+ const labelId = `selectex-label-${name}`;
46
+ // Item checked or not
47
+ const itemChecked = (id) => {
48
+ if (Array.isArray(valueState))
49
+ return valueState.indexOf(id) !== -1;
50
+ return valueState === id;
51
+ };
52
+ // Change handler
53
+ const handleChange = (event) => {
54
+ const value = event.target.value;
55
+ if (multiple && !Array.isArray(value))
56
+ setItemValue([value]);
57
+ else
58
+ setItemValue(value);
59
+ };
60
+ // Set item
61
+ const setItemValue = (id) => {
62
+ var _a;
63
+ if (id != valueState) {
64
+ setValueState(id);
65
+ const input = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
66
+ if (input) {
67
+ // Different value, trigger change event
68
+ ReactUtils.triggerChange(input, id, false);
69
+ }
70
+ }
71
+ };
72
+ // Get option id
73
+ const getId = (option) => {
74
+ return option[idField];
75
+ };
76
+ // Get option label
77
+ const getLabel = (option) => {
78
+ return typeof labelField === 'function'
79
+ ? labelField(option)
80
+ : option[labelField];
81
+ };
82
+ // Refs
83
+ const divRef = React.useRef();
84
+ // When value change
85
+ React.useEffect(() => {
86
+ if (loadData) {
87
+ loadData().then((result) => {
88
+ if (result == null || !isMounted.current)
89
+ return;
90
+ if (onLoadData)
91
+ onLoadData(result);
92
+ if (autoAddBlankItem) {
93
+ Utils.addBlankItem(result, idField, labelField);
94
+ }
95
+ setOptions(result);
96
+ });
97
+ }
98
+ }, [localValue]);
99
+ // When layout ready
100
+ React.useEffect(() => {
101
+ var _a;
102
+ const input = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
103
+ const inputChange = (event) => {
104
+ // Reset case
105
+ if (event.cancelable)
106
+ setValueState(multiple ? [] : '');
107
+ };
108
+ input === null || input === void 0 ? void 0 : input.addEventListener('change', inputChange);
109
+ return () => {
110
+ isMounted.current = false;
111
+ input === null || input === void 0 ? void 0 : input.removeEventListener('change', inputChange);
112
+ };
113
+ }, []);
114
+ // Layout
115
+ return (React.createElement(FormControl, { size: search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, fullWidth: fullWidth },
116
+ React.createElement(InputLabel, { id: labelId, shrink: search
117
+ ? MUGlobal.searchFieldShrink
118
+ : MUGlobal.inputFieldShrink }, label),
119
+ React.createElement(Select, { ref: divRef, value: localOptions.some((option) => itemChecked(getId(option)))
120
+ ? valueState !== null && valueState !== void 0 ? valueState : ''
121
+ : '', input: React.createElement(OutlinedInput, { notched: true, label: label }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
122
+ if (onChange)
123
+ onChange(event, child);
124
+ if (multiple)
125
+ handleChange(event);
126
+ }, renderValue: (selected) => {
127
+ // The text shows up
128
+ return localOptions
129
+ .filter((option) => {
130
+ const id = getId(option);
131
+ return Array.isArray(selected)
132
+ ? selected.indexOf(id) !== -1
133
+ : selected === id;
134
+ })
135
+ .map((option) => getLabel(option))
136
+ .join(', ');
137
+ }, sx: { minWidth: '150px' }, fullWidth: fullWidth, ...rest }, localOptions.map((option) => {
138
+ // Option id
139
+ const id = getId(option);
140
+ // Option label
141
+ const label = getLabel(option);
142
+ // Option
143
+ return (React.createElement(MenuItem, { key: id, value: id, onClick: (event) => {
144
+ if (onItemClick) {
145
+ onItemClick(event, option);
146
+ if (event.defaultPrevented)
147
+ return;
148
+ }
149
+ if (!multiple)
150
+ setItemValue(id);
151
+ } },
152
+ multiple && React.createElement(Checkbox, { checked: itemChecked(id) }),
153
+ React.createElement(ListItemText, { primary: label }),
154
+ itemIconRenderer && (React.createElement(ListItemRightIcon, null, itemIconRenderer(option[idField])))));
155
+ }))));
156
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Audit line update data model
3
+ */
4
+ export interface AuditLineUpdateData {
5
+ oldData: Record<string, unknown>;
6
+ newData: Record<string, unknown>;
7
+ }
8
+ /**
9
+ * Check obj is instance of AuditLineUpdateData
10
+ * @param obj Input
11
+ * @returns Result
12
+ */
13
+ export declare function IsAuditLineUpdateData(obj: any): obj is AuditLineUpdateData;
14
+ /**
15
+ * Show data comparison
16
+ * @param data Data
17
+ * @param modelTitle Model window title
18
+ * @param getLabel Get label callback
19
+ */
20
+ export declare const ShowDataComparison: (data: AuditLineUpdateData, modelTitle?: string, getLabel?: ((field: string) => string) | undefined) => void;
@@ -0,0 +1,58 @@
1
+ import { NotificationMessageType } from '@etsoo/notificationbase';
2
+ import { Utils } from '@etsoo/shared';
3
+ import { Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material';
4
+ import React from 'react';
5
+ import { globalApp } from './app/ReactApp';
6
+ /**
7
+ * Check obj is instance of AuditLineUpdateData
8
+ * @param obj Input
9
+ * @returns Result
10
+ */
11
+ export function IsAuditLineUpdateData(obj) {
12
+ return (typeof obj === 'object' &&
13
+ 'oldData' in obj &&
14
+ typeof obj.oldData === 'object' &&
15
+ 'newData' in obj &&
16
+ typeof obj.newData === 'object');
17
+ }
18
+ // Format value
19
+ const formatValue = (value, app) => {
20
+ if (value == null)
21
+ return '';
22
+ if (value instanceof Date)
23
+ return app.formatDate(value, 'ds');
24
+ return `${value}`;
25
+ };
26
+ /**
27
+ * Show data comparison
28
+ * @param data Data
29
+ * @param modelTitle Model window title
30
+ * @param getLabel Get label callback
31
+ */
32
+ export const ShowDataComparison = (data, modelTitle, getLabel) => {
33
+ modelTitle !== null && modelTitle !== void 0 ? modelTitle : (modelTitle = globalApp.get('dataComparison'));
34
+ getLabel !== null && getLabel !== void 0 ? getLabel : (getLabel = (key) => {
35
+ var _a;
36
+ return (_a = globalApp.get(Utils.formatInitial(key))) !== null && _a !== void 0 ? _a : key;
37
+ });
38
+ const keys = new Set([
39
+ ...Object.keys(data.oldData),
40
+ ...Object.keys(data.newData)
41
+ ]);
42
+ const rows = Array.from(keys).map((field) => ({
43
+ field,
44
+ oldValue: data.oldData[field],
45
+ newValue: data.newData[field]
46
+ }));
47
+ const inputs = (React.createElement(Table, null,
48
+ React.createElement(TableHead, null,
49
+ React.createElement(TableRow, null,
50
+ React.createElement(TableCell, { width: "18%" }, getLabel('field')),
51
+ React.createElement(TableCell, { width: "41%", align: "right" }, getLabel('oldValue')),
52
+ React.createElement(TableCell, { width: "41%", align: "right" }, getLabel('newValue')))),
53
+ React.createElement(TableBody, null, rows.map((row) => (React.createElement(TableRow, { key: row.field },
54
+ React.createElement(TableCell, null, getLabel(row.field)),
55
+ React.createElement(TableCell, { align: "right" }, formatValue(row.oldValue, globalApp)),
56
+ React.createElement(TableCell, { align: "right" }, formatValue(row.newValue, globalApp))))))));
57
+ globalApp.notifier.alert([undefined, modelTitle], undefined, NotificationMessageType.Info, { fullScreen: globalApp.smDown, inputs });
58
+ };
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ import { FormControlLabelProps } from '@mui/material';
3
+ /**
4
+ * Switch props
5
+ */
6
+ export interface SwitchProps extends Omit<FormControlLabelProps, 'control'> {
7
+ /**
8
+ * Value, default 'on'
9
+ */
10
+ value?: string;
11
+ /**
12
+ * Is the field read only?
13
+ */
14
+ readOnly?: boolean;
15
+ /**
16
+ * Size
17
+ */
18
+ size?: 'small' | 'medium';
19
+ /**
20
+ * Display as Checkbox
21
+ */
22
+ checkbox?: boolean;
23
+ }
24
+ /**
25
+ * Switch
26
+ * @param props Props
27
+ * @returns Component
28
+ */
29
+ export declare function Switch(props: SwitchProps): JSX.Element;
package/lib/Switch.js ADDED
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { FormControlLabel } from '@mui/material';
3
+ import MuiCheckbox from '@mui/material/Checkbox';
4
+ import MuiSwitch from '@mui/material/Switch';
5
+ /**
6
+ * Switch
7
+ * @param props Props
8
+ * @returns Component
9
+ */
10
+ export function Switch(props) {
11
+ var _a;
12
+ // Destruct
13
+ const { checked, defaultChecked, defaultValue, onChange, readOnly, size, checkbox = false, value = 'true', ...rest } = props;
14
+ // Checked state
15
+ const [controlChecked, setControlChecked] = React.useState((_a = checked !== null && checked !== void 0 ? checked : defaultChecked) !== null && _a !== void 0 ? _a : defaultValue == value);
16
+ React.useEffect(() => {
17
+ if (checked)
18
+ setControlChecked(checked);
19
+ }, [checked]);
20
+ // Handle change
21
+ const handleChange = (event, checked) => {
22
+ if (onChange)
23
+ onChange(event, checked);
24
+ setControlChecked(checked);
25
+ };
26
+ // Control
27
+ const control = checkbox ? (React.createElement(MuiCheckbox, { readOnly: readOnly, checked: controlChecked, onChange: handleChange, size: size, value: value })) : (React.createElement(MuiSwitch, { readOnly: readOnly, checked: controlChecked, onChange: handleChange, size: size, value: value }));
28
+ // Default state
29
+ React.useEffect(() => {
30
+ setControlChecked(controlChecked);
31
+ }, [controlChecked]);
32
+ // Layout
33
+ return React.createElement(FormControlLabel, { control: control, ...rest });
34
+ }
@@ -0,0 +1,25 @@
1
+ /// <reference types="react" />
2
+ import { SwitchProps } from '@mui/material/Switch';
3
+ /**
4
+ * Ant style switch props
5
+ */
6
+ export interface SwitchAntProps extends SwitchProps {
7
+ /**
8
+ *
9
+ */
10
+ activeColor?: string;
11
+ /**
12
+ * Start label
13
+ */
14
+ startLabel: string;
15
+ /**
16
+ * End label
17
+ */
18
+ endLabel: string;
19
+ }
20
+ /**
21
+ * Ant style switch
22
+ * @param props Props
23
+ * @returns Component
24
+ */
25
+ export declare function SwitchAnt(props: SwitchAntProps): JSX.Element;
@@ -0,0 +1,40 @@
1
+ import { Stack, Typography } from '@mui/material';
2
+ import Switch from '@mui/material/Switch';
3
+ import React from 'react';
4
+ /**
5
+ * Ant style switch
6
+ * @param props Props
7
+ * @returns Component
8
+ */
9
+ export function SwitchAnt(props) {
10
+ var _a;
11
+ // Destruct
12
+ const { activeColor, checked, defaultChecked, defaultValue, endLabel, startLabel, onChange, value = 'true', ...rest } = props;
13
+ // Checked state
14
+ const [controlChecked, setControlChecked] = React.useState((_a = checked !== null && checked !== void 0 ? checked : defaultChecked) !== null && _a !== void 0 ? _a : defaultValue == value);
15
+ React.useEffect(() => {
16
+ if (checked)
17
+ setControlChecked(checked);
18
+ }, [checked]);
19
+ // On change
20
+ const onChangeLocal = (event, checked) => {
21
+ if (onChange)
22
+ onChange(event, checked);
23
+ setControlChecked(checked);
24
+ };
25
+ // Layout
26
+ return (React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
27
+ React.createElement(Typography, { onClick: () => setControlChecked(false), sx: {
28
+ cursor: 'pointer',
29
+ color: controlChecked
30
+ ? undefined
31
+ : (theme) => activeColor !== null && activeColor !== void 0 ? activeColor : theme.palette.warning.main
32
+ } }, startLabel),
33
+ React.createElement(Switch, { checked: controlChecked, value: value, onChange: onChangeLocal, ...rest }),
34
+ React.createElement(Typography, { onClick: () => setControlChecked(true), sx: {
35
+ cursor: 'pointer',
36
+ color: controlChecked
37
+ ? (theme) => activeColor !== null && activeColor !== void 0 ? activeColor : theme.palette.warning.main
38
+ : undefined
39
+ } }, endLabel)));
40
+ }
@@ -0,0 +1,54 @@
1
+ import { BoxProps, TabProps, TabsProps } from '@mui/material';
2
+ import React from 'react';
3
+ /**
4
+ * Tab with box panel props
5
+ */
6
+ export interface TabBoxPanel extends Omit<TabProps, 'value' | 'children'> {
7
+ /**
8
+ * Children
9
+ */
10
+ children?: ((visible: boolean) => React.ReactNode) | React.ReactNode;
11
+ /**
12
+ * Panel box props
13
+ */
14
+ panel?: Omit<BoxProps, 'hidden'>;
15
+ /**
16
+ * To URL
17
+ */
18
+ to?: string;
19
+ }
20
+ /**
21
+ * Tabs with box props
22
+ */
23
+ export interface TabBoxPros extends BoxProps {
24
+ /**
25
+ * Container props
26
+ */
27
+ container?: Omit<TabsProps, 'value'>;
28
+ /**
29
+ * Default selected index
30
+ */
31
+ defaultIndex?: number;
32
+ /**
33
+ * Current index
34
+ */
35
+ index?: number;
36
+ /**
37
+ * Add a hidden input and its name
38
+ */
39
+ inputName?: string;
40
+ /**
41
+ * Root props
42
+ */
43
+ root?: BoxProps;
44
+ /**
45
+ * Tabs
46
+ */
47
+ tabs: TabBoxPanel[];
48
+ }
49
+ /**
50
+ * Tabs with box
51
+ * @param props Props
52
+ * @returns Component
53
+ */
54
+ export declare function TabBox(props: TabBoxPros): JSX.Element;
package/lib/TabBox.js ADDED
@@ -0,0 +1,31 @@
1
+ import { Utils } from '@etsoo/shared';
2
+ import { Box, Tab, Tabs } from '@mui/material';
3
+ import React from 'react';
4
+ import { Link } from 'react-router-dom';
5
+ /**
6
+ * Tabs with box
7
+ * @param props Props
8
+ * @returns Component
9
+ */
10
+ export function TabBox(props) {
11
+ // Destruct
12
+ const { index, inputName, root, container = {}, defaultIndex = 0, tabs } = props;
13
+ const { onChange, ...rest } = container;
14
+ // State
15
+ const [value, setValue] = React.useState(defaultIndex);
16
+ React.useEffect(() => {
17
+ if (index == null)
18
+ return;
19
+ setValue(index);
20
+ }, [index]);
21
+ // Layout
22
+ return (React.createElement(React.Fragment, null,
23
+ inputName && (React.createElement("input", { type: "hidden", name: inputName, value: value })),
24
+ React.createElement(Box, { ...root },
25
+ React.createElement(Tabs, { value: value, onChange: (event, newValue) => {
26
+ setValue(newValue);
27
+ if (onChange)
28
+ onChange(event, newValue);
29
+ }, ...rest }, tabs.map(({ children, panel, ...tabRest }, index) => (React.createElement(Tab, { key: index, value: index, LinkComponent: tabRest.to ? Link : undefined, ...tabRest }))))),
30
+ tabs.map(({ children, panel }, index) => (React.createElement(Box, { key: index, hidden: value !== index, ...panel }, Utils.getResult(children, value === index))))));
31
+ }
@@ -0,0 +1,65 @@
1
+ import { GridColumn, GridLoader } from '@etsoo/react';
2
+ import { GridMethodRef } from '@etsoo/react/lib/components/GridMethodRef';
3
+ import { DataTypes, IdDefaultType } from '@etsoo/shared';
4
+ import { TableProps } from '@mui/material';
5
+ import React from 'react';
6
+ /**
7
+ * Extended table min width for width-unset column
8
+ */
9
+ export declare const TableExMinWidth: number;
10
+ /**
11
+ * Extended table methods ref
12
+ */
13
+ export interface TableExMethodRef<T> extends GridMethodRef<T> {
14
+ /**
15
+ * Refresh data
16
+ */
17
+ refresh(): void;
18
+ }
19
+ /**
20
+ * Extended table props
21
+ */
22
+ export declare type TableExProps<T extends object, D extends DataTypes.Keys<T>> = TableProps & GridLoader<T> & {
23
+ /**
24
+ * Alternating colors for odd/even rows
25
+ */
26
+ alternatingColors?: [string?, string?];
27
+ /**
28
+ * Columns
29
+ */
30
+ columns: GridColumn<T>[];
31
+ /**
32
+ * Header cells background color and font color
33
+ */
34
+ headerColors?: [string?, string?];
35
+ /**
36
+ * Id field
37
+ */
38
+ idField?: D;
39
+ /**
40
+ * Max height
41
+ */
42
+ maxHeight?: number;
43
+ /**
44
+ * Methods
45
+ */
46
+ mRef?: React.Ref<TableExMethodRef<T>>;
47
+ /**
48
+ * On items select change
49
+ */
50
+ onSelectChange?: (selectedItems: T[]) => void;
51
+ /**
52
+ * Row height
53
+ */
54
+ rowHeight?: number;
55
+ /**
56
+ * Header and bottom height
57
+ */
58
+ otherHeight?: number;
59
+ };
60
+ /**
61
+ * Extended Table
62
+ * @param props Props
63
+ * @returns Component
64
+ */
65
+ export declare function TableEx<T extends object, D extends DataTypes.Keys<T> = IdDefaultType<T>>(props: TableExProps<T, D>): JSX.Element;