Skip to content

Commit 3867241

Browse files
committed
refactor: base replace with rc-motion
1 parent 133fd21 commit 3867241

File tree

14 files changed

+624
-1126
lines changed

14 files changed

+624
-1126
lines changed

assets/index.less

Lines changed: 252 additions & 210 deletions
Large diffs are not rendered by default.

docs/examples/assets/motion.less

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@duration: 0.3s;
2+
3+
.mask-motion {
4+
&-enter,
5+
&-appear,
6+
&-leave {
7+
&-active {
8+
transition: all @duration;
9+
}
10+
}
11+
12+
&-enter,
13+
&-appear {
14+
opacity: 0;
15+
16+
&-active {
17+
opacity: 1;
18+
}
19+
}
20+
21+
&-leave {
22+
opacity: 1;
23+
24+
&-active {
25+
opacity: 0;
26+
}
27+
}
28+
}
29+
30+
.panel-motion() {
31+
&-enter,
32+
&-appear,
33+
&-leave {
34+
&-active {
35+
transition: all @duration;
36+
}
37+
}
38+
}
39+
40+
.panel-motion {
41+
&-left {
42+
.panel-motion();
43+
44+
&-enter,
45+
&-appear {
46+
transform: translateX(-100%);
47+
48+
&-active {
49+
transform: translateX(0);
50+
}
51+
}
52+
53+
&-leave {
54+
transform: translateX(0);
55+
56+
&-active {
57+
transform: translateX(-100%);
58+
}
59+
}
60+
}
61+
62+
&-right {
63+
.panel-motion();
64+
65+
&-enter,
66+
&-appear {
67+
transform: translateX(100%);
68+
69+
&-active {
70+
transform: translateX(0);
71+
}
72+
}
73+
74+
&-leave {
75+
transform: translateX(0);
76+
77+
&-active {
78+
transform: translateX(100%);
79+
}
80+
}
81+
}
82+
}

docs/examples/base.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import React, { useState } from 'react';
33
import Drawer from 'rc-drawer';
4+
import motionProps from './motion';
45

56
const Demo = () => {
67
const [open, setOpen] = useState(false);
@@ -22,11 +23,13 @@ const Demo = () => {
2223
onClose={onTouchEnd}
2324
handler={false}
2425
level={null}
25-
afterVisibleChange={(c: boolean) => {
26-
// console.log('transitionEnd: ', c);
26+
afterOpenChange={(c: boolean) => {
27+
console.log('transitionEnd: ', c);
2728
}}
2829
placement="right"
2930
width={400}
31+
// Motion
32+
{...motionProps}
3033
>
3134
content
3235
</Drawer>

docs/examples/change.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
1+
import {
2+
AppstoreOutlined,
3+
MailOutlined,
4+
SettingOutlined,
5+
} from '@ant-design/icons';
26
import { Menu } from 'antd';
37
import * as React from 'react';
48

@@ -9,6 +13,7 @@ import 'antd/lib/style';
913

1014
import '../../assets/index.less';
1115
import './assets/index.less';
16+
import motionProps from './motion';
1217

1318
const SubMenu = Menu.SubMenu;
1419
const MenuItemGroup = Menu.ItemGroup;
@@ -49,6 +54,8 @@ class Demo extends React.Component {
4954
console.log('transitionEnd: ', c);
5055
}}
5156
width="20vw"
57+
// Motion
58+
{...motionProps}
5259
>
5360
<Menu
5461
defaultSelectedKeys={['1']}

docs/examples/motion.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { DrawerProps } from 'rc-drawer';
2+
import './assets/motion.less';
3+
4+
export const maskMotion: DrawerProps['maskMotion'] = {
5+
motionAppear: true,
6+
motionName: 'mask-motion',
7+
onAppearEnd: console.warn,
8+
};
9+
10+
export const motion: DrawerProps['motion'] = placement => ({
11+
motionAppear: true,
12+
motionName: `panel-motion-${placement}`,
13+
});
14+
15+
const motionProps: Partial<DrawerProps> = {
16+
maskMotion,
17+
motion,
18+
};
19+
20+
export default motionProps;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"dependencies": {
4848
"@babel/runtime": "^7.10.1",
4949
"classnames": "^2.2.6",
50+
"rc-motion": "^2.6.1",
5051
"rc-util": "^5.21.2"
5152
},
5253
"devDependencies": {

src/Drawer.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as React from 'react';
2+
import type { GetContainer } from 'rc-util/lib/PortalWrapper';
3+
import Portal from 'rc-util/lib/PortalWrapper';
4+
import DrawerPopup from './DrawerPopup';
5+
import type { DrawerPopupProps } from './DrawerPopup';
6+
7+
export type Placement = 'left' | 'top' | 'right' | 'bottom';
8+
9+
type LevelMove = number | [number, number];
10+
11+
export interface DrawerProps extends Omit<DrawerPopupProps, 'prefixCls'> {
12+
prefixCls?: string;
13+
14+
width?: string | number;
15+
height?: string | number;
16+
open?: boolean;
17+
handler?: React.ReactElement | null | false;
18+
placement?: Placement;
19+
level?: null | string | string[];
20+
levelMove?:
21+
| LevelMove
22+
| ((e: { target: HTMLElement; open: boolean }) => LevelMove);
23+
duration?: string;
24+
ease?: string;
25+
showMask?: boolean;
26+
onChange?: (open?: boolean) => void;
27+
onHandleClick?: (e: React.MouseEvent | React.KeyboardEvent) => void;
28+
onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void;
29+
keyboard?: boolean;
30+
contentWrapperStyle?: React.CSSProperties;
31+
autoFocus?: boolean;
32+
wrapperClassName?: string;
33+
forceRender?: boolean;
34+
getContainer?: GetContainer;
35+
}
36+
37+
const defaultGetContainer = () => document.body;
38+
39+
export default function Drawer(props: DrawerProps) {
40+
const {
41+
open,
42+
getContainer = defaultGetContainer,
43+
forceRender,
44+
wrapperClassName,
45+
prefixCls = 'rc-drawer',
46+
} = props;
47+
48+
return (
49+
<Portal
50+
visible={open}
51+
forceRender={forceRender}
52+
getContainer={getContainer}
53+
wrapperClassName={wrapperClassName}
54+
>
55+
{({ scrollLocker }) => (
56+
<DrawerPopup
57+
{...props}
58+
prefixCls={prefixCls}
59+
scrollLocker={scrollLocker}
60+
/>
61+
)}
62+
</Portal>
63+
);
64+
}

0 commit comments

Comments
 (0)