mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-10 10:00:00 +01:00
36 lines
871 B
React
36 lines
871 B
React
|
import React from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import Collapse from 'react-collapse'
|
||
|
import lodash from 'lodash'
|
||
|
|
||
|
|
||
|
// Wait 3 seconds so when a use 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>
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|