Skip to content

Commit 4ccd186

Browse files
committed
chore: cover
1 parent 06fd98d commit 4ccd186

16 files changed

+272
-837
lines changed

assets/index.less

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121
inset: 0;
2222
}
2323

24-
&-panel-wrapper {
24+
&-content-wrapper {
2525
position: absolute;
2626
z-index: @zIndex;
2727
overflow: hidden;
2828
transition: transform @duration;
2929

30-
&-hidden {
31-
display: none;
32-
}
33-
3430
// Placement
3531
.@{prefixCls}-left & {
3632
top: 0;
@@ -45,12 +41,16 @@
4541
}
4642
}
4743

48-
&-panel {
44+
&-content {
4945
width: 100%;
5046
height: 100%;
47+
overflow: auto;
5148
background: #fff;
5249
pointer-events: auto;
53-
overflow: auto;
50+
51+
&-hidden {
52+
display: none;
53+
}
5454
}
5555
}
5656

docs/demo/level.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/examples/level.tsx

Lines changed: 0 additions & 103 deletions
This file was deleted.

docs/examples/no-mask.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,31 @@ class Demo extends React.Component {
3131
public render() {
3232
return (
3333
<div>
34-
<button onClick={this.onSwitch}>Open</button>
34+
<div
35+
style={{
36+
width: '100%',
37+
height: 667,
38+
background: '#fff000',
39+
color: '#fff',
40+
textAlign: 'center',
41+
lineHeight: '667px',
42+
}}
43+
>
44+
内容区块
45+
<button
46+
onClick={this.onSwitch}
47+
style={{
48+
height: 24,
49+
width: 100,
50+
marginLeft: 20,
51+
color: '#000',
52+
lineHeight: '24px',
53+
}}
54+
>
55+
{!this.state.open ? '打开' : '关闭'}
56+
</button>
57+
</div>
58+
3559
<Drawer
3660
width="250px"
3761
mask={false}

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
setupFilesAfterEnv: ['<rootDir>/tests/setupFilesAfterEnv.ts']
3+
};

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@
6767
"eslint": "^7.0.0",
6868
"father-build": "^1.22.1",
6969
"glob": "^7.1.6",
70-
"jsonp": "^0.2.0",
7170
"less": "^3.10.3",
7271
"np": "^7.5.0",
7372
"prettier": "^2.6.2",
74-
"querystring": "^0.2.0",
75-
"rc-test": "^6.0.1",
7673
"react": "^16.10.2",
7774
"react-dom": "^16.10.2",
78-
"react-test-renderer": "^16.10.2",
7975
"typescript": "^4.6.4"
8076
}
8177
}

src/Drawer.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,23 @@ export type Placement = 'left' | 'top' | 'right' | 'bottom';
99
export interface DrawerProps extends Omit<DrawerPopupProps, 'prefixCls'> {
1010
prefixCls?: string;
1111

12-
width?: string | number;
13-
height?: string | number;
1412
open?: boolean;
15-
placement?: Placement;
16-
duration?: string;
1713
onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void;
18-
keyboard?: boolean;
19-
contentWrapperStyle?: React.CSSProperties;
20-
autoFocus?: boolean;
14+
/** @deprecated Only work on Portal mode. You can replace with rootClassName instead */
2115
wrapperClassName?: string;
2216
destroyOnClose?: boolean;
23-
2417
getContainer?: GetContainer | false;
2518
}
2619

2720
const defaultGetContainer = () => document.body;
2821

29-
export default function Drawer(props: DrawerProps) {
22+
const Drawer: React.FC<DrawerProps> = props => {
3023
const {
3124
open,
32-
getContainer = defaultGetContainer,
25+
getContainer,
3326
forceRender,
3427
wrapperClassName,
35-
prefixCls = 'rc-drawer',
28+
prefixCls,
3629
afterOpenChange,
3730
destroyOnClose,
3831
} = props;
@@ -73,4 +66,25 @@ export default function Drawer(props: DrawerProps) {
7366
)}
7467
</Portal>
7568
);
69+
};
70+
71+
// Default Value.
72+
// Since spread with default value will make this all over components.
73+
// Let's maintain this in one place.
74+
Drawer.defaultProps = {
75+
open: false,
76+
getContainer: defaultGetContainer,
77+
prefixCls: 'rc-drawer',
78+
placement: 'right',
79+
autoFocus: true,
80+
keyboard: true,
81+
width: 378,
82+
mask: true,
83+
maskClosable: true,
84+
};
85+
86+
if (process.env.NODE_ENV !== 'production') {
87+
Drawer.displayName = 'Drawer';
7688
}
89+
90+
export default Drawer;

src/DrawerPanel.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface DrawerPanelProps {
1212
className?: string;
1313
style?: React.CSSProperties;
1414
width?: number | string;
15+
height?: number | string;
1516
placement: Placement;
1617
children?: React.ReactNode;
1718
onClose?: React.KeyboardEventHandler<HTMLElement>;
@@ -27,8 +28,16 @@ const sentinelStyle: React.CSSProperties = {
2728

2829
const DrawerPanel = React.forwardRef<DrawerPanelRef, DrawerPanelProps>(
2930
(props, ref) => {
30-
const { prefixCls, className, style, placement, width, children, onClose } =
31-
props;
31+
const {
32+
prefixCls,
33+
className,
34+
style,
35+
placement,
36+
width,
37+
height,
38+
children,
39+
onClose,
40+
} = props;
3241

3342
// ================================ Refs ================================
3443
const panelRef = React.useRef<HTMLDivElement>();
@@ -76,13 +85,20 @@ const DrawerPanel = React.forwardRef<DrawerPanelRef, DrawerPanelProps>(
7685
};
7786

7887
// =============================== Render ===============================
88+
const panelStyle: React.CSSProperties = {};
89+
90+
if (placement === 'left' || placement === 'right') {
91+
panelStyle.width = width;
92+
} else {
93+
panelStyle.height = height;
94+
}
95+
7996
return (
8097
<>
8198
<div
82-
className={classNames(`${prefixCls}-panel`, className)}
99+
className={classNames(`${prefixCls}-content`, className)}
83100
style={{
84-
width:
85-
placement === 'left' || placement === 'right' ? width : '100%',
101+
...panelStyle,
86102
...style,
87103
}}
88104
aria-modal="true"

0 commit comments

Comments
 (0)