2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-08-17 15:59:29 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2021-01-08 00:15:53 -05:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-24 23:08:43 -04:00
|
|
|
|
2020-08-17 17:06:22 -05:00
|
|
|
class Responsive extends React.PureComponent {
|
2020-03-24 23:08:43 -04:00
|
|
|
|
|
|
|
shouldRender = (min, max, width) => {
|
|
|
|
return width > min && width < max
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-01-08 00:15:53 -05:00
|
|
|
const { children, min, max, width } = this.props
|
2020-03-24 23:08:43 -04:00
|
|
|
|
|
|
|
const shouldRender = this.shouldRender(min, max, width)
|
|
|
|
|
|
|
|
return shouldRender ? children : null
|
|
|
|
}
|
2020-05-06 00:33:54 -04:00
|
|
|
|
2020-08-17 17:06:22 -05:00
|
|
|
}
|
|
|
|
|
2021-01-08 00:15:53 -05:00
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
width: state.getIn(['settings', 'window_dimensions', 'width']),
|
|
|
|
})
|
|
|
|
|
2020-08-17 17:06:22 -05:00
|
|
|
Responsive.propTypes = {
|
|
|
|
min: PropTypes.number,
|
|
|
|
max: PropTypes.number,
|
|
|
|
}
|
|
|
|
|
|
|
|
Responsive.defaultProps = {
|
|
|
|
min: 0,
|
|
|
|
max: Infinity,
|
|
|
|
}
|
|
|
|
|
2021-01-08 00:15:53 -05:00
|
|
|
export default connect(mapStateToProps)(Responsive)
|