glitchier-soc/app/assets/javascripts/components/features/ui/containers/modal_container.jsx

69 lines
1.4 KiB
React
Raw Normal View History

import { connect } from 'react-redux';
import { closeModal } from '../../../actions/modal';
import Lightbox from '../../../components/lightbox';
import ImageLoader from 'react-imageloader';
import LoadingIndicator from '../../../components/loading_indicator';
2017-01-23 22:40:48 +02:00
import PureRenderMixin from 'react-addons-pure-render-mixin';
2016-10-24 19:07:40 +03:00
const mapStateToProps = state => ({
url: state.getIn(['modal', 'url']),
isVisible: state.getIn(['modal', 'open'])
});
const mapDispatchToProps = dispatch => ({
onCloseClicked () {
dispatch(closeModal());
},
onOverlayClicked () {
dispatch(closeModal());
}
});
const imageStyle = {
display: 'block',
maxWidth: '80vw',
maxHeight: '80vh'
2016-10-24 19:07:40 +03:00
};
const loadingStyle = {
background: '#373b4a',
width: '400px',
paddingBottom: '120px'
};
const preloader = () => (
<div style={loadingStyle}>
<LoadingIndicator />
</div>
);
2016-10-24 19:07:40 +03:00
const Modal = React.createClass({
propTypes: {
url: React.PropTypes.string,
isVisible: React.PropTypes.bool,
onCloseClicked: React.PropTypes.func,
onOverlayClicked: React.PropTypes.func
},
2017-01-23 22:40:48 +02:00
mixins: [PureRenderMixin],
2016-10-24 19:07:40 +03:00
render () {
const { url, ...other } = this.props;
return (
<Lightbox {...other}>
<ImageLoader
src={url}
preloader={preloader}
imgProps={{ style: imageStyle }}
/>
</Lightbox>
2016-10-24 19:07:40 +03:00
);
}
});
export default connect(mapStateToProps, mapDispatchToProps)(Modal);