parent
f8f40f15da
commit
de50eff6ac
@ -0,0 +1,15 @@ |
|||||||
|
export const MEDIA_OPEN = 'MEDIA_OPEN'; |
||||||
|
export const MODAL_CLOSE = 'MODAL_CLOSE'; |
||||||
|
|
||||||
|
export function openMedia(url) { |
||||||
|
return { |
||||||
|
type: MEDIA_OPEN, |
||||||
|
url: url |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export function closeModal() { |
||||||
|
return { |
||||||
|
type: MODAL_CLOSE |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,67 @@ |
|||||||
|
import { connect } from 'react-redux'; |
||||||
|
import { SkyLightStateless } from 'react-skylight'; |
||||||
|
import { closeModal } from '../../../actions/modal'; |
||||||
|
|
||||||
|
const mapStateToProps = state => ({ |
||||||
|
url: state.getIn(['modal', 'url']), |
||||||
|
isVisible: state.getIn(['modal', 'open']) |
||||||
|
}); |
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => ({ |
||||||
|
onCloseClicked () { |
||||||
|
dispatch(closeModal()); |
||||||
|
}, |
||||||
|
|
||||||
|
onOverlayClicked () { |
||||||
|
dispatch(closeModal()); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
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 Modal = React.createClass({ |
||||||
|
|
||||||
|
propTypes: { |
||||||
|
url: React.PropTypes.string, |
||||||
|
isVisible: React.PropTypes.bool, |
||||||
|
onCloseClicked: React.PropTypes.func, |
||||||
|
onOverlayClicked: React.PropTypes.func |
||||||
|
}, |
||||||
|
|
||||||
|
render () { |
||||||
|
const { url, ...other } = this.props; |
||||||
|
|
||||||
|
return ( |
||||||
|
<SkyLightStateless {...other} dialogStyles={styles.dialogStyles} overlayStyles={styles.overlayStyles}> |
||||||
|
<img src={url} style={styles.imageStyle} /> |
||||||
|
</SkyLightStateless> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(Modal); |
@ -0,0 +1,21 @@ |
|||||||
|
import { MEDIA_OPEN, MODAL_CLOSE } from '../actions/modal'; |
||||||
|
import Immutable from 'immutable'; |
||||||
|
|
||||||
|
const initialState = Immutable.Map({ |
||||||
|
url: '', |
||||||
|
open: false |
||||||
|
}); |
||||||
|
|
||||||
|
export default function modal(state = initialState, action) { |
||||||
|
switch(action.type) { |
||||||
|
case MEDIA_OPEN: |
||||||
|
return state.withMutations(map => { |
||||||
|
map.set('url', action.url); |
||||||
|
map.set('open', true); |
||||||
|
}); |
||||||
|
case MODAL_CLOSE: |
||||||
|
return state.set('open', false); |
||||||
|
default: |
||||||
|
return state; |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue