Merge pull request #296 from orangemug/feature/prefers-reduced-motion

Added prefers-reduced-motion support
This commit is contained in:
Orange Mug 2018-05-11 15:50:08 +01:00 committed by GitHub
commit c7cf051502
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 3 deletions

View file

@ -65,7 +65,15 @@
"stylelint": {
"extends": "stylelint-config-recommended-scss",
"rules": {
"no-descending-specificity": null
"no-descending-specificity": null,
"media-feature-name-no-unknown": [
true,
{
"ignoreMediaFeatureNames": [
"prefers-reduced-motion"
]
}
]
}
},
"eslintConfig": {

View file

@ -0,0 +1,30 @@
import React from 'react'
import PropTypes from 'prop-types'
import Collapse from 'react-collapse'
import accessibility from '../../libs/accessibility'
export default class CollapseAlt extends React.Component {
static propTypes = {
isActive: PropTypes.bool.isRequired,
children: PropTypes.element.isRequired
}
render() {
if (accessibility.reducedMotionEnabled()) {
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 PropTypes from 'prop-types'
import Collapse from 'react-collapse'
import Collapser from './Collapser'
import Collapse from './Collapse'
export default class LayerEditorGroup extends React.Component {
static propTypes = {
@ -22,7 +23,7 @@ export default class LayerEditorGroup extends React.Component {
<span style={{flexGrow: 1}} />
<Collapser isCollapsed={this.props.isActive} />
</div>
<Collapse isOpened={this.props.isActive}>
<Collapse isActive={this.props.isActive}>
<div className="react-collapse-container">
{this.props.children}
</div>

12
src/libs/accessibility.js Normal file
View file

@ -0,0 +1,12 @@
import lodash from 'lodash'
// Throttle for 3 seconds so when a user enables it they don't have to refresh the page.
const reducedMotionEnabled = lodash.throttle(() => {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches
}, 3000);
export default {
reducedMotionEnabled
}

View file

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

View file

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