♻️(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:
@@ -1,4 +1,5 @@
|
|||||||
import React, { PropsWithChildren, useContext, useMemo, useRef } from "react";
|
import React, { PropsWithChildren, useContext, useMemo, useRef } from "react";
|
||||||
|
import isChromatic from "chromatic/isChromatic";
|
||||||
import { Toast, ToastProps } from ":/components/Toast/index";
|
import { Toast, ToastProps } from ":/components/Toast/index";
|
||||||
import { tokens } from ":/cunningham-tokens";
|
import { tokens } from ":/cunningham-tokens";
|
||||||
import { Queue } from ":/utils/Queue";
|
import { Queue } from ":/utils/Queue";
|
||||||
@@ -100,7 +101,7 @@ export const ToastProvider = ({ children }: PropsWithChildren) => {
|
|||||||
|
|
||||||
// PLAY
|
// PLAY
|
||||||
// We need to check if the animate function exists because it's not available in some testing environments ( like jest-dom )
|
// 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(
|
container.current.animate(
|
||||||
[
|
[
|
||||||
{ transform: `translateY(${invert}px)` },
|
{ transform: `translateY(${invert}px)` },
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
} from "react";
|
} from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import isChromatic from "chromatic/isChromatic";
|
||||||
import { Button, ButtonProps } from ":/components/Button";
|
import { Button, ButtonProps } from ":/components/Button";
|
||||||
import { iconFromType, VariantType } from ":/utils/VariantUtils";
|
import { iconFromType, VariantType } from ":/utils/VariantUtils";
|
||||||
|
|
||||||
@@ -105,6 +106,9 @@ export const ProgressBar = ({ duration }: { duration: number }) => {
|
|||||||
const content = useRef<HTMLDivElement>(null);
|
const content = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isChromatic()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
content.current!.animate([{ width: "0%" }, { width: "100%" }], {
|
content.current!.animate([{ width: "0%" }, { width: "100%" }], {
|
||||||
duration,
|
duration,
|
||||||
easing: "linear",
|
easing: "linear",
|
||||||
|
|||||||
Reference in New Issue
Block a user