@veracity/vui 1.2.0-beta.1 → 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 (65) 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/toast/Toaster.d.ts +4 -0
  13. package/dist/cjs/toast/Toaster.d.ts.map +1 -0
  14. package/dist/cjs/toast/Toaster.js +15 -0
  15. package/dist/cjs/toast/index.d.ts +2 -1
  16. package/dist/cjs/toast/index.d.ts.map +1 -1
  17. package/dist/cjs/toast/index.js +7 -1
  18. package/dist/cjs/toast/toast.types.d.ts +1 -1
  19. package/dist/cjs/toast/toast.types.d.ts.map +1 -1
  20. package/dist/cjs/toast/useToast.d.ts +12 -0
  21. package/dist/cjs/toast/useToast.d.ts.map +1 -0
  22. package/dist/cjs/toast/useToast.js +46 -0
  23. package/dist/cjs/utils/react.d.ts.map +1 -1
  24. package/dist/cjs/utils/react.js +1 -6
  25. package/dist/esm/core/vuiProvider/context.d.ts +4 -0
  26. package/dist/esm/core/vuiProvider/context.d.ts.map +1 -0
  27. package/dist/esm/core/vuiProvider/context.js +3 -0
  28. package/dist/esm/core/vuiProvider/index.d.ts +1 -0
  29. package/dist/esm/core/vuiProvider/index.d.ts.map +1 -1
  30. package/dist/esm/core/vuiProvider/index.js +1 -0
  31. package/dist/esm/core/vuiProvider/reducers.d.ts +10 -0
  32. package/dist/esm/core/vuiProvider/reducers.d.ts.map +1 -0
  33. package/dist/esm/core/vuiProvider/reducers.js +13 -0
  34. package/dist/esm/core/vuiProvider/vuiProvider.d.ts.map +1 -1
  35. package/dist/esm/core/vuiProvider/vuiProvider.js +21 -8
  36. package/dist/esm/toast/Toaster.d.ts +4 -0
  37. package/dist/esm/toast/Toaster.d.ts.map +1 -0
  38. package/dist/esm/toast/Toaster.js +9 -0
  39. package/dist/esm/toast/index.d.ts +2 -1
  40. package/dist/esm/toast/index.d.ts.map +1 -1
  41. package/dist/esm/toast/index.js +2 -1
  42. package/dist/esm/toast/toast.types.d.ts +1 -1
  43. package/dist/esm/toast/toast.types.d.ts.map +1 -1
  44. package/dist/esm/toast/useToast.d.ts +12 -0
  45. package/dist/esm/toast/useToast.d.ts.map +1 -0
  46. package/dist/esm/toast/useToast.js +39 -0
  47. package/dist/esm/utils/react.d.ts.map +1 -1
  48. package/dist/esm/utils/react.js +1 -6
  49. package/package.json +1 -1
  50. package/src/core/vuiProvider/context.ts +5 -0
  51. package/src/core/vuiProvider/index.ts +1 -0
  52. package/src/core/vuiProvider/reducers.ts +18 -0
  53. package/src/core/vuiProvider/vuiProvider.tsx +31 -12
  54. package/src/toast/Toaster.tsx +31 -0
  55. package/src/toast/index.ts +3 -1
  56. package/src/toast/toast.types.ts +1 -1
  57. package/src/toast/useToast.tsx +63 -0
  58. package/src/utils/react.ts +1 -5
  59. package/dist/cjs/toast/Toast.d.ts +0 -11
  60. package/dist/cjs/toast/Toast.d.ts.map +0 -1
  61. package/dist/cjs/toast/Toast.js +0 -61
  62. package/dist/esm/toast/Toast.d.ts +0 -11
  63. package/dist/esm/toast/Toast.d.ts.map +0 -1
  64. package/dist/esm/toast/Toast.js +0 -49
  65. package/src/toast/Toast.tsx +0 -93
@@ -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;
@@ -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 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/utils/react.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EACZ,cAAc,EAEd,YAAY,EACZ,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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AAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;IAC7B,KAAK,CAAC,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"}
@@ -153,11 +153,6 @@ function reactDomRender(id, content) {
153
153
  const wrapper = document.getElementById(id);
154
154
  if (!wrapper)
155
155
  return;
156
- try {
157
- react_dom_1.default.render(content, wrapper);
158
- }
159
- catch (error) {
160
- console.log(error);
161
- }
156
+ react_dom_1.default.render(content, wrapper);
162
157
  }
