Skip to content

Commit ee3d296

Browse files
authored
refactor: drawer panel (#443)
1 parent dddc45c commit ee3d296

File tree

2 files changed

+30
-63
lines changed

2 files changed

+30
-63
lines changed

src/DrawerPanel.tsx

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import classNames from 'classnames';
2-
import { useComposeRef } from 'rc-util';
32
import * as React from 'react';
43
import { RefContext } from './context';
54
import pickAttrs from 'rc-util/lib/pickAttrs';
5+
import { useComposeRef } from 'rc-util/lib/ref';
66

77
export interface DrawerPanelRef {
88
focus: VoidFunction;
@@ -22,9 +22,7 @@ export type DrawerPanelAccessibility = Pick<
2222
keyof React.AriaAttributes
2323
>;
2424

25-
export interface DrawerPanelProps
26-
extends DrawerPanelEvents,
27-
DrawerPanelAccessibility {
25+
export interface DrawerPanelProps extends DrawerPanelEvents, DrawerPanelAccessibility {
2826
prefixCls: string;
2927
className?: string;
3028
id?: string;
@@ -37,49 +35,24 @@ const DrawerPanel = (props: DrawerPanelProps) => {
3735
const {
3836
prefixCls,
3937
className,
40-
style,
41-
children,
4238
containerRef,
43-
id,
44-
onMouseEnter,
45-
onMouseOver,
46-
onMouseLeave,
47-
onClick,
48-
onKeyDown,
49-
onKeyUp,
39+
...restProps
5040
} = props;
5141

52-
const eventHandlers = {
53-
onMouseEnter,
54-
onMouseOver,
55-
onMouseLeave,
56-
onClick,
57-
onKeyDown,
58-
onKeyUp,
59-
};
60-
6142
const { panel: panelRef } = React.useContext(RefContext);
6243
const mergedRef = useComposeRef(panelRef, containerRef);
6344

6445
// =============================== Render ===============================
6546

6647
return (
67-
<>
68-
<div
69-
id={id}
70-
className={classNames(`${prefixCls}-content`, className)}
71-
style={{
72-
...style,
73-
}}
74-
role="dialog"
75-
ref={mergedRef}
76-
{...pickAttrs(props, { aria: true })}
77-
aria-modal="true"
78-
{...eventHandlers}
79-
>
80-
{children}
81-
</div>
82-
</>
48+
<div
49+
className={classNames(`${prefixCls}-content`, className)}
50+
role="dialog"
51+
ref={mergedRef}
52+
{...pickAttrs(props, { aria: true })}
53+
aria-modal="true"
54+
{...restProps}
55+
/>
8356
);
8457
};
8558

src/DrawerPopup.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,8 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
175175

176176
// Merge push distance
177177
let pushConfig: PushConfig;
178-
if (push === false) {
179-
pushConfig = {
180-
distance: 0,
181-
};
182-
} else if (push === true) {
183-
pushConfig = {};
178+
if (typeof push === 'boolean') {
179+
pushConfig = push ? {} : { distance: 0 };
184180
} else {
185181
pushConfig = push || {};
186182
}
@@ -224,25 +220,23 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
224220
{(
225221
{ className: motionMaskClassName, style: motionMaskStyle },
226222
maskRef,
227-
) => {
228-
return (
229-
<div
230-
className={classNames(
231-
`${prefixCls}-mask`,
232-
motionMaskClassName,
233-
drawerClassNames?.mask,
234-
maskClassName,
235-
)}
236-
style={{
237-
...motionMaskStyle,
238-
...maskStyle,
239-
...styles?.mask,
240-
}}
241-
onClick={maskClosable && open ? onClose : undefined}
242-
ref={maskRef}
243-
/>
244-
);
245-
}}
223+
) => (
224+
<div
225+
className={classNames(
226+
`${prefixCls}-mask`,
227+
motionMaskClassName,
228+
drawerClassNames?.mask,
229+
maskClassName,
230+
)}
231+
style={{
232+
...motionMaskStyle,
233+
...maskStyle,
234+
...styles?.mask,
235+
}}
236+
onClick={maskClosable && open ? onClose : undefined}
237+
ref={maskRef}
238+
/>
239+
)}
246240
</CSSMotion>
247241
);
248242

0 commit comments

Comments
 (0)