'use strict'; const React = require('react/addons'); const Modal = React.createClass({ propTypes: { data: React.PropTypes.object.isRequired }, mixins: [React.addons.PureRenderMixin], componentDidMount() { document.addEventListener('keydown', this._onKeydown); }, componentWillUnmount() { document.removeEventListener('keydown', this._onKeydown); }, render() { let data = this.props.data; let type = data.get('type'); let callbacks = data.get('callbacks'); return (

Esc: {type === 'info' ? 'OK' : 'Decline'}
Enter: {type === 'info' ? 'OK' : 'Accept'}

{data.get('message')}

{type === 'info' ? : [ , ]}
); }, _onKeydown(e) { let type = this.props.data.get('type'); let callbacks = this.props.data.get('callbacks'); if (type === 'info') { if (e.which === 13 || e.which === 27) { callbacks.hide(); } } else if (type === 'offer') { if (e.which === 13) { callbacks.accept(); } else if (e.which === 27) { callbacks.decline(); } } } }); module.exports = Modal;