Spinner for Astro
Astro activity indicators for pending controls and page regions.
Installation
bunx --bun shadcn@latest add @gnostic/spinnernpx shadcn@latest add @gnostic/spinnerpnpm dlx shadcn@latest add @gnostic/spinnerComplete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/spinner/index.ts
export { default as Spinner } from "./spinner.astro"
src/components/ui/spinner/spinner.astro
---
import type { HTMLAttributes } from "astro/types"
import LoaderCircle from "@lucide/astro/icons/loader-circle"
import { cn } from "cn"
type Props = HTMLAttributes<"svg"> & {
color?: string
size?: number | string
"stroke-width"?: number | string
absoluteStrokeWidth?: boolean
title?: string
}
const { class: className, ...props } = Astro.props
---
<LoaderCircle
data-slot="spinner"
role="status"
aria-label="Loading"
class={cn("size-4 animate-spin", className)}
{...props}
/>
Usage
import { Spinner } from "@/components/ui/spinner"
<Spinner />
Notes
Spinnerworks well as a standalone loading indicator or inline inside aButton.- When it is purely decorative next to visible loading text, the button text can carry the main status message.
Example
<div class="flex items-center gap-2 text-sm">
<Spinner />
<span>Loading results...</span>
</div>
API Reference
Read the installed source for the complete prop types.
When to use Spinner
Use Spinner beside a short loading message or inside a button with a pending action. Choose a size that fits the nearby text. Keep the action label understandable while work is in progress.
Keyboard and behavior
The animation does not start a request or announce a result. Give the surrounding region a suitable status message, and avoid announcing a decorative spinner twice.
Theme and layout
The icon follows text color, so check contrast inside primary and outline buttons. Provide a static text indication for reduced motion and for tasks that fail or take a long time.