@dashadmin/dash-dialog 1.3.25 → 1.3.28
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/README.md +30 -0
- package/dist/AppDialog.js +127 -1
- package/dist/DialogService.js +82 -1
- package/dist/index.js +10 -90
- package/package.json +132 -122
- package/src/AppDialog.tsx +97 -0
- package/src/DialogService.tsx +88 -0
- package/src/IAppDialogProps.ts +39 -0
- package/src/index.ts +7 -0
package/README.md
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @dashadmin/dash-dialog
|
|
2
|
+
|
|
3
|
+
> Dialog components for Dash (AppDialog and friends).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Reusable dialog primitives such as `AppDialog` used for confirmations and modal content.
|
|
8
|
+
|
|
9
|
+
## Key exports & features
|
|
10
|
+
|
|
11
|
+
- `AppDialog` component
|
|
12
|
+
- Composable dialog primitives
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# From the public npm registry
|
|
18
|
+
npm install @dashadmin/dash-dialog
|
|
19
|
+
|
|
20
|
+
# Or the local Verdaccio registry (unscoped)
|
|
21
|
+
npm install dash-dialog --registry http://localhost:4873
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Development & publishing
|
|
25
|
+
|
|
26
|
+
This package is part of the **dash-frontend-core** monorepo. See [`DEVELOPMENT.md`](../../DEVELOPMENT.md) for the source-modification workflow, local Verdaccio publishing, npm publishing and version-bump policy.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
_Part of the [Dash Framework](https://www.npmjs.com/org/dashadmin) · `@dashadmin` scope._
|
package/dist/AppDialog.js
CHANGED
|
@@ -1 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
import * as React from "react";
|
|
34
|
+
import {
|
|
35
|
+
Dialog,
|
|
36
|
+
DialogTitle,
|
|
37
|
+
DialogContent,
|
|
38
|
+
DialogActions,
|
|
39
|
+
Button,
|
|
40
|
+
Paper
|
|
41
|
+
} from "@mui/material";
|
|
42
|
+
const PaperComponent = (props) => {
|
|
43
|
+
return /* @__PURE__ */ jsx(Paper, __spreadValues({}, props));
|
|
44
|
+
};
|
|
45
|
+
const AppDialog = (props) => {
|
|
46
|
+
const _a = props, {
|
|
47
|
+
onClose,
|
|
48
|
+
onConfirm,
|
|
49
|
+
onCancel,
|
|
50
|
+
open,
|
|
51
|
+
closeText = /* @__PURE__ */ jsx(Fragment, {}),
|
|
52
|
+
confirmText = /* @__PURE__ */ jsx(Fragment, {}),
|
|
53
|
+
cancelText = /* @__PURE__ */ jsx(Fragment, {}),
|
|
54
|
+
title,
|
|
55
|
+
variant,
|
|
56
|
+
className,
|
|
57
|
+
showCancelButton = false,
|
|
58
|
+
showConfirmButton = true,
|
|
59
|
+
dialogActions,
|
|
60
|
+
content,
|
|
61
|
+
children
|
|
62
|
+
} = _a, rest = __objRest(_a, [
|
|
63
|
+
"onClose",
|
|
64
|
+
"onConfirm",
|
|
65
|
+
"onCancel",
|
|
66
|
+
"open",
|
|
67
|
+
"closeText",
|
|
68
|
+
"confirmText",
|
|
69
|
+
"cancelText",
|
|
70
|
+
"title",
|
|
71
|
+
"variant",
|
|
72
|
+
"className",
|
|
73
|
+
"showCancelButton",
|
|
74
|
+
"showConfirmButton",
|
|
75
|
+
"dialogActions",
|
|
76
|
+
"content",
|
|
77
|
+
"children"
|
|
78
|
+
]);
|
|
79
|
+
const [isModalOpen, setIsModalOpen] = React.useState(open);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
setIsModalOpen(open);
|
|
82
|
+
}, [open]);
|
|
83
|
+
const handleOnClose = (_e) => {
|
|
84
|
+
setIsModalOpen(false);
|
|
85
|
+
if (onClose) {
|
|
86
|
+
onClose();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const handleOnCancel = (_e) => {
|
|
90
|
+
setIsModalOpen(false);
|
|
91
|
+
if (onCancel) {
|
|
92
|
+
onCancel();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const handleOnConfirm = (_e) => {
|
|
96
|
+
setIsModalOpen(false);
|
|
97
|
+
if (onConfirm) {
|
|
98
|
+
onConfirm();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return /* @__PURE__ */ jsxs(
|
|
102
|
+
Dialog,
|
|
103
|
+
__spreadProps(__spreadValues({
|
|
104
|
+
hideBackdrop: true,
|
|
105
|
+
disableEnforceFocus: true,
|
|
106
|
+
PaperComponent,
|
|
107
|
+
onClose: handleOnClose,
|
|
108
|
+
className,
|
|
109
|
+
open: isModalOpen
|
|
110
|
+
}, rest), {
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ jsx(DialogTitle, { id: "alert-dialog-title", children: title }),
|
|
113
|
+
/* @__PURE__ */ jsx(DialogContent, { children: children || content }),
|
|
114
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
115
|
+
dialogActions || /* @__PURE__ */ jsx(Fragment, {}),
|
|
116
|
+
showCancelButton === true ? /* @__PURE__ */ jsx(Button, { onClick: handleOnCancel, children: cancelText }) : /* @__PURE__ */ jsx(Fragment, {}),
|
|
117
|
+
showConfirmButton === true ? /* @__PURE__ */ jsx(Button, { onClick: handleOnConfirm, children: confirmText }) : /* @__PURE__ */ jsx(Fragment, {})
|
|
118
|
+
] })
|
|
119
|
+
]
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
var AppDialog_default = AppDialog;
|
|
124
|
+
export {
|
|
125
|
+
AppDialog,
|
|
126
|
+
AppDialog_default as default
|
|
127
|
+
};
|
package/dist/DialogService.js
CHANGED
|
@@ -1 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
import { AppDialog } from "./AppDialog";
|
|
22
|
+
import {
|
|
23
|
+
createContext,
|
|
24
|
+
useContext,
|
|
25
|
+
useState
|
|
26
|
+
} from "react";
|
|
27
|
+
import { Portal } from "@mui/material";
|
|
28
|
+
const DialogServiceContext = createContext(null);
|
|
29
|
+
const useDialog = () => useContext(DialogServiceContext);
|
|
30
|
+
const DialogServiceProvider = (props) => {
|
|
31
|
+
const { component, componentProps = {}, children } = props;
|
|
32
|
+
const DialogComponent = component || AppDialog;
|
|
33
|
+
const defaultState = {
|
|
34
|
+
open: false,
|
|
35
|
+
variant: "default",
|
|
36
|
+
content: "",
|
|
37
|
+
title: "",
|
|
38
|
+
children: null
|
|
39
|
+
};
|
|
40
|
+
const [dialogState, setDialogState] = useState(__spreadValues(__spreadValues({}, defaultState), componentProps));
|
|
41
|
+
const handleCancel = () => {
|
|
42
|
+
setDialogState(null);
|
|
43
|
+
if (dialogState.onCancel) {
|
|
44
|
+
dialogState.onCancel();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const handleClose = () => {
|
|
48
|
+
setDialogState(null);
|
|
49
|
+
if (dialogState.onClose) {
|
|
50
|
+
dialogState.onClose();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const handleConfirm = () => {
|
|
54
|
+
setDialogState(null);
|
|
55
|
+
if (dialogState.onConfirm) {
|
|
56
|
+
dialogState.onConfirm();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const exposedDialogHook = (options) => {
|
|
60
|
+
setDialogState(__spreadValues(__spreadValues(__spreadValues({}, dialogState), options), options ? { open: true } : { open: false }));
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
63
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(
|
|
64
|
+
DialogComponent,
|
|
65
|
+
__spreadProps(__spreadValues({
|
|
66
|
+
sx: { zIndex: 1e6 }
|
|
67
|
+
}, dialogState), {
|
|
68
|
+
onConfirm: () => handleConfirm(),
|
|
69
|
+
onClose: () => handleClose(),
|
|
70
|
+
onCancel: () => handleCancel()
|
|
71
|
+
})
|
|
72
|
+
) }),
|
|
73
|
+
/* @__PURE__ */ jsx(DialogServiceContext.Provider, { value: exposedDialogHook, children })
|
|
74
|
+
] });
|
|
75
|
+
};
|
|
76
|
+
var DialogService_default = DialogServiceProvider;
|
|
77
|
+
export {
|
|
78
|
+
DialogServiceContext,
|
|
79
|
+
DialogServiceProvider,
|
|
80
|
+
DialogService_default as default,
|
|
81
|
+
useDialog
|
|
82
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,92 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
onClose: i,
|
|
8
|
-
onConfirm: r,
|
|
9
|
-
onCancel: c,
|
|
10
|
-
open: a,
|
|
11
|
-
closeText: m = /* @__PURE__ */ e(o, {}),
|
|
12
|
-
confirmText: n = /* @__PURE__ */ e(o, {}),
|
|
13
|
-
cancelText: t = /* @__PURE__ */ e(o, {}),
|
|
14
|
-
title: C,
|
|
15
|
-
variant: p,
|
|
16
|
-
className: f,
|
|
17
|
-
showCancelButton: u = !1,
|
|
18
|
-
showConfirmButton: s = !0,
|
|
19
|
-
dialogActions: v,
|
|
20
|
-
content: S,
|
|
21
|
-
children: P,
|
|
22
|
-
...k
|
|
23
|
-
} = l, [B, d] = x.useState(a);
|
|
24
|
-
return x.useEffect(() => {
|
|
25
|
-
d(a);
|
|
26
|
-
}, [a]), /* @__PURE__ */ h(
|
|
27
|
-
j,
|
|
28
|
-
{
|
|
29
|
-
hideBackdrop: !0,
|
|
30
|
-
disableEnforceFocus: !0,
|
|
31
|
-
PaperComponent: b,
|
|
32
|
-
onClose: (g) => {
|
|
33
|
-
d(!1), i && i();
|
|
34
|
-
},
|
|
35
|
-
className: f,
|
|
36
|
-
open: B,
|
|
37
|
-
...k,
|
|
38
|
-
children: [
|
|
39
|
-
/* @__PURE__ */ e(w, { id: "alert-dialog-title", children: C }),
|
|
40
|
-
/* @__PURE__ */ e(E, { children: P || S }),
|
|
41
|
-
/* @__PURE__ */ h(F, { children: [
|
|
42
|
-
v || /* @__PURE__ */ e(o, {}),
|
|
43
|
-
u === !0 ? /* @__PURE__ */ e(D, { onClick: (g) => {
|
|
44
|
-
d(!1), c && c();
|
|
45
|
-
}, children: t }) : /* @__PURE__ */ e(o, {}),
|
|
46
|
-
s === !0 ? /* @__PURE__ */ e(D, { onClick: (g) => {
|
|
47
|
-
d(!1), r && r();
|
|
48
|
-
}, children: n }) : /* @__PURE__ */ e(o, {})
|
|
49
|
-
] })
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
}, O = T(null), J = () => _(O), K = (l) => {
|
|
54
|
-
const { component: i, componentProps: r = {}, children: c } = l, a = i || z, m = {
|
|
55
|
-
open: !1,
|
|
56
|
-
variant: "default",
|
|
57
|
-
content: "",
|
|
58
|
-
title: "",
|
|
59
|
-
children: null
|
|
60
|
-
}, [n, t] = A({ ...m, ...r }), C = () => {
|
|
61
|
-
t(null), n.onCancel && n.onCancel();
|
|
62
|
-
}, p = () => {
|
|
63
|
-
t(null), n.onClose && n.onClose();
|
|
64
|
-
}, f = () => {
|
|
65
|
-
t(null), n.onConfirm && n.onConfirm();
|
|
66
|
-
}, u = (s) => {
|
|
67
|
-
t({
|
|
68
|
-
...n,
|
|
69
|
-
...s,
|
|
70
|
-
...s ? { open: !0 } : { open: !1 }
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
return /* @__PURE__ */ h(o, { children: [
|
|
74
|
-
/* @__PURE__ */ e(M, { children: /* @__PURE__ */ e(
|
|
75
|
-
a,
|
|
76
|
-
{
|
|
77
|
-
sx: { zIndex: 1e6 },
|
|
78
|
-
...n,
|
|
79
|
-
onConfirm: () => f(),
|
|
80
|
-
onClose: () => p(),
|
|
81
|
-
onCancel: () => C()
|
|
82
|
-
}
|
|
83
|
-
) }),
|
|
84
|
-
/* @__PURE__ */ e(O.Provider, { value: u, children: c })
|
|
85
|
-
] });
|
|
86
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
DialogServiceProvider,
|
|
3
|
+
useDialog,
|
|
4
|
+
DialogServiceContext
|
|
5
|
+
} from "./DialogService";
|
|
6
|
+
import { default as default2 } from "./AppDialog";
|
|
87
7
|
export {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
8
|
+
DialogServiceContext,
|
|
9
|
+
DialogServiceProvider,
|
|
10
|
+
default2 as default,
|
|
11
|
+
useDialog
|
|
92
12
|
};
|
package/package.json
CHANGED
|
@@ -1,123 +1,133 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
2
|
+
"name": "@dashadmin/dash-dialog",
|
|
3
|
+
"version": "1.3.28",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint --ext .ts,.tsx .",
|
|
8
|
+
"format": "pnpm prettier --write . && pnpm format-check && pnpm lint",
|
|
9
|
+
"lint:check": "pnpm prettier --check .",
|
|
10
|
+
"lint:fix": "pnpm prettier --write .",
|
|
11
|
+
"check-updates": "pnpm npm-check-updates",
|
|
12
|
+
"updates-packages": "pnpm npm-check-updates -u",
|
|
13
|
+
"build": "tsup"
|
|
14
|
+
},
|
|
15
|
+
"browserslist": {
|
|
16
|
+
"production": [
|
|
17
|
+
">0.2%",
|
|
18
|
+
"not dead",
|
|
19
|
+
"not op_mini all"
|
|
20
|
+
],
|
|
21
|
+
"development": [
|
|
22
|
+
"last 1 chrome version",
|
|
23
|
+
"last 1 firefox version",
|
|
24
|
+
"last 1 safari version"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@emotion/react": "latest",
|
|
29
|
+
"@emotion/styled": "latest",
|
|
30
|
+
"@mui/material": "^7.3.10",
|
|
31
|
+
"@rollup/plugin-alias": "latest",
|
|
32
|
+
"@rollup/plugin-commonjs": "latest",
|
|
33
|
+
"@rollup/plugin-node-resolve": "latest",
|
|
34
|
+
"@rollup/plugin-replace": "latest",
|
|
35
|
+
"@rollup/plugin-typescript": "latest",
|
|
36
|
+
"query-string": "latest",
|
|
37
|
+
"react-admin": "5.14.6",
|
|
38
|
+
"react-custom-scrollbars-2": "latest",
|
|
39
|
+
"react-draggable": "latest",
|
|
40
|
+
"react-loading-overlay-ts": "latest",
|
|
41
|
+
"react-query": "latest",
|
|
42
|
+
"react-redux": "latest",
|
|
43
|
+
"react-router": "^7.9.6",
|
|
44
|
+
"react-router-dom": "^7.9.6",
|
|
45
|
+
"react-spinners": "latest",
|
|
46
|
+
"react-toastify": "latest",
|
|
47
|
+
"rollup-plugin-cleaner": "latest",
|
|
48
|
+
"rollup-plugin-dts": "latest",
|
|
49
|
+
"rollup-plugin-peer-deps-external": "latest",
|
|
50
|
+
"rollup-plugin-svg": "latest"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@babel/core": "latest",
|
|
54
|
+
"@babel/preset-env": "latest",
|
|
55
|
+
"@babel/preset-react": "latest",
|
|
56
|
+
"@babel/preset-typescript": "latest",
|
|
57
|
+
"@commitlint/config-conventional": "latest",
|
|
58
|
+
"@types/node": "latest",
|
|
59
|
+
"@types/react": "latest",
|
|
60
|
+
"@types/react-dom": "latest",
|
|
61
|
+
"@zerollup/ts-transform-paths": "latest",
|
|
62
|
+
"babel-loader": "latest",
|
|
63
|
+
"eslint": "latest",
|
|
64
|
+
"eslint-config-airbnb": "latest",
|
|
65
|
+
"eslint-config-airbnb-typescript": "latest",
|
|
66
|
+
"eslint-config-prettier": "latest",
|
|
67
|
+
"@dashadmin/dash-eslint": "workspace:*",
|
|
68
|
+
"eslint-import-resolver-typescript": "latest",
|
|
69
|
+
"eslint-plugin-html": "latest",
|
|
70
|
+
"eslint-plugin-import": "latest",
|
|
71
|
+
"eslint-plugin-jsdoc": "latest",
|
|
72
|
+
"eslint-plugin-json": "latest",
|
|
73
|
+
"eslint-plugin-jsx-a11y": "latest",
|
|
74
|
+
"eslint-plugin-prettier": "latest",
|
|
75
|
+
"eslint-plugin-react": "latest",
|
|
76
|
+
"eslint-plugin-react-hooks": "latest",
|
|
77
|
+
"@dashadmin/dash-prettier": "workspace:*",
|
|
78
|
+
"query-string": "latest",
|
|
79
|
+
"react-dom": "latest",
|
|
80
|
+
"rollup": "latest",
|
|
81
|
+
"rollup-plugin-copy-assets": "latest",
|
|
82
|
+
"rollup-plugin-external-globals": "latest",
|
|
83
|
+
"rollup-plugin-includepaths": "latest",
|
|
84
|
+
"rollup-plugin-less": "latest",
|
|
85
|
+
"rollup-plugin-node-resolve": "latest",
|
|
86
|
+
"rollup-plugin-postcss": "latest",
|
|
87
|
+
"rollup-plugin-sourcemaps": "latest",
|
|
88
|
+
"rollup-plugin-typescript2": "latest",
|
|
89
|
+
"@dashadmin/dash-tsconfig": "workspace:*",
|
|
90
|
+
"tsc": "latest",
|
|
91
|
+
"tsc-alias": "latest",
|
|
92
|
+
"ttypescript": "latest",
|
|
93
|
+
"typescript": "latest"
|
|
94
|
+
},
|
|
95
|
+
"peerDependencies": {
|
|
96
|
+
"react": "latest",
|
|
97
|
+
"react-custom-scrollbars-2": "^4.5.0",
|
|
98
|
+
"react-dom": "latest"
|
|
99
|
+
},
|
|
100
|
+
"eslintConfig": {
|
|
101
|
+
"extends": "react-app"
|
|
102
|
+
},
|
|
103
|
+
"_todo_storybook": {
|
|
104
|
+
"eslint-plugin-storybook": "latest"
|
|
105
|
+
},
|
|
106
|
+
"module": "dist/index.js",
|
|
107
|
+
"types": "./src/index.ts",
|
|
108
|
+
"exports": {
|
|
109
|
+
".": "./dist/index.js",
|
|
110
|
+
"./*": "./dist/*.js",
|
|
111
|
+
"./src/*": "./dist/*.js"
|
|
112
|
+
},
|
|
113
|
+
"publishConfig": {
|
|
114
|
+
"access": "public",
|
|
115
|
+
"registry": "https://registry.npmjs.org"
|
|
116
|
+
},
|
|
117
|
+
"files": [
|
|
118
|
+
"dist",
|
|
119
|
+
"src"
|
|
120
|
+
],
|
|
121
|
+
"typesVersions": {
|
|
122
|
+
"*": {
|
|
123
|
+
"src/*": [
|
|
124
|
+
"src/*",
|
|
125
|
+
"src/*/index"
|
|
126
|
+
],
|
|
127
|
+
"*": [
|
|
128
|
+
"src/*",
|
|
129
|
+
"src/*/index"
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogTitle,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogActions,
|
|
8
|
+
Button,
|
|
9
|
+
Paper,
|
|
10
|
+
PaperProps,
|
|
11
|
+
} from '@mui/material';
|
|
12
|
+
|
|
13
|
+
//import Draggable from 'react-draggable';
|
|
14
|
+
import IAppDialogProps from './IAppDialogProps';
|
|
15
|
+
|
|
16
|
+
//const DraggableInstance: any = Draggable;
|
|
17
|
+
|
|
18
|
+
const PaperComponent = (props: PaperProps) => {
|
|
19
|
+
/*return <DraggableInstance>
|
|
20
|
+
<Paper {...props} />
|
|
21
|
+
</DraggableInstance>*/
|
|
22
|
+
return <Paper {...props} />
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const AppDialog: React.FC<IAppDialogProps> = (props) => { const {
|
|
26
|
+
onClose,
|
|
27
|
+
onConfirm,
|
|
28
|
+
onCancel,
|
|
29
|
+
open,
|
|
30
|
+
closeText = <></>,
|
|
31
|
+
confirmText = <></>,
|
|
32
|
+
cancelText = <></>,
|
|
33
|
+
title,
|
|
34
|
+
variant,
|
|
35
|
+
className,
|
|
36
|
+
showCancelButton = false,
|
|
37
|
+
showConfirmButton = true,
|
|
38
|
+
dialogActions,
|
|
39
|
+
content,
|
|
40
|
+
children,
|
|
41
|
+
...rest
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
const [isModalOpen, setIsModalOpen] = React.useState(open);
|
|
45
|
+
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
setIsModalOpen(open);
|
|
48
|
+
}, [open]);
|
|
49
|
+
|
|
50
|
+
const handleOnClose = (_e: any) => {
|
|
51
|
+
setIsModalOpen(false);
|
|
52
|
+
if (onClose) { onClose(); }
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleOnCancel = (_e: any) => {
|
|
56
|
+
setIsModalOpen(false);
|
|
57
|
+
if (onCancel) { onCancel(); }
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const handleOnConfirm = (_e: any) => {
|
|
61
|
+
setIsModalOpen(false);
|
|
62
|
+
if (onConfirm) { onConfirm(); }
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Dialog
|
|
67
|
+
hideBackdrop
|
|
68
|
+
disableEnforceFocus
|
|
69
|
+
PaperComponent={PaperComponent}
|
|
70
|
+
onClose={handleOnClose}
|
|
71
|
+
className={className}
|
|
72
|
+
open={isModalOpen}
|
|
73
|
+
{...rest}
|
|
74
|
+
>
|
|
75
|
+
<DialogTitle id='alert-dialog-title'>{title}</DialogTitle>
|
|
76
|
+
<DialogContent>{children || content}</DialogContent>
|
|
77
|
+
<DialogActions>
|
|
78
|
+
{dialogActions || <></>}
|
|
79
|
+
{showCancelButton === true ? (
|
|
80
|
+
<Button onClick={handleOnCancel}>{cancelText}</Button>
|
|
81
|
+
) : (
|
|
82
|
+
<></>
|
|
83
|
+
)}
|
|
84
|
+
{showConfirmButton === true ? (
|
|
85
|
+
<Button onClick={handleOnConfirm} /*autoFocus*/>
|
|
86
|
+
{confirmText}
|
|
87
|
+
</Button>
|
|
88
|
+
) : (
|
|
89
|
+
<></>
|
|
90
|
+
)}
|
|
91
|
+
</DialogActions>
|
|
92
|
+
</Dialog>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
export default AppDialog;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import IAppDialogProps, { AppDialogOptions } from './IAppDialogProps';
|
|
3
|
+
|
|
4
|
+
import { AppDialog } from './AppDialog';
|
|
5
|
+
import {
|
|
6
|
+
FC,
|
|
7
|
+
PropsWithChildren,
|
|
8
|
+
createContext,
|
|
9
|
+
useContext,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { Portal } from '@mui/material';
|
|
13
|
+
|
|
14
|
+
export const DialogServiceContext =
|
|
15
|
+
createContext<(options: AppDialogOptions) => void>(null);
|
|
16
|
+
|
|
17
|
+
export const useDialog = () => useContext(DialogServiceContext);
|
|
18
|
+
|
|
19
|
+
export interface IDialogServiceProviderProps extends PropsWithChildren {
|
|
20
|
+
component?: FC<IAppDialogProps>;
|
|
21
|
+
componentProps?: Partial<IAppDialogProps>;
|
|
22
|
+
}
|
|
23
|
+
export const DialogServiceProvider = (props: IDialogServiceProviderProps) => {
|
|
24
|
+
const { component, componentProps = {}, children } = props;
|
|
25
|
+
|
|
26
|
+
const DialogComponent: FC<IAppDialogProps> = component || AppDialog;
|
|
27
|
+
|
|
28
|
+
const defaultState: IAppDialogProps = {
|
|
29
|
+
open: false,
|
|
30
|
+
variant: 'default',
|
|
31
|
+
content: '',
|
|
32
|
+
title: '',
|
|
33
|
+
children: null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const [dialogState, setDialogState] = useState<IAppDialogProps>({...defaultState,...componentProps});
|
|
37
|
+
|
|
38
|
+
/*const openDialog = (options: IAppDialogProps) => {
|
|
39
|
+
setDialogState({...dialogState,...options});
|
|
40
|
+
};*/
|
|
41
|
+
|
|
42
|
+
const handleCancel = () => {
|
|
43
|
+
setDialogState(null);
|
|
44
|
+
if (dialogState.onCancel) {
|
|
45
|
+
dialogState.onCancel();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleClose = () => {
|
|
50
|
+
setDialogState(null);
|
|
51
|
+
if (dialogState.onClose) {
|
|
52
|
+
dialogState.onClose();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleConfirm = () => {
|
|
57
|
+
setDialogState(null);
|
|
58
|
+
if (dialogState.onConfirm) {
|
|
59
|
+
dialogState.onConfirm();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const exposedDialogHook = (options: AppDialogOptions) => {
|
|
64
|
+
setDialogState({
|
|
65
|
+
...dialogState,
|
|
66
|
+
...options,
|
|
67
|
+
...(options ? { open: true } : { open: false }),
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return <>
|
|
72
|
+
<Portal><DialogComponent sx={{ zIndex: 1000000 }} // Ensure modal is on top
|
|
73
|
+
//open={Boolean(dialogState)}
|
|
74
|
+
{...dialogState}
|
|
75
|
+
/*...(dialogState?.onSubmit && { onSubmit:() => handleSubmit() })*/
|
|
76
|
+
/*...(dialogState?.onClose && { onClose:() => handleClose() })*/
|
|
77
|
+
onConfirm={() => handleConfirm()}
|
|
78
|
+
onClose={() => handleClose()}
|
|
79
|
+
onCancel={() => handleCancel()}
|
|
80
|
+
/>
|
|
81
|
+
</Portal>
|
|
82
|
+
<DialogServiceContext.Provider value={exposedDialogHook}>
|
|
83
|
+
{children}
|
|
84
|
+
</DialogServiceContext.Provider>
|
|
85
|
+
</>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default DialogServiceProvider;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ModalProps } from '@mui/material';
|
|
2
|
+
import { JSX, PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface IAppDialogProps extends PropsWithChildren<Omit<ModalProps, 'content' | 'title'| 'children'>> { /** */
|
|
5
|
+
variant: 'default' | 'info' | 'success' | 'danger';
|
|
6
|
+
/** */
|
|
7
|
+
//onSubmit?: () => void;
|
|
8
|
+
/** */
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
/** */
|
|
11
|
+
onConfirm?: () => void;
|
|
12
|
+
/** */
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
/** */
|
|
15
|
+
closeText?: React.ReactNode;
|
|
16
|
+
/** */
|
|
17
|
+
confirmText?: React.ReactNode;
|
|
18
|
+
/** */
|
|
19
|
+
cancelText?: React.ReactNode;
|
|
20
|
+
/** */
|
|
21
|
+
showCancelButton?: boolean;
|
|
22
|
+
/** */
|
|
23
|
+
showCloseButton?: boolean;
|
|
24
|
+
/** */
|
|
25
|
+
showConfirmButton?: boolean;
|
|
26
|
+
/** */
|
|
27
|
+
dialogActions?: JSX.Element;
|
|
28
|
+
|
|
29
|
+
/** */
|
|
30
|
+
title: string | JSX.Element;
|
|
31
|
+
/** */
|
|
32
|
+
content?: string | JSX.Element;
|
|
33
|
+
/** enable/disable sound (optional) */
|
|
34
|
+
|
|
35
|
+
sound?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export type AppDialogOptions = Omit<IAppDialogProps, 'open' | 'children'>;
|
|
38
|
+
|
|
39
|
+
export default IAppDialogProps;
|