1 | "use strict";
|
2 | "use client";
|
3 |
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
5 | exports.__esModule = true;
|
6 | exports.default = void 0;
|
7 | var React = _interopRequireWildcard(require("react"));
|
8 | var _classnames = _interopRequireDefault(require("classnames"));
|
9 | var _useTimeout = _interopRequireDefault(require("@restart/hooks/useTimeout"));
|
10 | var _ToastFade = _interopRequireDefault(require("./ToastFade"));
|
11 | var _ToastHeader = _interopRequireDefault(require("./ToastHeader"));
|
12 | var _ToastBody = _interopRequireDefault(require("./ToastBody"));
|
13 | var _ThemeProvider = require("./ThemeProvider");
|
14 | var _ToastContext = _interopRequireDefault(require("./ToastContext"));
|
15 | var _jsxRuntime = require("react/jsx-runtime");
|
16 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
18 | const Toast = React.forwardRef(({
|
19 | bsPrefix,
|
20 | className,
|
21 | transition: Transition = _ToastFade.default,
|
22 | show = true,
|
23 | animation = true,
|
24 | delay = 5000,
|
25 | autohide = false,
|
26 | onClose,
|
27 | onEntered,
|
28 | onExit,
|
29 | onExiting,
|
30 | onEnter,
|
31 | onEntering,
|
32 | onExited,
|
33 | bg,
|
34 | ...props
|
35 | }, ref) => {
|
36 | bsPrefix = (0, _ThemeProvider.useBootstrapPrefix)(bsPrefix, 'toast');
|
37 |
|
38 |
|
39 |
|
40 | const delayRef = (0, React.useRef)(delay);
|
41 | const onCloseRef = (0, React.useRef)(onClose);
|
42 | (0, React.useEffect)(() => {
|
43 | delayRef.current = delay;
|
44 | onCloseRef.current = onClose;
|
45 | }, [delay, onClose]);
|
46 | const autohideTimeout = (0, _useTimeout.default)();
|
47 | const autohideToast = !!(autohide && show);
|
48 | const autohideFunc = (0, React.useCallback)(() => {
|
49 | if (autohideToast) {
|
50 | onCloseRef.current == null ? void 0 : onCloseRef.current();
|
51 | }
|
52 | }, [autohideToast]);
|
53 | (0, React.useEffect)(() => {
|
54 |
|
55 | autohideTimeout.set(autohideFunc, delayRef.current);
|
56 | }, [autohideTimeout, autohideFunc]);
|
57 | const toastContext = (0, React.useMemo)(() => ({
|
58 | onClose
|
59 | }), [onClose]);
|
60 | const hasAnimation = !!(Transition && animation);
|
61 | const toast = (0, _jsxRuntime.jsx)("div", {
|
62 | ...props,
|
63 | ref: ref,
|
64 | className: (0, _classnames.default)(bsPrefix, className, bg && `bg-${bg}`, !hasAnimation && (show ? 'show' : 'hide')),
|
65 | role: "alert",
|
66 | "aria-live": "assertive",
|
67 | "aria-atomic": "true"
|
68 | });
|
69 | return (0, _jsxRuntime.jsx)(_ToastContext.default.Provider, {
|
70 | value: toastContext,
|
71 | children: hasAnimation && Transition ? (0, _jsxRuntime.jsx)(Transition, {
|
72 | in: show,
|
73 | onEnter: onEnter,
|
74 | onEntering: onEntering,
|
75 | onEntered: onEntered,
|
76 | onExit: onExit,
|
77 | onExiting: onExiting,
|
78 | onExited: onExited,
|
79 | unmountOnExit: true,
|
80 | children: toast
|
81 | }) : toast
|
82 | });
|
83 | });
|
84 | Toast.displayName = 'Toast';
|
85 | var _default = Object.assign(Toast, {
|
86 | Body: _ToastBody.default,
|
87 | Header: _ToastHeader.default
|
88 | });
|
89 | exports.default = _default;
|
90 | module.exports = exports.default; |
\ | No newline at end of file |