@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.
- package/.eslintignore +3 -0
- package/.eslintrc.json +38 -0
- package/.gitattributes +2 -0
- package/.github/workflows/main.yml +48 -0
- package/.prettierignore +5 -0
- package/.prettierrc +6 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/__tests__/ComboBox.tsx +30 -0
- package/__tests__/MUGlobalTests.tsx +58 -0
- package/__tests__/NotifierMUTests.tsx +217 -0
- package/__tests__/SelectEx.tsx +26 -0
- package/__tests__/tsconfig.json +19 -0
- package/babel.config.json +11 -0
- package/lib/AuditDisplay.d.ts +33 -0
- package/lib/AuditDisplay.js +52 -0
- package/lib/AutocompleteExtendedProps.d.ts +64 -0
- package/lib/AutocompleteExtendedProps.js +1 -0
- package/lib/BackButton.d.ts +13 -0
- package/lib/BackButton.js +33 -0
- package/lib/BridgeCloseButton.d.ts +23 -0
- package/lib/BridgeCloseButton.js +32 -0
- package/lib/ButtonLink.d.ts +17 -0
- package/lib/ButtonLink.js +19 -0
- package/lib/ComboBox.d.ts +38 -0
- package/lib/ComboBox.js +108 -0
- package/lib/CountdownButton.d.ts +23 -0
- package/lib/CountdownButton.js +81 -0
- package/lib/CustomFabProps.d.ts +27 -0
- package/lib/CustomFabProps.js +1 -0
- package/lib/DataGridEx.d.ts +94 -0
- package/lib/DataGridEx.js +329 -0
- package/lib/DataGridRenderers.d.ts +22 -0
- package/lib/DataGridRenderers.js +99 -0
- package/lib/DialogButton.d.ts +54 -0
- package/lib/DialogButton.js +45 -0
- package/lib/DnDList.d.ts +87 -0
- package/lib/DnDList.js +153 -0
- package/lib/DraggablePaperComponent.d.ts +8 -0
- package/lib/DraggablePaperComponent.js +12 -0
- package/lib/EmailInput.d.ts +11 -0
- package/lib/EmailInput.js +15 -0
- package/lib/FabBox.d.ts +21 -0
- package/lib/FabBox.js +31 -0
- package/lib/FlexBox.d.ts +14 -0
- package/lib/FlexBox.js +18 -0
- package/lib/GridDataFormat.d.ts +10 -0
- package/lib/GridDataFormat.js +43 -0
- package/lib/IconButtonLink.d.ts +17 -0
- package/lib/IconButtonLink.js +16 -0
- package/lib/InputField.d.ts +21 -0
- package/lib/InputField.js +39 -0
- package/lib/ItemList.d.ts +56 -0
- package/lib/ItemList.js +69 -0
- package/lib/ListItemRightIcon.d.ts +4 -0
- package/lib/ListItemRightIcon.js +8 -0
- package/lib/ListMoreDisplay.d.ts +35 -0
- package/lib/ListMoreDisplay.js +99 -0
- package/lib/LoadingButton.d.ts +16 -0
- package/lib/LoadingButton.js +41 -0
- package/lib/MUGlobal.d.ts +102 -0
- package/lib/MUGlobal.js +184 -0
- package/lib/MaskInput.d.ts +34 -0
- package/lib/MaskInput.js +43 -0
- package/lib/MobileListItemRenderer.d.ts +17 -0
- package/lib/MobileListItemRenderer.js +35 -0
- package/lib/MoreFab.d.ts +45 -0
- package/lib/MoreFab.js +95 -0
- package/lib/NotifierMU.d.ts +47 -0
- package/lib/NotifierMU.js +387 -0
- package/lib/NotifierPromptProps.d.ts +22 -0
- package/lib/NotifierPromptProps.js +1 -0
- package/lib/OptionGroup.d.ts +58 -0
- package/lib/OptionGroup.js +81 -0
- package/lib/PList.d.ts +15 -0
- package/lib/PList.js +12 -0
- package/lib/ProgressCount.d.ts +44 -0
- package/lib/ProgressCount.js +79 -0
- package/lib/PullToRefreshUI.d.ts +9 -0
- package/lib/PullToRefreshUI.js +18 -0
- package/lib/RLink.d.ts +14 -0
- package/lib/RLink.js +37 -0
- package/lib/ResponsibleContainer.d.ts +87 -0
- package/lib/ResponsibleContainer.js +156 -0
- package/lib/ScrollTopFab.d.ts +7 -0
- package/lib/ScrollTopFab.js +25 -0
- package/lib/ScrollerListEx.d.ts +81 -0
- package/lib/ScrollerListEx.js +167 -0
- package/lib/SearchBar.d.ts +29 -0
- package/lib/SearchBar.js +260 -0
- package/lib/SearchField.d.ts +21 -0
- package/lib/SearchField.js +39 -0
- package/lib/SearchOptionGroup.d.ts +9 -0
- package/lib/SearchOptionGroup.js +14 -0
- package/lib/SelectBool.d.ts +13 -0
- package/lib/SelectBool.js +22 -0
- package/lib/SelectEx.d.ts +50 -0
- package/lib/SelectEx.js +156 -0
- package/lib/ShowDataComparison.d.ts +20 -0
- package/lib/ShowDataComparison.js +58 -0
- package/lib/Switch.d.ts +29 -0
- package/lib/Switch.js +34 -0
- package/lib/SwitchAnt.d.ts +25 -0
- package/lib/SwitchAnt.js +40 -0
- package/lib/TabBox.d.ts +54 -0
- package/lib/TabBox.js +31 -0
- package/lib/TableEx.d.ts +65 -0
- package/lib/TableEx.js +270 -0
- package/lib/TextFieldEx.d.ts +101 -0
- package/lib/TextFieldEx.js +126 -0
- package/lib/Tiplist.d.ts +18 -0
- package/lib/Tiplist.js +157 -0
- package/lib/TooltipClick.d.ts +15 -0
- package/lib/TooltipClick.js +40 -0
- package/lib/UserAvatar.d.ts +24 -0
- package/lib/UserAvatar.js +25 -0
- package/lib/UserAvatarEditor.d.ts +53 -0
- package/lib/UserAvatarEditor.js +129 -0
- package/lib/app/CommonApp.d.ts +38 -0
- package/lib/app/CommonApp.js +149 -0
- package/lib/app/IServiceAppSettings.d.ts +11 -0
- package/lib/app/IServiceAppSettings.js +1 -0
- package/lib/app/IServicePage.d.ts +6 -0
- package/lib/app/IServicePage.js +1 -0
- package/lib/app/IServiceUser.d.ts +14 -0
- package/lib/app/IServiceUser.js +1 -0
- package/lib/app/ISmartERPUser.d.ts +14 -0
- package/lib/app/ISmartERPUser.js +1 -0
- package/lib/app/Labels.d.ts +65 -0
- package/lib/app/Labels.js +62 -0
- package/lib/app/ReactApp.d.ts +195 -0
- package/lib/app/ReactApp.js +296 -0
- package/lib/app/ServiceApp.d.ts +78 -0
- package/lib/app/ServiceApp.js +244 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.js +74 -0
- package/lib/pages/CommonPage.d.ts +11 -0
- package/lib/pages/CommonPage.js +60 -0
- package/lib/pages/CommonPageProps.d.ts +59 -0
- package/lib/pages/CommonPageProps.js +1 -0
- package/lib/pages/DataGridPage.d.ts +9 -0
- package/lib/pages/DataGridPage.js +79 -0
- package/lib/pages/DataGridPageProps.d.ts +17 -0
- package/lib/pages/DataGridPageProps.js +1 -0
- package/lib/pages/EditPage.d.ts +33 -0
- package/lib/pages/EditPage.js +29 -0
- package/lib/pages/FixedListPage.d.ts +15 -0
- package/lib/pages/FixedListPage.js +70 -0
- package/lib/pages/ListPage.d.ts +9 -0
- package/lib/pages/ListPage.js +50 -0
- package/lib/pages/ListPageProps.d.ts +7 -0
- package/lib/pages/ListPageProps.js +1 -0
- package/lib/pages/ResponsivePage.d.ts +9 -0
- package/lib/pages/ResponsivePage.js +45 -0
- package/lib/pages/ResponsivePageProps.d.ts +39 -0
- package/lib/pages/ResponsivePageProps.js +1 -0
- package/lib/pages/SearchPageProps.d.ts +30 -0
- package/lib/pages/SearchPageProps.js +1 -0
- package/lib/pages/TablePage.d.ts +9 -0
- package/lib/pages/TablePage.js +69 -0
- package/lib/pages/TablePageProps.d.ts +7 -0
- package/lib/pages/TablePageProps.js +1 -0
- package/lib/pages/ViewPage.d.ts +66 -0
- package/lib/pages/ViewPage.js +105 -0
- package/lib/texts/DateText.d.ts +34 -0
- package/lib/texts/DateText.js +25 -0
- package/lib/texts/MoneyText.d.ts +21 -0
- package/lib/texts/MoneyText.js +14 -0
- package/lib/texts/NumberText.d.ts +25 -0
- package/lib/texts/NumberText.js +14 -0
- package/package.json +97 -0
- package/src/AuditDisplay.tsx +114 -0
- package/src/AutocompleteExtendedProps.ts +83 -0
- package/src/BackButton.tsx +55 -0
- package/src/BridgeCloseButton.tsx +69 -0
- package/src/ButtonLink.tsx +32 -0
- package/src/ComboBox.tsx +251 -0
- package/src/CountdownButton.tsx +119 -0
- package/src/CustomFabProps.ts +32 -0
- package/src/DataGridEx.tsx +713 -0
- package/src/DataGridRenderers.tsx +140 -0
- package/src/DialogButton.tsx +163 -0
- package/src/DnDList.tsx +344 -0
- package/src/DraggablePaperComponent.tsx +19 -0
- package/src/EmailInput.tsx +24 -0
- package/src/FabBox.tsx +51 -0
- package/src/FlexBox.tsx +20 -0
- package/src/GridDataFormat.tsx +77 -0
- package/src/IconButtonLink.tsx +29 -0
- package/src/InputField.tsx +82 -0
- package/src/ItemList.tsx +204 -0
- package/src/ListItemRightIcon.tsx +9 -0
- package/src/ListMoreDisplay.tsx +205 -0
- package/src/LoadingButton.tsx +75 -0
- package/src/MUGlobal.ts +220 -0
- package/src/MaskInput.tsx +107 -0
- package/src/MobileListItemRenderer.tsx +79 -0
- package/src/MoreFab.tsx +211 -0
- package/src/NotifierMU.tsx +654 -0
- package/src/NotifierPromptProps.ts +24 -0
- package/src/OptionGroup.tsx +223 -0
- package/src/PList.tsx +27 -0
- package/src/ProgressCount.tsx +166 -0
- package/src/PullToRefreshUI.tsx +21 -0
- package/src/RLink.tsx +64 -0
- package/src/ResponsibleContainer.tsx +394 -0
- package/src/ScrollTopFab.tsx +34 -0
- package/src/ScrollerListEx.tsx +387 -0
- package/src/SearchBar.tsx +396 -0
- package/src/SearchField.tsx +82 -0
- package/src/SearchOptionGroup.tsx +31 -0
- package/src/SelectBool.tsx +33 -0
- package/src/SelectEx.tsx +290 -0
- package/src/ShowDataComparison.tsx +106 -0
- package/src/Switch.tsx +94 -0
- package/src/SwitchAnt.tsx +95 -0
- package/src/TabBox.tsx +118 -0
- package/src/TableEx.tsx +558 -0
- package/src/TextFieldEx.tsx +249 -0
- package/src/Tiplist.tsx +303 -0
- package/src/TooltipClick.tsx +84 -0
- package/src/UserAvatar.tsx +64 -0
- package/src/UserAvatarEditor.tsx +287 -0
- package/src/app/CommonApp.ts +223 -0
- package/src/app/IServiceAppSettings.ts +13 -0
- package/src/app/IServicePage.ts +6 -0
- package/src/app/IServiceUser.ts +17 -0
- package/src/app/ISmartERPUser.ts +16 -0
- package/src/app/Labels.ts +77 -0
- package/src/app/ReactApp.ts +504 -0
- package/src/app/ServiceApp.ts +352 -0
- package/src/index.ts +77 -0
- package/src/pages/CommonPage.tsx +128 -0
- package/src/pages/CommonPageProps.ts +70 -0
- package/src/pages/DataGridPage.tsx +140 -0
- package/src/pages/DataGridPageProps.ts +24 -0
- package/src/pages/EditPage.tsx +114 -0
- package/src/pages/FixedListPage.tsx +141 -0
- package/src/pages/ListPage.tsx +90 -0
- package/src/pages/ListPageProps.ts +12 -0
- package/src/pages/ResponsivePage.tsx +68 -0
- package/src/pages/ResponsivePageProps.ts +57 -0
- package/src/pages/SearchPageProps.ts +39 -0
- package/src/pages/TablePage.tsx +126 -0
- package/src/pages/TablePageProps.ts +12 -0
- package/src/pages/ViewPage.tsx +282 -0
- package/src/texts/DateText.tsx +74 -0
- package/src/texts/MoneyText.tsx +49 -0
- package/src/texts/NumberText.tsx +40 -0
- package/tsconfig.json +19 -0
package/lib/DnDList.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { DndContext } from '@dnd-kit/core';
|
|
2
|
+
import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
3
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
4
|
+
import { useTheme } from '@mui/material';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
function SortableItem(props) {
|
|
7
|
+
// Destruct
|
|
8
|
+
const { id, itemRenderer, style = {} } = props;
|
|
9
|
+
// Use sortable
|
|
10
|
+
const { attributes, listeners, setNodeRef, transform, transition, setActivatorNodeRef } = useSortable({ id });
|
|
11
|
+
const allStyle = {
|
|
12
|
+
...style,
|
|
13
|
+
transform: CSS.Transform.toString(transform),
|
|
14
|
+
transition
|
|
15
|
+
};
|
|
16
|
+
const nodeRef = {
|
|
17
|
+
style: allStyle,
|
|
18
|
+
ref: setNodeRef,
|
|
19
|
+
...attributes
|
|
20
|
+
};
|
|
21
|
+
const actionNodeRef = {
|
|
22
|
+
...listeners,
|
|
23
|
+
ref: setActivatorNodeRef
|
|
24
|
+
};
|
|
25
|
+
return itemRenderer(nodeRef, actionNodeRef);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* DnD item default style
|
|
29
|
+
* @param index Item index
|
|
30
|
+
* @param isDragging Is dragging
|
|
31
|
+
* @param theme Theme
|
|
32
|
+
* @returns Style
|
|
33
|
+
*/
|
|
34
|
+
export const DnDItemStyle = (index, isDragging, theme) => ({
|
|
35
|
+
padding: theme.spacing(1),
|
|
36
|
+
zIndex: isDragging ? 1 : 'auto',
|
|
37
|
+
background: isDragging
|
|
38
|
+
? theme.palette.primary.light
|
|
39
|
+
: index % 2 === 0
|
|
40
|
+
? theme.palette.grey[100]
|
|
41
|
+
: theme.palette.grey[50]
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* DnD (Drag and Drop) sortable list
|
|
45
|
+
* @param props Props
|
|
46
|
+
* @returns Component
|
|
47
|
+
*/
|
|
48
|
+
export function DnDList(props) {
|
|
49
|
+
// Destruct
|
|
50
|
+
const { keyField, itemRenderer, labelField, mRef, onChange, onDragEnd } = props;
|
|
51
|
+
let getItemStyle = props.getItemStyle;
|
|
52
|
+
if (getItemStyle == null) {
|
|
53
|
+
// Theme
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
getItemStyle = (index, isDragging) => DnDItemStyle(index, isDragging, theme);
|
|
56
|
+
}
|
|
57
|
+
// States
|
|
58
|
+
const [items, setItems] = React.useState([]);
|
|
59
|
+
const [activeId, setActiveId] = React.useState();
|
|
60
|
+
const changeItems = (newItems) => {
|
|
61
|
+
// Possible to alter items with the handler
|
|
62
|
+
if (onChange)
|
|
63
|
+
onChange(newItems);
|
|
64
|
+
// Update state
|
|
65
|
+
setItems(newItems);
|
|
66
|
+
};
|
|
67
|
+
// Drag event handlers
|
|
68
|
+
function handleDragStart(event) {
|
|
69
|
+
const { active } = event;
|
|
70
|
+
setActiveId(active.id);
|
|
71
|
+
}
|
|
72
|
+
function handleDragEnd(event) {
|
|
73
|
+
const { active, over } = event;
|
|
74
|
+
if (over && active.id !== over.id) {
|
|
75
|
+
// Indices
|
|
76
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
77
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
78
|
+
// Clone
|
|
79
|
+
const newItems = [...items];
|
|
80
|
+
// Removed item
|
|
81
|
+
const [removed] = newItems.splice(oldIndex, 1);
|
|
82
|
+
// Insert to the destination index
|
|
83
|
+
newItems.splice(newIndex, 0, removed);
|
|
84
|
+
changeItems(newItems);
|
|
85
|
+
// Drag end handler
|
|
86
|
+
if (onDragEnd)
|
|
87
|
+
onDragEnd(newItems);
|
|
88
|
+
}
|
|
89
|
+
setActiveId(undefined);
|
|
90
|
+
}
|
|
91
|
+
// Methods
|
|
92
|
+
React.useImperativeHandle(mRef, () => {
|
|
93
|
+
return {
|
|
94
|
+
addItem(newItem) {
|
|
95
|
+
// Existence check
|
|
96
|
+
if (items.some((item) => item[labelField] === newItem[labelField])) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// Clone
|
|
100
|
+
const newItems = [newItem, ...items];
|
|
101
|
+
// Update the state
|
|
102
|
+
changeItems(newItems);
|
|
103
|
+
return true;
|
|
104
|
+
},
|
|
105
|
+
addItems(inputItems) {
|
|
106
|
+
// Clone
|
|
107
|
+
const newItems = [...items];
|
|
108
|
+
// Insert items
|
|
109
|
+
inputItems.forEach((newItem) => {
|
|
110
|
+
// Existence check
|
|
111
|
+
if (newItems.some((item) => item[labelField] === newItem[labelField])) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
newItems.push(newItem);
|
|
115
|
+
});
|
|
116
|
+
// Update the state
|
|
117
|
+
changeItems(newItems);
|
|
118
|
+
return newItems.length - items.length;
|
|
119
|
+
},
|
|
120
|
+
editItem(newItem, index) {
|
|
121
|
+
// Existence check
|
|
122
|
+
const newIndex = items.findIndex((item) => item[labelField] === newItem[labelField]);
|
|
123
|
+
if (newIndex >= 0 && newIndex !== index) {
|
|
124
|
+
// Label field is the same with a different item
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
// Clone
|
|
128
|
+
const newItems = [...items];
|
|
129
|
+
// Remove the item
|
|
130
|
+
newItems.splice(index, 1, newItem);
|
|
131
|
+
// Update the state
|
|
132
|
+
changeItems(newItems);
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
deleteItem(index) {
|
|
136
|
+
// Clone
|
|
137
|
+
const newItems = [...items];
|
|
138
|
+
// Remove the item
|
|
139
|
+
newItems.splice(index, 1);
|
|
140
|
+
// Update the state
|
|
141
|
+
changeItems(newItems);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}, [items]);
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
setItems(props.items);
|
|
147
|
+
}, [props.items]);
|
|
148
|
+
return (React.createElement(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd },
|
|
149
|
+
React.createElement(SortableContext, { items: items, strategy: verticalListSortingStrategy }, items.map((item, index) => {
|
|
150
|
+
const id = item[keyField];
|
|
151
|
+
return (React.createElement(SortableItem, { id: id, key: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }));
|
|
152
|
+
}))));
|
|
153
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Paper } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Draggable from 'react-draggable';
|
|
4
|
+
/**
|
|
5
|
+
* Draggable paper component
|
|
6
|
+
* @param props Props
|
|
7
|
+
* @returns Component
|
|
8
|
+
*/
|
|
9
|
+
export function DraggablePaperComponent(props) {
|
|
10
|
+
return (React.createElement(Draggable, { handle: ".draggable-dialog-title", cancel: '[class*="MuiDialogContent-root"]' },
|
|
11
|
+
React.createElement(Paper, { ...props })));
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TextFieldProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* Email input props
|
|
5
|
+
*/
|
|
6
|
+
export declare type EmailInputProps = Omit<TextFieldProps, 'type'> & {};
|
|
7
|
+
/**
|
|
8
|
+
* Email input
|
|
9
|
+
* @param props Props
|
|
10
|
+
*/
|
|
11
|
+
export declare function EmailInput(props: EmailInputProps): JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TextField } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Email input
|
|
5
|
+
* @param props Props
|
|
6
|
+
*/
|
|
7
|
+
export function EmailInput(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
// Destruct
|
|
10
|
+
const { inputProps = {}, ...rest } = props;
|
|
11
|
+
// Default max length
|
|
12
|
+
(_a = inputProps.maxLength) !== null && _a !== void 0 ? _a : (inputProps.maxLength = 128);
|
|
13
|
+
// Layout
|
|
14
|
+
return (React.createElement(TextField, { type: "email", fullWidth: true, inputProps: inputProps, ...rest }));
|
|
15
|
+
}
|
package/lib/FabBox.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BoxProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* Fabs container box props
|
|
5
|
+
*/
|
|
6
|
+
export declare type FabBoxProps = BoxProps & {
|
|
7
|
+
/**
|
|
8
|
+
* Item gap
|
|
9
|
+
*/
|
|
10
|
+
itemGap?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Flex direction, row or column
|
|
13
|
+
*/
|
|
14
|
+
columnDirection?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Fabs container box
|
|
18
|
+
* @param props Props
|
|
19
|
+
* @returns Component
|
|
20
|
+
*/
|
|
21
|
+
export declare function FabBox(props: FabBoxProps): JSX.Element;
|
package/lib/FabBox.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Box, useTheme } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Fabs container box
|
|
5
|
+
* @param props Props
|
|
6
|
+
* @returns Component
|
|
7
|
+
*/
|
|
8
|
+
export function FabBox(props) {
|
|
9
|
+
// Destruct
|
|
10
|
+
const { columnDirection, itemGap = 1, sx = {}, ...rest } = props;
|
|
11
|
+
// Theme
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
const spaceGap = theme.spacing(itemGap);
|
|
14
|
+
if (columnDirection == null)
|
|
15
|
+
return React.createElement(React.Fragment, null);
|
|
16
|
+
// margin
|
|
17
|
+
const margin = columnDirection
|
|
18
|
+
? { marginTop: spaceGap }
|
|
19
|
+
: { marginLeft: spaceGap };
|
|
20
|
+
// Default style
|
|
21
|
+
if (typeof sx === 'object') {
|
|
22
|
+
Object.assign(sx, {
|
|
23
|
+
position: 'fixed',
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
flexDirection: columnDirection ? 'column' : 'row',
|
|
27
|
+
'& > :not(style) + :not(style)': margin
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return React.createElement(Box, { sx: sx, ...rest });
|
|
31
|
+
}
|
package/lib/FlexBox.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StackProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* Horizonal box
|
|
5
|
+
* @param props Props
|
|
6
|
+
* @returns Component
|
|
7
|
+
*/
|
|
8
|
+
export declare function HBox(props: Omit<StackProps, 'ref'>): JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* Vertial box
|
|
11
|
+
* @param props Props
|
|
12
|
+
* @returns Component
|
|
13
|
+
*/
|
|
14
|
+
export declare function VBox(props: Omit<StackProps, 'ref'>): JSX.Element;
|
package/lib/FlexBox.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Stack } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Horizonal box
|
|
5
|
+
* @param props Props
|
|
6
|
+
* @returns Component
|
|
7
|
+
*/
|
|
8
|
+
export function HBox(props) {
|
|
9
|
+
return React.createElement(Stack, { direction: "row", width: "100%", ...props });
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Vertial box
|
|
13
|
+
* @param props Props
|
|
14
|
+
* @returns Component
|
|
15
|
+
*/
|
|
16
|
+
export function VBox(props) {
|
|
17
|
+
return React.createElement(Stack, { direction: "column", ...props });
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GridColumnRenderProps, GridDataType } from '@etsoo/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Grid data format
|
|
5
|
+
* @param data Input data
|
|
6
|
+
* @param type Data type
|
|
7
|
+
* @param renderProps Render props
|
|
8
|
+
* @returns Result
|
|
9
|
+
*/
|
|
10
|
+
export declare function GridDataFormat(data: unknown, type: GridDataType, renderProps?: GridColumnRenderProps): React.ReactNode;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GridDataType } from '@etsoo/react';
|
|
2
|
+
import { DateUtils, NumberUtils } from '@etsoo/shared';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { DateText } from './texts/DateText';
|
|
5
|
+
/**
|
|
6
|
+
* Grid data format
|
|
7
|
+
* @param data Input data
|
|
8
|
+
* @param type Data type
|
|
9
|
+
* @param renderProps Render props
|
|
10
|
+
* @returns Result
|
|
11
|
+
*/
|
|
12
|
+
export function GridDataFormat(data, type, renderProps) {
|
|
13
|
+
// Null
|
|
14
|
+
if (data == null)
|
|
15
|
+
return undefined;
|
|
16
|
+
// For date time
|
|
17
|
+
// Conversion if necessary
|
|
18
|
+
if (type === GridDataType.Date || type === GridDataType.DateTime) {
|
|
19
|
+
const dateValue = data instanceof Date
|
|
20
|
+
? data
|
|
21
|
+
: typeof data === 'number' || typeof data === 'string'
|
|
22
|
+
? new Date(data)
|
|
23
|
+
: undefined;
|
|
24
|
+
if (dateValue == null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const option = type === GridDataType.DateTime ? 'ds' : 'd';
|
|
27
|
+
const nearDays = renderProps === null || renderProps === void 0 ? void 0 : renderProps.nearDays;
|
|
28
|
+
if (nearDays != null) {
|
|
29
|
+
return (React.createElement(DateText, { value: dateValue, locale: renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, timeZone: renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone, options: option, nearDays: nearDays }));
|
|
30
|
+
}
|
|
31
|
+
return DateUtils.format(dateValue, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, option, renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone);
|
|
32
|
+
}
|
|
33
|
+
// For numbers
|
|
34
|
+
if (typeof data === 'number') {
|
|
35
|
+
if (type === GridDataType.Money || type === GridDataType.IntMoney)
|
|
36
|
+
return NumberUtils.formatMoney(data, renderProps === null || renderProps === void 0 ? void 0 : renderProps.currency, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, type === GridDataType.IntMoney, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
37
|
+
else
|
|
38
|
+
return NumberUtils.format(data, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
39
|
+
}
|
|
40
|
+
if (typeof data === 'string')
|
|
41
|
+
return data;
|
|
42
|
+
return `${data}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconButtonProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* IconButtonLink props
|
|
5
|
+
*/
|
|
6
|
+
export declare type IconButtonLinkProps = Omit<IconButtonProps, 'href' | 'onClick'> & {
|
|
7
|
+
/**
|
|
8
|
+
* To href
|
|
9
|
+
*/
|
|
10
|
+
href: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* IconButtonLink
|
|
14
|
+
* @param props Props
|
|
15
|
+
* @returns Component
|
|
16
|
+
*/
|
|
17
|
+
export declare function IconButtonLink(props: IconButtonLinkProps): JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconButton } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
/**
|
|
5
|
+
* IconButtonLink
|
|
6
|
+
* @param props Props
|
|
7
|
+
* @returns Component
|
|
8
|
+
*/
|
|
9
|
+
export function IconButtonLink(props) {
|
|
10
|
+
// Destruct
|
|
11
|
+
const { href, ...rest } = props;
|
|
12
|
+
// Navigate
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
// Layout
|
|
15
|
+
return React.createElement(IconButton, { ...rest, onClick: () => navigate(href) });
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TextFieldProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* Input field props
|
|
5
|
+
*/
|
|
6
|
+
export declare type InputFieldProps = TextFieldProps & {
|
|
7
|
+
/**
|
|
8
|
+
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
9
|
+
*/
|
|
10
|
+
changeDelay?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Is the field read only?
|
|
13
|
+
*/
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Input field
|
|
18
|
+
* @param props Props
|
|
19
|
+
* @returns Component
|
|
20
|
+
*/
|
|
21
|
+
export declare function InputField(props: InputFieldProps): JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useDelayedExecutor } from '@etsoo/react';
|
|
2
|
+
import { TextField } from '@mui/material';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { MUGlobal } from './MUGlobal';
|
|
5
|
+
/**
|
|
6
|
+
* Input field
|
|
7
|
+
* @param props Props
|
|
8
|
+
* @returns Component
|
|
9
|
+
*/
|
|
10
|
+
export function InputField(props) {
|
|
11
|
+
// Destruct
|
|
12
|
+
const { changeDelay, InputLabelProps = {}, InputProps = {}, onChange, readOnly, size = MUGlobal.inputFieldSize, variant = MUGlobal.inputFieldVariant, ...rest } = props;
|
|
13
|
+
// Shrink
|
|
14
|
+
InputLabelProps.shrink = MUGlobal.searchFieldShrink;
|
|
15
|
+
// Read only
|
|
16
|
+
if (readOnly != null)
|
|
17
|
+
InputProps.readOnly = readOnly;
|
|
18
|
+
const isMounted = React.useRef(true);
|
|
19
|
+
const delayed = onChange != null && changeDelay != null && changeDelay >= 1
|
|
20
|
+
? useDelayedExecutor(onChange, changeDelay)
|
|
21
|
+
: undefined;
|
|
22
|
+
const onChangeEx = (event) => {
|
|
23
|
+
if (onChange == null)
|
|
24
|
+
return;
|
|
25
|
+
if (changeDelay == null || changeDelay < 1) {
|
|
26
|
+
onChange(event);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
delayed === null || delayed === void 0 ? void 0 : delayed.call(undefined, event);
|
|
30
|
+
};
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
isMounted.current = false;
|
|
34
|
+
delayed === null || delayed === void 0 ? void 0 : delayed.clear();
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
// Layout
|
|
38
|
+
return (React.createElement(TextField, { InputLabelProps: InputLabelProps, InputProps: InputProps, onChange: onChangeEx, size: size, variant: variant, ...rest }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Item list properties
|
|
5
|
+
*/
|
|
6
|
+
export interface ItemListProps<T extends object, D extends DataTypes.Keys<T>, L extends DataTypes.Keys<T, string>> {
|
|
7
|
+
/**
|
|
8
|
+
* Style class name
|
|
9
|
+
*/
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Id field name
|
|
13
|
+
*/
|
|
14
|
+
idField?: D;
|
|
15
|
+
/**
|
|
16
|
+
* Label field name or callback
|
|
17
|
+
*/
|
|
18
|
+
labelField?: L | ((item: T) => string);
|
|
19
|
+
/**
|
|
20
|
+
* Button icon
|
|
21
|
+
*/
|
|
22
|
+
icon?: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Button color
|
|
25
|
+
*/
|
|
26
|
+
color?: 'inherit' | 'primary' | 'secondary';
|
|
27
|
+
/**
|
|
28
|
+
* Close event
|
|
29
|
+
*/
|
|
30
|
+
onClose?(item: T, changed: boolean): void;
|
|
31
|
+
/**
|
|
32
|
+
* Current selected language
|
|
33
|
+
*/
|
|
34
|
+
selectedValue?: T[D];
|
|
35
|
+
/**
|
|
36
|
+
* Button size
|
|
37
|
+
*/
|
|
38
|
+
size?: 'small' | 'medium' | 'large';
|
|
39
|
+
/**
|
|
40
|
+
* Title
|
|
41
|
+
*/
|
|
42
|
+
title?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Items
|
|
45
|
+
*/
|
|
46
|
+
items: T[];
|
|
47
|
+
/**
|
|
48
|
+
* Button variant
|
|
49
|
+
*/
|
|
50
|
+
variant?: 'text' | 'outlined' | 'contained';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Item list component
|
|
54
|
+
* @param props Properties
|
|
55
|
+
*/
|
|
56
|
+
export declare function ItemList<T extends object = ListType, D extends DataTypes.Keys<T> = IdDefaultType<T>, L extends DataTypes.Keys<T, string> = LabelDefaultType<T>>(props: ItemListProps<T, D, L>): JSX.Element;
|
package/lib/ItemList.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Dialog, DialogTitle, List, ListItemText, DialogContent, Button, ListItemButton } from '@mui/material';
|
|
3
|
+
import { DataTypes } from '@etsoo/shared';
|
|
4
|
+
/**
|
|
5
|
+
* Item list component
|
|
6
|
+
* @param props Properties
|
|
7
|
+
*/
|
|
8
|
+
export function ItemList(props) {
|
|
9
|
+
var _a;
|
|
10
|
+
// properties destructure
|
|
11
|
+
const { className, color = 'primary', items, idField = 'id', labelField = 'label', icon, onClose, selectedValue, size = 'medium', title, variant = 'outlined' } = props;
|
|
12
|
+
// Get label
|
|
13
|
+
const getLabel = (item) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (typeof labelField === 'function') {
|
|
16
|
+
return labelField(item);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return (_a = DataTypes.convert(item[labelField], 'string')) !== null && _a !== void 0 ? _a : '';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
// Dialog open or not state
|
|
23
|
+
const [open, setOpen] = React.useState(false);
|
|
24
|
+
// Default state
|
|
25
|
+
const defaultItem = (_a = items.find((item) => item[idField] === selectedValue)) !== null && _a !== void 0 ? _a : items[0];
|
|
26
|
+
// Current item
|
|
27
|
+
const [currentItem, setCurrentItem] = React.useState(defaultItem);
|
|
28
|
+
// Click handler
|
|
29
|
+
const clickHandler = () => {
|
|
30
|
+
// More than one language
|
|
31
|
+
if (items.length < 2) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Open the dialog
|
|
35
|
+
setOpen(true);
|
|
36
|
+
};
|
|
37
|
+
// Close handler
|
|
38
|
+
const closeHandler = () => {
|
|
39
|
+
if (!open)
|
|
40
|
+
return;
|
|
41
|
+
// Close the dialog
|
|
42
|
+
setOpen(false);
|
|
43
|
+
// Emit close event
|
|
44
|
+
if (onClose) {
|
|
45
|
+
onClose(currentItem, false);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// Close item handler
|
|
49
|
+
const closeItemHandler = (item) => {
|
|
50
|
+
// Update the current item
|
|
51
|
+
setCurrentItem(item);
|
|
52
|
+
// Close the dialog
|
|
53
|
+
setOpen(false);
|
|
54
|
+
// Emit close event
|
|
55
|
+
if (onClose) {
|
|
56
|
+
onClose(item, true);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return (React.createElement(React.Fragment, null,
|
|
60
|
+
React.createElement(Button, { className: className, variant: variant, startIcon: icon, color: color, size: size, onClick: clickHandler }, getLabel(currentItem)),
|
|
61
|
+
React.createElement(Dialog, { "aria-labelledby": "dialog-title", open: open, onClose: closeHandler },
|
|
62
|
+
React.createElement(DialogTitle, { sx: { minWidth: '200px' }, id: "dialog-title" }, title || ''),
|
|
63
|
+
React.createElement(DialogContent, null,
|
|
64
|
+
React.createElement(List, null, items.map((item) => {
|
|
65
|
+
const id = item[idField];
|
|
66
|
+
return (React.createElement(ListItemButton, { key: id, disabled: id === currentItem[idField], onClick: () => closeItemHandler(item) },
|
|
67
|
+
React.createElement(ListItemText, null, getLabel(item))));
|
|
68
|
+
}))))));
|
|
69
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
|
+
import { CardProps } from '@mui/material';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { GridData, GridLoader } from '@etsoo/react';
|
|
5
|
+
/**
|
|
6
|
+
* ListMoreDisplay props
|
|
7
|
+
*/
|
|
8
|
+
export interface ListMoreDisplayProps<T extends object, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate> extends Omit<CardProps, 'children'>, GridLoader<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Children to display the list
|
|
11
|
+
*/
|
|
12
|
+
children: (data: T, index: number) => React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Search field template
|
|
15
|
+
*/
|
|
16
|
+
fieldTemplate?: F;
|
|
17
|
+
/**
|
|
18
|
+
* Header renderer
|
|
19
|
+
*/
|
|
20
|
+
headerRenderer?: (reset: (data?: GridData) => void) => React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Header title
|
|
23
|
+
*/
|
|
24
|
+
headerTitle?: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* More button label
|
|
27
|
+
*/
|
|
28
|
+
moreLabel?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* ListMoreDisplay
|
|
32
|
+
* @param props Props
|
|
33
|
+
* @returns Component
|
|
34
|
+
*/
|
|
35
|
+
export declare function ListMoreDisplay<T extends object, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate>(props: ListMoreDisplayProps<T, F>): JSX.Element;
|