refactor(message): refactor to cssinjs (#35565)

This commit is contained in:
TrickyPi 2022-05-24 09:29:33 +08:00 committed by GitHub
parent 3c506b86b3
commit 49bd49f711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 267 additions and 107 deletions

View File

@ -16,6 +16,7 @@ import type { ComponentToken as ListComponentToken } from '../../list/style';
import type { ComponentToken as MentionsComponentToken } from '../../mentions/style';
import type { ComponentToken as MenuComponentToken } from '../../menu/style';
import type { ComponentToken as ModalComponentToken } from '../../modal/style';
import type { ComponentToken as MessageComponentToken } from '../../message/style';
import type { ComponentToken as NotificationComponentToken } from '../../notification/style';
import type { ComponentToken as PopconfirmComponentToken } from '../../popconfirm/style';
import type { ComponentToken as ProgressComponentToken } from '../../progress/style';
@ -27,6 +28,8 @@ import type { ComponentToken as TimelineComponentToken } from '../../timeline/st
import type { ComponentToken as TypographyComponentToken } from '../../typography/style';
import type { ComponentToken as UploadComponentToken } from '../../upload/style';
export const PresetColors = [
'blue',
'purple',
@ -107,6 +110,7 @@ export interface OverrideToken {
Steps?: {};
Menu?: MenuComponentToken;
Modal?: ModalComponentToken;
Message?: MessageComponentToken;
Upload?: UploadComponentToken;
Tooltip?: {};
Space?: SpaceComponentToken;

View File

@ -1,111 +1,111 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
// @import '../../style/themes/index';
// @import '../../style/mixins/index';
@message-prefix-cls: ~'@{ant-prefix}-message';
// @message-prefix-cls: ~'@{ant-prefix}-message';
.@{message-prefix-cls} {
.reset-component();
// .@{message-prefix-cls} {
// .reset-component();
position: fixed;
top: 8px;
left: 0;
z-index: @zindex-message;
width: 100%;
pointer-events: none;
// position: fixed;
// top: 8px;
// left: 0;
// z-index: @zindex-message;
// width: 100%;
// pointer-events: none;
&-notice {
padding: 8px;
text-align: center;
}
// &-notice {
// padding: 8px;
// text-align: center;
// }
&-notice-content {
display: inline-block;
padding: @message-notice-content-padding;
background: @message-notice-content-bg;
border-radius: @border-radius-base;
box-shadow: @shadow-2;
pointer-events: all;
}
// &-notice-content {
// display: inline-block;
// padding: @message-notice-content-padding;
// background: @message-notice-content-bg;
// border-radius: @border-radius-base;
// box-shadow: @shadow-2;
// pointer-events: all;
// }
&-success .@{iconfont-css-prefix} {
color: @success-color;
}
// &-success .@{iconfont-css-prefix} {
// color: @success-color;
// }
&-error .@{iconfont-css-prefix} {
color: @error-color;
}
// &-error .@{iconfont-css-prefix} {
// color: @error-color;
// }
&-warning .@{iconfont-css-prefix} {
color: @warning-color;
}
// &-warning .@{iconfont-css-prefix} {
// color: @warning-color;
// }
&-info .@{iconfont-css-prefix},
&-loading .@{iconfont-css-prefix} {
color: @info-color;
}
// &-info .@{iconfont-css-prefix},
// &-loading .@{iconfont-css-prefix} {
// color: @info-color;
// }
.@{iconfont-css-prefix} {
position: relative;
top: 1px;
margin-right: 8px;
font-size: @font-size-lg;
}
// .@{iconfont-css-prefix} {
// position: relative;
// top: 1px;
// margin-right: 8px;
// font-size: @font-size-lg;
// }
&-move-up {
animation-fill-mode: forwards;
}
// &-move-up {
// animation-fill-mode: forwards;
// }
&-move-up-appear,
&-move-up-enter {
animation-name: MessageMoveIn;
animation-duration: 0.3s;
animation-play-state: paused;
animation-timing-function: @ease-out-circ;
}
// &-move-up-appear,
// &-move-up-enter {
// animation-name: MessageMoveIn;
// animation-duration: 0.3s;
// animation-play-state: paused;
// animation-timing-function: @ease-out-circ;
// }
&-move-up-appear&-move-up-appear-active,
&-move-up-enter&-move-up-enter-active {
animation-play-state: running;
}
// &-move-up-appear&-move-up-appear-active,
// &-move-up-enter&-move-up-enter-active {
// animation-play-state: running;
// }
&-move-up-leave {
animation-name: MessageMoveOut;
animation-duration: 0.3s;
animation-play-state: paused;
animation-timing-function: @ease-out-circ;
}
// &-move-up-leave {
// animation-name: MessageMoveOut;
// animation-duration: 0.3s;
// animation-play-state: paused;
// animation-timing-function: @ease-out-circ;
// }
&-move-up-leave&-move-up-leave-active {
animation-play-state: running;
}
}
// &-move-up-leave&-move-up-leave-active {
// animation-play-state: running;
// }
// }
@keyframes MessageMoveIn {
0% {
padding: 0;
transform: translateY(-100%);
opacity: 0;
}
// @keyframes MessageMoveIn {
// 0% {
// padding: 0;
// transform: translateY(-100%);
// opacity: 0;
// }
100% {
padding: 8px;
transform: translateY(0);
opacity: 1;
}
}
// 100% {
// padding: 8px;
// transform: translateY(0);
// opacity: 1;
// }
// }
@keyframes MessageMoveOut {
0% {
max-height: 150px;
padding: 8px;
opacity: 1;
}
// @keyframes MessageMoveOut {
// 0% {
// max-height: 150px;
// padding: 8px;
// opacity: 1;
// }
100% {
max-height: 0;
padding: 0;
opacity: 0;
}
}
// 100% {
// max-height: 0;
// padding: 0;
// opacity: 0;
// }
// }
@import './rtl';
// @import './rtl';

View File

@ -1,2 +1,155 @@
import '../../style/index.less';
import './index.less';
// deps-lint-skip-all
import type { CSSObject } from '@ant-design/cssinjs';
import { Keyframes } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../_util/theme';
import { genComponentStyleHook, resetComponent, mergeToken } from '../../_util/theme';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
// Component token here
}
interface MessageToken extends FullToken<'Message'> {
// Custom token here
messageNoticeContentPadding: string;
}
const genMessageStyle: GenerateStyle<MessageToken, CSSObject> = token => {
const {
componentCls,
iconCls,
boxShadow,
colorBgComponent,
colorSuccess,
colorError,
colorWarning,
colorInfo,
fontSizeLG,
motionEaseInOutCirc,
motionDurationSlow,
marginXS,
paddingXS,
radiusBase,
zIndexBase,
// Custom token
messageNoticeContentPadding,
} = token;
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%': {
// FIXME: hard code in v4
maxHeight: '150px',
padding: paddingXS,
opacity: 1,
},
'100%': {
maxHeight: 0,
padding: 0,
opacity: 0,
},
});
return {
[componentCls]: {
...resetComponent(token),
position: 'fixed',
top: marginXS,
// FIXME: hard code in v4
insetInlineStart: 0, // affected by ltr or rtl
// FIXME: hard code in v4
width: '100%',
pointerEvents: 'none',
zIndex: zIndexBase + 10,
[iconCls]: {
position: 'relative',
// FIXME: hard code in v4
top: '1px',
marginInlineEnd: marginXS, // affected by ltr or rtl
fontSize: fontSizeLG,
},
[`${componentCls}-notice`]: {
padding: paddingXS,
textAlign: 'center',
},
[`${componentCls}-notice-content`]: {
display: 'inline-block',
padding: messageNoticeContentPadding,
background: colorBgComponent,
borderRadius: radiusBase,
boxShadow: boxShadow as any,
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,
},
[`${componentCls}-move-up`]: {
animationFillMode: 'forwards',
},
[`
${componentCls}-move-up-appear,
${componentCls}-move-up-enter
`]: {
animationName: messageMoveIn,
animationDuration: motionDurationSlow,
animationPlayState: 'paused',
animationTimingFunction: motionEaseInOutCirc,
},
[`
${componentCls}-move-up-appear${componentCls}-move-up-appear-active,
${componentCls}-move-up-enter${componentCls}-move-up-enter-active
`]: {
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': {
direction: 'rtl',
span: {
direction: 'rtl',
},
},
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook('Message', token => {
// Gen-style functions here
const combinedToken = mergeToken<MessageToken>(token, {
// FIXME: hard code in v4
messageNoticeContentPadding: '10px 16px',
});
return [genMessageStyle(combinedToken)];
});

View File

@ -1,17 +1,17 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
// @import '../../style/themes/index';
// @import '../../style/mixins/index';
@message-prefix-cls: ~'@{ant-prefix}-message';
// @message-prefix-cls: ~'@{ant-prefix}-message';
.@{message-prefix-cls}-rtl {
direction: rtl;
// .@{message-prefix-cls}-rtl {
// direction: rtl;
span {
direction: rtl;
}
// span {
// direction: rtl;
// }
.@{iconfont-css-prefix} {
margin-right: 0;
margin-left: 8px;
}
}
// .@{iconfont-css-prefix} {
// margin-right: 0;
// margin-left: 8px;
// }
// }

View File

@ -9,6 +9,7 @@ import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import { ConfigContext } from '../config-provider';
import useStyle from './style';
import type {
MessageInstance,
ArgsProps,
@ -56,6 +57,8 @@ const Holder = React.forwardRef<HolderRef, HolderProps>((props, ref) => {
const prefixCls = staticPrefixCls || getPrefixCls('message');
const [, hashId] = useStyle(prefixCls);
// =============================== Style ===============================
const getStyle = () => ({
left: '50%',
@ -63,7 +66,7 @@ const Holder = React.forwardRef<HolderRef, HolderProps>((props, ref) => {
top: top ?? DEFAULT_OFFSET,
});
const getClassName = () => (rtl ? `${prefixCls}-rtl` : '');
const getClassName = () => classNames(hashId, rtl ? `${prefixCls}-rtl` : '');
// ============================== Motion ===============================
const getNotificationMotion = () => getMotion(prefixCls, transitionName);