Skip to content

Commit 3fb4135

Browse files
committed
bump 0.4.0
1 parent 0d0503e commit 3fb4135

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ReactDom.render(
6565
| levelTransition | string | `transform .3s cubic-bezier(0.78, 0.14, 0.15, 0.86)` | level css transition |
6666
| parent | string | `body` | parent element. |
6767
| onChange | function | null | change callback(open) |
68-
| onIconClick | function | null | icon click function |
68+
| onSwitch | function | null | icon or bg click function |
6969

7070

7171
## Development

examples/change.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class Demo extends React.Component {
3838
width="240px"
3939
onChange={this.onChange}
4040
open={this.state.open}
41-
onIconClick={this.onTouchEnd}
41+
onSwitch={this.onTouchEnd}
42+
iconChild={null}
43+
level={null}
4244
>
4345
<Menu
4446
style={{ width: 240 }}
@@ -88,6 +90,12 @@ class Demo extends React.Component {
8890
}}
8991
>
9092
内容区块
93+
<button
94+
onClick={this.onTouchEnd}
95+
style={{ height: 24, width: 100, marginLeft: 20, color: '#000', lineHeight: '24px' }}
96+
>
97+
{!this.state.open ? '打开' : '关闭'}
98+
</button>
9199
</div>
92100
</div>
93101
);

examples/parent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MenuItemGroup = Menu.ItemGroup;
1717

1818
ReactDom.render((
1919
<div >
20-
<Drawer parent="#__react-content" width="240px">
20+
<Drawer parent={null} width="240px">
2121
<Menu
2222
style={{ width: 240 }}
2323
defaultSelectedKeys={['1']}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-drawer-menu",
3-
"version": "0.3.5",
3+
"version": "0.4.0",
44
"description": "drawer menu animation component for react",
55
"keywords": [
66
"react",

src/Drawer.jsx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Drawer extends React.PureComponent {
2020
openClassName: PropTypes.string,
2121
iconChild: PropTypes.any,
2222
onChange: PropTypes.func,
23-
onIconClick: PropTypes.func,
23+
onSwitch: PropTypes.func,
2424
}
2525
static defaultProps = {
2626
className: 'drawer',
@@ -31,7 +31,8 @@ class Drawer extends React.PureComponent {
3131
level: 'all',
3232
levelTransition: 'transform .3s cubic-bezier(0.78, 0.14, 0.15, 0.86)',
3333
onChange: () => { },
34-
onIconClick: () => { },
34+
onSwitch: () => { },
35+
iconChild: (<i className="drawer-button-icon" />),
3536
}
3637

3738
levelDom = [];
@@ -47,11 +48,10 @@ class Drawer extends React.PureComponent {
4748
open: props.open !== undefined ? props.open : !!props.defaultOpen,
4849
};
4950
}
50-
5151
componentDidMount() {
52+
this.container = this.props.parent ? this.defaultGetContainer() : ReactDOM.findDOMNode(this);
5253
this.getParentAndLevelDom();
53-
this.container = this.defaultGetContainer();
54-
this.componentDidUpdate();
54+
this.forceUpdate();
5555
}
5656

5757
componentWillReceiveProps(nextProps) {
@@ -64,17 +64,18 @@ class Drawer extends React.PureComponent {
6464
}
6565
}
6666

67-
componentDidUpdate() {
68-
this.renderPickerComponent(this.getChildToRender());
69-
}
70-
7167
componentWillUnmount() {
7268
if (this.container) {
7369
this.setLevelDomTransform(false, true);
74-
this.contextWrapDom.style.transform = '';
70+
// 拦不住。。直接删除;
71+
if (this.props.parent) {
72+
this.container.parentNode.removeChild(this.container);
73+
}
74+
/* this.contextWrapDom.style.transform = '';
7575
this.container.style.opacity = 0;
7676
this.container.style.pointerEvents = 'none';
77-
this.container.style.transition = 'opacity .3s';
77+
this.container.style.transition = 'opacity 11.3s';
78+
console.log(this.container)
7879
const removeElemetFunc = () => {
7980
this.container.removeEventListener(transitionEnd, removeElemetFunc);
8081
this.levelDom.forEach(dom => {
@@ -84,7 +85,7 @@ class Drawer extends React.PureComponent {
8485
this.container.parentNode.removeChild(this.container);
8586
this.container = null;
8687
};
87-
this.container.addEventListener(transitionEnd, removeElemetFunc);
88+
this.container.addEventListener(transitionEnd, removeElemetFunc); */
8889
}
8990
}
9091

@@ -94,7 +95,7 @@ class Drawer extends React.PureComponent {
9495
}
9596
const { level, parent } = this.props;
9697
this.levelDom = [];
97-
this.parent = document.querySelectorAll(parent)[0];
98+
this.parent = parent && document.querySelectorAll(parent)[0] || this.container.parentNode;
9899
if (level === 'all') {
99100
const children = Array.prototype.slice.call(this.parent.children);
100101
children.forEach(child => {
@@ -105,7 +106,7 @@ class Drawer extends React.PureComponent {
105106
this.levelDom.push(child);
106107
}
107108
});
108-
} else {
109+
} else if (level) {
109110
dataToArray(this.props.level).forEach(key => {
110111
document.querySelectorAll(key)
111112
.forEach(item => {
@@ -122,7 +123,7 @@ class Drawer extends React.PureComponent {
122123
}
123124

124125
onTouchEnd = (e, close) => {
125-
this.props.onIconClick(e);
126+
this.props.onSwitch(e);
126127
if (this.props.open !== undefined) {
127128
return;
128129
}
@@ -262,7 +263,7 @@ class Drawer extends React.PureComponent {
262263
if (this.isOpenChange === undefined || this.isOpenChange) {
263264
this.setLevelDomTransform(open);
264265
}
265-
let iconChildToRender = (<i className={`${className}-button-icon`} />);
266+
let iconChildToRender;
266267
if (iconChild) {
267268
if (Array.isArray(iconChild)) {
268269
if (iconChild.length === 2) {
@@ -298,12 +299,14 @@ class Drawer extends React.PureComponent {
298299
>
299300
{children}
300301
</div>
301-
<div
302-
className={`${className}-button`}
303-
onClick={(e) => { this.onTouchEnd(e); }}
304-
>
305-
{iconChildToRender}
306-
</div>
302+
{iconChildToRender && (
303+
<div
304+
className={`${className}-button`}
305+
onClick={(e) => { this.onTouchEnd(e); }}
306+
>
307+
{iconChildToRender}
308+
</div>
309+
)}
307310
</div>
308311
</div>
309312
);
@@ -318,12 +321,17 @@ class Drawer extends React.PureComponent {
318321
return container;
319322
};
320323

321-
renderPickerComponent = (children) => {
322-
ReactDOM.unstable_renderSubtreeIntoContainer(this, children, this.container);
323-
}
324-
325324
render() {
326-
return null;
325+
const children = this.getChildToRender();
326+
if (!this.props.parent) {
327+
return (<div className={this.props.wrapperClassName}>
328+
{children}
329+
</div>);
330+
}
331+
if (!this.container) {
332+
return null;
333+
}
334+
return ReactDOM.createPortal(children, this.container);
327335
}
328336
}
329337

0 commit comments

Comments
 (0)