@symply.io/basic-components 1.3.11-alpha.2 → 1.3.11-alpha.4
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/ToastPrompt/Prompt.d.ts +3 -0
- package/ToastPrompt/{Presentation.js → Prompt.js} +21 -31
- package/ToastPrompt/index.d.ts +2 -13
- package/ToastPrompt/index.js +8 -12
- package/ToastPrompt/types.d.ts +35 -0
- package/ToastPrompt/types.js +1 -0
- package/ToastPrompt/useInteractions.d.ts +14 -0
- package/ToastPrompt/useInteractions.js +33 -0
- package/package.json +1 -1
- package/ToastPrompt/Logics.d.ts +0 -12
- package/ToastPrompt/Logics.js +0 -37
- package/ToastPrompt/Presentation.d.ts +0 -16
@@ -9,34 +9,27 @@ var __assign = (this && this.__assign) || function () {
|
|
9
9
|
};
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
|
-
|
13
|
-
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
-
t[p] = s[p];
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
-
t[p[i]] = s[p[i]];
|
20
|
-
}
|
21
|
-
return t;
|
22
|
-
};
|
23
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
-
import Typography from "@mui/material/Typography";
|
25
|
-
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
import { useMemo } from "react";
|
26
14
|
import Slide from "@mui/material/Slide";
|
27
|
-
import SnackbarContent from "@mui/material/SnackbarContent";
|
28
15
|
import Snackbar from "@mui/material/Snackbar";
|
16
|
+
import Typography from "@mui/material/Typography";
|
17
|
+
import SnackbarContent from "@mui/material/SnackbarContent";
|
18
|
+
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
29
19
|
import InfoIcon from "@mui/icons-material/Info";
|
30
20
|
import ErrorIcon from "@mui/icons-material/Error";
|
31
21
|
import WarningIcon from "@mui/icons-material/Warning";
|
32
22
|
import SuccessIcon from "@mui/icons-material/CheckCircle";
|
33
23
|
import { green, amber, red, blue } from "@mui/material/colors";
|
34
24
|
import useCustomTheme from "../useCustomTheme";
|
35
|
-
var
|
25
|
+
var Transition = function (args) {
|
26
|
+
return _jsx(Slide, __assign({}, args, { direction: "up" }));
|
27
|
+
};
|
28
|
+
function Prompt(props) {
|
36
29
|
var _a;
|
37
|
-
var
|
30
|
+
var open = props.open, icon = props.icon, variant = props.variant, message = props.message, timeout = props.timeout, onClose = props.onClose;
|
38
31
|
var theme = useCustomTheme();
|
39
|
-
var styles = {
|
32
|
+
var styles = useMemo(function () { return ({
|
40
33
|
success: {
|
41
34
|
backgroundColor: green[500]
|
42
35
|
},
|
@@ -49,21 +42,18 @@ var ToastPrompt = function (props) {
|
|
49
42
|
warning: {
|
50
43
|
backgroundColor: amber["A700"]
|
51
44
|
}
|
52
|
-
};
|
53
|
-
var
|
54
|
-
return _jsx(Slide, __assign({}, args, { direction: transitionDirection }));
|
55
|
-
};
|
56
|
-
var VariantIcon = {
|
45
|
+
}); }, []);
|
46
|
+
var VariantIcon = useMemo(function () { return ({
|
57
47
|
success: SuccessIcon,
|
58
48
|
warning: WarningIcon,
|
59
49
|
error: ErrorIcon,
|
60
50
|
info: InfoIcon
|
61
|
-
};
|
62
|
-
var Icon = VariantIcon[variant];
|
63
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Snackbar, __assign({ anchorOrigin: { vertical:
|
51
|
+
}); }, []);
|
52
|
+
var Icon = useMemo(function () { return VariantIcon[variant]; }, []);
|
53
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Snackbar, __assign({ anchorOrigin: { vertical: "bottom", horizontal: "left" }, open: open, onClose: onClose, autoHideDuration: timeout, TransitionComponent: Transition, sx: {
|
64
54
|
zIndex: 99999,
|
65
55
|
marginTop: "3vh"
|
66
|
-
} }, { children: _jsx(SnackbarContent,
|
56
|
+
} }, { children: _jsx(SnackbarContent, { sx: __assign(__assign({}, styles[variant]), { root: (_a = {},
|
67
57
|
_a[theme.breakpoints.down("sm")] = {
|
68
58
|
maxWidth: "320px",
|
69
59
|
borderRadius: "4px"
|
@@ -73,10 +63,10 @@ var ToastPrompt = function (props) {
|
|
73
63
|
fontWeight: 700,
|
74
64
|
display: "flex",
|
75
65
|
alignItems: "center"
|
76
|
-
} }, { children: [
|
66
|
+
} }, { children: [!icon ? (_jsx(Icon, { sx: {
|
77
67
|
fontSize: 20,
|
78
68
|
opacity: 0.9,
|
79
69
|
marginRight: theme.spacing(1)
|
80
|
-
} })) : (_jsx(_Fragment, { children: icon })), message] })) }
|
81
|
-
}
|
82
|
-
export default
|
70
|
+
} })) : (_jsx(_Fragment, { children: icon })), message] })) }) }), "".concat(Date.now() * Math.round(Math.random()))) })));
|
71
|
+
}
|
72
|
+
export default Prompt;
|
package/ToastPrompt/index.d.ts
CHANGED
@@ -1,14 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
export interface PromptProviderProps {
|
3
|
-
children: ReactNode;
|
4
|
-
}
|
5
|
-
export interface ShowPromptProps {
|
6
|
-
type: "success" | "warning" | "error" | "info";
|
7
|
-
message: string | 400;
|
8
|
-
timeout?: number;
|
9
|
-
}
|
1
|
+
import { PromptProviderProps, PromptContextProps } from "./types";
|
10
2
|
export declare function PromptProvider(props: PromptProviderProps): JSX.Element;
|
11
|
-
export declare function usePrompt():
|
12
|
-
showPrompt: (props: ShowPromptProps) => void;
|
13
|
-
};
|
14
|
-
export default PromptProvider;
|
3
|
+
export declare function usePrompt(): PromptContextProps;
|
package/ToastPrompt/index.js
CHANGED
@@ -10,21 +10,17 @@ var __assign = (this && this.__assign) || function () {
|
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
-
import { createContext,
|
14
|
-
import
|
15
|
-
import
|
16
|
-
var PromptContext = createContext({
|
13
|
+
import { createContext, useContext } from "react";
|
14
|
+
import Prompt from "./Prompt";
|
15
|
+
import useInteractions from "./useInteractions";
|
16
|
+
var PromptContext = createContext({
|
17
|
+
showPrompt: function () { }
|
18
|
+
});
|
17
19
|
export function PromptProvider(props) {
|
18
20
|
var children = props.children;
|
19
|
-
var
|
20
|
-
|
21
|
-
var type = props.type, message = props.message, timeout = props.timeout;
|
22
|
-
var _a = ((toastRef === null || toastRef === void 0 ? void 0 : toastRef.current) || {}).show, show = _a === void 0 ? function () { } : _a;
|
23
|
-
show(type, message, timeout);
|
24
|
-
}
|
25
|
-
return (_jsx(PromptContext.Provider, __assign({ value: { showPrompt: showPrompt } }, { children: _jsxs(_Fragment, { children: [children, _jsx(Logics, __assign({ ref: toastRef }, { children: _jsx(ToastPrompt, {}) }))] }) })));
|
21
|
+
var _a = useInteractions(), promptArgs = _a.promptArgs, onShow = _a.onShow, onHide = _a.onHide;
|
22
|
+
return (_jsx(PromptContext.Provider, __assign({ value: { showPrompt: onShow } }, { children: _jsxs(_Fragment, { children: [children, _jsx(Prompt, __assign({}, promptArgs, { onClose: onHide }))] }) })));
|
26
23
|
}
|
27
24
|
export function usePrompt() {
|
28
25
|
return useContext(PromptContext);
|
29
26
|
}
|
30
|
-
export default PromptProvider;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { CSSProperties, ReactNode } from "react";
|
2
|
+
import { SnackbarCloseReason } from "@mui/material/Snackbar";
|
3
|
+
import { SvgIconComponent } from "@mui/icons-material";
|
4
|
+
export declare type Variant = "success" | "warning" | "info" | "error";
|
5
|
+
export declare type PromptStyles = Record<Variant, {
|
6
|
+
backgroundColor: CSSProperties["color"];
|
7
|
+
}>;
|
8
|
+
export declare type PromptIcons = Record<Variant, SvgIconComponent>;
|
9
|
+
declare type PromptArgs = {
|
10
|
+
message: string;
|
11
|
+
variant: Variant;
|
12
|
+
timeout: number;
|
13
|
+
};
|
14
|
+
export interface InterfaceStates {
|
15
|
+
promptArgs: PromptArgs & Record<"open", boolean>;
|
16
|
+
onHide: (_: any, reason: SnackbarCloseReason) => void;
|
17
|
+
onShow: (args: PromptArgs) => void;
|
18
|
+
}
|
19
|
+
export interface PromptProps extends PromptArgs {
|
20
|
+
open: boolean;
|
21
|
+
icon?: SvgIconComponent;
|
22
|
+
onClose: InterfaceStates["onHide"];
|
23
|
+
}
|
24
|
+
export interface PromptStates {
|
25
|
+
styles: PromptStyles;
|
26
|
+
icons: PromptIcons;
|
27
|
+
icon: SvgIconComponent;
|
28
|
+
}
|
29
|
+
export interface PromptProviderProps {
|
30
|
+
children: ReactNode;
|
31
|
+
}
|
32
|
+
export interface PromptContextProps {
|
33
|
+
showPrompt: InterfaceStates["onShow"];
|
34
|
+
}
|
35
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
declare function useInteractions(): {
|
2
|
+
promptArgs: {
|
3
|
+
message: string;
|
4
|
+
variant: import("./types").Variant;
|
5
|
+
timeout: number;
|
6
|
+
} & Record<"open", boolean>;
|
7
|
+
onShow: (args: {
|
8
|
+
message: string;
|
9
|
+
variant: import("./types").Variant;
|
10
|
+
timeout: number;
|
11
|
+
}) => void;
|
12
|
+
onHide: (_: any, reason: import("@mui/material").SnackbarCloseReason) => void;
|
13
|
+
};
|
14
|
+
export default useInteractions;
|
@@ -0,0 +1,33 @@
|
|
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 { useState, useCallback } from "react";
|
13
|
+
function useInteractions() {
|
14
|
+
var ERROR_MESSAGE = "Internal Server Error";
|
15
|
+
var _a = useState({
|
16
|
+
open: false,
|
17
|
+
message: "Saved",
|
18
|
+
variant: "success",
|
19
|
+
timeout: 3500
|
20
|
+
}), promptArgs = _a[0], setPromptArgs = _a[1];
|
21
|
+
var onHide = useCallback(function (_, reason) {
|
22
|
+
if (reason === "clickaway") {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
setPromptArgs(function (args) { return (__assign(__assign({}, args), { open: false })); });
|
26
|
+
}, []);
|
27
|
+
var onShow = useCallback(function (args) {
|
28
|
+
var _a = args.message, message = _a === void 0 ? "Unknown message" : _a, _b = args.variant, variant = _b === void 0 ? "info" : _b, _c = args.timeout, timeout = _c === void 0 ? 3500 : _c;
|
29
|
+
setPromptArgs({ open: true, message: message, variant: variant, timeout: timeout });
|
30
|
+
}, []);
|
31
|
+
return { promptArgs: promptArgs, onShow: onShow, onHide: onHide };
|
32
|
+
}
|
33
|
+
export default useInteractions;
|
package/package.json
CHANGED
package/ToastPrompt/Logics.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
interface LogicsProps {
|
3
|
-
children: React.ReactNode | undefined;
|
4
|
-
}
|
5
|
-
export interface PromptPropsType {
|
6
|
-
open: boolean;
|
7
|
-
message: string | number;
|
8
|
-
variant: "success" | "warning" | "error" | "info" | undefined;
|
9
|
-
timeout: number;
|
10
|
-
}
|
11
|
-
declare const Logics: import("react").ForwardRefExoticComponent<LogicsProps & import("react").RefAttributes<unknown>>;
|
12
|
-
export default Logics;
|
package/ToastPrompt/Logics.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 { useState, cloneElement, forwardRef, useImperativeHandle } from "react";
|
13
|
-
var ERROR_MESSAGE = "Internal Server Error";
|
14
|
-
var Logics = forwardRef(function (props, ref) {
|
15
|
-
var children = props.children;
|
16
|
-
var _a = useState({
|
17
|
-
open: false,
|
18
|
-
message: "Saved",
|
19
|
-
variant: "success",
|
20
|
-
timeout: 3500
|
21
|
-
}), promptProps = _a[0], setPromptProps = _a[1];
|
22
|
-
function hide(_, reason) {
|
23
|
-
if (reason === "clickaway") {
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
setPromptProps(__assign(__assign({}, promptProps), { open: false }));
|
27
|
-
}
|
28
|
-
function show(type, message, timeout) {
|
29
|
-
if (timeout === void 0) { timeout = 3500; }
|
30
|
-
setPromptProps(__assign(__assign({}, promptProps), { open: true, variant: type, message: message === 400 ? ERROR_MESSAGE : message, timeout: timeout }));
|
31
|
-
}
|
32
|
-
useImperativeHandle(ref, function () { return ({
|
33
|
-
show: show
|
34
|
-
}); });
|
35
|
-
return cloneElement(children, __assign(__assign({}, promptProps), { onClose: hide }));
|
36
|
-
});
|
37
|
-
export default Logics;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { ElementType } from "react";
|
2
|
-
import { SlideProps } from "@mui/material/Slide";
|
3
|
-
import { SnackbarOrigin } from "@mui/material/Snackbar";
|
4
|
-
interface ToastPromptProps {
|
5
|
-
open?: boolean;
|
6
|
-
vertical?: SnackbarOrigin["vertical"];
|
7
|
-
horizontal?: SnackbarOrigin["horizontal"];
|
8
|
-
timeout?: number;
|
9
|
-
onClose?: () => void;
|
10
|
-
transitionDirection?: SlideProps["direction"];
|
11
|
-
message?: string;
|
12
|
-
icon?: ElementType;
|
13
|
-
variant?: "success" | "warning" | "info" | "error";
|
14
|
-
}
|
15
|
-
declare const ToastPrompt: (props: ToastPromptProps) => JSX.Element;
|
16
|
-
export default ToastPrompt;
|