2016-11-11 00:21:24 +02:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-11-07 19:23:36 +02:00
|
|
|
import IconButton from './icon_button';
|
2016-11-11 00:21:24 +02:00
|
|
|
import { Motion, spring } from 'react-motion';
|
2016-11-16 18:20:52 +02:00
|
|
|
import { injectIntl } from 'react-intl';
|
2016-11-07 19:23:36 +02:00
|
|
|
|
|
|
|
const overlayStyle = {
|
|
|
|
position: 'fixed',
|
|
|
|
top: '0',
|
|
|
|
left: '0',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2016-11-07 19:42:39 +02:00
|
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
display: 'flex',
|
2016-11-11 00:21:24 +02:00
|
|
|
justifyContent: 'center',
|
|
|
|
alignContent: 'center',
|
|
|
|
flexDirection: 'row',
|
2016-11-07 19:42:39 +02:00
|
|
|
zIndex: '9999'
|
2016-11-07 19:23:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const dialogStyle = {
|
|
|
|
color: '#282c37',
|
2016-11-11 00:21:24 +02:00
|
|
|
boxShadow: '0 0 30px rgba(0, 0, 0, 0.8)',
|
2016-11-07 19:23:36 +02:00
|
|
|
margin: 'auto',
|
|
|
|
position: 'relative'
|
|
|
|
};
|
|
|
|
|
|
|
|
const closeStyle = {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '4px',
|
|
|
|
right: '4px'
|
|
|
|
};
|
|
|
|
|
2016-11-11 00:21:24 +02:00
|
|
|
const Lightbox = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
isVisible: React.PropTypes.bool,
|
|
|
|
onOverlayClicked: React.PropTypes.func,
|
|
|
|
onCloseClicked: React.PropTypes.func
|
|
|
|
},
|
2016-11-07 19:42:39 +02:00
|
|
|
|
2016-11-11 00:21:24 +02:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-12-02 15:37:00 +02:00
|
|
|
componentDidMount () {
|
2016-12-06 20:18:37 +02:00
|
|
|
this._listener = e => {
|
2016-12-02 15:37:00 +02:00
|
|
|
if (e.key === 'Escape') {
|
|
|
|
this.props.onCloseClicked();
|
|
|
|
}
|
2016-12-06 20:18:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('keyup', this._listener);
|
2016-12-02 15:37:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
2016-12-06 20:18:37 +02:00
|
|
|
window.removeEventListener('keyup', this._listener);
|
2016-12-02 15:37:00 +02:00
|
|
|
},
|
|
|
|
|
2016-11-11 00:21:24 +02:00
|
|
|
render () {
|
2016-11-16 18:20:52 +02:00
|
|
|
const { intl, isVisible, onOverlayClicked, onCloseClicked, children } = this.props;
|
2016-11-11 00:21:24 +02:00
|
|
|
|
2016-11-23 10:20:34 +02:00
|
|
|
const content = isVisible ? children : <div />;
|
|
|
|
|
2016-11-11 00:21:24 +02:00
|
|
|
return (
|
|
|
|
<div className='lightbox' style={{...overlayStyle, display: isVisible ? 'flex' : 'none'}} onClick={onOverlayClicked}>
|
|
|
|
<Motion defaultStyle={{ y: -200 }} style={{ y: spring(isVisible ? 0 : -200) }}>
|
|
|
|
{({ y }) =>
|
|
|
|
<div style={{...dialogStyle, transform: `translateY(${y}px)`}}>
|
2016-11-16 18:20:52 +02:00
|
|
|
<IconButton title={intl.formatMessage({ id: 'lightbox.close', defaultMessage: 'Close' })} icon='times' onClick={onCloseClicked} size={16} style={closeStyle} />
|
2016-11-23 10:20:34 +02:00
|
|
|
{content}
|
2016-11-11 00:21:24 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</Motion>
|
2016-11-07 19:42:39 +02:00
|
|
|
</div>
|
2016-11-11 00:21:24 +02:00
|
|
|
);
|
|
|
|
}
|
2016-11-07 19:23:36 +02:00
|
|
|
|
2016-11-11 00:21:24 +02:00
|
|
|
});
|
2016-11-07 19:23:36 +02:00
|
|
|
|
2016-11-16 18:20:52 +02:00
|
|
|
export default injectIntl(Lightbox);
|