maputnik/src/components/layers/CollapseReducedMotion.jsx

36 lines
872 B
React
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import Collapse from 'react-collapse'
import lodash from 'lodash'
2018-05-10 17:07:34 +02:00
// Wait 3 seconds so when a user enables it they don't have to refresh the page.
const isReduceMotionEnabled = lodash.throttle(() => {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches
}, 3000);
export default class CollapseReducedMotion extends React.Component {
static propTypes = {
isActive: PropTypes.bool.isRequired,
children: PropTypes.element.isRequired
}
render() {
if (isReduceMotionEnabled()) {
return (
<div style={{display: this.props.isActive ? "block" : "none"}}>
{this.props.children}
</div>
)
}
else {
return (
<Collapse isOpened={this.props.isActive}>
{this.props.children}
</Collapse>
)
}
}
}