@symply.io/basic-components 1.7.13 → 1.8.0
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
CHANGED
|
@@ -935,7 +935,7 @@ import { usePrompt } from '@symply.io/basic-components';
|
|
|
935
935
|
|
|
936
936
|
<h5>Usage</h5>
|
|
937
937
|
```typescript
|
|
938
|
-
const { showPrompt } = usePrompt();
|
|
938
|
+
const { showPrompt, hidePrompt } = usePrompt();
|
|
939
939
|
```
|
|
940
940
|
|
|
941
941
|
<h5>Props</h5>
|
|
@@ -945,6 +945,7 @@ const { showPrompt } = usePrompt();
|
|
|
945
945
|
| message | string \| 400 | | true | The prompt message you want to show. |
|
|
946
946
|
| timeout | number | 3500 | false | The number of milliseconds to wait before automatically calling the `onClose` function. |
|
|
947
947
|
| type | 'success' \| 'warning' \| 'info' \| 'error' | | true | The type of prompt. |
|
|
948
|
+
| action | ReactNode \| null | | false | Customized button(s) at the end of the prompt. If this property is set, the default close icon button will be replaced directly. |
|
|
948
949
|
|
|
949
950
|
|
|
950
951
|
|
package/ToastPrompt/Prompt.js
CHANGED
|
@@ -23,8 +23,12 @@ function Transition(args) {
|
|
|
23
23
|
}
|
|
24
24
|
var Prompt = forwardRef(function (_, ref) {
|
|
25
25
|
var theme = useCustomTheme();
|
|
26
|
-
var _a = useInteractions(), open = _a.open, type = _a.type, message = _a.message, timeout = _a.timeout, onShow = _a.onShow, onHide = _a.onHide;
|
|
27
|
-
useImperativeHandle(ref, function () { return ({ onShow: onShow }); });
|
|
28
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Snackbar, __assign({ anchorOrigin: { vertical: "bottom", horizontal: "left" }, open: open, onClose:
|
|
26
|
+
var _a = useInteractions(), open = _a.open, type = _a.type, message = _a.message, timeout = _a.timeout, action = _a.action, onShow = _a.onShow, onHide = _a.onHide;
|
|
27
|
+
useImperativeHandle(ref, function () { return ({ onShow: onShow, onHide: onHide }); });
|
|
28
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Snackbar, __assign({ anchorOrigin: { vertical: "bottom", horizontal: "left" }, open: open, onClose: function (_, reason) {
|
|
29
|
+
if (reason !== "clickaway") {
|
|
30
|
+
onHide();
|
|
31
|
+
}
|
|
32
|
+
}, autoHideDuration: timeout, TransitionComponent: Transition, sx: { zIndex: 99999 } }, { children: _jsx(Alert, __assign({ variant: "filled", severity: type, sx: { width: "100%", fontSize: 14, fontWeight: 700 }, onClose: onHide, action: action }, { children: _jsx(Typography, __assign({ sx: { fontWeight: 800, fontSize: 14 } }, { children: message })) })) }), "".concat(Date.now() * Math.round(Math.random()))) })));
|
|
29
33
|
});
|
|
30
34
|
export default Prompt;
|
package/ToastPrompt/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PromptContextProps, PromptProviderProps } from "./types";
|
|
2
2
|
export declare function PromptProvider(props: PromptProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export declare function usePrompt(): PromptContextProps;
|
package/ToastPrompt/index.js
CHANGED
|
@@ -10,10 +10,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
13
|
+
import { useRef, useContext, useCallback, cloneElement, createContext, } from "react";
|
|
14
14
|
import Prompt from "./Prompt";
|
|
15
15
|
var PromptContext = createContext({
|
|
16
|
-
showPrompt: function () { }
|
|
16
|
+
showPrompt: function () { },
|
|
17
|
+
hidePrompt: function () { },
|
|
17
18
|
});
|
|
18
19
|
export function PromptProvider(props) {
|
|
19
20
|
var children = props.children;
|
|
@@ -22,7 +23,11 @@ export function PromptProvider(props) {
|
|
|
22
23
|
var _a;
|
|
23
24
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.onShow(args);
|
|
24
25
|
}, []);
|
|
25
|
-
|
|
26
|
+
var hidePrompt = useCallback(function () {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.onHide();
|
|
29
|
+
}, []);
|
|
30
|
+
return (_jsxs(PromptContext.Provider, __assign({ value: { showPrompt: showPrompt, hidePrompt: hidePrompt } }, { children: [children, cloneElement(_jsx(Prompt, { ref: ref }))] })));
|
|
26
31
|
}
|
|
27
32
|
export function usePrompt() {
|
|
28
33
|
return useContext(PromptContext);
|
package/ToastPrompt/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { CSSProperties, ReactNode
|
|
2
|
-
import type { SnackbarCloseReason } from "@mui/material/Snackbar";
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
3
2
|
import type { SvgIconComponent } from "@mui/icons-material";
|
|
4
3
|
export declare type Severity = "success" | "warning" | "info" | "error";
|
|
5
4
|
export declare type PromptStyles = Record<Severity, {
|
|
@@ -9,20 +8,23 @@ export declare type PromptIcons = Record<Severity, SvgIconComponent>;
|
|
|
9
8
|
declare type PromptArgs = {
|
|
10
9
|
message: string | 400;
|
|
11
10
|
type: Severity;
|
|
11
|
+
action?: ReactNode | null;
|
|
12
12
|
timeout?: number;
|
|
13
13
|
};
|
|
14
|
-
export interface
|
|
14
|
+
export interface InteractionStates {
|
|
15
15
|
promptArgs: PromptArgs & Record<"open", boolean>;
|
|
16
|
-
onHide: (
|
|
16
|
+
onHide: () => void;
|
|
17
17
|
onShow: (args: PromptArgs) => void;
|
|
18
18
|
}
|
|
19
19
|
export interface PromptProviderProps {
|
|
20
20
|
children: ReactNode;
|
|
21
21
|
}
|
|
22
22
|
export interface PromptContextProps {
|
|
23
|
-
showPrompt:
|
|
23
|
+
showPrompt: InteractionStates["onShow"];
|
|
24
|
+
hidePrompt: InteractionStates["onHide"];
|
|
24
25
|
}
|
|
25
26
|
export interface RefProps {
|
|
26
|
-
onShow:
|
|
27
|
+
onShow: InteractionStates["onShow"];
|
|
28
|
+
onHide: InteractionStates["onHide"];
|
|
27
29
|
}
|
|
28
30
|
export {};
|
|
@@ -3,11 +3,13 @@ declare function useInteractions(): {
|
|
|
3
3
|
onShow: (args: {
|
|
4
4
|
message: string | 400;
|
|
5
5
|
type: import("./types").Severity;
|
|
6
|
+
action?: import("react").ReactNode;
|
|
6
7
|
timeout?: number | undefined;
|
|
7
8
|
}) => void;
|
|
8
|
-
onHide: (
|
|
9
|
+
onHide: () => void;
|
|
9
10
|
message: string | 400;
|
|
10
11
|
type: import("./types").Severity;
|
|
12
|
+
action?: import("react").ReactNode;
|
|
11
13
|
timeout?: number | undefined;
|
|
12
14
|
open: boolean;
|
|
13
15
|
};
|
|
@@ -17,17 +17,15 @@ function useInteractions() {
|
|
|
17
17
|
open: false,
|
|
18
18
|
message: UNKNOWN_MESSAGE,
|
|
19
19
|
type: "error",
|
|
20
|
-
timeout: 3500
|
|
20
|
+
timeout: 3500,
|
|
21
|
+
action: null,
|
|
21
22
|
}), promptArgs = _a[0], setPromptArgs = _a[1];
|
|
22
|
-
var onHide = useCallback(function (
|
|
23
|
-
if (reason === "clickaway") {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
23
|
+
var onHide = useCallback(function () {
|
|
26
24
|
setPromptArgs(function (args) { return (__assign(__assign({}, args), { open: false })); });
|
|
27
25
|
}, []);
|
|
28
26
|
var onShow = useCallback(function (args) {
|
|
29
|
-
var _a = args.message, message = _a === void 0 ? UNKNOWN_MESSAGE : _a, _b = args.type, type = _b === void 0 ? "error" : _b, _c = args.timeout, timeout = _c === void 0 ? 3500 : _c;
|
|
30
|
-
setPromptArgs(function (args) { return (__assign(__assign({}, args), { message: message === 400 ? ERROR_MESSAGE : message, type: type, timeout: timeout,
|
|
27
|
+
var _a = args.message, message = _a === void 0 ? UNKNOWN_MESSAGE : _a, _b = args.type, type = _b === void 0 ? "error" : _b, _c = args.timeout, timeout = _c === void 0 ? 3500 : _c, action = args.action;
|
|
28
|
+
setPromptArgs(function (args) { return (__assign(__assign({}, args), { open: true, message: message === 400 ? ERROR_MESSAGE : message, type: type, timeout: timeout, action: action })); });
|
|
31
29
|
}, []);
|
|
32
30
|
return __assign(__assign({}, promptArgs), { onShow: onShow, onHide: onHide });
|
|
33
31
|
}
|