@veracity/vui 1.2.0-beta.0 → 1.2.0-beta.2

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.
Files changed (73) hide show
  1. package/dist/cjs/core/vuiProvider/context.d.ts +4 -0
  2. package/dist/cjs/core/vuiProvider/context.d.ts.map +1 -0
  3. package/dist/cjs/core/vuiProvider/context.js +7 -0
  4. package/dist/cjs/core/vuiProvider/index.d.ts +1 -0
  5. package/dist/cjs/core/vuiProvider/index.d.ts.map +1 -1
  6. package/dist/cjs/core/vuiProvider/index.js +1 -0
  7. package/dist/cjs/core/vuiProvider/reducers.d.ts +10 -0
  8. package/dist/cjs/core/vuiProvider/reducers.d.ts.map +1 -0
  9. package/dist/cjs/core/vuiProvider/reducers.js +17 -0
  10. package/dist/cjs/core/vuiProvider/vuiProvider.d.ts.map +1 -1
  11. package/dist/cjs/core/vuiProvider/vuiProvider.js +44 -8
  12. package/dist/cjs/dialog/showConfirm.js +1 -1
  13. package/dist/cjs/dialog/showPrompt.js +1 -1
  14. package/dist/cjs/toast/Toaster.d.ts +4 -0
  15. package/dist/cjs/toast/Toaster.d.ts.map +1 -0
  16. package/dist/cjs/toast/Toaster.js +15 -0
  17. package/dist/cjs/toast/index.d.ts +2 -1
  18. package/dist/cjs/toast/index.d.ts.map +1 -1
  19. package/dist/cjs/toast/index.js +7 -1
  20. package/dist/cjs/toast/toast.types.d.ts +1 -1
  21. package/dist/cjs/toast/toast.types.d.ts.map +1 -1
  22. package/dist/cjs/toast/useToast.d.ts +12 -0
  23. package/dist/cjs/toast/useToast.d.ts.map +1 -0
  24. package/dist/cjs/toast/useToast.js +46 -0
  25. package/dist/cjs/utils/react.d.ts +2 -2
  26. package/dist/cjs/utils/react.d.ts.map +1 -1
  27. package/dist/cjs/utils/react.js +3 -12
  28. package/dist/esm/core/vuiProvider/context.d.ts +4 -0
  29. package/dist/esm/core/vuiProvider/context.d.ts.map +1 -0
  30. package/dist/esm/core/vuiProvider/context.js +3 -0
  31. package/dist/esm/core/vuiProvider/index.d.ts +1 -0
  32. package/dist/esm/core/vuiProvider/index.d.ts.map +1 -1
  33. package/dist/esm/core/vuiProvider/index.js +1 -0
  34. package/dist/esm/core/vuiProvider/reducers.d.ts +10 -0
  35. package/dist/esm/core/vuiProvider/reducers.d.ts.map +1 -0
  36. package/dist/esm/core/vuiProvider/reducers.js +13 -0
  37. package/dist/esm/core/vuiProvider/vuiProvider.d.ts.map +1 -1
  38. package/dist/esm/core/vuiProvider/vuiProvider.js +21 -8
  39. package/dist/esm/dialog/showConfirm.js +1 -1
  40. package/dist/esm/dialog/showPrompt.js +1 -1
  41. package/dist/esm/toast/Toaster.d.ts +4 -0
  42. package/dist/esm/toast/Toaster.d.ts.map +1 -0
  43. package/dist/esm/toast/Toaster.js +9 -0
  44. package/dist/esm/toast/index.d.ts +2 -1
  45. package/dist/esm/toast/index.d.ts.map +1 -1
  46. package/dist/esm/toast/index.js +2 -1
  47. package/dist/esm/toast/toast.types.d.ts +1 -1
  48. package/dist/esm/toast/toast.types.d.ts.map +1 -1
  49. package/dist/esm/toast/useToast.d.ts +12 -0
  50. package/dist/esm/toast/useToast.d.ts.map +1 -0
  51. package/dist/esm/toast/useToast.js +39 -0
  52. package/dist/esm/utils/react.d.ts +2 -2
  53. package/dist/esm/utils/react.d.ts.map +1 -1
  54. package/dist/esm/utils/react.js +3 -11
  55. package/package.json +1 -1
  56. package/src/core/vuiProvider/context.ts +5 -0
  57. package/src/core/vuiProvider/index.ts +1 -0
  58. package/src/core/vuiProvider/reducers.ts +18 -0
  59. package/src/core/vuiProvider/vuiProvider.tsx +31 -12
  60. package/src/dialog/showConfirm.tsx +1 -1
  61. package/src/dialog/showPrompt.tsx +1 -1
  62. package/src/toast/Toaster.tsx +31 -0
  63. package/src/toast/index.ts +3 -1
  64. package/src/toast/toast.types.ts +1 -1
  65. package/src/toast/useToast.tsx +63 -0
  66. package/src/utils/react.ts +4 -10
  67. package/dist/cjs/toast/Toast.d.ts +0 -11
  68. package/dist/cjs/toast/Toast.d.ts.map +0 -1
  69. package/dist/cjs/toast/Toast.js +0 -62
  70. package/dist/esm/toast/Toast.d.ts +0 -11
  71. package/dist/esm/toast/Toast.d.ts.map +0 -1
  72. package/dist/esm/toast/Toast.js +0 -50
  73. package/src/toast/Toast.tsx +0 -94
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ declare const VuiContextProvider: import("react").Provider<any>, useVuiContext: () => any;
3
+ export { VuiContextProvider, useVuiContext };
4
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/context.ts"],"names":[],"mappings":";AAEA,QAAA,MAAO,kBAAkB,iCAAE,aAAa,WAA4C,CAAA;AAEpF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useVuiContext = exports.VuiContextProvider = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const [VuiContextProvider, useVuiContext] = (0, utils_1.createContext)({ isOptional: true });
6
+ exports.VuiContextProvider = VuiContextProvider;
7
+ exports.useVuiContext = useVuiContext;
@@ -1,4 +1,5 @@
1
1
  export * from './animations';
2
+ export * from './context';
2
3
  export { default as fontFaces } from './fontFaces';
3
4
  export { default as GlobalStyle } from './globalStyle';
4
5
  export { default as ResetCSS } from './resetCSS';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -19,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.VuiProvider = exports.default = exports.ResetCSS = exports.GlobalStyle = exports.fontFaces = void 0;
