2023-04-19 22:05:58 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2023-11-14 10:06:18 +08:00
|
|
|
import { Keyframes, unit } from '@ant-design/cssinjs';
|
2023-11-17 10:54:19 +08:00
|
|
|
|
|
|
|
import { CONTAINER_MAX_OFFSET } from '../../_util/hooks/useZIndex';
|
2023-04-19 22:05:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-17 10:54:19 +08:00
|
|
|
import type { AliasToken, FullToken, GenerateStyle } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2022-05-17 20:15:34 +08:00
|
|
|
import genNotificationPlacementStyle from './placement';
|
2023-09-13 15:19:18 +08:00
|
|
|
import genStackStyle from './stack';
|
2023-11-14 10:06:18 +08:00
|
|
|
import type { GenStyleFn } from '../../theme/util/genComponentStyleHook';
|
2022-05-16 18:02:46 +08:00
|
|
|
|
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
2022-05-20 17:40:03 +08:00
|
|
|
export interface ComponentToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 提醒框 z-index
|
|
|
|
* @descEN z-index of Notification
|
|
|
|
*/
|
2022-05-20 17:40:03 +08:00
|
|
|
zIndexPopup: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 提醒框宽度
|
|
|
|
* @descEN Width of Notification
|
|
|
|
*/
|
2022-05-20 17:40:03 +08:00
|
|
|
width: number;
|
2023-11-16 15:34:24 +08:00
|
|
|
/** @internal */
|
|
|
|
closeBtnHoverBg: string;
|
2023-05-09 19:24:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface NotificationToken extends FullToken<'Notification'> {
|
|
|
|
animationMaxHeight: number;
|
2022-05-17 20:15:34 +08:00
|
|
|
notificationBg: string;
|
2023-05-04 15:33:16 +08:00
|
|
|
notificationPadding: string;
|
2022-05-17 20:15:34 +08:00
|
|
|
notificationPaddingVertical: number;
|
|
|
|
notificationPaddingHorizontal: number;
|
2023-11-14 10:06:18 +08:00
|
|
|
notificationIconSize: number | string;
|
|
|
|
notificationCloseButtonSize: number | string;
|
2022-05-17 20:15:34 +08:00
|
|
|
notificationMarginBottom: number;
|
|
|
|
notificationMarginEdge: number;
|
2023-09-13 15:19:18 +08:00
|
|
|
notificationStackLayer: number;
|
2023-05-04 15:33:16 +08:00
|
|
|
}
|
|
|
|
|
2023-11-06 11:29:41 +08:00
|
|
|
export const genNoticeStyle = (token: NotificationToken): CSSObject => {
|
2022-05-17 20:15:34 +08:00
|
|
|
const {
|
|
|
|
iconCls,
|
|
|
|
componentCls, // .ant-notification
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadow,
|
2022-05-17 20:15:34 +08:00
|
|
|
fontSizeLG,
|
|
|
|
notificationMarginBottom,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadiusLG,
|
2022-05-17 20:15:34 +08:00
|
|
|
colorSuccess,
|
|
|
|
colorInfo,
|
|
|
|
colorWarning,
|
|
|
|
colorError,
|
|
|
|
colorTextHeading,
|
|
|
|
notificationBg,
|
|
|
|
notificationPadding,
|
|
|
|
notificationMarginEdge,
|
2022-11-01 15:06:38 +08:00
|
|
|
fontSize,
|
2022-05-17 20:15:34 +08:00
|
|
|
lineHeight,
|
2022-05-20 17:40:03 +08:00
|
|
|
width,
|
2022-08-29 17:09:41 +08:00
|
|
|
notificationIconSize,
|
2023-06-06 10:53:28 +08:00
|
|
|
colorText,
|
2022-05-17 20:15:34 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
const noticeCls = `${componentCls}-notice`;
|
|
|
|
|
2023-11-06 11:29:41 +08:00
|
|
|
return {
|
2023-04-19 22:05:58 +08:00
|
|
|
position: 'relative',
|
|
|
|
marginBottom: notificationMarginBottom,
|
|
|
|
marginInlineStart: 'auto',
|
|
|
|
background: notificationBg,
|
|
|
|
borderRadius: borderRadiusLG,
|
|
|
|
boxShadow,
|
|
|
|
|
2023-09-13 15:19:18 +08:00
|
|
|
[noticeCls]: {
|
|
|
|
padding: notificationPadding,
|
2023-11-06 11:29:41 +08:00
|
|
|
width,
|
2023-11-14 10:06:18 +08:00
|
|
|
maxWidth: `calc(100vw - ${unit(token.calc(notificationMarginEdge).mul(2).equal())})`,
|
2023-09-13 15:19:18 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
lineHeight,
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
},
|
|
|
|
|
2023-04-19 22:05:58 +08:00
|
|
|
[`${componentCls}-close-icon`]: {
|
|
|
|
fontSize,
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-message`]: {
|
|
|
|
marginBottom: token.marginXS,
|
|
|
|
color: colorTextHeading,
|
|
|
|
fontSize: fontSizeLG,
|
|
|
|
lineHeight: token.lineHeightLG,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-description`]: {
|
|
|
|
fontSize,
|
2023-06-06 10:53:28 +08:00
|
|
|
color: colorText,
|
2023-04-19 22:05:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&${noticeCls}-closable ${noticeCls}-message`]: {
|
|
|
|
paddingInlineEnd: token.paddingLG,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-with-icon ${noticeCls}-message`]: {
|
|
|
|
marginBottom: token.marginXS,
|
2023-11-14 10:06:18 +08:00
|
|
|
marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
|
2023-04-19 22:05:58 +08:00
|
|
|
fontSize: fontSizeLG,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-with-icon ${noticeCls}-description`]: {
|
2023-11-14 10:06:18 +08:00
|
|
|
marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
|
2023-04-19 22:05:58 +08:00
|
|
|
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,
|
2023-11-29 11:09:33 +08:00
|
|
|
lineHeight: 1,
|
2023-04-19 22:05:58 +08:00
|
|
|
|
|
|
|
// icon-font
|
|
|
|
[`&-success${iconCls}`]: {
|
|
|
|
color: colorSuccess,
|
|
|
|
},
|
|
|
|
[`&-info${iconCls}`]: {
|
|
|
|
color: colorInfo,
|
|
|
|
},
|
|
|
|
[`&-warning${iconCls}`]: {
|
|
|
|
color: colorWarning,
|
|
|
|
},
|
|
|
|
[`&-error${iconCls}`]: {
|
|
|
|
color: colorError,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-close`]: {
|
|
|
|
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',
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
color: token.colorIconHover,
|
2023-11-16 15:34:24 +08:00
|
|
|
backgroundColor: token.closeBtnHoverBg,
|
2023-04-19 22:05:58 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-btn`]: {
|
|
|
|
float: 'right',
|
|
|
|
marginTop: token.marginSM,
|
|
|
|
},
|
|
|
|
};
|
2023-11-06 11:29:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const genNotificationStyle: GenerateStyle<NotificationToken> = (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,
|
|
|
|
},
|
|
|
|
});
|
2023-04-19 22:05:58 +08:00
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
return [
|
|
|
|
// ============================ Holder ============================
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2022-05-17 20:15:34 +08:00
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
position: 'fixed',
|
|
|
|
zIndex: token.zIndexPopup,
|
2023-10-17 16:57:54 +08:00
|
|
|
marginRight: {
|
|
|
|
value: notificationMarginEdge,
|
|
|
|
_skip_check_: true,
|
|
|
|
},
|
2022-05-17 20:15:34 +08:00
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${componentCls}-hook-holder`]: {
|
|
|
|
position: 'relative',
|
|
|
|
},
|
2022-05-17 20:15:34 +08:00
|
|
|
|
2023-09-13 15:19:18 +08:00
|
|
|
// animation
|
|
|
|
[`${componentCls}-fade-appear-prepare`]: {
|
|
|
|
opacity: '0 !important',
|
2022-06-08 17:01:26 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${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`]: {
|
2023-09-13 15:19:18 +08:00
|
|
|
animationName: fadeOut,
|
2022-06-08 17:01:26 +08:00
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
|
|
|
|
// RTL
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
|
2023-04-19 22:05:58 +08:00
|
|
|
[`${noticeCls}-btn`]: {
|
2022-06-08 17:01:26 +08:00
|
|
|
float: 'left',
|
|
|
|
},
|
|
|
|
},
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
2022-06-08 17:01:26 +08:00
|
|
|
},
|
2022-05-17 20:15:34 +08:00
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
// ============================ Notice ============================
|
|
|
|
{
|
2023-04-19 22:05:58 +08:00
|
|
|
[componentCls]: {
|
2023-09-13 15:19:18 +08:00
|
|
|
[`${noticeCls}-wrapper`]: {
|
2023-11-06 11:29:41 +08:00
|
|
|
...genNoticeStyle(token),
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
},
|
2022-06-08 17:01:26 +08:00
|
|
|
},
|
|
|
|
];
|
2022-05-16 18:02:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2023-11-06 11:29:41 +08:00
|
|
|
export const prepareComponentToken = (token: AliasToken) => ({
|
2023-11-17 10:54:19 +08:00
|
|
|
zIndexPopup: token.zIndexPopupBase + CONTAINER_MAX_OFFSET + 50,
|
2023-11-06 11:29:41 +08:00
|
|
|
width: 384,
|
2023-11-16 15:34:24 +08:00
|
|
|
closeBtnHoverBg: token.wireframe ? 'transparent' : token.colorFillContent,
|
2023-11-06 11:29:41 +08:00
|
|
|
});
|
|
|
|
|
2023-11-14 10:06:18 +08:00
|
|
|
export const prepareNotificationToken: (
|
|
|
|
token: Parameters<GenStyleFn<'Notification'>>[0],
|
|
|
|
) => NotificationToken = (token) => {
|
2023-11-06 11:29:41 +08:00
|
|
|
const notificationPaddingVertical = token.paddingMD;
|
|
|
|
const notificationPaddingHorizontal = token.paddingLG;
|
|
|
|
const notificationToken = mergeToken<NotificationToken>(token, {
|
|
|
|
notificationBg: token.colorBgElevated,
|
|
|
|
notificationPaddingVertical,
|
|
|
|
notificationPaddingHorizontal,
|
2023-11-14 10:06:18 +08:00
|
|
|
notificationIconSize: token.calc(token.fontSizeLG).mul(token.lineHeightLG).equal(),
|
|
|
|
notificationCloseButtonSize: token.calc(token.controlHeightLG).mul(0.55).equal(),
|
2023-11-06 11:29:41 +08:00
|
|
|
notificationMarginBottom: token.margin,
|
2023-11-14 10:06:18 +08:00
|
|
|
notificationPadding: `${unit(token.paddingMD)} ${unit(token.paddingContentHorizontalLG)}`,
|
2023-11-06 11:29:41 +08:00
|
|
|
notificationMarginEdge: token.marginLG,
|
|
|
|
animationMaxHeight: 150,
|
|
|
|
notificationStackLayer: 3,
|
|
|
|
});
|
|
|
|
|
|
|
|
return notificationToken;
|
|
|
|
};
|
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2022-05-20 17:40:03 +08:00
|
|
|
'Notification',
|
2022-11-17 23:31:41 +08:00
|
|
|
(token) => {
|
2023-11-06 11:29:41 +08:00
|
|
|
const notificationToken = prepareNotificationToken(token);
|
2023-05-09 19:24:50 +08:00
|
|
|
|
2023-09-13 15:19:18 +08:00
|
|
|
return [
|
|
|
|
genNotificationStyle(notificationToken),
|
|
|
|
genNotificationPlacementStyle(notificationToken),
|
|
|
|
genStackStyle(notificationToken),
|
|
|
|
];
|
2022-05-20 17:40:03 +08:00
|
|
|
},
|
2023-11-06 11:29:41 +08:00
|
|
|
prepareComponentToken,
|
2022-05-20 17:40:03 +08:00
|
|
|
);
|