Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Interpolation, Theme } from "@emotion/react";
import CircularProgress from "@mui/material/CircularProgress";
import { Spinner } from "components/Spinner/Spinner";
import type { FC, HTMLAttributes } from "react";

interface LoaderProps extends HTMLAttributes<HTMLDivElement> {
Expand All @@ -18,7 +18,7 @@ export const Loader: FC<LoaderProps> = ({
data-testid="loader"
{...attrs}
>
<CircularProgress size={size} />
<Spinner aria-label="Loading..." size={size} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misunderstanding but it seems we have a Loader component wrapping a Spinner component wrapping a CircularProgress component. Is there a reason to have 3 levels nesting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The purpose of the 'Loader' is to act as a container that centrally positions the loading spinner on the page or within a section, with some padding around it. Meanwhile, the 'Spinner' can be utilized in other components, such as loading buttons. Perhaps 'Loader' is not the most suitable name, but I can't think of anything better at the moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, makes sense! Loader works for me :)

</div>
);
};
Expand Down
22 changes: 22 additions & 0 deletions site/src/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import CircularProgress, {
type CircularProgressProps,
} from "@mui/material/CircularProgress";
import isChromatic from "chromatic/isChromatic";
import type { FC } from "react";

/**
* Spinner component used to indicate loading states. This component abstracts
* the MUI CircularProgress to provide better control over its rendering,
* especially in snapshot tests with Chromatic.
*/
export const Spinner: FC<CircularProgressProps> = (props) => {
/**
* During Chromatic snapshots, we render the spinner as determinate to make it
* static without animations, using a deterministic value (75%).
*/
if (isChromatic()) {
props.variant = "determinate";
props.value = 75;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
return <CircularProgress {...props} />;
};
Loading