UNPKG

@razorpay/blade

Version:

The Design System that powers Razorpay

67 lines (62 loc) 2.66 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import toast, { useToasterStore } from 'react-hot-toast'; import { Toast } from './Toast.web.js'; import '../../utils/logger/index.js'; import { jsx } from 'react/jsx-runtime'; import { logger } from '../../utils/logger/logger.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var useToast = function useToast() { var _useToasterStore = useToasterStore(), toasts = _useToasterStore.toasts; var show = function show(props) { var _props$type; props.type = (_props$type = props.type) !== null && _props$type !== void 0 ? _props$type : 'informational'; // Do not show promotional toasts if there is already one if (toasts.find(function (t) { // @ts-expect-error - react-hot-toast doesn't recognize our promotional type return t.type === 'promotional'; }) && props.type === 'promotional') { if (true) { logger({ message: 'There can only be one promotional toast at a time', type: 'warn', moduleName: 'Toast' }); } return ''; } var isPromoToast = props.type === 'promotional'; if (props.autoDismiss === undefined) { // Promotional toasts should not auto dismiss props.autoDismiss = !isPromoToast; } if (props.duration === undefined) { // Set default durations if (isPromoToast) { props.duration = 8000; } else { props.duration = 4000; } } // If autoDismiss is false, set duration to infinity if (!props.autoDismiss) { props.duration = Infinity; } return toast.custom(function (_ref) { var visible = _ref.visible, id = _ref.id; return /*#__PURE__*/jsx(Toast, _objectSpread(_objectSpread({}, props), {}, { id: id, isVisible: visible })); }, props); }; return { toasts: toasts, show: show, dismiss: toast.dismiss }; }; export { useToast }; //# sourceMappingURL=useToast.js.map