Replace react-skylight with own solution that centers images better

This commit is contained in:
Eugen Rochko
2016-11-07 18:23:36 +01:00
parent f5c6baf29d
commit d0d799f911
8 changed files with 64 additions and 35 deletions

View File

@ -35,7 +35,8 @@ const IconButton = React.createClass({
width: `${this.props.size * 1.28571429}px`,
height: `${this.props.size}px`,
lineHeight: `${this.props.size}px`,
cursor: 'pointer'
cursor: 'pointer',
...this.props.style
};
return (

View File

@ -0,0 +1,44 @@
import IconButton from './icon_button';
const overlayStyle = {
position: 'fixed',
top: '0',
left: '0',
width: '100%',
height: '100%',
justifyContent: 'center',
alignContent: 'center',
background: 'rgba(0, 0, 0, 0.5)'
};
const dialogStyle = {
color: '#282c37',
background: '#d9e1e8',
borderRadius: '4px',
boxShadow: '0 0 15px rgba(0, 0, 0, 0.4)',
padding: '10px',
margin: 'auto',
position: 'relative'
};
const closeStyle = {
position: 'absolute',
top: '4px',
right: '4px'
};
const Lightbox = ({ isVisible, onOverlayClicked, onCloseClicked, children }) =>
<div className='lightbox' style={{ ...overlayStyle, display: isVisible ? 'flex' : 'none' }} onClick={onOverlayClicked}>
<div style={dialogStyle}>
<IconButton title='Close' icon='times' onClick={onCloseClicked} size={16} style={closeStyle} />
{children}
</div>
</div>
Lightbox.propTypes = {
isVisible: React.PropTypes.bool,
onOverlayClicked: React.PropTypes.func,
onCloseClicked: React.PropTypes.func
};
export default Lightbox;

View File

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { SkyLightStateless } from 'react-skylight';
import { closeModal } from '../../../actions/modal';
import Lightbox from '../../../components/lightbox';
const mapStateToProps = state => ({
url: state.getIn(['modal', 'url']),
@ -17,30 +17,11 @@ const mapDispatchToProps = dispatch => ({
}
});
const styles = {
overlayStyles: {
},
dialogStyles: {
width: '600px',
color: '#282c37',
fontSize: '16px',
lineHeight: '37px',
marginTop: '-300px',
left: '0',
right: '0',
marginLeft: 'auto',
marginRight: 'auto',
height: 'auto'
},
imageStyle: {
display: 'block',
maxWidth: '100%',
height: 'auto',
margin: '0 auto'
}
const imageStyle = {
display: 'block',
maxWidth: '100%',
height: 'auto',
margin: '0 auto'
};
const Modal = React.createClass({
@ -56,9 +37,9 @@ const Modal = React.createClass({
const { url, ...other } = this.props;
return (
<SkyLightStateless {...other} dialogStyles={styles.dialogStyles} overlayStyles={styles.overlayStyles}>
<img src={url} style={styles.imageStyle} />
</SkyLightStateless>
<Lightbox {...other}>
<img src={url} style={imageStyle} />
</Lightbox>
);
}