UNPKG

linkmore-design

Version:

🌈 πŸš€lmη»„δ»ΆεΊ“γ€‚πŸš€

61 lines (58 loc) β€’ 1.96 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createUseNotification; var _useNotification = _interopRequireDefault(require("rc-notification/lib/useNotification")); var React = _interopRequireWildcard(require("react")); var _configProvider = require("../../config-provider"); function createUseNotification(getNotificationInstance, getRCNoticeProps) { const useNotification = () => { // We can only get content by render let getPrefixCls; // We create a proxy to handle delay created instance let innerInstance = null; const proxy = { add: (noticeProps, holderCallback) => { innerInstance?.component.add(noticeProps, holderCallback); } }; const [hookNotify, holder] = (0, _useNotification.default)(proxy); function notify(args) { const { prefixCls: customizePrefixCls } = args; const mergedPrefixCls = getPrefixCls('notification', customizePrefixCls); getNotificationInstance({ ...args, prefixCls: mergedPrefixCls }, ({ prefixCls, instance }) => { innerInstance = instance; hookNotify(getRCNoticeProps(args, prefixCls)); }); } // Fill functions const hookApiRef = React.useRef({}); hookApiRef.current.open = notify; ['success', 'info', 'warning', 'error'].forEach(type => { hookApiRef.current[type] = args => hookApiRef.current.open({ ...args, type }); }); return [hookApiRef.current, /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, { key: "holder" }, context => { ({ getPrefixCls } = context); return holder; })]; }; return useNotification; }