2022-05-17 20:15:34 +08:00
|
|
|
import { Keyframes } from '@ant-design/cssinjs';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-05-17 20:15:34 +08:00
|
|
|
import genNotificationPlacementStyle from './placement';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
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 {
|
|
|
|
zIndexPopup: number;
|
|
|
|
width: number;
|
|
|
|
}
|
2022-05-16 18:02:46 +08:00
|
|
|
|
2022-05-17 20:15:34 +08:00
|
|
|
export interface NotificationToken extends FullToken<'Notification'> {
|
|
|
|
notificationBg: string;
|
|
|
|
notificationPaddingVertical: number;
|
|
|
|
notificationPaddingHorizontal: number;
|
|
|
|
notificationPadding: string;
|
|
|
|
notificationMarginBottom: number;
|
|
|
|
notificationMarginEdge: number;
|
2022-05-20 17:40:03 +08:00
|
|
|
animationMaxHeight: number;
|
2022-08-29 17:09:41 +08:00
|
|
|
notificationIconSize: number;
|
2022-09-20 21:50:36 +08:00
|
|
|
notificationCloseButtonSize: number;
|
2022-05-17 20:15:34 +08:00
|
|
|
}
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
|
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,
|
|
|
|
motionDurationMid,
|
|
|
|
motionEaseInOut,
|
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,
|
2022-05-17 20:15:34 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
const noticeCls = `${componentCls}-notice`;
|
|
|
|
|
2022-05-17 20:15:34 +08:00
|
|
|
const notificationFadeIn = new Keyframes('antNotificationFadeIn', {
|
|
|
|
'0%': {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
2022-05-20 17:40:03 +08:00
|
|
|
value: width,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
2022-05-20 17:40:03 +08:00
|
|
|
opacity: 0,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'100%': {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
2022-05-20 17:40:03 +08:00
|
|
|
value: 0,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
2022-05-20 17:40:03 +08:00
|
|
|
opacity: 1,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const notificationFadeOut = new Keyframes('antNotificationFadeOut', {
|
|
|
|
'0%': {
|
2022-05-20 17:40:03 +08:00
|
|
|
maxHeight: token.animationMaxHeight,
|
2022-05-17 20:15:34 +08:00
|
|
|
marginBottom: notificationMarginBottom,
|
2022-05-20 17:40:03 +08:00
|
|
|
opacity: 1,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
2022-05-16 18:02:46 +08:00
|
|
|
|
2022-05-17 20:15:34 +08:00
|
|
|
'100%': {
|
2022-05-20 17:40:03 +08:00
|
|
|
maxHeight: 0,
|
|
|
|
marginBottom: 0,
|
|
|
|
paddingTop: 0,
|
|
|
|
paddingBottom: 0,
|
|
|
|
opacity: 0,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
});
|
2022-05-16 18:02:46 +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,
|
|
|
|
marginInlineEnd: notificationMarginEdge,
|
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
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`&${componentCls}-top, &${componentCls}-bottom`]: {
|
|
|
|
[`${componentCls}-notice`]: {
|
|
|
|
marginInline: 'auto auto',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-topLeft, &${componentCls}-bottomLeft`]: {
|
|
|
|
[`${componentCls}-notice`]: {
|
|
|
|
marginInlineEnd: 'auto',
|
|
|
|
marginInlineStart: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// animation
|
|
|
|
[`${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`]:
|
|
|
|
{
|
|
|
|
animationName: notificationFadeIn,
|
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-fade-leave${componentCls}-fade-leave-active`]: {
|
|
|
|
animationName: notificationFadeOut,
|
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
|
|
|
|
// placement
|
|
|
|
...genNotificationPlacementStyle(token),
|
|
|
|
|
|
|
|
// RTL
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
|
|
|
|
[`${componentCls}-notice-btn`]: {
|
|
|
|
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 ============================
|
|
|
|
{
|
|
|
|
[noticeCls]: {
|
2022-05-17 20:15:34 +08:00
|
|
|
position: 'relative',
|
2022-05-20 17:40:03 +08:00
|
|
|
width,
|
|
|
|
maxWidth: `calc(100vw - ${notificationMarginEdge * 2}px)`,
|
2022-05-17 20:15:34 +08:00
|
|
|
marginBottom: notificationMarginBottom,
|
|
|
|
marginInlineStart: 'auto',
|
|
|
|
padding: notificationPadding,
|
|
|
|
overflow: 'hidden',
|
|
|
|
lineHeight,
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
background: notificationBg,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: borderRadiusLG,
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadow,
|
2022-05-17 20:15:34 +08:00
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${componentCls}-close-icon`]: {
|
2022-11-01 15:06:38 +08:00
|
|
|
fontSize,
|
2022-06-08 17:01:26 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-message`]: {
|
2022-05-20 17:40:03 +08:00
|
|
|
marginBottom: token.marginXS,
|
2022-05-17 20:15:34 +08:00
|
|
|
color: colorTextHeading,
|
|
|
|
fontSize: fontSizeLG,
|
2022-05-20 17:40:03 +08:00
|
|
|
lineHeight: token.lineHeightLG,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-description`]: {
|
2022-11-01 15:06:38 +08:00
|
|
|
fontSize,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`&${noticeCls}-closable ${noticeCls}-message`]: {
|
2022-05-20 17:40:03 +08:00
|
|
|
paddingInlineEnd: token.paddingLG,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-with-icon ${noticeCls}-message`]: {
|
2022-08-29 17:09:41 +08:00
|
|
|
marginBottom: token.marginXS,
|
|
|
|
marginInlineStart: token.marginSM + notificationIconSize,
|
2022-05-17 20:15:34 +08:00
|
|
|
fontSize: fontSizeLG,
|
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-with-icon ${noticeCls}-description`]: {
|
2022-08-29 17:09:41 +08:00
|
|
|
marginInlineStart: token.marginSM + notificationIconSize,
|
2022-11-01 15:06:38 +08:00
|
|
|
fontSize,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// 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
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-icon`]: {
|
2022-05-17 20:15:34 +08:00
|
|
|
position: 'absolute',
|
2022-08-29 17:09:41 +08:00
|
|
|
fontSize: notificationIconSize,
|
2022-08-29 19:06:55 +08:00
|
|
|
lineHeight: 0,
|
2022-05-17 20:15:34 +08:00
|
|
|
|
|
|
|
// icon-font
|
|
|
|
[`&-success${iconCls}`]: {
|
|
|
|
color: colorSuccess,
|
|
|
|
},
|
|
|
|
[`&-info${iconCls}`]: {
|
|
|
|
color: colorInfo,
|
|
|
|
},
|
|
|
|
[`&-warning${iconCls}`]: {
|
|
|
|
color: colorWarning,
|
|
|
|
},
|
|
|
|
[`&-error${iconCls}`]: {
|
|
|
|
color: colorError,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-close`]: {
|
2022-05-17 20:15:34 +08:00
|
|
|
position: 'absolute',
|
2022-05-20 17:40:03 +08:00
|
|
|
top: token.notificationPaddingVertical,
|
|
|
|
insetInlineEnd: token.notificationPaddingHorizontal,
|
2022-07-21 17:00:42 +08:00
|
|
|
color: token.colorIcon,
|
2022-05-17 20:15:34 +08:00
|
|
|
outline: 'none',
|
2022-09-20 21:50:36 +08:00
|
|
|
width: token.notificationCloseButtonSize,
|
|
|
|
height: token.notificationCloseButtonSize,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
|
2022-09-20 21:50:36 +08:00
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2022-05-17 20:15:34 +08:00
|
|
|
|
|
|
|
'&:hover': {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: token.colorIconHover,
|
2022-09-20 21:50:36 +08:00
|
|
|
backgroundColor: token.wireframe ? 'transparent' : token.colorFillContent,
|
2022-05-17 20:15:34 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-06-08 17:01:26 +08:00
|
|
|
[`${noticeCls}-btn`]: {
|
2022-05-17 20:15:34 +08:00
|
|
|
float: 'right',
|
2022-08-29 17:09:41 +08:00
|
|
|
marginTop: token.marginSM,
|
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
|
|
|
// ============================= Pure =============================
|
|
|
|
{
|
|
|
|
[`${noticeCls}-pure-panel`]: {
|
|
|
|
margin: 0,
|
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 ==============================
|
2022-05-20 17:40:03 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Notification',
|
2022-11-17 23:31:41 +08:00
|
|
|
(token) => {
|
2022-10-25 17:04:36 +08:00
|
|
|
const notificationPaddingVertical = token.paddingMD;
|
2022-05-20 17:40:03 +08:00
|
|
|
const notificationPaddingHorizontal = token.paddingLG;
|
|
|
|
|
|
|
|
const notificationToken = mergeToken<NotificationToken>(token, {
|
|
|
|
// default.less variables
|
2022-06-17 18:47:47 +08:00
|
|
|
notificationBg: token.colorBgElevated,
|
2022-05-20 17:40:03 +08:00
|
|
|
notificationPaddingVertical,
|
|
|
|
notificationPaddingHorizontal,
|
|
|
|
// index.less variables
|
2022-10-25 17:04:36 +08:00
|
|
|
notificationPadding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`,
|
2022-05-20 17:40:03 +08:00
|
|
|
notificationMarginBottom: token.margin,
|
|
|
|
notificationMarginEdge: token.marginLG,
|
|
|
|
animationMaxHeight: 150,
|
2022-08-29 17:09:41 +08:00
|
|
|
notificationIconSize: token.fontSizeLG * token.lineHeightLG,
|
2022-09-20 21:50:36 +08:00
|
|
|
notificationCloseButtonSize: token.controlHeightLG * 0.55,
|
2022-05-20 17:40:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return [genNotificationStyle(notificationToken)];
|
|
|
|
},
|
2022-11-17 23:31:41 +08:00
|
|
|
(token) => ({
|
2022-05-20 17:40:03 +08:00
|
|
|
zIndexPopup: token.zIndexPopupBase + 50,
|
|
|
|
width: 384,
|
|
|
|
}),
|
|
|
|
);
|