Skip to content

Instantly share code, notes, and snippets.

@jesenko
Last active November 20, 2015 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesenko/e453679c1f1579bd5127 to your computer and use it in GitHub Desktop.
Save jesenko/e453679c1f1579bd5127 to your computer and use it in GitHub Desktop.
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