Skip to content

Commit

Permalink
feat(a11y): respect reduced motion preference
Browse files Browse the repository at this point in the history
Relates to #31
  • Loading branch information
rbardini committed Apr 1, 2022
1 parent e83bdee commit d1a835b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { PaddingWithDefault, PaddingsParameter, Padding } from './types';
export const isEnabled = (values: PaddingWithDefault[]): boolean =>
values.length > 0;

export const isReducedMotionPreferred = (): boolean =>
window.matchMedia('(prefers-reduced-motion: reduce)').matches;

export const normalizeValues = (
parameters: PaddingsParameter,
): PaddingWithDefault[] => {
Expand Down
8 changes: 6 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { StoryWrapper, useEffect, useMemo } from '@storybook/addons';

import { DEFAULT_PADDING, PARAM_KEY } from './constants';
import { normalizeValues, getSelectedPadding } from './helpers';
import {
isReducedMotionPreferred,
getSelectedPadding,
normalizeValues,
} from './helpers';

const setStyle = (selector: string, css: string) => {
const existingStyle = document.getElementById(selector);
Expand Down Expand Up @@ -42,7 +46,7 @@ const WithPaddings: StoryWrapper = (getStory, context) => {
${selector} {
margin: 0;
padding: ${selectedPadding} !important;
transition: padding .3s;
${isReducedMotionPreferred() ? '' : 'transition: padding .3s;'}
}
${selector} .innerZoomElementWrapper > div {
Expand Down

0 comments on commit d1a835b

Please sign in to comment.