-
animation trajectory
-
-
-
+
+
+ {useAnimatedComponents && (
+ <>
+ animation trajectory
+
+
+
+
+ >
+ )}
-
+ {useAnimatedComponents && (
+
+ )}
>
)}
>
diff --git a/packages/visx-demo/src/sandboxes/visx-pattern/Example.tsx b/packages/visx-demo/src/sandboxes/visx-pattern/Example.tsx
index 644ef17e3..ace500aaa 100644
--- a/packages/visx-demo/src/sandboxes/visx-pattern/Example.tsx
+++ b/packages/visx-demo/src/sandboxes/visx-pattern/Example.tsx
@@ -21,19 +21,21 @@ export type PatternProps = {
margin?: typeof defaultMargin;
};
-const Patterns: React.FC<{ id: string }>[] = [
+const Patterns: React.FC<{ id: string; prefersReducedMotion?: boolean }>[] = [
({ id }) =>
,
- ({ id }) => (
+ ({ id, prefersReducedMotion }) => (
-
+ {!prefersReducedMotion && (
+
+ )}
),
@@ -78,21 +80,23 @@ const Patterns: React.FC<{ id: string }>[] = [
/>
),
({ id }) =>
,
- ({ id }) => {
+ ({ id, prefersReducedMotion }) => {
const width = 10;
const height = 10;
return (
-
+ {!prefersReducedMotion && (
+
+ )}
[] = [
];
export default function Example({ width, height, margin = defaultMargin }: PatternProps) {
+ // use non-animated components if prefers-reduced-motion is set
+ const prefersReducedMotionQuery = window?.matchMedia('(prefers-reduced-motion: reduce)');
+ const prefersReducedMotion = !prefersReducedMotionQuery || !!prefersReducedMotionQuery.matches;
+
const numColumns = 3;
const numRows = Patterns.length / numColumns;
const columnWidth = Math.max((width - margin.left - margin.right) / numColumns, 0);
@@ -132,7 +140,7 @@ export default function Example({ width, height, margin = defaultMargin }: Patte
return (
{/** Like SVG , Patterns are rendered with an id */}
-
+
{/** And are then referenced for a style attribute. */}
(
-
{renderBarStack && (
-
-
+
-
-
-
+
)}
{renderBarGroup && (
-
-
+
-
-
-
+
)}
{renderBarSeries && (
-
-
-
-
)}
{renderAreaStack && (
-
-
+
-
-
-
-
-
+
)}
{renderLineSeries && (
<>
-
{!renderBarSeries && (
-
)}
-
)}
{renderGlyphSeries && (
-
)}
-
- '' : undefined}
/>
{annotationDataKey && annotationDatum && (
-
-
+
)}
{showTooltip && (
diff --git a/packages/visx-demo/src/sandboxes/visx-xychart/ExampleControls.tsx b/packages/visx-demo/src/sandboxes/visx-xychart/ExampleControls.tsx
index 1c8505793..a37e6c258 100644
--- a/packages/visx-demo/src/sandboxes/visx-xychart/ExampleControls.tsx
+++ b/packages/visx-demo/src/sandboxes/visx-xychart/ExampleControls.tsx
@@ -9,6 +9,8 @@ import cityTemperature, { CityTemperature } from '@visx/mock-data/lib/mocks/city
import { GlyphCross, GlyphDot, GlyphStar } from '@visx/glyph';
import { curveLinear, curveStep, curveCardinal } from '@visx/curve';
import customTheme from './customTheme';
+import userPrefersReducedMotion from './userPrefersReducedMotion';
+import getAnimatedOrUnanimatedComponents from './getAnimatedOrUnanimatedComponents';
const dateScaleConfig = { type: 'band', paddingInner: 0.3 } as const;
const temperatureScaleConfig = { type: 'linear' } as const;
@@ -47,7 +49,7 @@ type ProvidedProps = {
y: Accessors;
date: Accessor;
};
- animationTrajectory: AnimationTrajectory;
+ animationTrajectory?: AnimationTrajectory;
annotationDataKey: DataKey | null;
annotationDatum?: CityTemperature;
annotationLabelPosition: { dx: number; dy: number };
@@ -85,15 +87,18 @@ type ProvidedProps = {
theme: XYChartTheme;
xAxisOrientation: 'top' | 'bottom';
yAxisOrientation: 'left' | 'right';
-};
+} & ReturnType;
type ControlsProps = {
children: (props: ProvidedProps) => React.ReactNode;
};
export default function ExampleControls({ children }: ControlsProps) {
+ const [useAnimatedComponents, setUseAnimatedComponents] = useState(!userPrefersReducedMotion());
const [theme, setTheme] = useState(darkTheme);
- const [animationTrajectory, setAnimationTrajectory] = useState('center');
+ const [animationTrajectory, setAnimationTrajectory] = useState(
+ 'center',
+ );
const [gridProps, setGridProps] = useState<[boolean, boolean]>([false, false]);
const [showGridRows, showGridColumns] = gridProps;
const [xAxisOrientation, setXAxisOrientation] = useState<'top' | 'bottom'>('bottom');
@@ -240,6 +245,7 @@ export default function ExampleControls({ children }: ControlsProps) {
theme,
xAxisOrientation,
yAxisOrientation,
+ ...getAnimatedOrUnanimatedComponents(useAnimatedComponents),
})}
{/** This style is used for annotated elements via colorAccessor. */}
{/** animation trajectory */}