@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.
- package/README.md +89 -0
- package/dist/Toast.d.ts +1 -1
- package/dist/Toast.d.ts.map +1 -1
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/ct-design-toast.browser.cjs.js +1 -1
- package/dist/ct-design-toast.browser.cjs.js.map +1 -1
- package/dist/ct-design-toast.browser.esm.js +1 -1
- package/dist/ct-design-toast.browser.esm.js.map +1 -1
- package/dist/ct-design-toast.cjs.js +96 -91
- package/dist/ct-design-toast.cjs.js.map +1 -1
- package/dist/ct-design-toast.esm.js +98 -88
- package/dist/ct-design-toast.esm.js.map +1 -1
- package/dist/ct-design-toast.umd.js +96 -186
- package/dist/ct-design-toast.umd.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.native.d.ts +4 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/style.d.ts +28 -20
- package/dist/style.d.ts.map +1 -1
- package/dist/type.d.ts +9 -19
- package/dist/type.d.ts.map +1 -1
- package/package.json +24 -16
- package/src/Toast.tsx +140 -0
- package/src/constants.ts +13 -0
- package/src/index.native.ts +3 -0
- package/src/index.ts +3 -0
- package/src/style.ts +42 -0
- package/src/type.ts +36 -0
- package/dist/StyledToast/StyledToast.d.ts +0 -4
- package/dist/StyledToast/StyledToast.d.ts.map +0 -1
- package/dist/StyledToast/index.d.ts +0 -2
- package/dist/StyledToast/index.d.ts.map +0 -1
- package/dist/StyledToast/type.d.ts +0 -5
- package/dist/StyledToast/type.d.ts.map +0 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import {
|
|
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
|
|
10
|
-
import
|
|
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["
|
|
20
|
+
IToastPosition["TOP"] = "top";
|
|
21
|
+
IToastPosition["BOTTOM"] = "bottom";
|
|
22
|
+
IToastPosition["BOTTOM_CENTER"] = "bottom_center";
|
|
23
23
|
})(IToastPosition || (IToastPosition = {}));
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const getToastBorderSize = (borderSize, theme) => {
|
|
26
26
|
switch (borderSize) {
|
|
27
|
-
case IToastBorderSize.XS:
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
left: '
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
position:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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/
|
|
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,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YAAY,IAAI,2BAA2B,CAAC,CAAC;AAEhD,QAAA,OAAO,MAAM,gBAAgB,EAAE,CAAC;KAEjC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;AAEpD,IAAA,QACEA,GAAA,CAAC,MAAM,EAAA,EAAC,EAAE,EAAC,cAAc,EAAA,QAAA,EACvBC,IAAC,CAAA,QAAQ,CAAC,SAAS,EACjB,EAAA,QAAQ,EAAE,cAAc,EACxB,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,EAAE,EAAA,QAAA,EAAA,CAEpF,eAAe,KACdD,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,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-
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@cleartrip/ct-design-
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemToast = {}, global.jsxRuntime, global.React, global.
|
|
5
|
-
})(this, (function (exports, jsxRuntime, react,
|
|
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["
|
|
17
|
+
IToastPosition["TOP"] = "top";
|
|
18
|
+
IToastPosition["BOTTOM"] = "bottom";
|
|
19
|
+
IToastPosition["BOTTOM_CENTER"] = "bottom_center";
|
|
53
20
|
})(exports.IToastPosition || (exports.IToastPosition = {}));
|
|
54
21
|
|
|
55
|
-
|
|
22
|
+
const getToastBorderSize = (borderSize, theme) => {
|
|
56
23
|
switch (borderSize) {
|
|
57
|
-
case exports.IToastBorderSize.XS:
|
|
58
|
-
return {
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
-
left: '
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
position:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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;
|