@redocly/theme
Version:
Shared UI components lib
17 lines • 971 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useToast = useToast;
const react_1 = require("react");
const ToastContext_1 = require("../contexts/Toast/ToastContext");
function createTypedToast(showToast, type) {
return (title, options) => showToast(Object.assign(Object.assign({}, options), { title,
type }));
}
function useToast() {
const context = (0, react_1.useContext)(ToastContext_1.ToastContext);
if (!context) {
throw new Error('useToast must be used within a ToastProvider');
}
return (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, context), { info: createTypedToast(context.showToast, 'info'), success: createTypedToast(context.showToast, 'success'), warning: createTypedToast(context.showToast, 'warning'), error: createTypedToast(context.showToast, 'error'), loading: createTypedToast(context.showToast, 'loading') })), [context]);
}
//# sourceMappingURL=use-toast.js.map