21
21
  __exportStar(require("./animations"), exports);
22
+ __exportStar(require("./context"), exports);
22
23
  var fontFaces_1 = require("./fontFaces");
23
24
  Object.defineProperty(exports, "fontFaces", { enumerable: true, get: function () { return __importDefault(fontFaces_1).default; } });
24
25
  var globalStyle_1 = require("./globalStyle");
@@ -0,0 +1,10 @@
1
+ import { ToastListItem } from '../../toast/toast.types';
2
+ export declare function toastsReducer(state: {
3
+ list: ToastListItem[];
4
+ }, action: {
5
+ type: 'add' | 'remove';
6
+ toast: ToastListItem;
7
+ }): {
8
+ list: ToastListItem[];
9
+ };
10
+ //# sourceMappingURL=reducers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducers.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/reducers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAEvD,wBAAgB,aAAa,CAC3B,KAAK,EAAE;IAAE,IAAI,EAAE,aAAa,EAAE,CAAA;CAAE,EAChC,MAAM,EAAE;IAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE;;EAazD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toastsReducer = void 0;
4
+ function toastsReducer(state, action) {
5
+ switch (action.type) {
6
+ case 'add': {
7
+ return { list: [action.toast, ...state.list] };
8
+ }
9
+ case 'remove': {
10
+ return { list: state.list.filter(t => t.id !== action.toast.id) };
11
+ }
12
+ default: {
13
+ throw new Error(`Unhandled action type: ${action.type}`);
14
+ }
15
+ }
16
+ }
17
+ exports.toastsReducer = toastsReducer;
@@ -1 +1 @@
1
- {"version":3,"file":"vuiProvider.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/vuiProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAKjC,OAAqB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvC,aAAK,gBAAgB,GAAG;IACtB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oGAAoG;AACpG,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,CAepD,CAAA;AAED,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"vuiProvider.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/vuiProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAc,MAAM,OAAO,CAAA;AAM7C,OAAqB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAMvC,aAAK,gBAAgB,GAAG;IACtB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oGAAoG;AACpG,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,CA6BpD,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -1,21 +1,57 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
29
+ const react_1 = __importStar(require("react"));
7
30
  const styled_components_1 = require("styled-components");
8
31
  const modalStyle_1 = __importDefault(require("../../modal/modalStyle"));
9
32
  const popoverStyle_1 = __importDefault(require("../../popover/popoverStyle"));
33
+ const portal_1 = require("../../portal");
10
34
  const theme_1 = __importDefault(require("../../theme"));
35
+ const toast_1 = require("../../toast");
36
+ const context_1 = require("./context");
11
37
  const globalStyle_1 = __importDefault(require("./globalStyle"));
38
+ const reducers_1 = require("./reducers");
12
39
  const resetCSS_1 = __importDefault(require("./resetCSS"));
13
40
  /** Provides theme to all wrapped components and by default includes CSS reset and global styles. */
14
- const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = theme_1.default }) => (react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme },
15
- react_1.default.createElement(react_1.default.Fragment, null,
16
- resetCSS && react_1.default.createElement(resetCSS_1.default, null),
17
- react_1.default.createElement(globalStyle_1.default, { globalStyle: globalStyle }),
18
- react_1.default.createElement(modalStyle_1.default, null),
19
- react_1.default.createElement(popoverStyle_1.default, null),
20
- children)));
41
+ const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = theme_1.default }) => {
42
+ const [toasts, dispatch] = (0, react_1.useReducer)(reducers_1.toastsReducer, { list: [] });
43
+ const addToast = (toast) => dispatch({ type: 'add', toast });
44
+ const removeToast = (id) => dispatch({ type: 'remove', toast: { id } });
45
+ const context = { toasts, addToast, removeToast };
46
+ return (react_1.default.createElement(context_1.VuiContextProvider, { value: context },
47
+ react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme },
48
+ react_1.default.createElement(react_1.default.Fragment, null,
49
+ resetCSS && react_1.default.createElement(resetCSS_1.default, null),
50
+ react_1.default.createElement(globalStyle_1.default, { globalStyle: globalStyle }),
51
+ react_1.default.createElement(modalStyle_1.default, null),
52
+ react_1.default.createElement(popoverStyle_1.default, null),
53
+ children,
54
+ react_1.default.createElement(portal_1.Portal, null,
55
+ react_1.default.createElement(toast_1.Toaster, null))))));
56
+ };
21
57
  exports.default = VuiProvider;
@@ -31,7 +31,7 @@ const showConfirm = (title, message) => {
31
31
  },
32
32
  text: 'Confirm'
33
33
  }, title: title })));
34
- (0, utils_1.reactDomRender)(document.getElementById(consts_1.containerId), confirmDialog);
34
+ (0, utils_1.reactDomRender)(consts_1.containerId, confirmDialog);
35
35
  });
36
36
  };
37
37
  exports.showConfirm = showConfirm;
@@ -36,7 +36,7 @@ const showPrompt = (title, value = '') => {
36
36
  },
37
37
  text: 'Submit'
38
38
  }, title: title })));
39
- (0, utils_1.reactDomRender)(document.getElementById(consts_1.containerId), promptDialog);
39
+ (0, utils_1.reactDomRender)(consts_1.containerId, promptDialog);
40
40
  });
41
41
  };
42
42
  exports.showPrompt = showPrompt;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const _default: React.MemoExoticComponent<() => JSX.Element>;
