Skip to content

Commit 73ce708

Browse files
committed
refactor: message & notification
1 parent d211688 commit 73ce708

File tree

15 files changed

+567
-435
lines changed

15 files changed

+567
-435
lines changed

components/message/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
88
import type { Key, VueNode } from '../_util/type';
99
import type { NotificationInstance } from '../vc-notification/Notification';
1010
import classNames from '../_util/classNames';
11+
import useStyle from './style';
1112

1213
let defaultDuration = 3;
1314
let defaultTop: string;
@@ -80,6 +81,7 @@ function getMessageInstance(args: MessageArgsProps, callback: (i: NotificationIn
8081
getContainer: getContainer || args.getPopupContainer,
8182
maxCount,
8283
name: 'message',
84+
useStyle,
8385
},
8486
(instance: any) => {
8587
if (messageInstance) {

components/message/style/index.less

-74
This file was deleted.

components/message/style/index.ts

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// deps-lint-skip-all
2+
import { Keyframes } from '../../_util/cssinjs';
3+
import type { FullToken, GenerateStyle } from '../../theme/internal';
4+
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
5+
import { resetComponent } from '../../_style';
6+
7+
/** Component only token. Which will handle additional calculation of alias token */
8+
export interface ComponentToken {
9+
// Component token here
10+
height: number;
11+
zIndexPopup: number;
12+
}
13+
14+
interface MessageToken extends FullToken<'Message'> {
15+
// Custom token here
16+
messageNoticeContentPadding: string;
17+
}
18+
19+
const genMessageStyle: GenerateStyle<MessageToken> = token => {
20+
const {
21+
componentCls,
22+
iconCls,
23+
boxShadowSecondary,
24+
colorBgElevated,
25+
colorSuccess,
26+
colorError,
27+
colorWarning,
28+
colorInfo,
29+
fontSizeLG,
30+
motionEaseInOutCirc,
31+
motionDurationSlow,
32+
marginXS,
33+
paddingXS,
34+
borderRadiusLG,
35+
zIndexPopup,
36+
// Custom token
37+
messageNoticeContentPadding,
38+
} = token;
39+
40+
const messageMoveIn = new Keyframes('MessageMoveIn', {
41+
'0%': {
42+
padding: 0,
43+
transform: 'translateY(-100%)',
44+
opacity: 0,
45+
},
46+
47+
'100%': {
48+
padding: paddingXS,
49+
transform: 'translateY(0)',
50+
opacity: 1,
51+
},
52+
});
53+
54+
const messageMoveOut = new Keyframes('MessageMoveOut', {
55+
'0%': {
56+
maxHeight: token.height,
57+
padding: paddingXS,
58+
opacity: 1,
59+
},
60+
'100%': {
61+
maxHeight: 0,
62+
padding: 0,
63+
opacity: 0,
64+
},
65+
});
66+
67+
return [
68+
// ============================ Holder ============================
69+
{
70+
[componentCls]: {
71+
...resetComponent(token),
72+
position: 'fixed',
73+
top: marginXS,
74+
width: '100%',
75+
pointerEvents: 'none',
76+
zIndex: zIndexPopup,
77+
78+
[`${componentCls}-move-up`]: {
79+
animationFillMode: 'forwards',
80+
},
81+
[`
82+
${componentCls}-move-up-appear,
83+
${componentCls}-move-up-enter
84+
`]: {
85+
animationName: messageMoveIn,
86+
animationDuration: motionDurationSlow,
87+
animationPlayState: 'paused',
88+
animationTimingFunction: motionEaseInOutCirc,
89+
},
90+
[`
91+
${componentCls}-move-up-appear${componentCls}-move-up-appear-active,
92+
${componentCls}-move-up-enter${componentCls}-move-up-enter-active
93+
`]: {
94+
animationPlayState: 'running',
95+
},
96+
[`${componentCls}-move-up-leave`]: {
97+
animationName: messageMoveOut,
98+
animationDuration: motionDurationSlow,
99+
animationPlayState: 'paused',
100+
animationTimingFunction: motionEaseInOutCirc,
101+
},
102+
[`${componentCls}-move-up-leave${componentCls}-move-up-leave-active`]: {
103+
animationPlayState: 'running',
104+
},
105+
'&-rtl': {
106+
direction: 'rtl',
107+
span: {
108+
direction: 'rtl',
109+
},
110+
},
111+
},
112+
},
113+
114+
// ============================ Notice ============================
115+
{
116+
[`${componentCls}-notice`]: {
117+
padding: paddingXS,
118+
textAlign: 'center',
119+
120+
[iconCls]: {
121+
verticalAlign: 'text-bottom',
122+
marginInlineEnd: marginXS, // affected by ltr or rtl
123+
fontSize: fontSizeLG,
124+
},
125+
126+
[`${componentCls}-notice-content`]: {
127+
display: 'inline-block',
128+
padding: messageNoticeContentPadding,
129+
background: colorBgElevated,
130+
borderRadius: borderRadiusLG,
131+
boxShadow: boxShadowSecondary,
132+
pointerEvents: 'all',
133+
},
134+
135+
[`${componentCls}-success ${iconCls}`]: {
136+
color: colorSuccess,
137+
},
138+
[`${componentCls}-error ${iconCls}`]: {
139+
color: colorError,
140+
},
141+
[`${componentCls}-warning ${iconCls}`]: {
142+
color: colorWarning,
143+
},
144+
[`
145+
${componentCls}-info ${iconCls},
146+
${componentCls}-loading ${iconCls}`]: {
147+
color: colorInfo,
148+
},
149+
},
150+
},
151+
152+
// ============================= Pure =============================
153+
{
154+
[`${componentCls}-notice-pure-panel`]: {
155+
padding: 0,
156+
textAlign: 'start',
157+
},
158+
},
159+
];
160+
};
161+
162+
// ============================== Export ==============================
163+
export default genComponentStyleHook(
164+
'Message',
165+
token => {
166+
// Gen-style functions here
167+
const combinedToken = mergeToken<MessageToken>(token, {
168+
messageNoticeContentPadding: `${
169+
(token.controlHeightLG - token.fontSize * token.lineHeight) / 2
170+
}px ${token.paddingSM}px`,
171+
});
172+
return [genMessageStyle(combinedToken)];
173+
},
174+
token => ({
175+
height: 150,
176+
zIndexPopup: token.zIndexPopupBase + 10,
177+
}),
178+
);

components/message/style/index.tsx

-2
This file was deleted.

components/message/style/rtl.less

-17
This file was deleted.

components/notification/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { renderHelper } from '../_util/util';
1010
import { globalConfig } from '../config-provider';
1111
import type { NotificationInstance as VCNotificationInstance } from '../vc-notification/Notification';
1212
import classNames from '../_util/classNames';
13-
13+
import useStyle from './style';
1414
export type NotificationPlacement =
1515
| 'top'
1616
| 'topLeft'
@@ -163,6 +163,7 @@ function getNotificationInstance(
163163
{
164164
name: 'notification',
165165
prefixCls: customizePrefixCls || defaultPrefixCls,
166+
useStyle,
166167
class: notificationClass,
167168
style: getPlacementStyle(placement, top, bottom),
168169
appContext,

0 commit comments

Comments
 (0)