-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
80 lines (66 loc) · 1.97 KB
/
index.jsx
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
76
77
78
79
80
import React from 'react';
import b from 'b_';
import Style from './index.css!';
const YModal = React.createClass({
displayName: 'y-modal',
getInitialState(){
this.wrapperCssClass = b('y-modal', 'wrapper');
this.body = document.body;
return {
visible: false
};
},
show(){
this.setState({ visible: true });
},
hide(){
this.setState({ visible: false });
},
lockBody(){
this.body.style.paddingRight = this.getScrollWidth() + 'px';
this.body.style.overflow = 'hidden';
},
unlockBody(){
this.body.style.paddingRight = 0;
this.body.style.overflow = 'visible';
},
getScrollWidth(){
return window.innerWidth - document.documentElement.clientWidth;
},
checkForClose: function(e){
var classList = e.target.className.split(' ');
if (classList.indexOf(this.wrapperCssClass) !== -1) {
this.hide();
}
},
render(){
const classes = b('y-modal', {
theme: this.props.theme || 'normal',
visible: this.state.visible
});
if (this.state.visible) {
this.lockBody();
} else {
this.unlockBody();
}
return (
<div className={classes}>
<div
className={this.wrapperCssClass}
onClick={this.checkForClose}>
<div className={b('y-modal', 'expander')} />
<div className={b('y-modal', 'content', { visible: this.state.visible })}>
{ this.props.children }
<div
className={b('y-modal', 'close')}
onClick={this.hide}/>
</div>
</div>
<div className={b('y-modal', 'veil')} />
</div>
);
}
});
YModal.Style = Style;
YModal.Class = YModal;
export default YModal;