Last active
November 20, 2015 11:56
-
-
Save jesenko/e453679c1f1579bd5127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rand = ()=> (Math.floor(Math.random() * 20) - 10); | |
const modalStyle = { | |
position: 'fixed', | |
zIndex: 1040, | |
top: 0, bottom: 0, left: 0, right: 0 | |
}; | |
const backdropStyle = { | |
...modalStyle, | |
zIndex: 'auto', | |
backgroundColor: '#000', | |
opacity: 0.5 | |
}; | |
const dialogStyle = function() { | |
// we use some psuedo random coords so modals | |
// don't sit right on top of each other. | |
let top = 50 + rand(); | |
let left = 50 + rand(); | |
return { | |
position: 'absolute', | |
width: 400, | |
top: top + '%', left: left + '%', | |
transform: `translate(-${top}%, -${left}%)`, | |
border: '1px solid #e5e5e5', | |
backgroundColor: 'white', | |
boxShadow: '0 5px 15px rgba(0,0,0,.5)', | |
padding: 20 | |
}; | |
}; | |
const ModalExample = React.createClass({ | |
getInitialState(){ | |
return { showModal: false }; | |
}, | |
render() { | |
return ( | |
<div className='modal-example'> | |
<Button onClick={this.open}> | |
Open Modal | |
</Button> | |
<p>Multiple modals at same levels throws on close!</p> | |
<Modal | |
aria-labelledby='modal-label' | |
style={modalStyle} | |
backdropStyle={backdropStyle} | |
show={this.state.showModal} | |
onHide={this.close} | |
> | |
<div style={dialogStyle()} > | |
<h4 id='modal-label'>Text in a modal</h4> | |
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p> | |
<input autoFocus/> | |
<ModalExample/> | |
</div> | |
</Modal> | |
<Modal | |
aria-labelledby='modal-label' | |
style={modalStyle} | |
backdropStyle={backdropStyle} | |
show={this.state.showModal} | |
onHide={this.close} | |
> | |
<div style={dialogStyle()} > | |
<h4 id='modal-label'>Text in a modal</h4> | |
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p> | |
<input autoFocus/> | |
<ModalExample/> | |
</div> | |
</Modal> | |
</div> | |
); | |
}, | |
close(){ | |
this.setState({ showModal: false }); | |
}, | |
open(){ | |
this.setState({ showModal: true }); | |
} | |
}); | |
React.render(<ModalExample/>, mountNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment