Skip to content

Commit b6da4d9

Browse files
committed
chore: push of dist
1 parent 5a9f816 commit b6da4d9

File tree

5 files changed

+79
-30
lines changed

5 files changed

+79
-30
lines changed

assets/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
position: absolute;
2626
z-index: @zIndex;
2727
overflow: hidden;
28+
transition: transform @duration;
2829

2930
&-hidden {
3031
display: none;

docs/examples/multiple.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'antd/lib/style';
99

1010
import '../../assets/index.less';
1111
import './assets/index.less';
12+
import motionProps from './motion';
1213

1314
class Demo extends React.Component {
1415
public state = {
@@ -63,6 +64,8 @@ class Demo extends React.Component {
6364
onClose={this.onClick}
6465
className="drawer1"
6566
placement="right"
67+
push={{ distance: 64 }}
68+
{...motionProps}
6669
>
6770
<div>
6871
<Button onClick={this.onChildClick}>打开子级</Button>
@@ -73,7 +76,7 @@ class Demo extends React.Component {
7376
className="drawer2"
7477
level=".drawer1"
7578
placement="right"
76-
levelMove={100}
79+
{...motionProps}
7780
>
7881
<div style={{ width: 200 }}>
7982
二级抽屉
@@ -85,6 +88,7 @@ class Demo extends React.Component {
8588
level={['.drawer1', '.drawer2']}
8689
placement="right"
8790
levelMove={this.getLevelMove}
91+
{...motionProps}
8892
>
8993
<div style={{ width: 200 }}>三级抽屉</div>
9094
</Drawer>

docs/examples/no-mask.tsx

Lines changed: 12 additions & 14 deletions
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

@@ -27,7 +31,13 @@ class Demo extends React.Component {
2731
public render() {
2832
return (
2933
<div>
30-
<Drawer width="250px" showMask={false}>
34+
<button onClick={this.onSwitch}>Open</button>
35+
<Drawer
36+
width="250px"
37+
mask={false}
38+
open={this.state.open}
39+
placement="right"
40+
>
3141
<Menu
3242
style={{ height: '200%', width: 'calc(100% - 1px)' }} // 选中的线超出
3343
defaultSelectedKeys={['1']}
@@ -84,18 +94,6 @@ class Demo extends React.Component {
8494
</SubMenu>
8595
</Menu>
8696
</Drawer>
87-
<div
88-
style={{
89-
width: '100%',
90-
height: 667,
91-
background: '#fff000',
92-
color: '#fff',
93-
textAlign: 'center',
94-
lineHeight: '667px',
95-
}}
96-
>
97-
内容区块
98-
</div>
9997
</div>
10098
);
10199
}

src/DrawerPopup.tsx

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import CSSMotion from 'rc-motion';
44
import type { CSSMotionProps } from 'rc-motion';
55
import DrawerPanel from './DrawerPanel';
66
import type ScrollLocker from 'rc-util/lib/Dom/scrollLocker';
7+
import DrawerContext from './context';
8+
import type { DrawerContextProps } from './context';
79

810
export type Placement = 'left' | 'right' | 'top' | 'bottom';
911

@@ -12,6 +14,7 @@ export interface DrawerPopupProps {
1214
open?: boolean;
1315
placement?: Placement;
1416
inline?: boolean;
17+
push?: { distance?: number | string };
1518

1619
// MISC
1720
scrollLocker?: ScrollLocker;
@@ -47,6 +50,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
4750
open,
4851
placement = 'left',
4952
inline,
53+
push,
5054

5155
// MISC
5256
scrollLocker,
@@ -74,16 +78,40 @@ export default function DrawerPopup(props: DrawerPopupProps) {
7478
onClose,
7579
} = props;
7680

81+
// ============================ Push ============================
82+
const { distance } = push || {};
83+
const [pushed, setPushed] = React.useState(false);
84+
85+
const parentContext = React.useContext(DrawerContext);
86+
const pushDistance = distance ?? parentContext?.pushDistance ?? 180;
87+
88+
const mergedContext = React.useMemo<DrawerContextProps>(
89+
() => ({
90+
pushDistance,
91+
push: () => {
92+
setPushed(true);
93+
},
94+
pull: () => {
95+
setPushed(false);
96+
},
97+
}),
98+
[pushDistance],
99+
);
100+
77101
// ========================= ScrollLock =========================
78102
React.useEffect(() => {
79103
if (open) {
80104
scrollLocker?.lock();
105+
parentContext?.push?.();
106+
} else {
107+
parentContext?.pull?.();
81108
}
82109
}, [open]);
83110

84111
React.useEffect(
85112
() => () => {
86113
scrollLocker?.unLock();
114+
parentContext?.pull?.();
87115
},
88116
[],
89117
);
@@ -114,7 +142,12 @@ export default function DrawerPopup(props: DrawerPopupProps) {
114142
const motionProps = typeof motion === 'function' ? motion(placement) : motion;
115143

116144
const panelNode: React.ReactNode = (
117-
<div className={classNames(`${prefixCls}-panel-wrapper`)}>
145+
<div
146+
className={classNames(`${prefixCls}-panel-wrapper`)}
147+
style={{
148+
transform: pushed ? `translateX(${-pushDistance}px)` : '',
149+
}}
150+
>
118151
<CSSMotion
119152
key="panel"
120153
{...motionProps}
@@ -150,19 +183,21 @@ export default function DrawerPopup(props: DrawerPopupProps) {
150183

151184
// =========================== Render ===========================
152185
return (
153-
<div
154-
className={classNames(
155-
prefixCls,
156-
`${prefixCls}-${placement}`,
157-
rootClassName,
158-
{
159-
[`${prefixCls}-inline`]: inline,
160-
},
161-
)}
162-
style={rootStyle}
163-
>
164-
{maskNode}
165-
{panelNode}
166-
</div>
186+
<DrawerContext.Provider value={mergedContext}>
187+
<div
188+
className={classNames(
189+
prefixCls,
190+
`${prefixCls}-${placement}`,
191+
rootClassName,
192+
{
193+
[`${prefixCls}-inline`]: inline,
194+
},
195+
)}
196+
style={rootStyle}
197+
>
198+
{maskNode}
199+
{panelNode}
200+
</div>
201+
</DrawerContext.Provider>
167202
);
168203
}

src/context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react';
2+
3+
export interface DrawerContextProps {
4+
pushDistance?: number | string;
5+
push: VoidFunction;
6+
pull: VoidFunction;
7+
}
8+
9+
const DrawerContext = React.createContext<DrawerContextProps>({});
10+
11+
export default DrawerContext;

0 commit comments

Comments
 (0)