2022-05-24 09:29:33 +08:00
|
|
|
// deps-lint-skip-all
|
2023-04-19 22:05:58 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-05-24 09:29:33 +08:00
|
|
|
import { Keyframes } from '@ant-design/cssinjs';
|
2023-05-09 19:24:50 +08:00
|
|
|
import type { CSSProperties } from 'react';
|
2023-04-19 22:05:58 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
2022-05-24 09:29:33 +08:00
|
|
|
|
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
|
|
export interface ComponentToken {
|
|
|
|
// Component token here
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 提示框 z-index
|
|
|
|
* @descEN z-index of Message
|
|
|
|
*/
|
2022-05-26 09:52:18 +08:00
|
|
|
zIndexPopup: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 提示框背景色
|
|
|
|
* @descEN Background color of Message
|
|
|
|
*/
|
2023-05-09 19:24:50 +08:00
|
|
|
contentBg: string;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 提示框内边距
|
|
|
|
* @descEN Padding of Message
|
|
|
|
*/
|
2023-05-09 19:24:50 +08:00
|
|
|
contentPadding: CSSProperties['padding'];
|
2022-05-24 09:29:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface MessageToken extends FullToken<'Message'> {
|
|
|
|
// Custom token here
|
2023-05-09 19:24:50 +08:00
|
|
|
height: number;
|
2022-05-24 09:29:33 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genMessageStyle: GenerateStyle<MessageToken> = (token) => {
|
2022-05-24 09:29:33 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
iconCls,
|
2023-02-03 11:20:21 +08:00
|
|
|
boxShadow,
|
2023-03-05 16:39:43 +08:00
|
|
|
colorText,
|
2022-05-24 09:29:33 +08:00
|
|
|
colorSuccess,
|
|
|
|
colorError,
|
|
|
|
colorWarning,
|
|
|
|
colorInfo,
|
|
|
|
fontSizeLG,
|
|
|
|
motionEaseInOutCirc,
|
|
|
|
motionDurationSlow,
|
|
|
|
marginXS,
|
|
|
|
paddingXS,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadiusLG,
|
2022-05-26 09:52:18 +08:00
|
|
|
zIndexPopup,
|
2022-05-24 09:29:33 +08:00
|
|
|
// Custom token
|
2023-05-09 19:24:50 +08:00
|
|
|
contentPadding,
|
|
|
|
contentBg,
|
2022-05-24 09:29:33 +08:00
|
|
|
} = token;
|
|
|
|
|
2023-04-19 22:05:58 +08:00
|
|
|
const noticeCls = `${componentCls}-notice`;
|
|
|
|
|
2022-05-24 09:29:33 +08:00
|
|
|
const messageMoveIn = new Keyframes('MessageMoveIn', {
|
|
|
|
'0%': {
|
|
|
|
padding: 0,
|
|
|
|
transform: 'translateY(-100%)',
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
'100%': {
|
|
|
|
padding: paddingXS,
|
|
|
|
transform: 'translateY(0)',
|
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const messageMoveOut = new Keyframes('MessageMoveOut', {
|
|
|
|
'0%': {
|
2022-05-26 09:52:18 +08:00
|
|
|
maxHeight: token.height,
|
2022-05-24 09:29:33 +08:00
|
|
|
padding: paddingXS,
|
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
'100%': {
|
|
|
|
maxHeight: 0,
|
|
|
|
padding: 0,
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-04-19 22:05:58 +08:00
|
|
|
const noticeStyle: CSSObject = {
|
|
|
|
padding: paddingXS,
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
[`${componentCls}-custom-content > ${iconCls}`]: {
|
|
|
|
verticalAlign: 'text-bottom',
|
|
|
|
marginInlineEnd: marginXS, // affected by ltr or rtl
|
|
|
|
fontSize: fontSizeLG,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${noticeCls}-content`]: {
|
|
|
|
display: 'inline-block',
|
2023-05-09 19:24:50 +08:00
|
|
|
padding: contentPadding,
|
|
|
|
background: contentBg,
|
2023-04-19 22:05:58 +08:00
|
|
|
borderRadius: borderRadiusLG,
|
|
|
|
boxShadow,
|
|
|
|
pointerEvents: 'all',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-success > ${iconCls}`]: {
|
|
|
|
color: colorSuccess,
|
|
|
|
},
|
|
|
|
[`${componentCls}-error > ${iconCls}`]: {
|
|
|
|
color: colorError,
|
|
|
|
},
|
|
|
|
[`${componentCls}-warning > ${iconCls}`]: {
|
|
|
|
color: colorWarning,
|
|
|
|
},
|
|
|
|
[`${componentCls}-info > ${iconCls},
|
|
|
|
${componentCls}-loading > ${iconCls}`]: {
|
|
|
|
color: colorInfo,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-06-07 23:29:12 +08:00
|
|
|
return [
|
|
|
|
// ============================ Holder ============================
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2023-03-05 16:39:43 +08:00
|
|
|
color: colorText,
|
2022-06-07 23:29:12 +08:00
|
|
|
position: 'fixed',
|
|
|
|
top: marginXS,
|
|
|
|
width: '100%',
|
|
|
|
pointerEvents: 'none',
|
|
|
|
zIndex: zIndexPopup,
|
|
|
|
|
|
|
|
[`${componentCls}-move-up`]: {
|
|
|
|
animationFillMode: 'forwards',
|
|
|
|
},
|
|
|
|
[`
|
2022-05-24 09:29:33 +08:00
|
|
|
${componentCls}-move-up-appear,
|
|
|
|
${componentCls}-move-up-enter
|
|
|
|
`]: {
|
2022-06-07 23:29:12 +08:00
|
|
|
animationName: messageMoveIn,
|
|
|
|
animationDuration: motionDurationSlow,
|
|
|
|
animationPlayState: 'paused',
|
|
|
|
animationTimingFunction: motionEaseInOutCirc,
|
|
|
|
},
|
|
|
|
[`
|
2022-05-24 09:29:33 +08:00
|
|
|
${componentCls}-move-up-appear${componentCls}-move-up-appear-active,
|
|
|
|
${componentCls}-move-up-enter${componentCls}-move-up-enter-active
|
|
|
|
`]: {
|
2022-06-07 23:29:12 +08:00
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
[`${componentCls}-move-up-leave`]: {
|
|
|
|
animationName: messageMoveOut,
|
|
|
|
animationDuration: motionDurationSlow,
|
|
|
|
animationPlayState: 'paused',
|
|
|
|
animationTimingFunction: motionEaseInOutCirc,
|
|
|
|
},
|
|
|
|
[`${componentCls}-move-up-leave${componentCls}-move-up-leave-active`]: {
|
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
'&-rtl': {
|
2022-05-24 09:29:33 +08:00
|
|
|
direction: 'rtl',
|
2022-06-07 23:29:12 +08:00
|
|
|
span: {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ============================ Notice ============================
|
|
|
|
{
|
2023-04-19 22:05:58 +08:00
|
|
|
[componentCls]: {
|
2023-09-13 15:19:18 +08:00
|
|
|
[`${noticeCls}-wrapper`]: {
|
2023-04-19 22:05:58 +08:00
|
|
|
...noticeStyle,
|
2022-05-24 09:29:33 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-08 17:01:26 +08:00
|
|
|
|
|
|
|
// ============================= Pure =============================
|
|
|
|
{
|
|
|
|
[`${componentCls}-notice-pure-panel`]: {
|
2023-04-19 22:05:58 +08:00
|
|
|
...noticeStyle,
|
2022-06-08 17:01:26 +08:00
|
|
|
padding: 0,
|
|
|
|
textAlign: 'start',
|
|
|
|
},
|
|
|
|
},
|
2022-06-07 23:29:12 +08:00
|
|
|
];
|
2022-05-24 09:29:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-05-26 09:52:18 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Message',
|
2022-11-19 13:47:33 +08:00
|
|
|
(token) => {
|
2022-05-26 09:52:18 +08:00
|
|
|
// Gen-style functions here
|
2023-05-09 19:24:50 +08:00
|
|
|
const combinedToken = mergeToken<MessageToken>(token, {
|
|
|
|
height: 150,
|
|
|
|
});
|
2022-05-26 09:52:18 +08:00
|
|
|
return [genMessageStyle(combinedToken)];
|
|
|
|
},
|
2022-11-19 13:47:33 +08:00
|
|
|
(token) => ({
|
2022-05-26 09:52:18 +08:00
|
|
|
zIndexPopup: token.zIndexPopupBase + 10,
|
2023-05-09 19:24:50 +08:00
|
|
|
contentBg: token.colorBgElevated,
|
|
|
|
contentPadding: `${(token.controlHeightLG - token.fontSize * token.lineHeight) / 2}px ${
|
|
|
|
token.paddingSM
|
|
|
|
}px`,
|
2022-05-26 09:52:18 +08:00
|
|
|
}),
|
|
|
|
);
|