mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-10 07:47:46 +01:00
Merge pull request #296 from orangemug/feature/prefers-reduced-motion
Added prefers-reduced-motion support
This commit is contained in:
commit
c7cf051502
6 changed files with 62 additions and 3 deletions
10
package.json
10
package.json
|
@ -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": {
|
||||
|
|
30
src/components/layers/Collapse.jsx
Normal file
30
src/components/layers/Collapse.jsx
Normal 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>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
12
src/libs/accessibility.js
Normal 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
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue