gab-social/app/javascript/gabsocial/features/ui/util/responsive_component.js

35 lines
704 B
JavaScript
Raw Normal View History

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