@symply.io/basic-components 1.4.0-beta.8 → 1.4.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.
@@ -1,3 +1,4 @@
1
- import type { PromptProps } from "./types";
2
- declare function Prompt(props: PromptProps): JSX.Element;
1
+ /// <reference types="react" />
2
+ import { RefProps } from "./types";
3
+ declare const Prompt: import("react").ForwardRefExoticComponent<import("react").RefAttributes<RefProps | null>>;
3
4
  export default Prompt;
@@ -9,19 +9,22 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { forwardRef, useImperativeHandle } from "react";
13
14
  import Alert from "@mui/material/Alert";
14
15
  import Slide from "@mui/material/Slide";
15
- import AlertTitle from "@mui/material/AlertTitle";
16
16
  import Snackbar from "@mui/material/Snackbar";
17
+ import Typography from "@mui/material/Typography";
17
18
  import ThemeProvider from "@mui/material/styles/ThemeProvider";
18
19
  import useCustomTheme from "../useCustomTheme";
20
+ import useInteractions from "./useInteractions";
19
21
  function Transition(args) {
20
22
  return _jsx(Slide, __assign({}, args, { direction: "up" }));
21
23
  }
22
- function Prompt(props) {
23
- var open = props.open, type = props.type, message = props.message, timeout = props.timeout, onClose = props.onClose;
24
+ var Prompt = forwardRef(function (_, ref) {
24
25
  var theme = useCustomTheme();
25
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Snackbar, __assign({ anchorOrigin: { vertical: "bottom", horizontal: "left" }, open: open, onClose: onClose, autoHideDuration: timeout, TransitionComponent: Transition, sx: { zIndex: 99999 } }, { children: _jsxs(Alert, __assign({ variant: "filled", severity: type, sx: { width: "100%", fontSize: 14, fontWeight: 700 }, onClose: onClose }, { children: [_jsx(AlertTitle, __assign({ sx: { textTransform: "capitalize", fontSize: 16, fontWeight: 900 } }, { children: type })), message] })) }), "".concat(Date.now() * Math.round(Math.random()))) })));
26
- }
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: onHide, autoHideDuration: timeout, TransitionComponent: Transition, sx: { zIndex: 99999 } }, { children: _jsx(Alert, __assign({ variant: "filled", severity: type, sx: { width: "100%", fontSize: 14, fontWeight: 700 }, onClose: onHide }, { children: _jsx(Typography, __assign({ sx: { fontWeight: 800, fontSize: 14 } }, { children: message })) })) }), "".concat(Date.now() * Math.round(Math.random()))) })));
29
+ });
27
30
  export default Prompt;
@@ -10,16 +10,19 @@ 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 { createContext, useContext, cloneElement } from "react";
13
+ import { createContext, useContext, useRef, useCallback, cloneElement } from "react";
14
14
  import Prompt from "./Prompt";
15
- import useInteractions from "./useInteractions";
16
15
  var PromptContext = createContext({
17
16
  showPrompt: function () { }
18
17
  });
19
18
  export function PromptProvider(props) {
20
19
  var children = props.children;
21
- var _a = useInteractions(), promptArgs = _a.promptArgs, onShow = _a.onShow, onHide = _a.onHide;
22
- return (_jsxs(PromptContext.Provider, __assign({ value: { showPrompt: onShow } }, { children: [children, cloneElement(_jsx(Prompt, __assign({}, promptArgs, { onClose: onHide })))] })));
20
+ var ref = useRef(null);
21
+ var showPrompt = useCallback(function (args) {
22
+ var _a;
23
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.onShow(args);
24
+ }, []);
25
+ return (_jsxs(PromptContext.Provider, __assign({ value: { showPrompt: showPrompt } }, { children: [children, cloneElement(_jsx(Prompt, { ref: ref }))] })));
23
26
  }
24
27
  export function usePrompt() {
25
28
  return useContext(PromptContext);
@@ -16,14 +16,13 @@ export interface InterfaceStates {
16
16
  onHide: (event: SyntheticEvent | Event, reason?: SnackbarCloseReason) => void;
17
17
  onShow: (args: PromptArgs) => void;
18
18
  }
19
- export interface PromptProps extends PromptArgs {
20
- open: boolean;
21
- onClose: InterfaceStates["onHide"];
22
- }
23
19
  export interface PromptProviderProps {
24
20
  children: ReactNode;
25
21
  }
26
22
  export interface PromptContextProps {
27
23
  showPrompt: InterfaceStates["onShow"];
28
24
  }
25
+ export interface RefProps {
26
+ onShow: InterfaceStates["onShow"];
27
+ }
29
28
  export {};
@@ -1,15 +1,14 @@
1
1
  /// <reference types="react" />
2
2
  declare function useInteractions(): {
3
- promptArgs: {
4
- message: string | 400;
5
- type: import("./types").Severity;
6
- timeout?: number | undefined;
7
- } & Record<"open", boolean>;
8
3
  onShow: (args: {
9
4
  message: string | 400;
10
5
  type: import("./types").Severity;
11
6
  timeout?: number | undefined;
12
7
  }) => void;
13
8
  onHide: (event: Event | import("react").SyntheticEvent<Element, Event>, reason?: import("@mui/material").SnackbarCloseReason | undefined) => void;
9
+ message: string | 400;
10
+ type: import("./types").Severity;
11
+ timeout?: number | undefined;
12
+ open: boolean;
14
13
  };
15
14
  export default useInteractions;
@@ -27,13 +27,8 @@ function useInteractions() {
27
27
  }, []);
28
28
  var onShow = useCallback(function (args) {
29
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({
31
- message: message === 400 ? ERROR_MESSAGE : message,
32
- type: type,
33
- timeout: timeout,
34
- open: true
35
- });
30
+ setPromptArgs(function (args) { return (__assign(__assign({}, args), { message: message === 400 ? ERROR_MESSAGE : message, type: type, timeout: timeout, open: true })); });
36
31
  }, []);
37
- return { promptArgs: promptArgs, onShow: onShow, onHide: onHide };
32
+ return __assign(__assign({}, promptArgs), { onShow: onShow, onHide: onHide });
38
33
  }
39
34
  export default useInteractions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.4.0-beta.8",
3
+ "version": "1.4.0",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",