-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap.js
More file actions
75 lines (69 loc) · 2.04 KB
/
Copy pathwrap.js
File metadata and controls
75 lines (69 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component, PropTypes } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
class Wrapper extends Component {
constructor(wProps) {
super(wProps);
this.state = wProps.state;
}
componentDidMount() {
this.props.onChange(nextState => this.setState(nextState));
}
getChildContext() {
const {
isActive, isContext, isFocus, navigate, panel, route, routeIndex, router, toggleExpand,
updateSettings
} = this.state;
return {
isActive,
isContext,
isFocus,
navigate,
panel,
route,
routeIndex,
router,
toggleExpand,
updateSettings
};
}
render() {
const WrappedComponent = this.props.component;
return <WrappedComponent {...this.state.panel.props} mountedRef={this.props.mountedRef} panels={this.state} />;
}
}
Wrapper.propTypes = {
onChange: PropTypes.func.isRequired,
mountedRef: PropTypes.any.isRequired,
state: PropTypes.object.isRequired
};
const routeShape = PropTypes.shape({
app: PropTypes.string.isRequired,
context: PropTypes.string.isRequired,
panelId: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
isVisible: PropTypes.bool.isRequired,
width: PropTypes.number.isRequired
});
Wrapper.childContextTypes = {
isActive: PropTypes.func.isRequired,
isContext: PropTypes.bool,
isFocus: PropTypes.bool,
navigate: PropTypes.func.isRequired,
panel: PropTypes.object.isRequired,
route: routeShape.isRequired,
routeIndex: PropTypes.number.isRequired,
router: PropTypes.shape({
routes: PropTypes.shape({
byContext: PropTypes.objectOf(routeShape),
items: PropTypes.arrayOf(PropTypes.string)
}),
uri: PropTypes.string.isRequired
}),
toggleExpand: PropTypes.func.isRequired,
updateSettings: PropTypes.func.isRequired
};
const wrap = WrappedComponent => ($el, props, onChange) => {
render(<Wrapper component={WrappedComponent} onChange={onChange} mountedRef={$el} state={props} />, $el);
return () => unmountComponentAtNode($el);
};
export default wrap;