You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.3 KiB
101 lines
2.3 KiB
7 years ago
|
const Component = require('react').Component
|
||
|
const h = require('react-hyperscript')
|
||
|
const inherits = require('util').inherits
|
||
|
const connect = require('react-redux').connect
|
||
|
const FadeModal = require('boron').FadeModal
|
||
7 years ago
|
const actions = require('../../actions')
|
||
|
const isMobileView = require('../../../lib/is-mobile-view')
|
||
|
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification')
|
||
7 years ago
|
|
||
|
function mapStateToProps (state) {
|
||
|
return {
|
||
|
active: state.appState.modalOpen
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function mapDispatchToProps (dispatch) {
|
||
|
return {
|
||
|
hideModal: () => {
|
||
|
dispatch(actions.hideModal())
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
// Global Modal Component
|
||
7 years ago
|
inherits(Modal, Component)
|
||
|
function Modal () {
|
||
|
Component.call(this)
|
||
|
}
|
||
|
|
||
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(Modal)
|
||
|
|
||
7 years ago
|
const mobileModalStyles = {
|
||
|
width: '95%',
|
||
7 years ago
|
// Used to create matching t/l/r/b space in mobile view.
|
||
7 years ago
|
top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
|
||
7 years ago
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
const laptopModalStyles = {
|
||
|
width: '66%',
|
||
7 years ago
|
top: 'calc(30% + 10px)',
|
||
7 years ago
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
||
|
}
|
||
|
|
||
|
const backdropStyles = {
|
||
|
backgroundColor: 'rgba(245, 245, 245, 0.85)',
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
Modal.prototype.render = function () {
|
||
7 years ago
|
|
||
7 years ago
|
return h(FadeModal,
|
||
|
{
|
||
7 years ago
|
className: 'modal',
|
||
7 years ago
|
keyboard: false,
|
||
|
onHide: () => {this.onHide()},
|
||
|
ref: (ref) => {
|
||
|
this.modalRef = ref
|
||
|
},
|
||
7 years ago
|
modalStyle: isMobileView() ? mobileModalStyles : laptopModalStyles,
|
||
7 years ago
|
backdropStyle: backdropStyles,
|
||
7 years ago
|
},
|
||
|
this.props.children,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
Modal.prototype.componentWillReceiveProps = function(nextProps) {
|
||
|
if (nextProps.active) {
|
||
|
this.show()
|
||
|
} else if (this.props.active) {
|
||
|
this.hide()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Modal.prototype.onHide = function() {
|
||
|
if (this.props.onHideCallback) {
|
||
|
this.props.onHideCallback()
|
||
|
}
|
||
|
this.props.hideModal()
|
||
|
}
|
||
|
|
||
|
Modal.prototype.hide = function() {
|
||
|
this.modalRef.hide()
|
||
|
}
|
||
|
|
||
|
Modal.prototype.show = function() {
|
||
|
this.modalRef.show()
|
||
|
}
|
||
|
|
||
7 years ago
|
// TODO: specify default props and proptypes
|
||
7 years ago
|
// Modal.defaultProps = {}
|
||
|
|
||
7 years ago
|
// const elementType = require('react-prop-types/lib/elementType')
|
||
|
// const PropTypes from 'prop-types'
|
||
|
|
||
7 years ago
|
// Modal.propTypes = {
|
||
|
// active: PropTypes.bool,
|
||
|
// hideModal: PropTypes.func.isRequired,
|
||
|
// component: elementType,
|
||
|
// onHideCallback: PropTypes.func,
|
||
|
// }
|