Last active
August 29, 2015 14:24
-
-
Save kinncj/4c0c7df95189761d30fb to your computer and use it in GitHub Desktop.
ReactJS Modal
This file contains hidden or 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
'use strict'; | |
import { createClass } from 'react/addons'; | |
let App = createClass({ | |
render: function() { | |
return <div> | |
<Button label="Open!" target="modalTest" classNames=".buttonStyle" /> | |
<Modal name="modalTest"> | |
<div class='modal'> | |
Xuplau! | |
</div> | |
</Modal> | |
</div>; | |
} | |
}); |
This file contains hidden or 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
<div id="main"></div> | |
<script type="text/jsx"> | |
React.render( | |
<App />, | |
document.getElementById('main') | |
); | |
</script> |
This file contains hidden or 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
'use strict'; | |
import { createClass } from 'react/addons'; | |
let Modal = createClass({ | |
getInitialState: function() { | |
return { | |
visible: false | |
}; | |
}, | |
componentDidMount: function() { | |
window.addEventListener('re4kt.modal.click', this.listener.bind(this), false); | |
}, | |
componentWillUnmount: function() { | |
window.removeEventListener('re4kt.modal.click', this.listener.bind(this), false); | |
}, | |
onOpen: function() { | |
this.setState({visible:true}); | |
}, | |
onClose: function() { | |
this.setState({visible:false}); | |
}, | |
listener: function(event) { | |
if (event.detail.target !== this.props.name) { | |
console.log('target:', event.detail.target); | |
return; | |
} | |
var action = event.detail.action.charAt(0).toUpperCase() + event.detail.action.slice(1); | |
this['on' + action](); | |
}, | |
render: function() { | |
if (!this.state.visible) { | |
var style = { | |
'display': none; | |
}; | |
return <div style={style}></div>; | |
} | |
return <div>{this.props.children}</div> | |
} | |
}); | |
export default Modal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modal IE Compliant
Button IE Compliant