chore: update ant-design dependencies and add new icon types
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
import * as React from 'react';
|
||||
import type { NoticeProps } from 'rc-notification/lib/Notice';
|
||||
import type { IconType } from './interface';
|
||||
export declare const TypeIcon: {
|
||||
info: React.JSX.Element;
|
||||
success: React.JSX.Element;
|
||||
error: React.JSX.Element;
|
||||
warning: React.JSX.Element;
|
||||
loading: React.JSX.Element;
|
||||
};
|
||||
export declare function getCloseIcon(prefixCls: string, closeIcon?: React.ReactNode): React.ReactNode;
|
||||
export interface PureContentProps {
|
||||
prefixCls: string;
|
||||
icon?: React.ReactNode;
|
||||
message?: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
/** @deprecated Please use `actions` instead */
|
||||
btn?: React.ReactNode;
|
||||
actions?: React.ReactNode;
|
||||
type?: IconType;
|
||||
role?: 'alert' | 'status';
|
||||
}
|
||||
export declare const PureContent: React.FC<PureContentProps>;
|
||||
export interface PurePanelProps extends Omit<NoticeProps, 'prefixCls' | 'eventKey'>, Omit<PureContentProps, 'prefixCls' | 'children'> {
|
||||
prefixCls?: string;
|
||||
}
|
||||
/** @private Internal Component. Do not use in your production. */
|
||||
declare const PurePanel: React.FC<PurePanelProps>;
|
||||
export default PurePanel;
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
"use client";
|
||||
|
||||
var __rest = this && this.__rest || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from 'react';
|
||||
import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
|
||||
import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
|
||||
import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
|
||||
import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
|
||||
import InfoCircleFilled from "@ant-design/icons/es/icons/InfoCircleFilled";
|
||||
import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
|
||||
import classNames from 'classnames';
|
||||
import { Notice } from 'rc-notification';
|
||||
import { devUseWarning } from '../_util/warning';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
||||
import useStyle from './style';
|
||||
import PurePanelStyle from './style/pure-panel';
|
||||
export const TypeIcon = {
|
||||
info: /*#__PURE__*/React.createElement(InfoCircleFilled, null),
|
||||
success: /*#__PURE__*/React.createElement(CheckCircleFilled, null),
|
||||
error: /*#__PURE__*/React.createElement(CloseCircleFilled, null),
|
||||
warning: /*#__PURE__*/React.createElement(ExclamationCircleFilled, null),
|
||||
loading: /*#__PURE__*/React.createElement(LoadingOutlined, null)
|
||||
};
|
||||
export function getCloseIcon(prefixCls, closeIcon) {
|
||||
if (closeIcon === null || closeIcon === false) {
|
||||
return null;
|
||||
}
|
||||
return closeIcon || /*#__PURE__*/React.createElement(CloseOutlined, {
|
||||
className: `${prefixCls}-close-icon`
|
||||
});
|
||||
}
|
||||
const typeToIcon = {
|
||||
success: CheckCircleFilled,
|
||||
info: InfoCircleFilled,
|
||||
error: CloseCircleFilled,
|
||||
warning: ExclamationCircleFilled
|
||||
};
|
||||
export const PureContent = props => {
|
||||
const {
|
||||
prefixCls,
|
||||
icon,
|
||||
type,
|
||||
message,
|
||||
description,
|
||||
actions,
|
||||
role = 'alert'
|
||||
} = props;
|
||||
let iconNode = null;
|
||||
if (icon) {
|
||||
iconNode = /*#__PURE__*/React.createElement("span", {
|
||||
className: `${prefixCls}-icon`
|
||||
}, icon);
|
||||
} else if (type) {
|
||||
iconNode = /*#__PURE__*/React.createElement(typeToIcon[type] || null, {
|
||||
className: classNames(`${prefixCls}-icon`, `${prefixCls}-icon-${type}`)
|
||||
});
|
||||
}
|
||||
return /*#__PURE__*/React.createElement("div", {
|
||||
className: classNames({
|
||||
[`${prefixCls}-with-icon`]: iconNode
|
||||
}),
|
||||
role: role
|
||||
}, iconNode, /*#__PURE__*/React.createElement("div", {
|
||||
className: `${prefixCls}-message`
|
||||
}, message), description && /*#__PURE__*/React.createElement("div", {
|
||||
className: `${prefixCls}-description`
|
||||
}, description), actions && /*#__PURE__*/React.createElement("div", {
|
||||
className: `${prefixCls}-actions`
|
||||
}, actions));
|
||||
};
|
||||
/** @private Internal Component. Do not use in your production. */
|
||||
const PurePanel = props => {
|
||||
const {
|
||||
prefixCls: staticPrefixCls,
|
||||
className,
|
||||
icon,
|
||||
type,
|
||||
message,
|
||||
description,
|
||||
btn,
|
||||
actions,
|
||||
closable = true,
|
||||
closeIcon,
|
||||
className: notificationClassName
|
||||
} = props,
|
||||
restProps = __rest(props, ["prefixCls", "className", "icon", "type", "message", "description", "btn", "actions", "closable", "closeIcon", "className"]);
|
||||
const {
|
||||
getPrefixCls
|
||||
} = React.useContext(ConfigContext);
|
||||
const mergedActions = actions !== null && actions !== void 0 ? actions : btn;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const warning = devUseWarning('Notification');
|
||||
warning.deprecated(!btn, 'btn', 'actions');
|
||||
}
|
||||
const prefixCls = staticPrefixCls || getPrefixCls('notification');
|
||||
const noticePrefixCls = `${prefixCls}-notice`;
|
||||
const rootCls = useCSSVarCls(prefixCls);
|
||||
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
||||
return wrapCSSVar(/*#__PURE__*/React.createElement("div", {
|
||||
className: classNames(`${noticePrefixCls}-pure-panel`, hashId, className, cssVarCls, rootCls)
|
||||
}, /*#__PURE__*/React.createElement(PurePanelStyle, {
|
||||
prefixCls: prefixCls
|
||||
}), /*#__PURE__*/React.createElement(Notice, Object.assign({}, restProps, {
|
||||
prefixCls: prefixCls,
|
||||
eventKey: "pure",
|
||||
duration: null,
|
||||
closable: closable,
|
||||
className: classNames({
|
||||
notificationClassName
|
||||
}),
|
||||
closeIcon: getCloseIcon(prefixCls, closeIcon),
|
||||
content: /*#__PURE__*/React.createElement(PureContent, {
|
||||
prefixCls: noticePrefixCls,
|
||||
icon: icon,
|
||||
type: type,
|
||||
message: message,
|
||||
description: description,
|
||||
actions: mergedActions
|
||||
})
|
||||
}))));
|
||||
};
|
||||
export default PurePanel;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import type { ArgsProps, GlobalConfigProps } from './interface';
|
||||
import PurePanel from './PurePanel';
|
||||
import useNotification from './useNotification';
|
||||
export type { ArgsProps };
|
||||
interface BaseMethods {
|
||||
open: (config: ArgsProps) => void;
|
||||
destroy: (key?: React.Key) => void;
|
||||
config: (config: GlobalConfigProps) => void;
|
||||
useNotification: typeof useNotification;
|
||||
/** @private Internal Component. Do not use in your production. */
|
||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||
}
|
||||
type StaticFn = (config: ArgsProps) => void;
|
||||
interface NoticeMethods {
|
||||
success: StaticFn;
|
||||
info: StaticFn;
|
||||
warning: StaticFn;
|
||||
error: StaticFn;
|
||||
}
|
||||
declare const staticMethods: NoticeMethods & BaseMethods;
|
||||
declare const actWrapper: (wrapper: any) => void;
|
||||
export { actWrapper };
|
||||
declare const actDestroy: () => void;
|
||||
export { actDestroy };
|
||||
export default staticMethods;
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
"use client";
|
||||
|
||||
import React, { useContext } from 'react';
|
||||
import { AppConfigContext } from '../app/context';
|
||||
import ConfigProvider, { ConfigContext, globalConfig, warnContext } from '../config-provider';
|
||||
import { unstableSetRender } from '../config-provider/UnstableContext';
|
||||
import PurePanel from './PurePanel';
|
||||
import useNotification, { useInternalNotification } from './useNotification';
|
||||
let notification = null;
|
||||
let act = callback => callback();
|
||||
let taskQueue = [];
|
||||
let defaultGlobalConfig = {};
|
||||
function getGlobalContext() {
|
||||
const {
|
||||
getContainer,
|
||||
rtl,
|
||||
maxCount,
|
||||
top,
|
||||
bottom,
|
||||
showProgress,
|
||||
pauseOnHover
|
||||
} = defaultGlobalConfig;
|
||||
const mergedContainer = (getContainer === null || getContainer === void 0 ? void 0 : getContainer()) || document.body;
|
||||
return {
|
||||
getContainer: () => mergedContainer,
|
||||
rtl,
|
||||
maxCount,
|
||||
top,
|
||||
bottom,
|
||||
showProgress,
|
||||
pauseOnHover
|
||||
};
|
||||
}
|
||||
const GlobalHolder = /*#__PURE__*/React.forwardRef((props, ref) => {
|
||||
const {
|
||||
notificationConfig,
|
||||
sync
|
||||
} = props;
|
||||
const {
|
||||
getPrefixCls
|
||||
} = useContext(ConfigContext);
|
||||
const prefixCls = defaultGlobalConfig.prefixCls || getPrefixCls('notification');
|
||||
const appConfig = useContext(AppConfigContext);
|
||||
const [api, holder] = useInternalNotification(Object.assign(Object.assign(Object.assign({}, notificationConfig), {
|
||||
prefixCls
|
||||
}), appConfig.notification));
|
||||
React.useEffect(sync, []);
|
||||
React.useImperativeHandle(ref, () => {
|
||||
const instance = Object.assign({}, api);
|
||||
Object.keys(instance).forEach(method => {
|
||||
instance[method] = (...args) => {
|
||||
sync();
|
||||
return api[method].apply(api, args);
|
||||
};
|
||||
});
|
||||
return {
|
||||
instance,
|
||||
sync
|
||||
};
|
||||
});
|
||||
return holder;
|
||||
});
|
||||
const GlobalHolderWrapper = /*#__PURE__*/React.forwardRef((_, ref) => {
|
||||
const [notificationConfig, setNotificationConfig] = React.useState(getGlobalContext);
|
||||
const sync = () => {
|
||||
setNotificationConfig(getGlobalContext);
|
||||
};
|
||||
React.useEffect(sync, []);
|
||||
const global = globalConfig();
|
||||
const rootPrefixCls = global.getRootPrefixCls();
|
||||
const rootIconPrefixCls = global.getIconPrefixCls();
|
||||
const theme = global.getTheme();
|
||||
const dom = /*#__PURE__*/React.createElement(GlobalHolder, {
|
||||
ref: ref,
|
||||
sync: sync,
|
||||
notificationConfig: notificationConfig
|
||||
});
|
||||
return /*#__PURE__*/React.createElement(ConfigProvider, {
|
||||
prefixCls: rootPrefixCls,
|
||||
iconPrefixCls: rootIconPrefixCls,
|
||||
theme: theme
|
||||
}, global.holderRender ? global.holderRender(dom) : dom);
|
||||
});
|
||||
const flushNotificationQueue = () => {
|
||||
if (!notification) {
|
||||
const holderFragment = document.createDocumentFragment();
|
||||
const newNotification = {
|
||||
fragment: holderFragment
|
||||
};
|
||||
notification = newNotification;
|
||||
// Delay render to avoid sync issue
|
||||
act(() => {
|
||||
const reactRender = unstableSetRender();
|
||||
reactRender(/*#__PURE__*/React.createElement(GlobalHolderWrapper, {
|
||||
ref: node => {
|
||||
const {
|
||||
instance,
|
||||
sync
|
||||
} = node || {};
|
||||
Promise.resolve().then(() => {
|
||||
if (!newNotification.instance && instance) {
|
||||
newNotification.instance = instance;
|
||||
newNotification.sync = sync;
|
||||
flushNotificationQueue();
|
||||
}
|
||||
});
|
||||
}
|
||||
}), holderFragment);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Notification not ready
|
||||
if (!notification.instance) {
|
||||
return;
|
||||
}
|
||||
// >>> Execute task
|
||||
taskQueue.forEach(task => {
|
||||
switch (task.type) {
|
||||
case 'open':
|
||||
{
|
||||
act(() => {
|
||||
notification.instance.open(Object.assign(Object.assign({}, defaultGlobalConfig), task.config));
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'destroy':
|
||||
act(() => {
|
||||
var _a;
|
||||
(_a = notification === null || notification === void 0 ? void 0 : notification.instance) === null || _a === void 0 ? void 0 : _a.destroy(task.key);
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
// Clean up
|
||||
taskQueue = [];
|
||||
};
|
||||
// ==============================================================================
|
||||
// == Export ==
|
||||
// ==============================================================================
|
||||
function setNotificationGlobalConfig(config) {
|
||||
defaultGlobalConfig = Object.assign(Object.assign({}, defaultGlobalConfig), config);
|
||||
// Trigger sync for it
|
||||
act(() => {
|
||||
var _a;
|
||||
(_a = notification === null || notification === void 0 ? void 0 : notification.sync) === null || _a === void 0 ? void 0 : _a.call(notification);
|
||||
});
|
||||
}
|
||||
function open(config) {
|
||||
const global = globalConfig();
|
||||
if (process.env.NODE_ENV !== 'production' && !global.holderRender) {
|
||||
warnContext('notification');
|
||||
}
|
||||
taskQueue.push({
|
||||
type: 'open',
|
||||
config
|
||||
});
|
||||
flushNotificationQueue();
|
||||
}
|
||||
const destroy = key => {
|
||||
taskQueue.push({
|
||||
type: 'destroy',
|
||||
key
|
||||
});
|
||||
flushNotificationQueue();
|
||||
};
|
||||
const methods = ['success', 'info', 'warning', 'error'];
|
||||
const baseStaticMethods = {
|
||||
open,
|
||||
destroy,
|
||||
config: setNotificationGlobalConfig,
|
||||
useNotification,
|
||||
_InternalPanelDoNotUseOrYouWillBeFired: PurePanel
|
||||
};
|
||||
const staticMethods = baseStaticMethods;
|
||||
methods.forEach(type => {
|
||||
staticMethods[type] = config => open(Object.assign(Object.assign({}, config), {
|
||||
type
|
||||
}));
|
||||
});
|
||||
// ==============================================================================
|
||||
// == Test ==
|
||||
// ==============================================================================
|
||||
const noop = () => {};
|
||||
let _actWrapper = noop;
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
_actWrapper = wrapper => {
|
||||
act = wrapper;
|
||||
};
|
||||
}
|
||||
const actWrapper = _actWrapper;
|
||||
export { actWrapper };
|
||||
let _actDestroy = noop;
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
_actDestroy = () => {
|
||||
notification = null;
|
||||
};
|
||||
}
|
||||
const actDestroy = _actDestroy;
|
||||
export { actDestroy };
|
||||
export default staticMethods;
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
import type * as React from 'react';
|
||||
import type { ClosableType } from '../_util/hooks';
|
||||
interface DivProps extends React.HTMLProps<HTMLDivElement> {
|
||||
'data-testid'?: string;
|
||||
}
|
||||
export declare const NotificationPlacements: readonly ["top", "topLeft", "topRight", "bottom", "bottomLeft", "bottomRight"];
|
||||
export type NotificationPlacement = (typeof NotificationPlacements)[number];
|
||||
export type IconType = 'success' | 'info' | 'error' | 'warning';
|
||||
export interface ArgsProps {
|
||||
message: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
/** @deprecated Please use `actions` instead */
|
||||
btn?: React.ReactNode;
|
||||
actions?: React.ReactNode;
|
||||
key?: React.Key;
|
||||
onClose?: () => void;
|
||||
duration?: number | null;
|
||||
showProgress?: boolean;
|
||||
pauseOnHover?: boolean;
|
||||
icon?: React.ReactNode;
|
||||
placement?: NotificationPlacement;
|
||||
style?: React.CSSProperties;
|
||||
className?: string;
|
||||
readonly type?: IconType;
|
||||
onClick?: () => void;
|
||||
closeIcon?: React.ReactNode;
|
||||
closable?: ClosableType;
|
||||
props?: DivProps;
|
||||
role?: 'alert' | 'status';
|
||||
}
|
||||
type StaticFn = (args: ArgsProps) => void;
|
||||
export interface NotificationInstance {
|
||||
success: StaticFn;
|
||||
error: StaticFn;
|
||||
info: StaticFn;
|
||||
warning: StaticFn;
|
||||
open: StaticFn;
|
||||
destroy: (key?: React.Key) => void;
|
||||
}
|
||||
export interface GlobalConfigProps {
|
||||
top?: number;
|
||||
bottom?: number;
|
||||
duration?: number;
|
||||
showProgress?: boolean;
|
||||
pauseOnHover?: boolean;
|
||||
prefixCls?: string;
|
||||
getContainer?: () => HTMLElement | ShadowRoot;
|
||||
placement?: NotificationPlacement;
|
||||
closeIcon?: React.ReactNode;
|
||||
closable?: ClosableType;
|
||||
rtl?: boolean;
|
||||
maxCount?: number;
|
||||
props?: DivProps;
|
||||
}
|
||||
export interface NotificationConfig {
|
||||
top?: number;
|
||||
bottom?: number;
|
||||
prefixCls?: string;
|
||||
getContainer?: () => HTMLElement | ShadowRoot;
|
||||
placement?: NotificationPlacement;
|
||||
maxCount?: number;
|
||||
rtl?: boolean;
|
||||
stack?: boolean | {
|
||||
threshold?: number;
|
||||
};
|
||||
duration?: number;
|
||||
showProgress?: boolean;
|
||||
pauseOnHover?: boolean;
|
||||
closeIcon?: React.ReactNode;
|
||||
}
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export const NotificationPlacements = ['top', 'topLeft', 'topRight', 'bottom', 'bottomLeft', 'bottomRight'];
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
import type { CSSObject } from '@ant-design/cssinjs';
|
||||
import type { AliasToken, FullToken, GenStyleFn } from '../../theme/internal';
|
||||
/** Component only token. Which will handle additional calculation of alias token */
|
||||
export interface ComponentToken {
|
||||
/**
|
||||
* @desc 提醒框 z-index
|
||||
* @descEN z-index of Notification
|
||||
*/
|
||||
zIndexPopup: number;
|
||||
/**
|
||||
* @desc 提醒框宽度
|
||||
* @descEN Width of Notification
|
||||
*/
|
||||
width: number | string;
|
||||
/**
|
||||
* @desc 成功提醒框容器背景色
|
||||
* @descEN Background color of success notification container
|
||||
*/
|
||||
colorSuccessBg?: string;
|
||||
/**
|
||||
* @desc 错误提醒框容器背景色
|
||||
* @descEN Background color of error notification container
|
||||
*/
|
||||
colorErrorBg?: string;
|
||||
/**
|
||||
* @desc 信息提醒框容器背景色
|
||||
* @descEN Background color of info notification container
|
||||
*/
|
||||
colorInfoBg?: string;
|
||||
/**
|
||||
* @desc 警告提醒框容器背景色
|
||||
* @descEN Background color of warning notification container
|
||||
*/
|
||||
colorWarningBg?: string;
|
||||
}
|
||||
/**
|
||||
* @desc Notification 组件的 Token
|
||||
* @descEN Token for Notification component
|
||||
*/
|
||||
export interface NotificationToken extends FullToken<'Notification'> {
|
||||
/**
|
||||
* @desc 动画最大高度
|
||||
* @descEN Maximum height of animation
|
||||
*/
|
||||
animationMaxHeight: number | string;
|
||||
/**
|
||||
* @desc 提醒框背景色
|
||||
* @descEN Background color of Notification
|
||||
*/
|
||||
notificationBg: string;
|
||||
/**
|
||||
* @desc 提醒框内边距
|
||||
* @descEN Padding of Notification
|
||||
*/
|
||||
notificationPadding: string;
|
||||
/**
|
||||
* @desc 提醒框垂直内边距
|
||||
* @descEN Vertical padding of Notification
|
||||
*/
|
||||
notificationPaddingVertical: number;
|
||||
/**
|
||||
* @desc 提醒框水平内边距
|
||||
* @descEN Horizontal padding of Notification
|
||||
*/
|
||||
notificationPaddingHorizontal: number;
|
||||
/**
|
||||
* @desc 提醒框图标尺寸
|
||||
* @descEN Icon size of Notification
|
||||
*/
|
||||
notificationIconSize: number | string;
|
||||
/**
|
||||
* @desc 提醒框关闭按钮尺寸
|
||||
* @descEN Close button size of Notification
|
||||
*/
|
||||
notificationCloseButtonSize: number | string;
|
||||
/**
|
||||
* @desc 提醒框底部外边距
|
||||
* @descEN Bottom margin of Notification
|
||||
*/
|
||||
notificationMarginBottom: number;
|
||||
/**
|
||||
* @desc 提醒框边缘外边距
|
||||
* @descEN Edge margin of Notification
|
||||
*/
|
||||
notificationMarginEdge: number;
|
||||
/**
|
||||
* @desc 提醒框堆叠层数
|
||||
* @descEN Stack layer of Notification
|
||||
*/
|
||||
notificationStackLayer: number;
|
||||
/**
|
||||
* @desc 提醒框进度条背景色
|
||||
* @descEN Background color of Notification progress bar
|
||||
*/
|
||||
notificationProgressBg: string;
|
||||
/**
|
||||
* @desc 提醒框进度条高度
|
||||
* @descEN Height of Notification progress bar
|
||||
*/
|
||||
notificationProgressHeight: number;
|
||||
}
|
||||
export declare const genNoticeStyle: (token: NotificationToken) => CSSObject;
|
||||
export declare const prepareComponentToken: (token: AliasToken) => {
|
||||
zIndexPopup: number;
|
||||
width: number;
|
||||
colorSuccessBg: string;
|
||||
colorErrorBg: string;
|
||||
colorInfoBg: string;
|
||||
colorWarningBg: string;
|
||||
};
|
||||
export declare const prepareNotificationToken: (token: Parameters<GenStyleFn<'Notification'>>[0]) => NotificationToken;
|
||||
declare const _default: (prefixCls: string, rootCls?: string) => readonly [(node: React.ReactElement) => React.ReactElement, string, string];
|
||||
export default _default;
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
import { Keyframes, unit } from '@ant-design/cssinjs';
|
||||
import { CONTAINER_MAX_OFFSET } from '../../_util/hooks';
|
||||
import { genFocusStyle, resetComponent } from '../../style';
|
||||
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
||||
import genNotificationPlacementStyle from './placement';
|
||||
import genStackStyle from './stack';
|
||||
export const genNoticeStyle = token => {
|
||||
const {
|
||||
iconCls,
|
||||
componentCls,
|
||||
// .ant-notification
|
||||
boxShadow,
|
||||
fontSizeLG,
|
||||
notificationMarginBottom,
|
||||
borderRadiusLG,
|
||||
colorSuccess,
|
||||
colorInfo,
|
||||
colorWarning,
|
||||
colorError,
|
||||
colorTextHeading,
|
||||
notificationBg,
|
||||
notificationPadding,
|
||||
notificationMarginEdge,
|
||||
notificationProgressBg,
|
||||
notificationProgressHeight,
|
||||
fontSize,
|
||||
lineHeight,
|
||||
width,
|
||||
notificationIconSize,
|
||||
colorText,
|
||||
colorSuccessBg,
|
||||
colorErrorBg,
|
||||
colorInfoBg,
|
||||
colorWarningBg
|
||||
} = token;
|
||||
const noticeCls = `${componentCls}-notice`;
|
||||
return {
|
||||
position: 'relative',
|
||||
marginBottom: notificationMarginBottom,
|
||||
marginInlineStart: 'auto',
|
||||
background: notificationBg,
|
||||
borderRadius: borderRadiusLG,
|
||||
boxShadow,
|
||||
[noticeCls]: {
|
||||
padding: notificationPadding,
|
||||
width,
|
||||
maxWidth: `calc(100vw - ${unit(token.calc(notificationMarginEdge).mul(2).equal())})`,
|
||||
lineHeight,
|
||||
wordWrap: 'break-word',
|
||||
borderRadius: borderRadiusLG,
|
||||
overflow: 'hidden',
|
||||
// Type-specific background colors
|
||||
'&-success': {
|
||||
background: colorSuccessBg
|
||||
},
|
||||
'&-error': {
|
||||
background: colorErrorBg
|
||||
},
|
||||
'&-info': {
|
||||
background: colorInfoBg
|
||||
},
|
||||
'&-warning': {
|
||||
background: colorWarningBg
|
||||
}
|
||||
},
|
||||
[`${noticeCls}-message`]: {
|
||||
color: colorTextHeading,
|
||||
fontSize: fontSizeLG,
|
||||
lineHeight: token.lineHeightLG
|
||||
},
|
||||
[`${noticeCls}-description`]: {
|
||||
fontSize,
|
||||
color: colorText,
|
||||
marginTop: token.marginXS
|
||||
},
|
||||
[`${noticeCls}-closable ${noticeCls}-message`]: {
|
||||
paddingInlineEnd: token.paddingLG
|
||||
},
|
||||
[`${noticeCls}-with-icon ${noticeCls}-message`]: {
|
||||
marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
|
||||
fontSize: fontSizeLG
|
||||
},
|
||||
[`${noticeCls}-with-icon ${noticeCls}-description`]: {
|
||||
marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
|
||||
fontSize
|
||||
},
|
||||
// Icon & color style in different selector level
|
||||
// https://github.com/ant-design/ant-design/issues/16503
|
||||
// https://github.com/ant-design/ant-design/issues/15512
|
||||
[`${noticeCls}-icon`]: {
|
||||
position: 'absolute',
|
||||
fontSize: notificationIconSize,
|
||||
lineHeight: 1,
|
||||
// icon-font
|
||||
[`&-success${iconCls}`]: {
|
||||
color: colorSuccess
|
||||
},
|
||||
[`&-info${iconCls}`]: {
|
||||
color: colorInfo
|
||||
},
|
||||
[`&-warning${iconCls}`]: {
|
||||
color: colorWarning
|
||||
},
|
||||
[`&-error${iconCls}`]: {
|
||||
color: colorError
|
||||
}
|
||||
},
|
||||
[`${noticeCls}-close`]: Object.assign({
|
||||
position: 'absolute',
|
||||
top: token.notificationPaddingVertical,
|
||||
insetInlineEnd: token.notificationPaddingHorizontal,
|
||||
color: token.colorIcon,
|
||||
outline: 'none',
|
||||
width: token.notificationCloseButtonSize,
|
||||
height: token.notificationCloseButtonSize,
|
||||
borderRadius: token.borderRadiusSM,
|
||||
transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
'&:hover': {
|
||||
color: token.colorIconHover,
|
||||
backgroundColor: token.colorBgTextHover
|
||||
},
|
||||
'&:active': {
|
||||
backgroundColor: token.colorBgTextActive
|
||||
}
|
||||
}, genFocusStyle(token)),
|
||||
[`${noticeCls}-progress`]: {
|
||||
position: 'absolute',
|
||||
display: 'block',
|
||||
appearance: 'none',
|
||||
inlineSize: `calc(100% - ${unit(borderRadiusLG)} * 2)`,
|
||||
left: {
|
||||
_skip_check_: true,
|
||||
value: borderRadiusLG
|
||||
},
|
||||
right: {
|
||||
_skip_check_: true,
|
||||
value: borderRadiusLG
|
||||
},
|
||||
bottom: 0,
|
||||
blockSize: notificationProgressHeight,
|
||||
border: 0,
|
||||
'&, &::-webkit-progress-bar': {
|
||||
borderRadius: borderRadiusLG,
|
||||
backgroundColor: `rgba(0, 0, 0, 0.04)`
|
||||
},
|
||||
'&::-moz-progress-bar': {
|
||||
background: notificationProgressBg
|
||||
},
|
||||
'&::-webkit-progress-value': {
|
||||
borderRadius: borderRadiusLG,
|
||||
background: notificationProgressBg
|
||||
}
|
||||
},
|
||||
[`${noticeCls}-actions`]: {
|
||||
float: 'right',
|
||||
marginTop: token.marginSM
|
||||
}
|
||||
};
|
||||
};
|
||||
const genNotificationStyle = token => {
|
||||
const {
|
||||
componentCls,
|
||||
// .ant-notification
|
||||
notificationMarginBottom,
|
||||
notificationMarginEdge,
|
||||
motionDurationMid,
|
||||
motionEaseInOut
|
||||
} = token;
|
||||
const noticeCls = `${componentCls}-notice`;
|
||||
const fadeOut = new Keyframes('antNotificationFadeOut', {
|
||||
'0%': {
|
||||
maxHeight: token.animationMaxHeight,
|
||||
marginBottom: notificationMarginBottom
|
||||
},
|
||||
'100%': {
|
||||
maxHeight: 0,
|
||||
marginBottom: 0,
|
||||
paddingTop: 0,
|
||||
paddingBottom: 0,
|
||||
opacity: 0
|
||||
}
|
||||
});
|
||||
return [
|
||||
// ============================ Holder ============================
|
||||
{
|
||||
[componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
|
||||
position: 'fixed',
|
||||
zIndex: token.zIndexPopup,
|
||||
marginRight: {
|
||||
value: notificationMarginEdge,
|
||||
_skip_check_: true
|
||||
},
|
||||
[`${componentCls}-hook-holder`]: {
|
||||
position: 'relative'
|
||||
},
|
||||
// animation
|
||||
[`${componentCls}-fade-appear-prepare`]: {
|
||||
opacity: '0 !important'
|
||||
},
|
||||
[`${componentCls}-fade-enter, ${componentCls}-fade-appear`]: {
|
||||
animationDuration: token.motionDurationMid,
|
||||
animationTimingFunction: motionEaseInOut,
|
||||
animationFillMode: 'both',
|
||||
opacity: 0,
|
||||
animationPlayState: 'paused'
|
||||
},
|
||||
[`${componentCls}-fade-leave`]: {
|
||||
animationTimingFunction: motionEaseInOut,
|
||||
animationFillMode: 'both',
|
||||
animationDuration: motionDurationMid,
|
||||
animationPlayState: 'paused'
|
||||
},
|
||||
[`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
|
||||
animationPlayState: 'running'
|
||||
},
|
||||
[`${componentCls}-fade-leave${componentCls}-fade-leave-active`]: {
|
||||
animationName: fadeOut,
|
||||
animationPlayState: 'running'
|
||||
},
|
||||
// RTL
|
||||
'&-rtl': {
|
||||
direction: 'rtl',
|
||||
[`${noticeCls}-actions`]: {
|
||||
float: 'left'
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
// ============================ Notice ============================
|
||||
{
|
||||
[componentCls]: {
|
||||
[`${noticeCls}-wrapper`]: genNoticeStyle(token)
|
||||
}
|
||||
}];
|
||||
};
|
||||
// ============================== Export ==============================
|
||||
export const prepareComponentToken = token => ({
|
||||
zIndexPopup: token.zIndexPopupBase + CONTAINER_MAX_OFFSET + 50,
|
||||
width: 384,
|
||||
colorSuccessBg: token.colorSuccessBg,
|
||||
colorErrorBg: token.colorErrorBg,
|
||||
colorInfoBg: token.colorInfoBg,
|
||||
colorWarningBg: token.colorWarningBg
|
||||
});
|
||||
export const prepareNotificationToken = token => {
|
||||
const notificationPaddingVertical = token.paddingMD;
|
||||
const notificationPaddingHorizontal = token.paddingLG;
|
||||
const notificationToken = mergeToken(token, {
|
||||
notificationBg: token.colorBgElevated,
|
||||
notificationPaddingVertical,
|
||||
notificationPaddingHorizontal,
|
||||
notificationIconSize: token.calc(token.fontSizeLG).mul(token.lineHeightLG).equal(),
|
||||
notificationCloseButtonSize: token.calc(token.controlHeightLG).mul(0.55).equal(),
|
||||
notificationMarginBottom: token.margin,
|
||||
notificationPadding: `${unit(token.paddingMD)} ${unit(token.paddingContentHorizontalLG)}`,
|
||||
notificationMarginEdge: token.marginLG,
|
||||
animationMaxHeight: 150,
|
||||
notificationStackLayer: 3,
|
||||
notificationProgressHeight: 2,
|
||||
notificationProgressBg: `linear-gradient(90deg, ${token.colorPrimaryBorderHover}, ${token.colorPrimary})`
|
||||
});
|
||||
return notificationToken;
|
||||
};
|
||||
export default genStyleHooks('Notification', token => {
|
||||
const notificationToken = prepareNotificationToken(token);
|
||||
return [genNotificationStyle(notificationToken), genNotificationPlacementStyle(notificationToken), genStackStyle(notificationToken)];
|
||||
}, prepareComponentToken);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { CSSObject } from '@ant-design/cssinjs';
|
||||
import type { NotificationToken } from '.';
|
||||
import type { GenerateStyle } from '../../theme/internal';
|
||||
declare const genNotificationPlacementStyle: GenerateStyle<NotificationToken, CSSObject>;
|
||||
export default genNotificationPlacementStyle;
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import { Keyframes } from '@ant-design/cssinjs';
|
||||
const genNotificationPlacementStyle = token => {
|
||||
const {
|
||||
componentCls,
|
||||
notificationMarginEdge,
|
||||
animationMaxHeight
|
||||
} = token;
|
||||
const noticeCls = `${componentCls}-notice`;
|
||||
const rightFadeIn = new Keyframes('antNotificationFadeIn', {
|
||||
'0%': {
|
||||
transform: `translate3d(100%, 0, 0)`,
|
||||
opacity: 0
|
||||
},
|
||||
'100%': {
|
||||
transform: `translate3d(0, 0, 0)`,
|
||||
opacity: 1
|
||||
}
|
||||
});
|
||||
const topFadeIn = new Keyframes('antNotificationTopFadeIn', {
|
||||
'0%': {
|
||||
top: -animationMaxHeight,
|
||||
opacity: 0
|
||||
},
|
||||
'100%': {
|
||||
top: 0,
|
||||
opacity: 1
|
||||
}
|
||||
});
|
||||
const bottomFadeIn = new Keyframes('antNotificationBottomFadeIn', {
|
||||
'0%': {
|
||||
bottom: token.calc(animationMaxHeight).mul(-1).equal(),
|
||||
opacity: 0
|
||||
},
|
||||
'100%': {
|
||||
bottom: 0,
|
||||
opacity: 1
|
||||
}
|
||||
});
|
||||
const leftFadeIn = new Keyframes('antNotificationLeftFadeIn', {
|
||||
'0%': {
|
||||
transform: `translate3d(-100%, 0, 0)`,
|
||||
opacity: 0
|
||||
},
|
||||
'100%': {
|
||||
transform: `translate3d(0, 0, 0)`,
|
||||
opacity: 1
|
||||
}
|
||||
});
|
||||
return {
|
||||
[componentCls]: {
|
||||
[`&${componentCls}-top, &${componentCls}-bottom`]: {
|
||||
marginInline: 0,
|
||||
[noticeCls]: {
|
||||
marginInline: 'auto auto'
|
||||
}
|
||||
},
|
||||
[`&${componentCls}-top`]: {
|
||||
[`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
|
||||
animationName: topFadeIn
|
||||
}
|
||||
},
|
||||
[`&${componentCls}-bottom`]: {
|
||||
[`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
|
||||
animationName: bottomFadeIn
|
||||
}
|
||||
},
|
||||
[`&${componentCls}-topRight, &${componentCls}-bottomRight`]: {
|
||||
[`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
|
||||
animationName: rightFadeIn
|
||||
}
|
||||
},
|
||||
[`&${componentCls}-topLeft, &${componentCls}-bottomLeft`]: {
|
||||
marginRight: {
|
||||
value: 0,
|
||||
_skip_check_: true
|
||||
},
|
||||
marginLeft: {
|
||||
value: notificationMarginEdge,
|
||||
_skip_check_: true
|
||||
},
|
||||
[noticeCls]: {
|
||||
marginInlineEnd: 'auto',
|
||||
marginInlineStart: 0
|
||||
},
|
||||
[`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
|
||||
animationName: leftFadeIn
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
export default genNotificationPlacementStyle;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("react").FunctionComponent<import("@ant-design/cssinjs-utils/lib/util/genStyleUtils").SubStyleComponentProps>;
|
||||
export default _default;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { unit } from '@ant-design/cssinjs';
|
||||
import { genNoticeStyle, prepareComponentToken, prepareNotificationToken } from '.';
|
||||
import { genSubStyleComponent } from '../../theme/internal';
|
||||
export default genSubStyleComponent(['Notification', 'PurePanel'], token => {
|
||||
const noticeCls = `${token.componentCls}-notice`;
|
||||
const notificationToken = prepareNotificationToken(token);
|
||||
return {
|
||||
[`${noticeCls}-pure-panel`]: Object.assign(Object.assign({}, genNoticeStyle(notificationToken)), {
|
||||
width: notificationToken.width,
|
||||
maxWidth: `calc(100vw - ${unit(token.calc(notificationToken.notificationMarginEdge).mul(2).equal())})`,
|
||||
margin: 0
|
||||
})
|
||||
};
|
||||
}, prepareComponentToken);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { NotificationToken } from '.';
|
||||
import type { GenerateStyle } from '../../theme/internal';
|
||||
declare const genStackStyle: GenerateStyle<NotificationToken>;
|
||||
export default genStackStyle;
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
import { NotificationPlacements } from '../interface';
|
||||
const placementAlignProperty = {
|
||||
topLeft: 'left',
|
||||
topRight: 'right',
|
||||
bottomLeft: 'left',
|
||||
bottomRight: 'right',
|
||||
top: 'left',
|
||||
bottom: 'left'
|
||||
};
|
||||
const genPlacementStackStyle = (token, placement) => {
|
||||
const {
|
||||
componentCls
|
||||
} = token;
|
||||
return {
|
||||
[`${componentCls}-${placement}`]: {
|
||||
[`&${componentCls}-stack > ${componentCls}-notice-wrapper`]: {
|
||||
[placement.startsWith('top') ? 'top' : 'bottom']: 0,
|
||||
[placementAlignProperty[placement]]: {
|
||||
value: 0,
|
||||
_skip_check_: true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
const genStackChildrenStyle = token => {
|
||||
const childrenStyle = {};
|
||||
for (let i = 1; i < token.notificationStackLayer; i++) {
|
||||
childrenStyle[`&:nth-last-child(${i + 1})`] = {
|
||||
overflow: 'hidden',
|
||||
[`& > ${token.componentCls}-notice`]: {
|
||||
opacity: 0,
|
||||
transition: `opacity ${token.motionDurationMid}`
|
||||
}
|
||||
};
|
||||
}
|
||||
return Object.assign({
|
||||
[`&:not(:nth-last-child(-n+${token.notificationStackLayer}))`]: {
|
||||
opacity: 0,
|
||||
overflow: 'hidden',
|
||||
color: 'transparent',
|
||||
pointerEvents: 'none'
|
||||
}
|
||||
}, childrenStyle);
|
||||
};
|
||||
const genStackedNoticeStyle = token => {
|
||||
const childrenStyle = {};
|
||||
for (let i = 1; i < token.notificationStackLayer; i++) {
|
||||
childrenStyle[`&:nth-last-child(${i + 1})`] = {
|
||||
background: token.colorBgBlur,
|
||||
backdropFilter: 'blur(10px)',
|
||||
'-webkit-backdrop-filter': 'blur(10px)'
|
||||
};
|
||||
}
|
||||
return Object.assign({}, childrenStyle);
|
||||
};
|
||||
const genStackStyle = token => {
|
||||
const {
|
||||
componentCls
|
||||
} = token;
|
||||
return Object.assign({
|
||||
[`${componentCls}-stack`]: {
|
||||
[`& > ${componentCls}-notice-wrapper`]: Object.assign({
|
||||
transition: `transform ${token.motionDurationSlow}, backdrop-filter 0s`,
|
||||
willChange: 'transform, opacity',
|
||||
position: 'absolute'
|
||||
}, genStackChildrenStyle(token))
|
||||
},
|
||||
[`${componentCls}-stack:not(${componentCls}-stack-expanded)`]: {
|
||||
[`& > ${componentCls}-notice-wrapper`]: Object.assign({}, genStackedNoticeStyle(token))
|
||||
},
|
||||
[`${componentCls}-stack${componentCls}-stack-expanded`]: {
|
||||
[`& > ${componentCls}-notice-wrapper`]: {
|
||||
'&:not(:nth-last-child(-n + 1))': {
|
||||
opacity: 1,
|
||||
overflow: 'unset',
|
||||
color: 'inherit',
|
||||
pointerEvents: 'auto',
|
||||
[`& > ${token.componentCls}-notice`]: {
|
||||
opacity: 1
|
||||
}
|
||||
},
|
||||
'&:after': {
|
||||
content: '""',
|
||||
position: 'absolute',
|
||||
height: token.margin,
|
||||
width: '100%',
|
||||
insetInline: 0,
|
||||
bottom: token.calc(token.margin).mul(-1).equal(),
|
||||
background: 'transparent',
|
||||
pointerEvents: 'auto'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, NotificationPlacements.map(placement => genPlacementStackStyle(token, placement)).reduce((acc, cur) => Object.assign(Object.assign({}, acc), cur), {}));
|
||||
};
|
||||
export default genStackStyle;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import React from 'react';
|
||||
import type { NotificationConfig, NotificationInstance } from './interface';
|
||||
type HolderProps = NotificationConfig & {
|
||||
onAllRemoved?: VoidFunction;
|
||||
};
|
||||
export declare function useInternalNotification(notificationConfig?: HolderProps): readonly [NotificationInstance, React.ReactElement];
|
||||
export default function useNotification(notificationConfig?: NotificationConfig): readonly [NotificationInstance, React.ReactElement<unknown, string | React.JSXElementConstructor<any>>];
|
||||
export {};
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
"use client";
|
||||
|
||||
var __rest = this && this.__rest || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import React, { useContext } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { NotificationProvider, useNotification as useRcNotification } from 'rc-notification';
|
||||
import { devUseWarning } from '../_util/warning';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
||||
import { useToken } from '../theme/internal';
|
||||
import { getCloseIcon, PureContent } from './PurePanel';
|
||||
import useStyle from './style';
|
||||
import { getMotion, getPlacementStyle, getCloseIconConfig } from './util';
|
||||
const DEFAULT_OFFSET = 24;
|
||||
const DEFAULT_DURATION = 4.5;
|
||||
const DEFAULT_PLACEMENT = 'topRight';
|
||||
const Wrapper = ({
|
||||
children,
|
||||
prefixCls
|
||||
}) => {
|
||||
const rootCls = useCSSVarCls(prefixCls);
|
||||
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
||||
return wrapCSSVar(/*#__PURE__*/React.createElement(NotificationProvider, {
|
||||
classNames: {
|
||||
list: classNames(hashId, cssVarCls, rootCls)
|
||||
}
|
||||
}, children));
|
||||
};
|
||||
const renderNotifications = (node, {
|
||||
prefixCls,
|
||||
key
|
||||
}) => (/*#__PURE__*/React.createElement(Wrapper, {
|
||||
prefixCls: prefixCls,
|
||||
key: key
|
||||
}, node));
|
||||
const Holder = /*#__PURE__*/React.forwardRef((props, ref) => {
|
||||
const {
|
||||
top,
|
||||
bottom,
|
||||
prefixCls: staticPrefixCls,
|
||||
getContainer: staticGetContainer,
|
||||
maxCount,
|
||||
rtl,
|
||||
onAllRemoved,
|
||||
stack,
|
||||
duration,
|
||||
pauseOnHover = true,
|
||||
showProgress
|
||||
} = props;
|
||||
const {
|
||||
getPrefixCls,
|
||||
getPopupContainer,
|
||||
notification,
|
||||
direction
|
||||
} = useContext(ConfigContext);
|
||||
const [, token] = useToken();
|
||||
const prefixCls = staticPrefixCls || getPrefixCls('notification');
|
||||
// =============================== Style ===============================
|
||||
const getStyle = placement => getPlacementStyle(placement, top !== null && top !== void 0 ? top : DEFAULT_OFFSET, bottom !== null && bottom !== void 0 ? bottom : DEFAULT_OFFSET);
|
||||
const getClassName = () => classNames({
|
||||
[`${prefixCls}-rtl`]: rtl !== null && rtl !== void 0 ? rtl : direction === 'rtl'
|
||||
});
|
||||
// ============================== Motion ===============================
|
||||
const getNotificationMotion = () => getMotion(prefixCls);
|
||||
// ============================== Origin ===============================
|
||||
const [api, holder] = useRcNotification({
|
||||
prefixCls,
|
||||
style: getStyle,
|
||||
className: getClassName,
|
||||
motion: getNotificationMotion,
|
||||
closable: true,
|
||||
closeIcon: getCloseIcon(prefixCls),
|
||||
duration: duration !== null && duration !== void 0 ? duration : DEFAULT_DURATION,
|
||||
getContainer: () => (staticGetContainer === null || staticGetContainer === void 0 ? void 0 : staticGetContainer()) || (getPopupContainer === null || getPopupContainer === void 0 ? void 0 : getPopupContainer()) || document.body,
|
||||
maxCount,
|
||||
pauseOnHover,
|
||||
showProgress,
|
||||
onAllRemoved,
|
||||
renderNotifications,
|
||||
stack: stack === false ? false : {
|
||||
threshold: typeof stack === 'object' ? stack === null || stack === void 0 ? void 0 : stack.threshold : undefined,
|
||||
offset: 8,
|
||||
gap: token.margin
|
||||
}
|
||||
});
|
||||
// ================================ Ref ================================
|
||||
React.useImperativeHandle(ref, () => Object.assign(Object.assign({}, api), {
|
||||
prefixCls,
|
||||
notification
|
||||
}));
|
||||
return holder;
|
||||
});
|
||||
// ==============================================================================
|
||||
// == Hook ==
|
||||
// ==============================================================================
|
||||
export function useInternalNotification(notificationConfig) {
|
||||
const holderRef = React.useRef(null);
|
||||
const warning = devUseWarning('Notification');
|
||||
// ================================ API ================================
|
||||
const wrapAPI = React.useMemo(() => {
|
||||
// Wrap with notification content
|
||||
// >>> Open
|
||||
const open = config => {
|
||||
var _a;
|
||||
if (!holderRef.current) {
|
||||
process.env.NODE_ENV !== "production" ? warning(false, 'usage', 'You are calling notice in render which will break in React 18 concurrent mode. Please trigger in effect instead.') : void 0;
|
||||
return;
|
||||
}
|
||||
const {
|
||||
open: originOpen,
|
||||
prefixCls,
|
||||
notification
|
||||
} = holderRef.current;
|
||||
const noticePrefixCls = `${prefixCls}-notice`;
|
||||
const {
|
||||
message,
|
||||
description,
|
||||
icon,
|
||||
type,
|
||||
btn,
|
||||
actions,
|
||||
className,
|
||||
style,
|
||||
role = 'alert',
|
||||
closeIcon,
|
||||
closable
|
||||
} = config,
|
||||
restConfig = __rest(config, ["message", "description", "icon", "type", "btn", "actions", "className", "style", "role", "closeIcon", "closable"]);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warning.deprecated(!btn, 'btn', 'actions');
|
||||
}
|
||||
const mergedActions = actions !== null && actions !== void 0 ? actions : btn;
|
||||
const realCloseIcon = getCloseIcon(noticePrefixCls, getCloseIconConfig(closeIcon, notificationConfig, notification));
|
||||
return originOpen(Object.assign(Object.assign({
|
||||
// use placement from props instead of hard-coding "topRight"
|
||||
placement: (_a = notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.placement) !== null && _a !== void 0 ? _a : DEFAULT_PLACEMENT
|
||||
}, restConfig), {
|
||||
content: (/*#__PURE__*/React.createElement(PureContent, {
|
||||
prefixCls: noticePrefixCls,
|
||||
icon: icon,
|
||||
type: type,
|
||||
message: message,
|
||||
description: description,
|
||||
actions: mergedActions,
|
||||
role: role
|
||||
})),
|
||||
className: classNames(type && `${noticePrefixCls}-${type}`, className, notification === null || notification === void 0 ? void 0 : notification.className),
|
||||
style: Object.assign(Object.assign({}, notification === null || notification === void 0 ? void 0 : notification.style), style),
|
||||
closeIcon: realCloseIcon,
|
||||
closable: closable !== null && closable !== void 0 ? closable : !!realCloseIcon
|
||||
}));
|
||||
};
|
||||
// >>> destroy
|
||||
const destroy = key => {
|
||||
var _a, _b;
|
||||
if (key !== undefined) {
|
||||
(_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.close(key);
|
||||
} else {
|
||||
(_b = holderRef.current) === null || _b === void 0 ? void 0 : _b.destroy();
|
||||
}
|
||||
};
|
||||
const clone = {
|
||||
open,
|
||||
destroy
|
||||
};
|
||||
const keys = ['success', 'info', 'warning', 'error'];
|
||||
keys.forEach(type => {
|
||||
clone[type] = config => open(Object.assign(Object.assign({}, config), {
|
||||
type
|
||||
}));
|
||||
});
|
||||
return clone;
|
||||
}, []);
|
||||
// ============================== Return ===============================
|
||||
return [wrapAPI, /*#__PURE__*/React.createElement(Holder, Object.assign({
|
||||
key: "notification-holder"
|
||||
}, notificationConfig, {
|
||||
ref: holderRef
|
||||
}))];
|
||||
}
|
||||
export default function useNotification(notificationConfig) {
|
||||
return useInternalNotification(notificationConfig);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import type * as React from 'react';
|
||||
import type { CSSMotionProps } from 'rc-motion';
|
||||
import type { NotificationConfig, NotificationPlacement } from './interface';
|
||||
import type { NotificationConfig as CPNotificationConfig } from '../config-provider/context';
|
||||
export declare function getPlacementStyle(placement: NotificationPlacement, top: number, bottom: number): React.CSSProperties;
|
||||
export declare function getMotion(prefixCls: string): CSSMotionProps;
|
||||
export declare function getCloseIconConfig(closeIcon: React.ReactNode, notificationConfig?: NotificationConfig, notification?: CPNotificationConfig): React.ReactNode;
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
export function getPlacementStyle(placement, top, bottom) {
|
||||
let style;
|
||||
switch (placement) {
|
||||
case 'top':
|
||||
style = {
|
||||
left: '50%',
|
||||
transform: 'translateX(-50%)',
|
||||
right: 'auto',
|
||||
top,
|
||||
bottom: 'auto'
|
||||
};
|
||||
break;
|
||||
case 'topLeft':
|
||||
style = {
|
||||
left: 0,
|
||||
top,
|
||||
bottom: 'auto'
|
||||
};
|
||||
break;
|
||||
case 'topRight':
|
||||
style = {
|
||||
right: 0,
|
||||
top,
|
||||
bottom: 'auto'
|
||||
};
|
||||
break;
|
||||
case 'bottom':
|
||||
style = {
|
||||
left: '50%',
|
||||
transform: 'translateX(-50%)',
|
||||
right: 'auto',
|
||||
top: 'auto',
|
||||
bottom
|
||||
};
|
||||
break;
|
||||
case 'bottomLeft':
|
||||
style = {
|
||||
left: 0,
|
||||
top: 'auto',
|
||||
bottom
|
||||
};
|
||||
break;
|
||||
default:
|
||||
style = {
|
||||
right: 0,
|
||||
top: 'auto',
|
||||
bottom
|
||||
};
|
||||
break;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
export function getMotion(prefixCls) {
|
||||
return {
|
||||
motionName: `${prefixCls}-fade`
|
||||
};
|
||||
}
|
||||
export function getCloseIconConfig(closeIcon, notificationConfig, notification) {
|
||||
if (typeof closeIcon !== 'undefined') {
|
||||
return closeIcon;
|
||||
}
|
||||
if (typeof (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.closeIcon) !== 'undefined') {
|
||||
return notificationConfig.closeIcon;
|
||||
}
|
||||
return notification === null || notification === void 0 ? void 0 : notification.closeIcon;
|
||||
}
|
||||
Reference in New Issue
Block a user