@cleartrip/ct-design-toast 4.0.0-TEST.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,11 @@
1
- import { __assign } from 'tslib';
2
1
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useState, useEffect } from 'react';
4
- import { useTheme } from '@cleartrip/ct-design-theme';
5
- import { Portal } from '@cleartrip/ct-design-portal';
6
- import { Transition } from '@cleartrip/ct-design-transition';
7
- import { Typography } from '@cleartrip/ct-design-typography';
2
+ import { useRef, useEffect } from 'react';
8
3
  import { Container } from '@cleartrip/ct-design-container';
9
- import styled from 'styled-components';
10
- import classNames from 'classnames';
4
+ import { Portal } from '@cleartrip/ct-design-portal';
5
+ import { Typography, TypographyVariant, TypographyColor } from '@cleartrip/ct-design-typography';
6
+ import { useAnimatedStyles, Animated } from '@cleartrip/ct-design-animated';
7
+ import { makeStyles, useStyles } from '@cleartrip/ct-design-style-manager';
8
+ import { isPwa } from '@cleartrip/ct-design-common-utils';
11
9
 
12
10
  var IToastBorderSize;
13
11
  (function (IToastBorderSize) {
@@ -19,98 +17,110 @@ var IToastBorderSize;
19
17
  })(IToastBorderSize || (IToastBorderSize = {}));
20
18
  var IToastPosition;
21
19
  (function (IToastPosition) {
22
- IToastPosition["BOTTOM_CENTER"] = "BOTTOM_CENTER";
20
+ IToastPosition["TOP"] = "top";
21
+ IToastPosition["BOTTOM"] = "bottom";
22
+ IToastPosition["BOTTOM_CENTER"] = "bottom_center";
23
23
  })(IToastPosition || (IToastPosition = {}));
24
24
 
