mirror of
https://github.com/maputnik/editor.git
synced 2026-07-28 16:57:26 +00:00
Move accessibility checks into module.
This commit is contained in:
@@ -1,14 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import Collapse from 'react-collapse'
|
import Collapse from 'react-collapse'
|
||||||
import lodash from 'lodash'
|
import accessibility from '../../libs/accessibility'
|
||||||
|
|
||||||
|
|
||||||
// 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 {
|
export default class CollapseReducedMotion extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
isActive: PropTypes.bool.isRequired,
|
isActive: PropTypes.bool.isRequired,
|
||||||
@@ -16,7 +11,7 @@ export default class CollapseReducedMotion extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (isReduceMotionEnabled()) {
|
if (accessibility.reducedMotionEnabled()) {
|
||||||
return (
|
return (
|
||||||
<div style={{display: this.props.isActive ? "block" : "none"}}>
|
<div style={{display: this.props.isActive ? "block" : "none"}}>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user