UNPKG

linkmore-design

Version:

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

54 lines (52 loc) β€’ 2.13 kB
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import useRCNotification from 'rc-notification/lib/useNotification'; import * as React from 'react'; import { ConfigConsumer } from "../../config-provider"; export default function createUseNotification(getNotificationInstance, getRCNoticeProps) { var useNotification = function useNotification() { // We can only get content by render var getPrefixCls; // We create a proxy to handle delay created instance var innerInstance = null; var proxy = { add: function add(noticeProps, holderCallback) { var _innerInstance; (_innerInstance = innerInstance) === null || _innerInstance === void 0 ? void 0 : _innerInstance.component.add(noticeProps, holderCallback); } }; var _useRCNotification = useRCNotification(proxy), _useRCNotification2 = _slicedToArray(_useRCNotification, 2), hookNotify = _useRCNotification2[0], holder = _useRCNotification2[1]; function notify(args) { var customizePrefixCls = args.prefixCls; var mergedPrefixCls = getPrefixCls('notification', customizePrefixCls); getNotificationInstance(_objectSpread(_objectSpread({}, args), {}, { prefixCls: mergedPrefixCls }), function (_ref) { var prefixCls = _ref.prefixCls, instance = _ref.instance; innerInstance = instance; hookNotify(getRCNoticeProps(args, prefixCls)); }); } // Fill functions var hookApiRef = React.useRef({}); hookApiRef.current.open = notify; ['success', 'info', 'warning', 'error'].forEach(function (type) { hookApiRef.current[type] = function (args) { return hookApiRef.current.open(_objectSpread(_objectSpread({}, args), {}, { type: type })); }; }); return [hookApiRef.current, /*#__PURE__*/React.createElement(ConfigConsumer, { key: "holder" }, function (context) { getPrefixCls = context.getPrefixCls; return holder; })]; }; return useNotification; }