mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Create handleReduceMotion
util function to manage animations (#85785)
This commit is contained in:
parent
02096c4e22
commit
00be24d6b3
16
packages/grafana-ui/src/utils/handleReducedMotion.ts
Normal file
16
packages/grafana-ui/src/utils/handleReducedMotion.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { CSSInterpolation } from '@emotion/css';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param styles - Styles to apply when no `prefers-reduced-motion` preference is set.
|
||||||
|
* @param reducedMotionStyles - Styles to apply when `prefers-reduced-motion` is enabled.
|
||||||
|
* Applies one of `styles` or `reducedMotionStyles` depending on a users `prefers-reduced-motion` setting. Omitting `reducedMotionStyles` entirely will result in no styles being applied when `prefers-reduced-motion` is enabled. In most cases this is a reasonable default.
|
||||||
|
*/
|
||||||
|
export const handleReducedMotion = (styles: CSSInterpolation, reducedMotionStyles?: CSSInterpolation) => {
|
||||||
|
const result: Record<string, CSSInterpolation> = {
|
||||||
|
'@media (prefers-reduced-motion: no-preference)': styles,
|
||||||
|
};
|
||||||
|
if (reducedMotionStyles) {
|
||||||
|
result['@media (prefers-reduced-motion: reduce)'] = reducedMotionStyles;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
@ -19,5 +19,6 @@ export { createLogger } from './logger';
|
|||||||
export { attachDebugger } from './debug';
|
export { attachDebugger } from './debug';
|
||||||
export * from './nodeGraph';
|
export * from './nodeGraph';
|
||||||
export { fuzzyMatch } from './fuzzy';
|
export { fuzzyMatch } from './fuzzy';
|
||||||
|
export { handleReducedMotion } from './handleReducedMotion';
|
||||||
|
|
||||||
export { ReactUtils };
|
export { ReactUtils };
|
||||||
|
Loading…
Reference in New Issue
Block a user