- Notifications
You must be signed in to change notification settings - Fork914
chore: add spinner component#16014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
07f6e53
Deprecate Spinner
BrunoQuaresma2fc5748
chore: add Spinner component
BrunoQuaresma5353da2
Avoid animation on Chromatic
BrunoQuaresma962c0dd
Fix lint error
BrunoQuaresma7d97bc3
Fix chromatic import
BrunoQuaresma9561e20
Run make fmt
BrunoQuaresmaa901ab6
Make Spinner to looks more closer to the design
BrunoQuaresma07c8a7f
Merge branch 'bq/add-spinner-component' of https://github.com/coder/c…
BrunoQuaresmac8466e0
Improve loading animation
BrunoQuaresmaa36e017
Merge branch 'bq/add-spinner-component' of https://github.com/coder/c…
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletionsite/src/components/Loader/Loader.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletionssite/src/components/Spinner/Spinner.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { PlusIcon } from "lucide-react"; | ||
import { Spinner } from "./Spinner"; | ||
const meta: Meta<typeof Spinner> = { | ||
title: "components/Spinner", | ||
component: Spinner, | ||
args: { | ||
children: <PlusIcon className="size-icon-lg" />, | ||
}, | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof Spinner>; | ||
export const Idle: Story = {}; | ||
export const Loading: Story = { | ||
args: { loading: true }, | ||
}; |
93 changes: 74 additions & 19 deletionssite/src/components/Spinner/Spinner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,77 @@ | ||
/** | ||
*This componentwas inspired by | ||
*https://www.radix-ui.com/themes/docs/components/spinner and developed using | ||
*https://v0.dev/ help. | ||
*/ | ||
import isChromatic from "chromatic/isChromatic"; | ||
import { type VariantProps, cva } from "class-variance-authority"; | ||
import type { ReactNode } from "react"; | ||
import { cn } from "utils/cn"; | ||
const leaves = 8; | ||
const spinnerVariants = cva("", { | ||
variants: { | ||
size: { | ||
lg: "size-icon-lg", | ||
sm: "size-icon-sm", | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "lg", | ||
}, | ||
}); | ||
type SpinnerProps = React.SVGProps<SVGSVGElement> & | ||
VariantProps<typeof spinnerVariants> & { | ||
children?: ReactNode; | ||
loading?: boolean; | ||
}; | ||
export function Spinner({ | ||
className, | ||
size, | ||
loading, | ||
children, | ||
...props | ||
}: SpinnerProps) { | ||
if (!loading) { | ||
return children; | ||
} | ||
return ( | ||
<svg | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
className={cn(spinnerVariants({ size, className }))} | ||
{...props} | ||
> | ||
<title>Loading spinner</title> | ||
{[...Array(leaves)].map((_, i) => { | ||
const rotation = i * (360 / leaves); | ||
return ( | ||
<rect | ||
key={i} | ||
x="10.9" | ||
y="2" | ||
width="2" | ||
height="5.5" | ||
rx="1" | ||
// 0.8 = leaves * 0.1 | ||
className={ | ||
isChromatic() ? "" : "animate-[loading_0.8s_ease-in-out_infinite]" | ||
} | ||
style={{ | ||
transform: `rotate(${rotation}deg)`, | ||
transformOrigin: "center", | ||
animationDelay: `${-i * 0.1}s`, | ||
}} | ||
/> | ||
); | ||
})} | ||
</svg> | ||
); | ||
} |
24 changes: 24 additions & 0 deletionssite/src/components/deprecated/Spinner/Spinner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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. | ||
* | ||
* @deprecated prefer `components.Spinner` | ||
*/ | ||
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; | ||
} | ||
return <CircularProgress {...props} />; | ||
}; |
9 changes: 9 additions & 0 deletionssite/tailwind.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.