♻️(react) disable animation when Chromatic is running

We need to disable Javascript animation when Chromatic is taking
snapshots in order to avoid having changes detected each time a build
is ran.
This commit is contained in:
Nathan Vasse
2024-03-18 16:33:09 +01:00
committed by NathanVss
parent 9c614953b8
commit 06fca5b34e
2 changed files with 6 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import React, { PropsWithChildren, useContext, useMemo, useRef } from "react";
import isChromatic from "chromatic/isChromatic";
import { Toast, ToastProps } from ":/components/Toast/index";
import { tokens } from ":/cunningham-tokens";
import { Queue } from ":/utils/Queue";
@@ -100,7 +101,7 @@ export const ToastProvider = ({ children }: PropsWithChildren) => {
// PLAY
// We need to check if the animate function exists because it's not available in some testing environments ( like jest-dom )
if (typeof container.current.animate === "function") {
if (typeof container.current.animate === "function" && !isChromatic()) {
container.current.animate(
[
{ transform: `translateY(${invert}px)` },

View File

@@ -6,6 +6,7 @@ import React, {
useRef,
} from "react";
import classNames from "classnames";
import isChromatic from "chromatic/isChromatic";
import { Button, ButtonProps } from ":/components/Button";
import { iconFromType, VariantType } from ":/utils/VariantUtils";
@@ -105,6 +106,9 @@ export const ProgressBar = ({ duration }: { duration: number }) => {
const content = useRef<HTMLDivElement>(null);
useEffect(() => {
if (isChromatic()) {
return;
}
content.current!.animate([{ width: "0%" }, { width: "100%" }], {
duration,
easing: "linear",