Added 'prefers-reduced-motion' css support.

This commit is contained in:
orangemug 2018-05-10 16:05:55 +01:00
parent 06eac68f9d
commit a41b25eea7
4 changed files with 47 additions and 3 deletions

View file

@ -0,0 +1,35 @@
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>
)
}
}
}

View file

@ -1,7 +1,8 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import Collapse from 'react-collapse'
import Collapser from './Collapser' import Collapser from './Collapser'
import CollapseReducedMotion from './CollapseReducedMotion'
export default class LayerEditorGroup extends React.Component { export default class LayerEditorGroup extends React.Component {
static propTypes = { static propTypes = {
@ -22,11 +23,11 @@ export default class LayerEditorGroup extends React.Component {
<span style={{flexGrow: 1}} /> <span style={{flexGrow: 1}} />
<Collapser isCollapsed={this.props.isActive} /> <Collapser isCollapsed={this.props.isActive} />
</div> </div>
<Collapse isOpened={this.props.isActive}> <CollapseReducedMotion isActive={this.props.isActive}>
<div className="react-collapse-container"> <div className="react-collapse-container">
{this.props.children} {this.props.children}
</div> </div>
</Collapse> </CollapseReducedMotion>
</div> </div>
} }
} }

View file

@ -126,6 +126,10 @@
border-width: 2px; border-width: 2px;
border-color: $color-gray; border-color: $color-gray;
transition: background-color 0.1s ease-out; transition: background-color 0.1s ease-out;
@media screen and (prefers-reduced-motion: reduce) {
transition-duration: 0ms;
}
} }
&-icon { &-icon {

View file

@ -43,6 +43,10 @@
-webkit-transition: opacity 600ms, visibility 600ms; -webkit-transition: opacity 600ms, visibility 600ms;
transition: opacity 600ms, visibility 600ms; transition: opacity 600ms, visibility 600ms;
@media screen and (prefers-reduced-motion: reduce) {
transition-duration: 0;
}
@include flex-row; @include flex-row;
} }