UNPKG

@i-novus/ui-core

Version:

Базовые UI компоненты

36 lines (35 loc) 2.33 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ToastContainer, toast } from 'react-toastify'; import classNames from 'classnames'; import { CloseIcon } from '../core/icons'; import { useConfigProvider } from '../core'; const DEFAULT_CONTAINER_ID = 'default-container'; const CloseButton = ({ prefix, closeToast }) => { const { getPrefix } = useConfigProvider(); const prefixCls = getPrefix(prefix); return (_jsx("button", { type: "button", className: classNames(`${prefixCls}-notification-close`), onClick: closeToast, children: _jsx(CloseIcon, {}) })); }; export const NotificationContent = ({ title, description, prefix }) => { const { getPrefix } = useConfigProvider(); const prefixCls = getPrefix(prefix); return (_jsxs("div", { className: classNames(`${prefixCls}-notification-content`), children: [_jsx("div", { className: classNames(`${prefixCls}-notification-row`), children: _jsx("span", { className: classNames(`${prefixCls}-notification-title`), children: title }) }), _jsx("span", { className: classNames(`${prefixCls}-notification-description`), children: description })] })); }; export const useNotification = () => { const { prefix } = useConfigProvider(); const push = (config, CustomComponent) => { return toast(CustomComponent || (_jsx(NotificationContent, { title: config?.title, description: config?.description })), { className: classNames(`${prefix}-notification`, CustomComponent && `${prefix}-notification_custom`), bodyClassName: CustomComponent ? `${prefix}-notification__body_custom` : '', containerId: config?.containerId || DEFAULT_CONTAINER_ID, closeButton: !CustomComponent, ...config, }); }; return { push, ...toast }; }; export const NotificationContainer = (globalConfig) => { const { closeButton = CloseButton, prefix } = globalConfig; const { getPrefix } = useConfigProvider(); const prefixCls = getPrefix(prefix); return (_jsx(ToastContainer, { enableMultiContainer: true, containerId: globalConfig?.containerId || DEFAULT_CONTAINER_ID, className: classNames(`${prefixCls}-notification-container_${globalConfig?.size || 'small'}`), role: "alert", hideProgressBar: true, autoClose: false, closeButton: closeButton, ...globalConfig })); };