3
+ export default _default;
4
+ //# sourceMappingURL=Toaster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toaster.d.ts","sourceRoot":"","sources":["../../../src/toast/Toaster.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;;AA8BzB,wBAAkC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const box_1 = require("../box");
8
+ const core_1 = require("../core");
9
+ const theme_1 = require("../theme");
10
+ const Toaster = () => {
11
+ var _a, _b;
12
+ const { toasts } = (0, core_1.useVuiContext)();
13
+ return (react_1.default.createElement(box_1.Box, { bottom: "1rem", display: "block", maxW: "100%", minW: { md: 600, sm: 600, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: theme_1.zIndices.toast }, (_b = (_a = toasts === null || toasts === void 0 ? void 0 : toasts.list) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (toast) => (react_1.default.createElement("div", { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
14
+ };
15
+ exports.default = react_1.default.memo(Toaster);
@@ -1,2 +1,3 @@
1
- export * from './Toast';
1
+ export { default as Toaster } from './Toaster';
2
+ export * from './useToast';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAE9C,cAAc,YAAY,CAAA"}
@@ -13,5 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Toast"), exports);
20
+ exports.Toaster = void 0;
21
+ var Toaster_1 = require("./Toaster");
22
+ Object.defineProperty(exports, "Toaster", { enumerable: true, get: function () { return __importDefault(Toaster_1).default; } });
23
+ __exportStar(require("./useToast"), exports);
@@ -2,7 +2,7 @@ import { ReactNode } from 'react';
2
2
  import { NotificationProps } from '../notification';
3
3
  export interface ToastListItem {
4
4
  id: string;
5
- component: ReactNode;
5
+ component?: ReactNode;
6
6
  }
7
7
  export interface ToastSetup {
8
8
  options: ToastOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"toast.types.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,SAAS,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAA;IACrB,aAAa,EAAE,aAAa,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB"}
1
+ {"version":3,"file":"toast.types.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAA;IACrB,aAAa,EAAE,aAAa,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB"}
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { ToastOptions } from './toast.types';
3
+ export declare const useToast: () => {
4
+ showToast: (options?: ToastOptions | undefined) => void;
5
+ hideToast: (id: string) => any;
6
+ showInfo: (text: ReactNode) => void;
7
+ showSuccess: (text: ReactNode) => void;
8
+ showWarning: (text: ReactNode) => void;
9
+ showError: (text: ReactNode) => void;
10
+ showLoading: (text: ReactNode) => void;
11
+ };
12
+ //# sourceMappingURL=useToast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToast.d.ts","sourceRoot":"","sources":["../../../src/toast/useToast.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKxC,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAA;AAUxD,eAAO,MAAM,QAAQ;uDAKyB,IAAI;oBAFzB,MAAM;qBAqCL,SAAS;wBACN,SAAS;wBACT,SAAS;sBACX,SAAS;wBACP,SAAS;CAGrC,CAAA"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useToast = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const core_1 = require("../core");
9
+ const notification_1 = require("../notification");
10
+ const utils_1 = require("../utils");
11
+ const setup = {
12
+ options: {
13
+ duration: 5000,
14
+ dismissible: true
15
+ },
16
+ componentList: []
17
+ };
18
+ const useToast = () => {
19
+ const { addToast, removeToast } = (0, core_1.useVuiContext)();
20
+ const hideToast = (id) => removeToast(id);
21
+ const showToast = (options) => {
22
+ const id = (options === null || options === void 0 ? void 0 : options.id) ? options.id : (0, utils_1.uid)('toast');
23
+ const { duration = setup.options.duration } = options || {};
24
+ const { dismissible = setup.options.dismissible } = options || {};
25
+ const { status = setup.options.duration } = options || {};
26
+ const { action } = options || {};
27
+ const { icon } = options || {};
28
+ const { text } = options || {};
29
+ const { title } = options || {};
30
+ const onClose = () => hideToast(id);
31
+ const toast = {
32
+ id,
33
+ component: (react_1.default.createElement(notification_1.Notification, { action: action, animation: "fadeDown", icon: icon, mt: { md: 1, sm: '4px', xs: '4px' }, onClose: dismissible ? onClose : undefined, shadow: 1, status: status, text: text, title: title, w: 1 }))
34
+ };
35
+ addToast(toast);
36
+ if (duration !== 0)
37
+ window.setTimeout(() => hideToast(id), duration);
38
+ };
39
+ const showInfo = (text) => showToast({ text, status: 'info' });
40
+ const showSuccess = (text) => showToast({ text, status: 'success' });
41
+ const showWarning = (text) => showToast({ text, status: 'warning' });
42
+ const showError = (text) => showToast({ text, status: 'error' });
43
+ const showLoading = (text) => showToast({ text, status: 'loading' });
44
+ return { showToast, hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
45
+ };
46
+ exports.useToast = useToast;
@@ -1,4 +1,4 @@
1
- import React, { DependencyList, ReactNode, RefObject } from 'react';
1
+ import React, { DependencyList, ReactElement, RefObject } from 'react';
2
2
  import { AnyFunction, CreateContextOptions, CreateContextReturn } from './types';
3
3
  declare type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>;
4
4
  /**
@@ -37,6 +37,6 @@ export declare function useIds(id: string, prefixes: string[]): string[];
37
37
  */
38
38
  export declare function useIsMounted(): () => boolean;
39
39
  /** A resolver to render a DOM node depending on React major version. */
40
- export declare function reactDomRender(wrapper: HTMLElement | null, content: ReactNode): void;
40
+ export declare function reactDomRender(id: string, content: ReactElement): void;
41
41
  export {};
42
42
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/utils/react.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EACZ,cAAc,EAEd,SAAS,EACT,SAAS,EAMV,MAAM,OAAO,CAAA;AAKd,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEhF,aAAK,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;AAEhF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,QAcxE;AAED,sEAA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AAC,EAAE,CAAC,CAAA;CACV,CAAA;AAGD,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC;kBAwBzC,OAAO;WAAS,MAAM,IAAI;GAE7C;AAED,4GAA4G;AAC5G,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAEpD;AAGD;;GAEG;AACH,wBAAgB,YAAY,kBAY3B;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,QAI/D"}
@@ -149,19 +149,10 @@ function useIsMounted() {
149
149
  }
150
150
  exports.useIsMounted = useIsMounted;
151
151
  /** A resolver to render a DOM node depending on React major version. */
152
- function reactDomRender(wrapper, content) {
153
- var _a, _b, _c;
152
+ function reactDomRender(id, content) {
153
+ const wrapper = document.getElementById(id);
154
154
  if (!wrapper)
155
155
  return;
156
- if (react_dom_1.default === null || react_dom_1.default === void 0 ? void 0 : react_dom_1.default.createRoot) {
157
- // Rendering for React 18
158
- const root = (_a = react_dom_1.default === null || react_dom_1.default === void 0 ? void 0 : react_dom_1.default.createRoot) === null || _a === void 0 ? void 0 : _a.call(react_dom_1.default, wrapper);
159
- (_b = root === null || root === void 0 ? void 0 : root.render) === null || _b === void 0 ? void 0 : _b.call(root, content);
160
- }
161
- else {
162
- // Rendering for legacy React 17
163
- ;
164
- (_c = react_dom_1.default === null || react_dom_1.default === void 0 ? void 0 : react_dom_1.default.render) === null || _c === void 0 ? void 0 : _c.call(react_dom_1.default, content, wrapper);
165
- }
156
+ react_dom_1.default.render(content, wrapper);
166
157
  }
167
158
  exports.reactDomRender = reactDomRender;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ declare const VuiContextProvider: import("react").Provider<any>, useVuiContext: () => any;
3
+ export { VuiContextProvider, useVuiContext };
4
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/context.ts"],"names":[],"mappings":";AAEA,QAAA,MAAO,kBAAkB,iCAAE,aAAa,WAA4C,CAAA;AAEpF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { createContext } from '../../utils';
2
+ const [VuiContextProvider, useVuiContext] = createContext({ isOptional: true });
3
+ export { VuiContextProvider, useVuiContext };
@@ -1,4 +1,5 @@
1
1
  export * from './animations';
2
+ export * from './context';
2
3
  export { default as fontFaces } from './fontFaces';
3
4
  export { default as GlobalStyle } from './globalStyle';
4
5
  export { default as ResetCSS } from './resetCSS';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * from './animations';
2
+ export * from './context';
2
3
  export { default as fontFaces } from './fontFaces';
3
4
  export { default as GlobalStyle } from './globalStyle';
4
5
  export { default as ResetCSS } from './resetCSS';
@@ -0,0 +1,10 @@
1
+ import { ToastListItem } from '../../toast/toast.types';
2
+ export declare function toastsReducer(state: {
3
+ list: ToastListItem[];
4
+ }, action: {
5
+ type: 'add' | 'remove';
6
+ toast: ToastListItem;
7
+ }): {
8
+ list: ToastListItem[];
9
+ };
10
+ //# sourceMappingURL=reducers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducers.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/reducers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAEvD,wBAAgB,aAAa,CAC3B,KAAK,EAAE;IAAE,IAAI,EAAE,aAAa,EAAE,CAAA;CAAE,EAChC,MAAM,EAAE;IAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE;;EAazD"}
@@ -0,0 +1,13 @@
1
+ export function toastsReducer(state, action) {
2
+ switch (action.type) {
3
+ case 'add': {
4
+ return { list: [action.toast, ...state.list] };
5
+ }
6
+ case 'remove': {
7
+ return { list: state.list.filter(t => t.id !== action.toast.id) };
8
+ }
9
+ default: {
10
+ throw new Error(`Unhandled action type: ${action.type}`);
11
+ }
12
+ }
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"vuiProvider.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/vuiProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAKjC,OAAqB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvC,aAAK,gBAAgB,GAAG;IACtB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oGAAoG;AACpG,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,CAepD,CAAA;AAED,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"vuiProvider.d.ts","sourceRoot":"","sources":["../../../../src/core/vuiProvider/vuiProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAc,MAAM,OAAO,CAAA;AAM7C,OAAqB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAMvC,aAAK,gBAAgB,GAAG;IACtB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oGAAoG;AACpG,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,CA6BpD,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -1,16 +1,29 @@
1
- import React from 'react';
1
+ import React, { useReducer } from 'react';
2
2
  import { ThemeProvider } from 'styled-components';
3
3
  import ModalStyle from '../../modal/modalStyle';
4
4
  import PopoverStyle from '../../popover/popoverStyle';
5
+ import { Portal } from '../../portal';
5
6
  import defaultTheme from '../../theme';
7
+ import { Toaster } from '../../toast';
8
+ import { VuiContextProvider } from './context';
6
9
  import GlobalStyle from './globalStyle';
10
+ import { toastsReducer } from './reducers';
7
11
  import ResetCSS from './resetCSS';
8
12
  /** Provides theme to all wrapped components and by default includes CSS reset and global styles. */
9
- const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = defaultTheme }) => (React.createElement(ThemeProvider, { theme: theme },
10
- React.createElement(React.Fragment, null,
11
- resetCSS && React.createElement(ResetCSS, null),
12
- React.createElement(GlobalStyle, { globalStyle: globalStyle }),
13
- React.createElement(ModalStyle, null),
14
- React.createElement(PopoverStyle, null),
15
- children)));
13
+ const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = defaultTheme }) => {
14
+ const [toasts, dispatch] = useReducer(toastsReducer, { list: [] });
15
+ const addToast = (toast) => dispatch({ type: 'add', toast });
16
+ const removeToast = (id) => dispatch({ type: 'remove', toast: { id } });
17
+ const context = { toasts, addToast, removeToast };
18
+ return (React.createElement(VuiContextProvider, { value: context },
19
+ React.createElement(ThemeProvider, { theme: theme },
20
+ React.createElement(React.Fragment, null,
21
+ resetCSS && React.createElement(ResetCSS, null),
22
+ React.createElement(GlobalStyle, { globalStyle: globalStyle }),
23
+ React.createElement(ModalStyle, null),
24
+ React.createElement(PopoverStyle, null),
25
+ children,
26
+ React.createElement(Portal, null,
27
+ React.createElement(Toaster, null))))));
28
+ };
16
29
  export default VuiProvider;
@@ -25,6 +25,6 @@ export const showConfirm = (title, message) => {
25
25
  },
26
26
  text: 'Confirm'
27
27
  }, title: title })));
28
- reactDomRender(document.getElementById(containerId), confirmDialog);
28
+ reactDomRender(containerId, confirmDialog);
29
29
  });