25
- var getToastBorderSize = function (borderSize, theme) {
25
+ const getToastBorderSize = (borderSize, theme) => {
26
26
  switch (borderSize) {
27
- case IToastBorderSize.XS: {
28
- return {
29
- borderRadius: theme.border.radius[4],
30
- };
31
- }
32
- case IToastBorderSize.SM: {
33
- return {
34
- borderRadius: theme.border.radius[6],
35
- };
36
- }
37
- case IToastBorderSize.MD: {
38
- return {
39
- borderRadius: theme.border.radius[8],
40
- };
41
- }
42
- case IToastBorderSize.LG: {
43
- return {
44
- borderRadius: theme.border.radius[16],
45
- };
46
- }
47
- case IToastBorderSize.XL: {
48
- return {
49
- borderRadius: theme.border.radius[32],
50
- };
51
- }
52
- default: {
53
- return {
54
- borderRadius: theme.border.radius[8],
55
- };
56
- }
27
+ case IToastBorderSize.XS:
28
+ return { borderRadius: theme.border.radius[4] };
29
+ case IToastBorderSize.SM:
30
+ return { borderRadius: theme.border.radius[6] };
31
+ case IToastBorderSize.LG:
32
+ return { borderRadius: theme.border.radius[16] };
33
+ case IToastBorderSize.XL:
34
+ return { borderRadius: theme.border.radius[32] };
35
+ case IToastBorderSize.MD:
36
+ default:
37
+ return { borderRadius: theme.border.radius[8] };
57
38
  }
58
39
  };
59
- var getToastPosition = function (_a) {
60
- var position = _a.position, _b = _a.bottom, bottom = _b === void 0 ? '100px' : _b; _a.theme;
40
+ const getToastPosition = ({ position = IToastPosition.BOTTOM_CENTER, theme, }) => {
61
41
  switch (position) {
62
42
  case IToastPosition.BOTTOM_CENTER: {
63
- return {
64
- left: '50%',
65
- transform: 'translate(-50%, 0)',
66
- bottom: bottom,
67
- };
68
- }
69
- default: {
70
- return {
71
- left: '50%',
72
- transform: 'translate(-50%, 0)',
73
- bottom: bottom,
74
- };
43
+ if (isPwa()) {
44
+ return { left: 0, right: 0, margin: 'auto' };
45
+ }
46
+ return {};
75
47
  }
48
+ case IToastPosition.TOP:
49
+ return { top: theme.spacing[4], left: theme.spacing[4] };
50
+ case IToastPosition.BOTTOM:
51
+ default:
52
+ return { left: theme.spacing[4], right: 'auto' };
76
53
  }
77
54
  };
78
- var getToastStyles = function (_a) {
79
- var borderSize = _a.borderSize, position = _a.position, bottom = _a.bottom, theme = _a.theme;
80
- var tooltipPosition = getToastPosition({ position: position, bottom: bottom, theme: theme }) || {};
81
- return __assign(__assign({ width: '288px', position: 'fixed', background: theme.color.background.defaultDarkest, padding: '8px 12px', display: 'flex', alignItems: 'center' }, tooltipPosition), getToastBorderSize(borderSize, theme));
82
- };
83
-
84
- var StyledToast = styled.div(function (_a) {
85
- var css = _a.css;
86
- return (__assign({}, css));
87
- });
88
55
 
89
- var DEFAULT_ANIMATION_TIME = 400;
90
- var DEFAULT_TOAST_CLOSE_TIMEOUT = 2000;
91
- var Toast = function (_a) {
92
- var _b = _a.borderSize, borderSize = _b === void 0 ? IToastBorderSize.MD : _b, _c = _a.position, position = _c === void 0 ? IToastPosition.BOTTOM_CENTER : _c, bottom = _a.bottom, _d = _a.show, show = _d === void 0 ? true : _d, text = _a.text, prefixComponent = _a.prefixComponent, suffixComponent = _a.suffixComponent, _e = _a.animationDuration, animationDuration = _e === void 0 ? DEFAULT_ANIMATION_TIME : _e, _f = _a.isAutoClose, isAutoClose = _f === void 0 ? true : _f, _g = _a.closeTimeout, closeTimeout = _g === void 0 ? DEFAULT_TOAST_CLOSE_TIMEOUT : _g, _h = _a.css, css = _h === void 0 ? {} : _h, _j = _a.className, className = _j === void 0 ? '' : _j, _k = _a.styleConfig, styleConfig = _k === void 0 ? {} : _k;
93
- var theme = useTheme();
94
- var prefixContainer = styleConfig.prefixContainer, textTypography = styleConfig.textTypography, toastContainer = styleConfig.toastContainer, suffixContainer = styleConfig.suffixContainer;
95
- var _l = useState(show), showToast = _l[0], setShowToast = _l[1];
96
- var toastStyles = getToastStyles({
97
- borderSize: borderSize,
98
- position: position,
99
- bottom: bottom,
100
- theme: theme,
101
- });
102
- useEffect(function () {
103
- var id;
104
- if (isAutoClose) {
105
- id = setTimeout(function () {
106
- setShowToast(false);
107
- }, closeTimeout);
56
+ const DEFAULT_TOAST_CLOSE_TIMEOUT = 2000;
57
+ const DEFAULT_ANIMATION_TIME = 400;
58
+ const staticStyles = makeStyles((theme) => ({
59
+ root: {
60
+ display: 'flex',
61
+ alignItems: 'center',
62
+ bottom: 30,
63
+ margin: 'auto',
64
+ maxWidth: '100%',
65
+ position: 'absolute',
66
+ backgroundColor: theme.color.background.defaultDarkest,
67
+ paddingVertical: theme.spacing[2],
68
+ paddingHorizontal: theme.spacing[3],
69
+ flexDirection: 'row',
70
+ alignSelf: 'center',
71
+ gap: theme.spacing[2],
72
+ },
73
+ prefixContainer: {
74
+ display: 'flex',
75
+ alignItems: 'center',
76
+ justifyContent: 'center',
77
+ },
78
+ textContainer: {
79
+ display: 'flex',
80
+ flexDirection: 'row',
81
+ flex: 1,
82
+ },
83
+ suffixContainer: {
84
+ display: 'flex',
85
+ },
86
+ }));
87
+ const Toast = ({ borderSize = IToastBorderSize.MD, position = IToastPosition.BOTTOM_CENTER, bottomOffset = 30, show = false, text, prefixComponent, suffixComponent, animationDuration = DEFAULT_ANIMATION_TIME, isAutoClose = true, closeTimeout = DEFAULT_TOAST_CLOSE_TIMEOUT, styleConfig, onHide: onToastClose, }) => {
88
+ const { prefixContainer = [], textTypography = [], toastContainer = [], suffixContainer = [] } = styleConfig || {};
89
+ const timerRef = useRef(null);
90
+ const [containerStyle, containerController] = useAnimatedStyles({
91
+ from: { translateY: +bottomOffset, opacity: 0 },
92
+ to: { translateY: -bottomOffset, opacity: 1 },
93
+ config: {
94
+ duration: animationDuration,
95
+ immediate: show ? true : false,
96
+ },
97
+ }, [show]);
98
+ const dynamicRootStyles = useStyles((theme) => ({
99
+ root: Object.assign(Object.assign(Object.assign({}, getToastBorderSize(borderSize, theme)), getToastPosition({ position, theme })), { opacity: show ? 1 : 0 }),
100
+ }), [show, borderSize, position]);
101
+ const handleTimerClear = () => {
102
+ if (!timerRef.current)
103
+ return;
104
+ clearTimeout(timerRef.current);
105
+ timerRef.current = null;
106
+ };
107
+ useEffect(() => {
108
+ if (!show) {
109
+ handleTimerClear();
110
+ return;
108
111
  }
109
- return function () {
110
- id && clearTimeout(id);
111
- };
112
- }, []);
113
- return (jsx(Portal, { children: jsx(Transition, __assign({ type: 'fade', slideDirection: 'up', in: showToast, timeout: animationDuration }, { children: jsxs(StyledToast, __assign({ css: __assign(__assign({}, toastStyles), ((toastContainer === null || toastContainer === void 0 ? void 0 : toastContainer.css) || css)), className: className }, { children: [prefixComponent && (jsx(Container, __assign({ className: classNames('flex flex-middle mr-2', prefixContainer === null || prefixContainer === void 0 ? void 0 : prefixContainer.className), css: prefixContainer === null || prefixContainer === void 0 ? void 0 : prefixContainer.css }, { children: prefixComponent }))), jsx(Typography, __assign({ variant: 'B3', color: 'neutral', className: 'p-1', styleConfig: textTypography }, { children: text })), suffixComponent && (jsx(Container, __assign({ className: classNames('flex flex-middle ml-auto', suffixContainer === null || suffixContainer === void 0 ? void 0 : suffixContainer.className), css: suffixContainer === null || suffixContainer === void 0 ? void 0 : suffixContainer.css }, { children: suffixComponent })))] })) })) }));
112
+ containerController.start();
113
+ if (!isAutoClose)
114
+ return;
115
+ timerRef.current = setTimeout(() => {
116
+ onToastClose === null || onToastClose === void 0 ? void 0 : onToastClose();
117
+ containerController.start({
118
+ to: { opacity: 0, translateY: +bottomOffset },
119
+ });
120
+ }, closeTimeout || DEFAULT_TOAST_CLOSE_TIMEOUT);
121
+ return () => handleTimerClear();
122
+ }, [show, isAutoClose, closeTimeout, bottomOffset]);
123
+ return (jsx(Portal, { id: 'toast-portal', children: jsxs(Animated.Container, { animated: containerStyle, styleConfig: { root: [staticStyles.root, dynamicRootStyles.root, ...toastContainer] }, children: [prefixComponent && (jsx(Container, { styleConfig: { root: [staticStyles.prefixContainer, ...prefixContainer] }, children: prefixComponent })), jsx(Container, { styleConfig: { root: [staticStyles.textContainer, ...textTypography] }, children: jsx(Typography, { variant: TypographyVariant.B3, color: TypographyColor.NEUTRAL, children: text }) }), suffixComponent && (jsx(Container, { styleConfig: { root: [staticStyles.suffixContainer, ...suffixContainer] }, children: suffixComponent }))] }) }));
114
124
  };
115
125
 
116
126
  export { IToastBorderSize, IToastPosition, Toast };
@@ -1 +1 @@
1
- {"version":3,"file":"ct-design-toast.esm.js","sources":["../packages/components/Toast/src/type.ts","../packages/components/Toast/src/style.ts","../packages/components/Toast/src/StyledToast/StyledToast.t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GAAA,KAAA,CAAA,GAAf,eAAe,CAAE,SAAS,CAAC,EAC7E,GAAG,EAAE,eAAe,KAAA,IAAA,IAAf,eAAe,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAf,eAAe,CAAE,GAAG,EAExB,EAAA,EAAA,QAAA,EAAA,eAAe,IACN,CACb,CAAA,EAAA,CAAA,CACW,EACH,CAAA,CAAA,EAAA,CACN,EACT;AACJ;;;;"}
1
+ {"version":3,"file":"ct-design-toast.esm.js","sources":["../packages/components/Toast/src/constants.ts","../packages/components/Toast/src/style.ts","../packages/components/Toast/src/Toast.tsx"],"sourcesContent":[null,null,null],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;IAAY,iBAMX;AAND,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,gBAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,gBAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,gBAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,gBAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACX,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,GAM3B,EAAA,CAAA,CAAA,CAAA;IAEW,eAIX;AAJD,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,cAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,cAAA,CAAA,eAAA,CAAA,GAAA,eAA+B,CAAA;AACjC,CAAC,EAJW,cAAc,KAAd,cAAc,GAIzB,EAAA,CAAA,CAAA;;ACPM,MAAM,kBAAkB,GAAG,CAAC,UAAiC,EAAE,KAAY,KAAI;IACpF,QAAQ,UAAU;QAChB,KAAK,gBAAgB,CAAC,EAAE;AACtB,YAAA,OAAO,EAAE,YAAY,EAAE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CAAA,CACb,EACDA,GAAA,CAAC,SAAS,EAAA,EAAC,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,aAAa,EAAE,GAAG,cAAc,CAAC,EAAE,EAC/E,QAAA,EAAAA,GAAA,CAAC,UAAU,EAAA,EAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,EAAA,QAAA,EACtE,IAAI,EAAA,CACM,EACH,CAAA,EACX,eAAe,KACdA,GAAA,CAAC,SAAS,EAAA,EAAC,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,GAAG,eAAe,CAAC,EAAE,EACjF,QAAA,EAAA,eAAe,EACN,CAAA,CACb,CACkB,EAAA,CAAA,EAAA,CACd,EACT;AACJ;;;;"}
@@ -1,43 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@cleartrip/ct-design-theme'), require('@cleartrip/ct-design-portal'), require('@cleartrip/ct-design-transition'), require('@cleartrip/ct-design-typography'), require('@cleartrip/ct-design-container'), require('styled-components')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@cleartrip/ct-design-theme', '@cleartrip/ct-design-portal', '@cleartrip/ct-design-transition', '@cleartrip/ct-design-typography', '@cleartrip/ct-design-container', 'styled-components'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemToast = {}, global.jsxRuntime, global.React, global.ctDesignTheme, global.ctDesignPortal, global.ctDesignTransition, global.ctDesignTypography, global.ctDesignContainer, global.styled));
5
- })(this, (function (exports, jsxRuntime, react, ctDesignTheme, ctDesignPortal, ctDesignTransition, ctDesignTypography, ctDesignContainer, styled) { 'use strict';
6
-
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
-
9
- var styled__default = /*#__PURE__*/_interopDefault(styled);
10
-
11
- /******************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
26
-
27
- var __assign = function () {
28
- __assign = Object.assign || function __assign(t) {
29
- for (var s, i = 1, n = arguments.length; i < n; i++) {
30
- s = arguments[i];
31
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
32
- }
33
- return t;
34
- };
35
- return __assign.apply(this, arguments);
36
- };
37
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
38
- var e = new Error(message);
39
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
40
- };
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@cleartrip/ct-design-container'), require('@cleartrip/ct-design-portal'), require('@cleartrip/ct-design-typography'), require('@cleartrip/ct-design-animated'), require('@cleartrip/ct-design-style-manager'), require('@cleartrip/ct-design-common-utils')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@cleartrip/ct-design-container', '@cleartrip/ct-design-portal', '@cleartrip/ct-design-typography', '@cleartrip/ct-design-animated', '@cleartrip/ct-design-style-manager', '@cleartrip/ct-design-common-utils'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemToast = {}, global.jsxRuntime, global.React, global.ctDesignContainer, global.ctDesignPortal, global.ctDesignTypography, global.ctDesignAnimated, global.ctDesignStyleManager, global.ctDesignCommonUtils));
5
+ })(this, (function (exports, jsxRuntime, react, ctDesignContainer, ctDesignPortal, ctDesignTypography, ctDesignAnimated, ctDesignStyleManager, ctDesignCommonUtils) { 'use strict';
41
6
 
42
7
  exports.IToastBorderSize = void 0;
43
8
  (function (IToastBorderSize) {
@@ -49,165 +14,110 @@
49
14
  })(exports.IToastBorderSize || (exports.IToastBorderSize = {}));
50
15
  exports.IToastPosition = void 0;
51
16
  (function (IToastPosition) {
52
- IToastPosition["BOTTOM_CENTER"] = "BOTTOM_CENTER";
17
+ IToastPosition["TOP"] = "top";
18
+ IToastPosition["BOTTOM"] = "bottom";
19
+ IToastPosition["BOTTOM_CENTER"] = "bottom_center";
53
20
  })(exports.IToastPosition || (exports.IToastPosition = {}));
54
21
 
55
- var getToastBorderSize = function (borderSize, theme) {
22
+ const getToastBorderSize = (borderSize, theme) => {
56
23
  switch (borderSize) {
57
- case exports.IToastBorderSize.XS: {
58
- return {
59
- borderRadius: theme.border.radius[4],
60
- };
61
- }
62
- case exports.IToastBorderSize.SM: {
63
- return {
64
- borderRadius: theme.border.radius[6],
65
- };
66
- }
67
- case exports.IToastBorderSize.MD: {
68
- return {
69
- borderRadius: theme.border.radius[8],
70
- };
71
- }
72
- case exports.IToastBorderSize.LG: {
73
- return {
74
- borderRadius: theme.border.radius[16],
75
- };
76
- }
77
- case exports.IToastBorderSize.XL: {
78
- return {
79
- borderRadius: theme.border.radius[32],
80
- };
81
- }
82
- default: {
83
- return {
84
- borderRadius: theme.border.radius[8],
85
- };
86
- }
24
+ case exports.IToastBorderSize.XS:
25
+ return { borderRadius: theme.border.radius[4] };
26
+ case exports.IToastBorderSize.SM:
27
+ return { borderRadius: theme.border.radius[6] };
28
+ case exports.IToastBorderSize.LG:
29
+ return { borderRadius: theme.border.radius[16] };
30
+ case exports.IToastBorderSize.XL:
31
+ return { borderRadius: theme.border.radius[32] };
32
+ case exports.IToastBorderSize.MD:
33
+ default:
34
+ return { borderRadius: theme.border.radius[8] };
87
35
  }
88
36
  };
89
- var getToastPosition = function (_a) {
90
- var position = _a.position, _b = _a.bottom, bottom = _b === void 0 ? '100px' : _b; _a.theme;
37
+ const getToastPosition = ({ position = exports.IToastPosition.BOTTOM_CENTER, theme, }) => {
91
38
  switch (position) {
92
39
  case exports.IToastPosition.BOTTOM_CENTER: {
93
- return {
94
- left: '50%',
95
- transform: 'translate(-50%, 0)',
96
- bottom: bottom,
97
- };
98
- }
99
- default: {
100
- return {
101
- left: '50%',
102
- transform: 'translate(-50%, 0)',
103
- bottom: bottom,
104
- };
40
+ if (ctDesignCommonUtils.isPwa()) {
41
+ return { left: 0, right: 0, margin: 'auto' };
42
+ }
43
+ return {};
105
44
  }
45
+ case exports.IToastPosition.TOP:
46
+ return { top: theme.spacing[4], left: theme.spacing[4] };
47
+ case exports.IToastPosition.BOTTOM:
48
+ default:
49
+ return { left: theme.spacing[4], right: 'auto' };
106
50
  }
107
51
  };
108
- var getToastStyles = function (_a) {
109
- var borderSize = _a.borderSize, position = _a.position, bottom = _a.bottom, theme = _a.theme;
110
- var tooltipPosition = getToastPosition({ position: position, bottom: bottom, theme: theme }) || {};
111
- return __assign(__assign({ width: '288px', position: 'fixed', background: theme.color.background.defaultDarkest, padding: '8px 12px', display: 'flex', alignItems: 'center' }, tooltipPosition), getToastBorderSize(borderSize, theme));
112
- };
113
-
114
- var StyledToast = styled__default.default.div(function (_a) {
115
- var css = _a.css;
116
- return (__assign({}, css));
117
- });
118
-
119
- var classnamesExports = {};
120
- var classnames = {
121
- get exports(){ return classnamesExports; },
122
- set exports(v){ classnamesExports = v; },
123
- };
124
-
125
- /*!
126
- Copyright (c) 2018 Jed Watson.
127
- Licensed under the MIT License (MIT), see
128
- http://jedwatson.github.io/classnames
129
- */
130
- (function (module) {
131
- /* global define */
132
-
133
- (function () {
134
-
135
- var hasOwn = {}.hasOwnProperty;
136
- function classNames() {
137
- var classes = '';
138
- for (var i = 0; i < arguments.length; i++) {
139
- var arg = arguments[i];
140
- if (arg) {
141
- classes = appendClass(classes, parseValue(arg));
142
- }
143
- }
144
- return classes;
145
- }
146
- function parseValue(arg) {
147
- if (typeof arg === 'string' || typeof arg === 'number') {
148
- return arg;
149
- }
150
- if (typeof arg !== 'object') {
151
- return '';
152
- }
153
- if (Array.isArray(arg)) {
154
- return classNames.apply(null, arg);
155
- }
156
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
157
- return arg.toString();
158
- }
159
- var classes = '';
160
- for (var key in arg) {
161
- if (hasOwn.call(arg, key) && arg[key]) {
162
- classes = appendClass(classes, key);
163
- }
164
- }
165
- return classes;
166
- }
167
- function appendClass(value, newClass) {
168
- if (!newClass) {
169
- return value;
170
- }
171
- if (value) {
172
- return value + ' ' + newClass;
173
- }
174
- return value + newClass;
175
- }
176
- if (module.exports) {
177
- classNames.default = classNames;
178
- module.exports = classNames;
179
- } else {
180
- window.classNames = classNames;
181
- }
182
- })();
183
- })(classnames);
184
- var classNames = classnamesExports;
185
52
 
186
- var DEFAULT_ANIMATION_TIME = 400;
187
- var DEFAULT_TOAST_CLOSE_TIMEOUT = 2000;
188
- var Toast = function (_a) {
189
- var _b = _a.borderSize, borderSize = _b === void 0 ? exports.IToastBorderSize.MD : _b, _c = _a.position, position = _c === void 0 ? exports.IToastPosition.BOTTOM_CENTER : _c, bottom = _a.bottom, _d = _a.show, show = _d === void 0 ? true : _d, text = _a.text, prefixComponent = _a.prefixComponent, suffixComponent = _a.suffixComponent, _e = _a.animationDuration, animationDuration = _e === void 0 ? DEFAULT_ANIMATION_TIME : _e, _f = _a.isAutoClose, isAutoClose = _f === void 0 ? true : _f, _g = _a.closeTimeout, closeTimeout = _g === void 0 ? DEFAULT_TOAST_CLOSE_TIMEOUT : _g, _h = _a.css, css = _h === void 0 ? {} : _h, _j = _a.className, className = _j === void 0 ? '' : _j, _k = _a.styleConfig, styleConfig = _k === void 0 ? {} : _k;
190
- var theme = ctDesignTheme.useTheme();
191
- var prefixContainer = styleConfig.prefixContainer, textTypography = styleConfig.textTypography, toastContainer = styleConfig.toastContainer, suffixContainer = styleConfig.suffixContainer;
192
- var _l = react.useState(show), showToast = _l[0], setShowToast = _l[1];
193
- var toastStyles = getToastStyles({
194
- borderSize: borderSize,
195
- position: position,
196
- bottom: bottom,
197
- theme: theme,
198
- });
199
- react.useEffect(function () {
200
- var id;
201
- if (isAutoClose) {
202
- id = setTimeout(function () {
203
- setShowToast(false);
204
- }, closeTimeout);
53
+ const DEFAULT_TOAST_CLOSE_TIMEOUT = 2000;
54
+ const DEFAULT_ANIMATION_TIME = 400;
55
+ const staticStyles = ctDesignStyleManager.makeStyles((theme) => ({
56
+ root: {
57
+ display: 'flex',
58
+ alignItems: 'center',
59
+ bottom: 30,
60
+ margin: 'auto',
61
+ maxWidth: '100%',
62
+ position: 'absolute',
63
+ backgroundColor: theme.color.background.defaultDarkest,
64
+ paddingVertical: theme.spacing[2],
65
+ paddingHorizontal: theme.spacing[3],
66
+ flexDirection: 'row',
67
+ alignSelf: 'center',
68
+ gap: theme.spacing[2],
69
+ },
70
+ prefixContainer: {
71
+ display: 'flex',
72
+ alignItems: 'center',
73
+ justifyContent: 'center',
74
+ },
75
+ textContainer: {
76
+ display: 'flex',
77
+ flexDirection: 'row',
78
+ flex: 1,
79
+ },
80
+ suffixContainer: {
81
+ display: 'flex',
82
+ },
83
+ }));
84
+ const Toast = ({ borderSize = exports.IToastBorderSize.MD, position = exports.IToastPosition.BOTTOM_CENTER, bottomOffset = 30, show = false, text, prefixComponent, suffixComponent, animationDuration = DEFAULT_ANIMATION_TIME, isAutoClose = true, closeTimeout = DEFAULT_TOAST_CLOSE_TIMEOUT, styleConfig, onHide: onToastClose, }) => {
85
+ const { prefixContainer = [], textTypography = [], toastContainer = [], suffixContainer = [] } = styleConfig || {};
86
+ const timerRef = react.useRef(null);
87
+ const [containerStyle, containerController] = ctDesignAnimated.useAnimatedStyles({
88
+ from: { translateY: +bottomOffset, opacity: 0 },
89
+ to: { translateY: -bottomOffset, opacity: 1 },
90
+ config: {
91
+ duration: animationDuration,
92
+ immediate: show ? true : false,
93
+ },
94
+ }, [show]);
95
+ const dynamicRootStyles = ctDesignStyleManager.useStyles((theme) => ({
96
+ root: Object.assign(Object.assign(Object.assign({}, getToastBorderSize(borderSize, theme)), getToastPosition({ position, theme })), { opacity: show ? 1 : 0 }),
97
+ }), [show, borderSize, position]);
98
+ const handleTimerClear = () => {
99
+ if (!timerRef.current)
100
+ return;
101
+ clearTimeout(timerRef.current);
102
+ timerRef.current = null;
103
+ };
104
+ react.useEffect(() => {
105
+ if (!show) {
106
+ handleTimerClear();
107
+ return;
205
108
  }
206
- return function () {
207
- id && clearTimeout(id);
208
- };
209
- }, []);
210
- return (jsxRuntime.jsx(ctDesignPortal.Portal, { children: jsxRuntime.jsx(ctDesignTransition.Transition, __assign({ type: 'fade', slideDirection: 'up', in: showToast, timeout: animationDuration }, { children: jsxRuntime.jsxs(StyledToast, __assign({ css: __assign(__assign({}, toastStyles), ((toastContainer === null || toastContainer === void 0 ? void 0 : toastContainer.css) || css)), className: className }, { children: [prefixComponent && (jsxRuntime.jsx(ctDesignContainer.Container, __assign({ className: classNames('flex flex-middle mr-2', prefixContainer === null || prefixContainer === void 0 ? void 0 : prefixContainer.className), css: prefixContainer === null || prefixContainer === void 0 ? void 0 : prefixContainer.css }, { children: prefixComponent }))), jsxRuntime.jsx(ctDesignTypography.Typography, __assign({ variant: 'B3', color: 'neutral', className: 'p-1', styleConfig: textTypography }, { children: text })), suffixComponent && (jsxRuntime.jsx(ctDesignContainer.Container, __assign({ className: classNames('flex flex-middle ml-auto', suffixContainer === null || suffixContainer === void 0 ? void 0 : suffixContainer.className), css: suffixContainer === null || suffixContainer === void 0 ? void 0 : suffixContainer.css }, { children: suffixComponent })))] })) })) }));
109
+ containerController.start();
110
+ if (!isAutoClose)
111
+ return;
112
+ timerRef.current = setTimeout(() => {
113
+ onToastClose === null || onToastClose === void 0 ? void 0 : onToastClose();
114
+ containerController.start({
115
+ to: { opacity: 0, translateY: +bottomOffset },
116
+ });
117
+ }, closeTimeout || DEFAULT_TOAST_CLOSE_TIMEOUT);
118
+ return () => handleTimerClear();
119
+ }, [show, isAutoClose, closeTimeout, bottomOffset]);
120
+ return (jsxRuntime.jsx(ctDesignPortal.Portal, { id: 'toast-portal', children: jsxRuntime.jsxs(ctDesignAnimated.Animated.Container, { animated: containerStyle, styleConfig: { root: [staticStyles.root, dynamicRootStyles.root, ...toastContainer] }, children: [prefixComponent && (jsxRuntime.jsx(ctDesignContainer.Container, { styleConfig: { root: [staticStyles.prefixContainer, ...prefixContainer] }, children: prefixComponent })), jsxRuntime.jsx(ctDesignContainer.Container, { styleConfig: { root: [staticStyles.textContainer, ...textTypography] }, children: jsxRuntime.jsx(ctDesignTypography.Typography, { variant: ctDesignTypography.TypographyVariant.B3, color: ctDesignTypography.TypographyColor.NEUTRAL, children: text }) }), suffixComponent && (jsxRuntime.jsx(ctDesignContainer.Container, { styleConfig: { root: [staticStyles.suffixContainer, ...suffixContainer] }, children: suffixComponent }))] }) }));
211
121
  };
212
122
 
213
123
  exports.Toast = Toast;