163
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;
@@ -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 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/utils/react.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EACZ,cAAc,EAEd,YAAY,EACZ,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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AAE,MAAM,EAAE,YAEpD;AAGD;;GAEG;AACH,wBAAgB,YAAY,kBAY3B;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,QAI/D"}
@@ -116,10 +116,5 @@ export function reactDomRender(id, content) {
116
116
  const wrapper = document.getElementById(id);
117
117
  if (!wrapper)
118
118
  return;
119
- try {
120
- ReactDOM.render(content, wrapper);
121
- }
122
- catch (error) {
123
- console.log(error);
124
- }
119
+ ReactDOM.render(content, wrapper);
125
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "1.2.0-beta.1",
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
@@ -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
+ }
@@ -177,9 +177,5 @@ export function useIsMounted() {
177
177
  export function reactDomRender(id: string, content: ReactElement) {
178
178
  const wrapper = document.getElementById(id)
179
179
  if (!wrapper) return
180
- try {
181
- ReactDOM.render(content, wrapper)
182
- } catch (error) {
183
- console.log(error)
184
- }
180
+ ReactDOM.render(content, wrapper)
185
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;AAmCxD,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,61 +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 content = (react_1.default.createElement(core_1.VuiProvider, null,
23
- 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))))));
24
- (0, utils_1.reactDomRender)(wrapperId, content);
25
- };
26
- const hide = (id) => {
27
- setup.componentList = setup.componentList.filter(i => i.id !== id);
28
- render();
29
- };
30
- exports.hideToast = hide;
31
- const show = (options) => {
32
- const id = (options === null || options === void 0 ? void 0 : options.id) ? options.id : (0, utils_1.uid)('toast');
33
- const { duration = setup.options.duration } = options || {};
34
- const { dismissible = setup.options.dismissible } = options || {};
35
- const { status = setup.options.duration } = options || {};
36
- const { action } = options || {};
37
- const { icon } = options || {};
38
- const { text } = options || {};
39
- const { title } = options || {};
40
- (0, utils_1.addContainer)(wrapperId);
41
- render();
42
- const onClose = () => hide(id);
43
- setup.componentList.unshift({
44
- id,
45
- 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 }))
46
- });
47
- render();
48
- if (duration !== 0)
49
- window.setTimeout(() => hide(id), duration);
50
- };
51
- exports.showToast = show;
52
- const showInfo = (text) => show({ text, status: 'info' });
53
- exports.showInfo = showInfo;
54
- const showSuccess = (text) => show({ text, status: 'success' });
55
- exports.showSuccess = showSuccess;
56
- const showWarning = (text) => show({ text, status: 'warning' });
57
- exports.showWarning = showWarning;
58
- const showError = (text) => show({ text, status: 'error' });
59
- exports.showError = showError;
60
- const showLoading = (text) => show({ text, status: 'loading' });
61
- 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;AAmCxD,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,49 +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 content = (React.createElement(VuiProvider, null,
17
- 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))))));
18
- reactDomRender(wrapperId, content);
19
- };
20
- const hide = (id) => {
21
- setup.componentList = setup.componentList.filter(i => i.id !== id);
22
- render();
23
- };
24
- const show = (options) => {
25
- const id = options?.id ? options.id : uid('toast');
26
- const { duration = setup.options.duration } = options || {};
27
- const { dismissible = setup.options.dismissible } = options || {};
28
- const { status = setup.options.duration } = options || {};
29
- const { action } = options || {};
30
- const { icon } = options || {};
31
- const { text } = options || {};
32
- const { title } = options || {};
33
- addContainer(wrapperId);
34
- render();
35
- const onClose = () => hide(id);
36
- setup.componentList.unshift({
37
- id,
38
- 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 }))
39
- });
40
- render();
41
- if (duration !== 0)
42
- window.setTimeout(() => hide(id), duration);
43
- };
44
- const showInfo = (text) => show({ text, status: 'info' });
45
- const showSuccess = (text) => show({ text, status: 'success' });
46
- const showWarning = (text) => show({ text, status: 'warning' });
47
- const showError = (text) => show({ text, status: 'error' });
48
- const showLoading = (text) => show({ text, status: 'loading' });
49
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading };
@@ -1,93 +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 content = (
22
- <VuiProvider>
23
- <Box
24
- bottom="1rem"
25
- display="block"
26
- maxW="100%"
27
- minW={{ md: 600, sm: 600, xs: '100%' }}
28
- p={{ md: '16px', sm: '4px', xs: '2px' }}
29
- position="fixed"
30
- right={{ md: '1rem', sm: 0, xs: 0 }}
31
- zIndex={zIndices.toast}
32
- >
33
- {setup.componentList.map(item => (
34
- <div key={item.id}>{item.component}</div>
35
- ))}
36
- </Box>
37
- </VuiProvider>
38
- )
39
-
40
- reactDomRender(wrapperId, content)
41
- }
42
-
43
- const hide = (id: string): void => {
44
- setup.componentList = setup.componentList.filter(i => i.id !== id)
45
- render()
46
- }
47
-
48
- const show = (options?: ToastOptions): void => {
49
- const id = options?.id ? options.id : uid('toast')
50
-
51
- const { duration = setup.options.duration } = options || {}
52
- const { dismissible = setup.options.dismissible } = options || {}
53
- const { status = setup.options.duration } = options || {}
54
- const { action } = options || {}
55
- const { icon } = options || {}
56
- const { text } = options || {}
57
- const { title } = options || {}
58
-
59
- addContainer(wrapperId)
60
-
61
- render()
62
-
63
- const onClose = () => hide(id)
64
-
65
- setup.componentList.unshift({
66
- id,
67
- component: (
68
- <Notification
69
- action={action}
70
- animation="fadeDown"
71
- icon={icon}
72
- mt={{ md: 1, sm: '4px', xs: '4px' }}
73
- onClose={dismissible ? onClose : undefined}
74
- shadow={1}
75
- status={status as NotificationStatus}
76
- text={text}
77
- title={title}
78
- w={1}
79
- />
80
- )
81
- })
82
- render()
83
-
84
- if (duration !== 0) window.setTimeout(() => hide(id), duration)
85
- }
86
-
87
- const showInfo = (text: ReactNode) => show({ text, status: 'info' })
88
- const showSuccess = (text: ReactNode) => show({ text, status: 'success' })
89
- const showWarning = (text: ReactNode) => show({ text, status: 'warning' })
90
- const showError = (text: ReactNode) => show({ text, status: 'error' })
91
- const showLoading = (text: ReactNode) => show({ text, status: 'loading' })
92
-
93
- export { show as showToast, hide as hideToast, showInfo, showSuccess, showWarning, showError, showLoading }