30
30
  };
@@ -30,6 +30,6 @@ export const showPrompt = (title, value = '') => {
30
30
  },
31
31
  text: 'Submit'
32
32
  }, title: title })));
33
- reactDomRender(document.getElementById(containerId), promptDialog);
33
+ reactDomRender(containerId, promptDialog);
34
34
  });
35
35
  };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const _default: React.MemoExoticComponent<() => JSX.Element>;
3
+ export default _default;
4
+ //# sourceMappingURL=Toaster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toaster.d.ts","sourceRoot":"","sources":["../../../src/toast/Toaster.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;;AA8BzB,wBAAkC"}
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { Box } from '../box';
3
+ import { useVuiContext } from '../core';
4
+ import { zIndices } from '../theme';
5
+ const Toaster = () => {
6
+ const { toasts } = useVuiContext();
7
+ return (React.createElement(Box, { bottom: "1rem", display: "block", maxW: "100%", minW: { md: 600, sm: 600, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: zIndices.toast }, toasts?.list?.map?.((toast) => (React.createElement("div", { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
8
+ };
9
+ export default React.memo(Toaster);
@@ -1,2 +1,3 @@
1
- export * from './Toast';
1
+ export { default as Toaster } from './Toaster';
2
+ export * from './useToast';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAE9C,cAAc,YAAY,CAAA"}
@@ -1 +1,2 @@
1
- export * from './Toast';
1
+ export { default as Toaster } from './Toaster';
2
+ export * from './useToast';
@@ -2,7 +2,7 @@ import { ReactNode } from 'react';
2
2
  import { NotificationProps } from '../notification';
3
3
  export interface ToastListItem {
4
4
  id: string;
5
- component: ReactNode;
5
+ component?: ReactNode;
6
6
  }
7
7
  export interface ToastSetup {
8
8
  options: ToastOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"toast.types.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,SAAS,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAA;IACrB,aAAa,EAAE,aAAa,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB"}
1
+ {"version":3,"file":"toast.types.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAA;IACrB,aAAa,EAAE,aAAa,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB"}
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { ToastOptions } from './toast.types';
3
+ export declare const useToast: () => {
4
+ showToast: (options?: ToastOptions | undefined) => void;
5
+ hideToast: (id: string) => any;
6
+ showInfo: (text: ReactNode) => void;
7
+ showSuccess: (text: ReactNode) => void;
8
+ showWarning: (text: ReactNode) => void;
9
+ showError: (text: ReactNode) => void;
10
+ showLoading: (text: ReactNode) => void;
11
+ };
12
+ //# sourceMappingURL=useToast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToast.d.ts","sourceRoot":"","sources":["../../../src/toast/useToast.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKxC,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAA;AAUxD,eAAO,MAAM,QAAQ;uDAKyB,IAAI;oBAFzB,MAAM;qBAqCL,SAAS;wBACN,SAAS;wBACT,SAAS;sBACX,SAAS;wBACP,SAAS;CAGrC,CAAA"}
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { useVuiContext } from '../core';
3
+ import { Notification } from '../notification';
4
+ import { uid } from '../utils';
5
+ const setup = {
6
+ options: {
7
+ duration: 5000,
8
+ dismissible: true
9
+ },
10
+ componentList: []
11
+ };
12
+ export const useToast = () => {
13
+ const { addToast, removeToast } = useVuiContext();
14
+ const hideToast = (id) => removeToast(id);
15
+ const showToast = (options) => {
16
+ const id = options?.id ? options.id : uid('toast');
17
+ const { duration = setup.options.duration } = options || {};
18
+ const { dismissible = setup.options.dismissible } = options || {};
19
+ const { status = setup.options.duration } = options || {};
20
+ const { action } = options || {};
21
+ const { icon } = options || {};
22
+ const { text } = options || {};
23
+ const { title } = options || {};
24
+ const onClose = () => hideToast(id);
25
+ const toast = {
26
+ id,
27
+ component: (React.createElement(Notification, { action: action, animation: "fadeDown", icon: icon, mt: { md: 1, sm: '4px', xs: '4px' }, onClose: dismissible ? onClose : undefined, shadow: 1, status: status, text: text, title: title, w: 1 }))
28
+ };
29
+ addToast(toast);
30
+ if (duration !== 0)
31
+ window.setTimeout(() => hideToast(id), duration);
32
+ };
33
+ const showInfo = (text) => showToast({ text, status: 'info' });
34
+ const showSuccess = (text) => showToast({ text, status: 'success' });
35
+ const showWarning = (text) => showToast({ text, status: 'warning' });
36
+ const showError = (text) => showToast({ text, status: 'error' });
37
+ const showLoading = (text) => showToast({ text, status: 'loading' });
38
+ return { showToast, hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
39
+ };
@@ -1,4 +1,4 @@
1
- import React, { DependencyList, ReactNode, RefObject } from 'react';
1
+ import React, { DependencyList, ReactElement, RefObject } from 'react';
2
2
  import { AnyFunction, CreateContextOptions, CreateContextReturn } from './types';
3
3
  declare type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>;
4
4
  /**
@@ -37,6 +37,6 @@ export declare function useIds(id: string, prefixes: string[]): string[];
37
37
  */
38
38
  export declare function useIsMounted(): () => boolean;
39
39
  /** A resolver to render a DOM node depending on React major version. */
40
- export declare function reactDomRender(wrapper: HTMLElement | null, content: ReactNode): void;
40
+ export declare function reactDomRender(id: string, content: ReactElement): void;
41
41
  export {};
42
42
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/utils/react.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EACZ,cAAc,EAEd,SAAS,EACT,SAAS,EAMV,MAAM,OAAO,CAAA;AAKd,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEhF,aAAK,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;AAEhF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,QAcxE;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,WAAW,EAAE,OAAO,GAAE,oBAAyB,oCAoB5E;AAED,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,UACjD,CAAC,GAAG,IAAI,UAGvB;AAGD,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,CAA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AED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,QAI/D"}
@@ -112,17 +112,9 @@ export function useIsMounted() {
112
112
  return useCallback(() => isMounted.current, []);
113
113
  }
114
114
  /** A resolver to render a DOM node depending on React major version. */
115
- export function reactDomRender(wrapper, content) {
115
+ export function reactDomRender(id, content) {
116
+ const wrapper = document.getElementById(id);
116
117
  if (!wrapper)
117
118
  return;
118
- if (ReactDOM?.createRoot) {
119
- // Rendering for React 18
120
- const root = ReactDOM?.createRoot?.(wrapper);
121
- root?.render?.(content);
122
- }
123
- else {
124
- // Rendering for legacy React 17
125
- ;
126
- ReactDOM?.render?.(content, wrapper);
127
- }
119
+ ReactDOM.render(content, wrapper);
128
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "1.2.0-beta.0",
3
+ "version": "1.2.0-beta.2",
4
4
  "description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
@@ -0,0 +1,5 @@
1
+ import { createContext } from '../../utils'
2
+
3
+ const [VuiContextProvider, useVuiContext] = createContext<any>({ isOptional: true })
4
+
5
+ export { VuiContextProvider, useVuiContext }
@@ -1,4 +1,5 @@
1
1
  export * from './animations'
2
+ export * from './context'
2
3
  export { default as fontFaces } from './fontFaces'
3
4
  export { default as GlobalStyle } from './globalStyle'
4
5
  export { default as ResetCSS } from './resetCSS'
@@ -0,0 +1,18 @@
1
+ import { ToastListItem } from '../../toast/toast.types'
2
+
3
+ export function toastsReducer(
4
+ state: { list: ToastListItem[] },
5
+ action: { type: 'add' | 'remove'; toast: ToastListItem }
6
+ ) {
7
+ switch (action.type) {
8
+ case 'add': {
9
+ return { list: [action.toast, ...state.list] }
10
+ }
11
+ case 'remove': {
12
+ return { list: state.list.filter(t => t.id !== action.toast.id) }
13
+ }
14
+ default: {
15
+ throw new Error(`Unhandled action type: ${action.type}`)
16
+ }
17
+ }
18
+ }
@@ -1,11 +1,16 @@
1
- import React, { FC } from 'react'
1
+ import React, { FC, useReducer } from 'react'
2
2
  import { ThemeProvider } from 'styled-components'
3
3
 
4
4
  import ModalStyle from '../../modal/modalStyle'
5
5
  import PopoverStyle from '../../popover/popoverStyle'
6
+ import { Portal } from '../../portal'
6
7
  import defaultTheme, { VuiTheme } from '../../theme'
8
+ import { Toaster } from '../../toast'
9
+ import { ToastListItem } from '../../toast/toast.types'
7
10
  import { ChildrenProp } from '../types'
11
+ import { VuiContextProvider } from './context'
8
12
  import GlobalStyle from './globalStyle'
13
+ import { toastsReducer } from './reducers'
9
14
  import ResetCSS from './resetCSS'
10
15
 
11
16
  type VuiProviderProps = {
@@ -23,16 +28,30 @@ const VuiProvider: FC<VuiProviderProps & ChildrenProp> = ({
23
28
  globalStyle = true,
24
29
  resetCSS = true,
25
30
  theme = defaultTheme as VuiTheme
26
- }) => (
27
- <ThemeProvider theme={theme}>
28
- <>
29
- {resetCSS && <ResetCSS />}
30
- <GlobalStyle globalStyle={globalStyle} />
31
- <ModalStyle />
32
- <PopoverStyle />
33
- {children}
34
- </>
35
- </ThemeProvider>
36
- )
31
+ }) => {
32
+ const [toasts, dispatch] = useReducer(toastsReducer, { list: [] })
33
+
34
+ const addToast = (toast: ToastListItem) => dispatch({ type: 'add', toast })
35
+ const removeToast = (id: string) => dispatch({ type: 'remove', toast: { id } })
36
+
37
+ const context = { toasts, addToast, removeToast }
38
+
39
+ return (
40
+ <VuiContextProvider value={context}>
41
+ <ThemeProvider theme={theme}>
42
+ <>
43
+ {resetCSS && <ResetCSS />}
44
+ <GlobalStyle globalStyle={globalStyle} />
45
+ <ModalStyle />
46
+ <PopoverStyle />
47
+ {children}
48
+ <Portal>
49
+ <Toaster />
50
+ </Portal>
51
+ </>
52
+ </ThemeProvider>
53
+ </VuiContextProvider>
54
+ )
55
+ }
37
56
 
38
57
  export default VuiProvider
@@ -40,6 +40,6 @@ export const showConfirm = (title: string, message: string): Promise<boolean> =>
40
40
  </VuiProvider>
41
41
  )
42
42
 
43
- reactDomRender(document.getElementById(containerId), confirmDialog)
43
+ reactDomRender(containerId, confirmDialog)
44
44
  })
45
45
  }
@@ -50,6 +50,6 @@ export const showPrompt = (title: string, value = ''): Promise<string | false> =
50
50
  </VuiProvider>
51
51
  )
52
52
 
53
- reactDomRender(document.getElementById(containerId), promptDialog)
53
+ reactDomRender(containerId, promptDialog)
54
54
  })
55
55
  }
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+
3
+ import { Box } from '../box'
4
+ import { useVuiContext } from '../core'
5
+ import { zIndices } from '../theme'
6
+ import { ToastListItem } from './toast.types'
7
+
8
+ const Toaster = () => {
9
+ const { toasts } = useVuiContext()
10
+
11
+ return (
12
+ <Box
13
+ bottom="1rem"
14
+ display="block"
15
+ maxW="100%"
16
+ minW={{ md: 600, sm: 600, xs: '100%' }}
17
+ p={{ md: '16px', sm: '4px', xs: '2px' }}
18
+ position="fixed"
19
+ right={{ md: '1rem', sm: 0, xs: 0 }}
20
+ zIndex={zIndices.toast}
21
+ >
22
+ {toasts?.list?.map?.((toast: ToastListItem) => (
23
+ <div id={`toast_${toast.id}`} key={toast.id}>
24
+ {toast.component}
25
+ </div>
26
+ ))}
27
+ </Box>
28
+ )
29
+ }
30
+
31
+ export default React.memo(Toaster)
@@ -1 +1,3 @@
1
- export * from './Toast'
1
+ export { default as Toaster } from './Toaster'
2
+
3
+ export * from './useToast'
@@ -4,7 +4,7 @@ import { NotificationProps } from '../notification'
4
4
 
5
5
  export interface ToastListItem {
6
6
  id: string
7
- component: ReactNode
7
+ component?: ReactNode
8
8
  }
9
9
 
10
10
  export interface ToastSetup {
@@ -0,0 +1,63 @@
1
+ import React, { ReactNode } from 'react'
2
+
3
+ import { useVuiContext } from '../core'
4
+ import { Notification, NotificationStatus } from '../notification'
5
+ import { uid } from '../utils'
6
+ import { ToastOptions, ToastSetup } from './toast.types'
7
+
8
+ const setup: ToastSetup = {
9
+ options: {
10
+ duration: 5000,
11
+ dismissible: true
12
+ },
13
+ componentList: []
14
+ }
15
+
16
+ export const useToast = () => {
17
+ const { addToast, removeToast } = useVuiContext()
18
+
19
+ const hideToast = (id: string) => removeToast(id)
20
+
21
+ const showToast = (options?: ToastOptions): void => {
22
+ const id = options?.id ? options.id : uid('toast')
23
+ const { duration = setup.options.duration } = options || {}
24
+ const { dismissible = setup.options.dismissible } = options || {}
25
+ const { status = setup.options.duration } = options || {}
26
+ const { action } = options || {}
27
+ const { icon } = options || {}
28
+ const { text } = options || {}
29
+ const { title } = options || {}
30
+
31
+ const onClose = () => hideToast(id)
32
+
33
+ const toast = {
34
+ id,
35
+ component: (
36
+ <Notification
37
+ action={action}
38
+ animation="fadeDown"
39
+ icon={icon}
40
+ mt={{ md: 1, sm: '4px', xs: '4px' }}
41
+ onClose={dismissible ? onClose : undefined}
42
+ shadow={1}
43
+ status={status as NotificationStatus}
44
+ text={text}
45
+ title={title}
46
+ w={1}
47
+ />
48
+ )
49
+ }
50
+
51
+ addToast(toast)
52
+
53
+ if (duration !== 0) window.setTimeout(() => hideToast(id), duration)
54
+ }
55
+
56
+ const showInfo = (text: ReactNode) => showToast({ text, status: 'info' })
57
+ const showSuccess = (text: ReactNode) => showToast({ text, status: 'success' })
58
+ const showWarning = (text: ReactNode) => showToast({ text, status: 'warning' })
59
+ const showError = (text: ReactNode) => showToast({ text, status: 'error' })
60
+ const showLoading = (text: ReactNode) => showToast({ text, status: 'loading' })
61
+
62
+ return { showToast, hideToast, showInfo, showSuccess, showWarning, showError, showLoading }
63
+ }
@@ -3,7 +3,7 @@
3
3
  import React, {
4
4
  DependencyList,
5
5
  Dispatch,
6
- ReactNode,
6
+ ReactElement,
7
7
  RefObject,
8
8
  SetStateAction,
9
9
  useCallback,
@@ -174,14 +174,8 @@ export function useIsMounted() {
174
174
  }
175
175
 
176
176
  /** A resolver to render a DOM node depending on React major version. */
177
- export function reactDomRender(wrapper: HTMLElement | null, content: ReactNode) {
177
+ export function reactDomRender(id: string, content: ReactElement) {
178
+ const wrapper = document.getElementById(id)
178
179
  if (!wrapper) return
179
- if ((ReactDOM as any)?.createRoot) {
180
- // Rendering for React 18
181
- const root = (ReactDOM as any)?.createRoot?.(wrapper)
182
- root?.render?.(content)
183
- } else {
184
- // Rendering for legacy React 17
185
- ;(ReactDOM as any)?.render?.(content, wrapper)
186
- }
180
+ ReactDOM.render(content, wrapper)
187
181
  }
@@ -1,11 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { ToastOptions } from './toast.types';
3
- declare const hide: (id: string) => void;
4
- declare const show: (options?: ToastOptions | undefined) => void;
5
- declare const showInfo: (text: ReactNode) => void;
6
- declare const showSuccess: (text: ReactNode) => void;
7
- declare const showWarning: (text: ReactNode) => void;
8
- declare const showError: (text: ReactNode) => void;
9
- declare const showLoading: (text: ReactNode) => void;
10
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
11
- //# sourceMappingURL=Toast.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/toast/Toast.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOxC,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAA;AAoCxD,QAAA,MAAM,IAAI,OAAQ,MAAM,KAAG,IAG1B,CAAA;AAED,QAAA,MAAM,IAAI,0CAA6B,IAqCtC,CAAA;AAED,QAAA,MAAM,QAAQ,SAAU,SAAS,SAAmC,CAAA;AACpE,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAC1E,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAC1E,QAAA,MAAM,SAAS,SAAU,SAAS,SAAoC,CAAA;AACtE,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAE1E,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,IAAI,IAAI,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.showLoading = exports.showError = exports.showWarning = exports.showSuccess = exports.showInfo = exports.hideToast = exports.showToast = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const box_1 = require("../box");
9
- const core_1 = require("../core");
10
- const notification_1 = require("../notification");
11
- const theme_1 = require("../theme");
12
- const utils_1 = require("../utils");
13
- const wrapperId = 'toastsWrapper';
14
- const setup = {
15
- options: {
16
- duration: 5000,
17
- dismissible: true
18
- },
19
- componentList: []
20
- };
21
- const render = () => {
22
- const wrapper = document.getElementById(wrapperId);
23
- const content = (react_1.default.createElement(core_1.VuiProvider, null,
24
- react_1.default.createElement(box_1.Box, { bottom: "1rem", display: "block", maxW: "100%", minW: { md: 600, sm: 600, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: theme_1.zIndices.toast }, setup.componentList.map(item => (react_1.default.createElement("div", { key: item.id }, item.component))))));
25
- (0, utils_1.reactDomRender)(wrapper, content);
26
- };
27
- const hide = (id) => {
28
- setup.componentList = setup.componentList.filter(i => i.id !== id);
29
- render();
30
- };
31
- exports.hideToast = hide;
32
- const show = (options) => {
33
- const id = (options === null || options === void 0 ? void 0 : options.id) ? options.id : (0, utils_1.uid)('toast');
34
- const { duration = setup.options.duration } = options || {};
35
- const { dismissible = setup.options.dismissible } = options || {};
36
- const { status = setup.options.duration } = options || {};
37
- const { action } = options || {};
38
- const { icon } = options || {};
39
- const { text } = options || {};
40
- const { title } = options || {};
41
- (0, utils_1.addContainer)(wrapperId);
42
- render();
43
- const onClose = () => hide(id);
44
- setup.componentList.unshift({
45
- id,
46
- component: (react_1.default.createElement(notification_1.Notification, { action: action, animation: "fadeDown", icon: icon, mt: { md: 1, sm: '4px', xs: '4px' }, onClose: dismissible ? onClose : undefined, shadow: 1, status: status, text: text, title: title, w: 1 }))
47
- });
48
- render();
49
- if (duration !== 0)
50
- window.setTimeout(() => hide(id), duration);
51
- };
52
- exports.showToast = show;
53
- const showInfo = (text) => show({ text, status: 'info' });
54
- exports.showInfo = showInfo;
55
- const showSuccess = (text) => show({ text, status: 'success' });
56
- exports.showSuccess = showSuccess;
57
- const showWarning = (text) => show({ text, status: 'warning' });
58
- exports.showWarning = showWarning;
59
- const showError = (text) => show({ text, status: 'error' });
60
- exports.showError = showError;
61
- const showLoading = (text) => show({ text, status: 'loading' });
62
- exports.showLoading = showLoading;
@@ -1,11 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { ToastOptions } from './toast.types';
3
- declare const hide: (id: string) => void;
4
- declare const show: (options?: ToastOptions | undefined) => void;
5
- declare const showInfo: (text: ReactNode) => void;
6
- declare const showSuccess: (text: ReactNode) => void;
7
- declare const showWarning: (text: ReactNode) => void;
8
- declare const showError: (text: ReactNode) => void;
9
- declare const showLoading: (text: ReactNode) => void;
10
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
11
- //# sourceMappingURL=Toast.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/toast/Toast.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOxC,OAAO,EAAE,YAAY,EAAc,MAAM,eAAe,CAAA;AAoCxD,QAAA,MAAM,IAAI,OAAQ,MAAM,KAAG,IAG1B,CAAA;AAED,QAAA,MAAM,IAAI,0CAA6B,IAqCtC,CAAA;AAED,QAAA,MAAM,QAAQ,SAAU,SAAS,SAAmC,CAAA;AACpE,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAC1E,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAC1E,QAAA,MAAM,SAAS,SAAU,SAAS,SAAoC,CAAA;AACtE,QAAA,MAAM,WAAW,SAAU,SAAS,SAAsC,CAAA;AAE1E,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,IAAI,IAAI,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA"}
@@ -1,50 +0,0 @@
1
- import React from 'react';
2
- import { Box } from '../box';
3
- import { VuiProvider } from '../core';
4
- import { Notification } from '../notification';
5
- import { zIndices } from '../theme';
6
- import { addContainer, reactDomRender, uid } from '../utils';
7
- const wrapperId = 'toastsWrapper';
8
- const setup = {
9
- options: {
10
- duration: 5000,
11
- dismissible: true
12
- },
13
- componentList: []
14
- };
15
- const render = () => {
16
- const wrapper = document.getElementById(wrapperId);
17
- const content = (React.createElement(VuiProvider, null,
18
- React.createElement(Box, { bottom: "1rem", display: "block", maxW: "100%", minW: { md: 600, sm: 600, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: zIndices.toast }, setup.componentList.map(item => (React.createElement("div", { key: item.id }, item.component))))));
19
- reactDomRender(wrapper, content);
20
- };
21
- const hide = (id) => {
22
- setup.componentList = setup.componentList.filter(i => i.id !== id);
23
- render();
24
- };
25
- const show = (options) => {
26
- const id = options?.id ? options.id : uid('toast');
27
- const { duration = setup.options.duration } = options || {};
28
- const { dismissible = setup.options.dismissible } = options || {};
29
- const { status = setup.options.duration } = options || {};
30
- const { action } = options || {};
31
- const { icon } = options || {};
32
- const { text } = options || {};
33
- const { title } = options || {};
34
- addContainer(wrapperId);
35
- render();
36
- const onClose = () => hide(id);
37
- setup.componentList.unshift({
38
- id,
39
- component: (React.createElement(Notification, { action: action, animation: "fadeDown", icon: icon, mt: { md: 1, sm: '4px', xs: '4px' }, onClose: dismissible ? onClose : undefined, shadow: 1, status: status, text: text, title: title, w: 1 }))
40
- });
41
- render();
42
- if (duration !== 0)
43
- window.setTimeout(() => hide(id), duration);
44
- };
45
- const showInfo = (text) => show({ text, status: 'info' });
46
- const showSuccess = (text) => show({ text, status: 'success' });
47
- const showWarning = (text) => show({ text, status: 'warning' });
48
- const showError = (text) => show({ text, status: 'error' });
49
- const showLoading = (text) => show({ text, status: 'loading' });
50
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
@@ -1,94 +0,0 @@
1
- import React, { ReactNode } from 'react'
2
-
3
- import { Box } from '../box'
4
- import { VuiProvider } from '../core'
5
- import { Notification, NotificationStatus } from '../notification'
6
- import { zIndices } from '../theme'
7
- import { addContainer, reactDomRender, uid } from '../utils'
8
- import { ToastOptions, ToastSetup } from './toast.types'
9
-
10
- const wrapperId = 'toastsWrapper'
11
-
12
- const setup: ToastSetup = {
13
- options: {
14
- duration: 5000,
15
- dismissible: true
16
- },
17
- componentList: []
18
- }
19
-
20
- const render = (): void => {
21
- const wrapper = document.getElementById(wrapperId)
22
- const content = (
23
- <VuiProvider>
24
- <Box
25
- bottom="1rem"
26
- display="block"
27
- maxW="100%"
28
- minW={{ md: 600, sm: 600, xs: '100%' }}
29
- p={{ md: '16px', sm: '4px', xs: '2px' }}
30
- position="fixed"
31
- right={{ md: '1rem', sm: 0, xs: 0 }}
32
- zIndex={zIndices.toast}
33
- >
34
- {setup.componentList.map(item => (
35
- <div key={item.id}>{item.component}</div>
36
- ))}
37
- </Box>
38
- </VuiProvider>
39
- )
40
-
41
- reactDomRender(wrapper, content)
42
- }
43
-
44
- const hide = (id: string): void => {
45
- setup.componentList = setup.componentList.filter(i => i.id !== id)
46
- render()
47
- }
48
-
49
- const show = (options?: ToastOptions): void => {
50
- const id = options?.id ? options.id : uid('toast')
51
-
52
- const { duration = setup.options.duration } = options || {}
53
- const { dismissible = setup.options.dismissible } = options || {}
54
- const { status = setup.options.duration } = options || {}
55
- const { action } = options || {}
56
- const { icon } = options || {}
57
- const { text } = options || {}
58
- const { title } = options || {}
59
-
60
- addContainer(wrapperId)
61
-
62
- render()
63
-
64
- const onClose = () => hide(id)
65
-
66
- setup.componentList.unshift({
67
- id,
68
- component: (
69
- <Notification
70
- action={action}
71
- animation="fadeDown"
72
- icon={icon}
73
- mt={{ md: 1, sm: '4px', xs: '4px' }}
74
- onClose={dismissible ? onClose : undefined}
75
- shadow={1}
76
- status={status as NotificationStatus}
77
- text={text}
78
- title={title}
79
- w={1}
80
- />
81
- )
82
- })
83
- render()
84
-
85
- if (duration !== 0) window.setTimeout(() => hide(id), duration)
86
- }
87
-
88
- const showInfo = (text: ReactNode) => show({ text, status: 'info' })
89
- const showSuccess = (text: ReactNode) => show({ text, status: 'success' })
90
- const showWarning = (text: ReactNode) => show({ text, status: 'warning' })
91
- const showError = (text: ReactNode) => show({ text, status: 'error' })
92
- const showLoading = (text: ReactNode) => show({ text, status: 'loading' })
93
-
94
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading }