-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
569 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,66 @@ | ||
--- | ||
title: Spinner | ||
description: Renders a loading indicator. | ||
component: true | ||
--- | ||
|
||
<ComponentPreview name="spinner-demo" /> | ||
|
||
## About | ||
|
||
The Spinner is built and maintained by [flixlix](https://luca-felix.com). | ||
|
||
## Installation | ||
|
||
<Tabs defaultValue="cli"> | ||
|
||
<TabsList> | ||
<TabsTrigger value="cli">CLI</TabsTrigger> | ||
<TabsTrigger value="manual">Manual</TabsTrigger> | ||
</TabsList> | ||
<TabsContent value="cli"> | ||
|
||
<Steps> | ||
|
||
<Step>Run the following command:</Step> | ||
|
||
```bash | ||
npx shadcn-ui@latest add spinner | ||
``` | ||
|
||
<Step>Add the `spinner` animation to your tailwind config</Step> | ||
```js title="tailwind.config.js" {9-12, 16} | ||
/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
... | ||
theme: { | ||
extend: { | ||
... | ||
keyframes: { | ||
... | ||
"spinner": { | ||
"0%": { opacity: 1 }, | ||
"to": { opacity: .15 } | ||
} | ||
}, | ||
animation: { | ||
... | ||
"spinner": "spinner 1.2s linear infinite" | ||
}, | ||
}, | ||
}, | ||
... | ||
} | ||
``` | ||
|
||
</Steps> | ||
|
||
</TabsContent> | ||
|
||
</Tabs> | ||
|
||
## Examples | ||
|
||
### custom size | ||
|
||
<ComponentPreview name="spinner-size" /> |
This file contains 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
This file contains 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,13 @@ | ||
{ | ||
"name": "spinner", | ||
"dependencies": [ | ||
"spinner" | ||
], | ||
"files": [ | ||
{ | ||
"name": "spinner.tsx", | ||
"content": "import React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst Spinner = React.forwardRef<\n HTMLDivElement,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ className, ...props }, ref) => {\n const computeDelay = (i: number) => `${-1.2 + i * 0.1}s`\n const computeRotation = (i: number) => `${i * 30}deg`\n return (\n <div\n className={cn(\"size-5\", className)}\n role=\"status\"\n aria-label=\"Loading\"\n ref={ref}\n {...props}\n >\n <div className=\"relative left-1/2 top-1/2 size-full\">\n {[...Array(12)].map((_, i) => (\n <div\n key={i}\n className=\"absolute left-[-10%] top-[-3.9%] h-[8%] w-[24%] animate-spinner rounded-full bg-foreground\"\n style={{\n animationDelay: computeDelay(i),\n transform: `rotate(${computeRotation(i)}) translate(146%)`,\n }}\n />\n ))}\n </div>\n </div>\n )\n})\nSpinner.displayName = \"Spinner\"\n\nexport { Spinner }\n" | ||
} | ||
], | ||
"type": "components:ui" | ||
} |
This file contains 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,13 @@ | ||
{ | ||
"name": "spinner", | ||
"dependencies": [ | ||
"spinner" | ||
], | ||
"files": [ | ||
{ | ||
"name": "spinner.tsx", | ||
"content": "import React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst Spinner = React.forwardRef<\n HTMLDivElement,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ className, ...props }, ref) => {\n const computeDelay = (i: number) => `${-1.2 + i * 0.1}s`\n const computeRotation = (i: number) => `${i * 30}deg`\n return (\n <div\n className={cn(\"size-5\", className)}\n role=\"status\"\n aria-label=\"Loading\"\n ref={ref}\n {...props}\n >\n <div className=\"relative left-1/2 top-1/2 size-full\">\n {[...Array(12)].map((_, i) => (\n <div\n key={i}\n className=\"absolute left-[-10%] top-[-3.9%] h-[8%] w-[24%] animate-spinner bg-foreground\"\n style={{\n animationDelay: computeDelay(i),\n transform: `rotate(${computeRotation(i)}) translate(146%)`,\n }}\n />\n ))}\n </div>\n </div>\n )\n})\nSpinner.displayName = \"Spinner\"\n\nexport { Spinner }\n" | ||
} | ||
], | ||
"type": "components:ui" | ||
} |
This file contains 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,5 @@ | ||
import { Spinner } from "@/registry/default/ui/spinner" | ||
|
||
export default function SpinnerDemo() { | ||
return <Spinner /> | ||
} |
This file contains 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,5 @@ | ||
import { Spinner } from "@/registry/default/ui/spinner" | ||
|
||
export default function SpinnerSize() { | ||
return <Spinner className="size-8" /> | ||
} |
This file contains 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,36 @@ | ||
import React from "react" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Spinner = React.forwardRef< | ||
HTMLDivElement, | ||
React.ComponentPropsWithoutRef<"div"> | ||
>(({ className, ...props }, ref) => { | ||
const computeDelay = (i: number) => `${-1.2 + i * 0.1}s` | ||
const computeRotation = (i: number) => `${i * 30}deg` | ||
return ( | ||
<div | ||
className={cn("size-5", className)} | ||
role="status" | ||
aria-label="Loading" | ||
ref={ref} | ||
{...props} | ||
> | ||
<div className="relative left-1/2 top-1/2 size-full"> | ||
{[...Array(12)].map((_, i) => ( | ||
<div | ||
key={i} | ||
className="absolute left-[-10%] top-[-3.9%] h-[8%] w-[24%] animate-spinner rounded-full bg-foreground" | ||
style={{ | ||
animationDelay: computeDelay(i), | ||
transform: `rotate(${computeRotation(i)}) translate(146%)`, | ||
}} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
}) | ||
Spinner.displayName = "Spinner" | ||
|
||
export { Spinner } |
This file contains 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.