You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
71 lines
2.5 KiB
"use strict";
|
|
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports["default"] = createUseNotification;
|
|
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
|
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
|
|
var React = _interopRequireWildcard(require("react"));
|
|
|
|
var _useNotification = _interopRequireDefault(require("rc-notification/lib/useNotification"));
|
|
|
|
var _configProvider = require("../../config-provider");
|
|
|
|
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) {
|
|
innerInstance === null || innerInstance === void 0 ? void 0 : innerInstance.component.add(noticeProps, holderCallback);
|
|
}
|
|
};
|
|
|
|
var _useRCNotification = (0, _useNotification["default"])(proxy),
|
|
_useRCNotification2 = (0, _slicedToArray2["default"])(_useRCNotification, 2),
|
|
hookNotify = _useRCNotification2[0],
|
|
holder = _useRCNotification2[1];
|
|
|
|
function notify(args) {
|
|
var customizePrefixCls = args.prefixCls;
|
|
var mergedPrefixCls = getPrefixCls('notification', customizePrefixCls);
|
|
getNotificationInstance((0, _extends2["default"])((0, _extends2["default"])({}, 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((0, _extends2["default"])((0, _extends2["default"])({}, args), {
|
|
type: type
|
|
}));
|
|
};
|
|
});
|
|
return [hookApiRef.current, /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, {
|
|
key: "holder"
|
|
}, function (context) {
|
|
getPrefixCls = context.getPrefixCls;
|
|
return holder;
|
|
})];
|
|
};
|
|
|
|
return useNotification;
|
|
} |