@symply.io/basic-components 1.4.0 → 1.4.1-alpha.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/BasicModal/index.js +77 -12
- package/BasicModal/types.d.ts +5 -9
- package/README.md +3 -0
- package/package.json +1 -1
- package/BasicModal/Content.d.ts +0 -3
- package/BasicModal/Content.js +0 -37
package/BasicModal/index.js
CHANGED
@@ -9,6 +9,42 @@ var __assign = (this && this.__assign) || function () {
|
|
9
9
|
};
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19
|
+
});
|
20
|
+
};
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
25
|
+
function step(op) {
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
27
|
+
while (_) try {
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
30
|
+
switch (op[0]) {
|
31
|
+
case 0: case 1: t = op; break;
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
35
|
+
default:
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
40
|
+
if (t[2]) _.ops.pop();
|
41
|
+
_.trys.pop(); continue;
|
42
|
+
}
|
43
|
+
op = body.call(thisArg, _);
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
46
|
+
}
|
47
|
+
};
|
12
48
|
var __rest = (this && this.__rest) || function (s, e) {
|
13
49
|
var t = {};
|
14
50
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
@@ -20,32 +56,61 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
20
56
|
}
|
21
57
|
return t;
|
22
58
|
};
|
23
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
-
import { forwardRef } from "react";
|
59
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
60
|
+
import { useCallback, forwardRef, cloneElement, useRef } from "react";
|
25
61
|
import Grid from "@mui/material/Grid";
|
62
|
+
import Button from "@mui/material/Button";
|
26
63
|
import Dialog from "@mui/material/Dialog";
|
64
|
+
import IconButton from "@mui/material/IconButton";
|
65
|
+
import DialogTitle from "@mui/material/DialogTitle";
|
27
66
|
import Slide from "@mui/material/Slide";
|
28
67
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
68
|
+
import DialogContent from "@mui/material/DialogContent";
|
69
|
+
import DialogActions from "@mui/material/DialogActions";
|
70
|
+
import DialogContentText from "@mui/material/DialogContentText";
|
29
71
|
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
30
|
-
import
|
72
|
+
import CloseIcon from "@mui/icons-material/Close";
|
31
73
|
import useCustomTheme from "../useCustomTheme";
|
32
74
|
var Transition = forwardRef(function Transition(props, ref) {
|
33
75
|
return _jsx(Slide, __assign({ direction: "up" }, props, { ref: ref }));
|
34
76
|
});
|
35
77
|
function BasicModal(props) {
|
36
|
-
var
|
78
|
+
var _this = this;
|
79
|
+
var desc = props.desc, title = props.title, loading = props.loading, buttons = props.buttons, _a = props.open, open = _a === void 0 ? false : _a, _b = props.noForm, noForm = _b === void 0 ? false : _b, children = props.children, disabled = props.disabled, _c = props.maxWidth, maxWidth = _c === void 0 ? "sm" : _c, _d = props.color, color = _d === void 0 ? "primary" : _d, _e = props.submitText, submitText = _e === void 0 ? "Save" : _e, _f = props.cancelText, cancelText = _f === void 0 ? "Cancel" : _f, _g = props.hideBottomButtons, hideBottomButtons = _g === void 0 ? false : _g, _h = props.showTopRightCloseButton, showTopRightCloseButton = _h === void 0 ? false : _h, onClose = props.onClose, onSubmit = props.onSubmit, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["desc", "title", "loading", "buttons", "open", "noForm", "children", "disabled", "maxWidth", "color", "submitText", "cancelText", "hideBottomButtons", "showTopRightCloseButton", "onClose", "onSubmit", "primaryColor", "secondaryColor"]);
|
80
|
+
var formRef = useRef(null);
|
37
81
|
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
38
82
|
var fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
39
|
-
|
83
|
+
var onFormSubmit = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
84
|
+
var allValid;
|
85
|
+
return __generator(this, function (_a) {
|
86
|
+
switch (_a.label) {
|
87
|
+
case 0:
|
88
|
+
if (!formRef.current) return [3, 3];
|
89
|
+
allValid = formRef.current.checkValidity();
|
90
|
+
if (!!allValid) return [3, 1];
|
91
|
+
formRef.current.reportValidity();
|
92
|
+
return [3, 3];
|
93
|
+
case 1: return [4, onSubmit()];
|
94
|
+
case 2:
|
95
|
+
_a.sent();
|
96
|
+
_a.label = 3;
|
97
|
+
case 3: return [2];
|
98
|
+
}
|
99
|
+
});
|
100
|
+
}); }, []);
|
101
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsxs(Dialog, __assign({ disableEnforceFocus: true, open: open, onClose: function (_, reason) {
|
40
102
|
if (reason !== "backdropClick") {
|
41
103
|
onClose();
|
42
104
|
}
|
43
|
-
}, maxWidth: maxWidth, fullWidth: true, TransitionComponent: Transition, "aria-labelledby": "form-dialog-title", fullScreen: fullScreen, disableEscapeKeyDown: true }, { children:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
105
|
+
}, maxWidth: maxWidth, fullWidth: true, TransitionComponent: Transition, "aria-labelledby": "form-dialog-title", fullScreen: fullScreen, disableEscapeKeyDown: true }, rest, { children: [_jsxs(DialogTitle, __assign({ sx: {
|
106
|
+
"& > span": {
|
107
|
+
fontWeight: "700!important"
|
108
|
+
}
|
109
|
+
} }, { children: [_jsx("span", { children: title }), showTopRightCloseButton ? (_jsx(IconButton, __assign({ "aria-label": "close", onClick: onClose, sx: {
|
110
|
+
position: "absolute",
|
111
|
+
right: 8,
|
112
|
+
top: 8,
|
113
|
+
color: theme.palette.grey[500]
|
114
|
+
} }, { children: _jsx(CloseIcon, {}) }))) : (_jsx(_Fragment, {}))] })), _jsx(DialogContent, __assign({ sx: { paddingTop: theme.spacing(1.25) } }, { children: _jsxs(Grid, __assign({ component: noForm ? "div" : "form", ref: noForm ? undefined : formRef }, { children: [desc && _jsx(DialogContentText, { children: desc }), Boolean(children) && cloneElement(children)] })) })), !hideBottomButtons && (_jsx(DialogActions, __assign({ sx: { padding: theme.spacing(1.25) } }, { children: _jsx(Grid, __assign({ container: true, spacing: 2, justifyContent: "flex-end", alignItems: "center", sx: { margin: 0 } }, { children: buttons || (_jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ onClick: onClose, variant: "outlined", color: color, disabled: loading, fullWidth: true }, { children: cancelText })) })), _jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ type: noForm ? "button" : "submit", onClick: noForm ? onSubmit : onFormSubmit, variant: "contained", color: color, disabled: loading || disabled, fullWidth: true }, { children: submitText })) }))] })) })) })))] })) })));
|
50
115
|
}
|
51
116
|
export default BasicModal;
|
package/BasicModal/types.d.ts
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
import type { ReactNode, CSSProperties } from "react";
|
2
2
|
import type { ButtonProps } from "@mui/material/Button";
|
3
|
-
|
3
|
+
import type { DialogProps } from "@mui/material/Dialog";
|
4
|
+
export interface BasicModalProps extends DialogProps {
|
4
5
|
children: ReactNode;
|
5
6
|
color?: ButtonProps["color"];
|
6
|
-
title: string;
|
7
7
|
desc?: string;
|
8
8
|
loading?: boolean;
|
9
9
|
disabled?: boolean;
|
10
10
|
buttons?: ReactNode;
|
11
11
|
submitText?: string;
|
12
12
|
cancelText?: string;
|
13
|
-
showTopRightCloseButton?: boolean;
|
14
13
|
hideBottomButtons?: boolean;
|
15
14
|
noForm?: boolean;
|
16
|
-
onClose: () =>
|
17
|
-
onSubmit: () =>
|
18
|
-
}
|
19
|
-
export interface BasicModalProps extends BasicModalContentProps {
|
20
|
-
open?: boolean;
|
21
|
-
maxWidth?: "xs" | "sm" | "md" | "lg" | "xl";
|
15
|
+
onClose: () => unknown | Promise<unknown>;
|
16
|
+
onSubmit: () => unknown | Promise<unknown>;
|
22
17
|
primaryColor?: CSSProperties["color"];
|
23
18
|
secondaryColor?: CSSProperties["color"];
|
19
|
+
showTopRightCloseButton?: boolean;
|
24
20
|
}
|
package/README.md
CHANGED
@@ -176,6 +176,8 @@ import AutocompleteWithFilter from '@symply.io/basic-components/AutocompleteWith
|
|
176
176
|
|
177
177
|
Reusable modal component.
|
178
178
|
|
179
|
+
It is extended from `@mui/material/Dialog`, so it includes all properties of `@mui/material/Dialog`.
|
180
|
+
|
179
181
|
<h5>Import</h5>
|
180
182
|
|
181
183
|
```typescript
|
@@ -200,6 +202,7 @@ import BasicModal from '@symply.io/basic-components/BasicModal';
|
|
200
202
|
| onClose | func | | true | Callback fired when the cancel button requests to be clicked.<br />**Signature:**<br/>`function() => void` |
|
201
203
|
| onSubmit | func | | true | Callback fired when the submit button requests to be clicked.<br />**Signature:**<br/>`function() => void` |
|
202
204
|
| open | bool | false | true | If `true`, the component is shown. |
|
205
|
+
| scroll | 'body' \| 'paper' | 'paper' | false | Determine the container for scrolling the dialog. |
|
203
206
|
| showTopRightCloseButton | bool | false | false | If `true`, show a close icon button at the top right of the modal. |
|
204
207
|
| submitText | string | ‘Save’ | false | The text of the submit button. |
|
205
208
|
| title | string | | true | The title of the component, to show at the top left. |
|
package/package.json
CHANGED
package/BasicModal/Content.d.ts
DELETED
package/BasicModal/Content.js
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
13
|
-
import { cloneElement } from "react";
|
14
|
-
import useTheme from "@mui/material/styles/useTheme";
|
15
|
-
import DialogTitle from "@mui/material/DialogTitle";
|
16
|
-
import DialogContent from "@mui/material/DialogContent";
|
17
|
-
import DialogActions from "@mui/material/DialogActions";
|
18
|
-
import DialogContentText from "@mui/material/DialogContentText";
|
19
|
-
import Button from "@mui/material/Button";
|
20
|
-
import IconButton from "@mui/material/IconButton";
|
21
|
-
import CloseIcon from "@mui/icons-material/Close";
|
22
|
-
import Grid from "@mui/material/Grid";
|
23
|
-
function Content(props) {
|
24
|
-
var children = props.children, title = props.title, desc = props.desc, _a = props.color, color = _a === void 0 ? "primary" : _a, loading = props.loading, disabled = props.disabled, buttons = props.buttons, _b = props.submitText, submitText = _b === void 0 ? "Save" : _b, _c = props.cancelText, cancelText = _c === void 0 ? "Cancel" : _c, _d = props.showTopRightCloseButton, showTopRightCloseButton = _d === void 0 ? false : _d, _e = props.hideBottomButtons, hideBottomButtons = _e === void 0 ? false : _e, _f = props.noForm, noForm = _f === void 0 ? false : _f, onClose = props.onClose, onSubmit = props.onSubmit;
|
25
|
-
var theme = useTheme();
|
26
|
-
return (_jsxs(_Fragment, { children: [_jsxs(DialogTitle, __assign({ sx: {
|
27
|
-
"& > span": {
|
28
|
-
fontWeight: "700!important"
|
29
|
-
}
|
30
|
-
} }, { children: [_jsx("span", { children: title }), showTopRightCloseButton ? (_jsx(IconButton, __assign({ "aria-label": "close", onClick: onClose, sx: {
|
31
|
-
position: "absolute",
|
32
|
-
right: 8,
|
33
|
-
top: 8,
|
34
|
-
color: theme.palette.grey[500]
|
35
|
-
} }, { children: _jsx(CloseIcon, {}) }))) : null] })), _jsxs(DialogContent, __assign({ sx: { paddingTop: theme.spacing(1.25) } }, { children: [desc && _jsx(DialogContentText, { children: desc }), Boolean(children) && cloneElement(children)] })), !hideBottomButtons && (_jsx(DialogActions, __assign({ sx: { padding: theme.spacing(1.25) } }, { children: _jsx(Grid, __assign({ container: true, spacing: 2, justifyContent: "flex-end", alignItems: "center", sx: { margin: 0 } }, { children: buttons || (_jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ onClick: onClose, variant: "outlined", color: color, disabled: loading, fullWidth: true }, { children: cancelText })) })), _jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ type: noForm ? "button" : "submit", onClick: noForm ? onSubmit : undefined, variant: "contained", color: color, disabled: loading || disabled, fullWidth: true }, { children: submitText })) }))] })) })) })))] }));
|
36
|
-
}
|
37
|
-
export default Content;
|