Skip to content

Commit 28c9a38

Browse files
committed
docs: add NotificationList demo styling
1 parent 4b68fc7 commit 28c9a38

4 files changed

Lines changed: 180 additions & 26 deletions

File tree

assets/geek.less

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
@notificationPrefixCls: notification;
2+
@notificationMotionDuration: 0.3s;
3+
@notificationMotionEase: cubic-bezier(0.22, 1, 0.36, 1);
4+
@notificationMotionOffset: 64px;
5+
6+
.@{notificationPrefixCls} {
7+
&-list {
8+
position: fixed;
9+
top: 0;
10+
right: 0;
11+
z-index: 1000;
12+
width: 360px;
13+
max-height: 100vh;
14+
padding: 24px;
15+
box-sizing: border-box;
16+
display: flex;
17+
flex-direction: column;
18+
pointer-events: none;
19+
overflow-y: auto;
20+
overflow-x: hidden;
21+
}
22+
23+
&-notice {
24+
pointer-events: auto;
25+
box-sizing: border-box;
26+
width: 100%;
27+
padding: 14px 16px;
28+
border: 2px solid #111;
29+
border-radius: 14px;
30+
background: linear-gradient(180deg, #ffffff 0%, #f4f9ff 100%);
31+
box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.16);
32+
color: #111;
33+
font-size: 14px;
34+
line-height: 1.5;
35+
}
36+
}
37+
38+
.notification-fade {
39+
backface-visibility: hidden;
40+
will-change: transform, opacity;
41+
}
42+
43+
.notification-fade-appear-prepare,
44+
.notification-fade-enter-prepare {
45+
opacity: 0;
46+
transform: translate3d(@notificationMotionOffset, 0, 0);
47+
}
48+
49+
.notification-fade-appear-start,
50+
.notification-fade-enter-start {
51+
opacity: 0;
52+
transform: translate3d(@notificationMotionOffset, 0, 0);
53+
}
54+
55+
.notification-fade-appear-active,
56+
.notification-fade-enter-active {
57+
opacity: 1;
58+
transform: translate3d(0, 0, 0);
59+
transition:
60+
transform @notificationMotionDuration @notificationMotionEase,
61+
opacity @notificationMotionDuration @notificationMotionEase,
62+
height @notificationMotionDuration @notificationMotionEase,
63+
margin @notificationMotionDuration @notificationMotionEase;
64+
}
65+
66+
.notification-fade-leave-start {
67+
opacity: 1;
68+
transform: translate3d(0, 0, 0);
69+
}
70+
71+
.notification-fade-leave-active {
72+
opacity: 0;
73+
transform: translate3d(@notificationMotionOffset, 0, 0);
74+
transition:
75+
transform @notificationMotionDuration @notificationMotionEase,
76+
opacity @notificationMotionDuration @notificationMotionEase,
77+
height @notificationMotionDuration @notificationMotionEase,
78+
margin @notificationMotionDuration @notificationMotionEase;
79+
}

docs/demo/NotificationList.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: NotificationList
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/NotificationList.tsx"></code>

docs/examples/NotificationList.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import type { CSSMotionProps } from '@rc-component/motion';
3+
import '../../assets/geek.less';
4+
import NotificationList, { type NotificationListConfig } from '../../src/NotificationList';
5+
6+
const motion: CSSMotionProps = {
7+
motionName: 'notification-fade',
8+
motionAppear: true,
9+
motionEnter: true,
10+
motionLeave: true,
11+
onLeaveStart: (ele) => {
12+
const { offsetHeight } = ele;
13+
return { height: offsetHeight };
14+
},
15+
onLeaveActive: () => ({ height: 0, opacity: 0, margin: 0 }),
16+
};
17+
18+
const Demo = () => {
19+
const [configList, setConfigList] = React.useState<NotificationListConfig[]>([]);
20+
const keyRef = React.useRef(0);
21+
22+
const createConfig = React.useCallback(() => {
23+
const key = keyRef.current;
24+
keyRef.current += 1;
25+
26+
setConfigList((prevConfigList) => [
27+
...prevConfigList,
28+
{
29+
key,
30+
duration: false,
31+
content: `Config ${key + 1}`,
32+
},
33+
]);
34+
}, []);
35+
36+
const removeLastConfig = React.useCallback(() => {
37+
setConfigList((prevConfigList) => prevConfigList.slice(0, -1));
38+
}, []);
39+
40+
return (
41+
<>
42+
<div style={{ marginBottom: 16, display: 'flex', gap: 8 }}>
43+
<button type="button" onClick={createConfig}>
44+
Add Config
45+
</button>
46+
<button type="button" onClick={removeLastConfig}>
47+
Remove Last Config
48+
</button>
49+
</div>
50+
51+
<NotificationList
52+
configList={configList}
53+
prefixCls="notification"
54+
classNames={{ root: 'notification-notice' }}
55+
motion={motion}
56+
placement="topRight"
57+
/>
58+
</>
59+
);
60+
};
61+
62+
export default Demo;

src/NotificationList.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,37 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
7070
className={clsx(listPrefixCls, `${listPrefixCls}-${placement}`)}
7171
{...placementMotion}
7272
>
73-
{({ config, className, style }, nodeRef) => (
74-
<Notification
75-
{...config}
76-
ref={nodeRef}
77-
className={clsx(className, config.className)}
78-
style={{
79-
...style,
80-
...config.style,
81-
}}
82-
classNames={{
83-
root: clsx(classNames?.root, config.classNames?.root),
84-
close: clsx(classNames?.close, config.classNames?.close),
85-
}}
86-
styles={{
87-
root: {
88-
...styles?.root,
89-
...config.styles?.root,
90-
},
91-
close: {
92-
...styles?.close,
93-
...config.styles?.close,
94-
},
95-
}}
96-
pauseOnHover={config.pauseOnHover ?? pauseOnHover}
97-
/>
98-
)}
73+
{({ config, className, style }, nodeRef) => {
74+
const { key, ...notificationConfig } = config;
75+
76+
return (
77+
<Notification
78+
key={key}
79+
{...notificationConfig}
80+
ref={nodeRef}
81+
className={clsx(className, config.className)}
82+
style={{
83+
...style,
84+
...config.style,
85+
}}
86+
classNames={{
87+
root: clsx(classNames?.root, config.classNames?.root),
88+
close: clsx(classNames?.close, config.classNames?.close),
89+
}}
90+
styles={{
91+
root: {
92+
...styles?.root,
93+
...config.styles?.root,
94+
},
95+
close: {
96+
...styles?.close,
97+
...config.styles?.close,
98+
},
99+
}}
100+
pauseOnHover={config.pauseOnHover ?? pauseOnHover}
101+
/>
102+
);
103+
}}
99104
</CSSMotionList>
100105
);
101106
};

0 commit comments

Comments
 (0)