Spinner
An indicator that can be used to show a loading state.
Processing payment...
$100.00
import { Item, ItemContent, ItemMedia, ItemTitle } from "~/components/ui/item"
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerDemo() {
return (
<div class="flex w-full max-w-xs flex-col gap-4 [--radius:1rem]">
<Item variant="muted">
<ItemMedia>
<Spinner />
</ItemMedia>
<ItemContent>
<ItemTitle class="line-clamp-1">Processing payment...</ItemTitle>
</ItemContent>
<ItemContent class="flex-none justify-end">
<span class="text-sm tabular-nums">$100.00</span>
</ItemContent>
</Item>
</div>
)
}Installation
Copy and paste the following code into your project.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { type ComponentProps } from "@solidjs/web"
import { cn } from "~/lib/utils"
type SpinnerProps = ComponentProps<"svg">
const Spinner = (props: SpinnerProps) => (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
role="status"
aria-label="Loading"
data-slot="spinner"
{...props}
class={cn("size-4 animate-spin", props.class)}
>
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
</svg>
)
export { Spinner, type SpinnerProps }Update the import paths to match your project setup.
Usage
import { Spinner } from "~/components/ui/spinner"<Spinner />Customization
You can replace the default spinner icon with any other icon by editing the Spinner component.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import type { ComponentProps } from "@solidjs/web"
import { omit } from "solid-js"
import { cn } from "~/lib/utils"
const CustomSpinner = (props: ComponentProps<"svg">) => {
const others = omit(props, "class")
return (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
role="status"
aria-label="Loading"
class={cn("size-4 animate-spin", props.class)}
{...others}
>
<path d="M12 2v4" />
<path d="m16.2 7.8 2.9-2.9" />
<path d="M18 12h4" />
<path d="m16.2 16.2 2.9 2.9" />
<path d="M12 18v4" />
<path d="m4.9 19.1 2.9-2.9" />
<path d="M2 12h4" />
<path d="m4.9 4.9 2.9 2.9" />
</svg>
)
}
export default function SpinnerCustom() {
return (
<div class="flex items-center gap-4">
<CustomSpinner />
</div>
)
}// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { type ComponentProps } from "@solidjs/web"
import { cn } from "~/lib/utils"
const Spinner = (props: ComponentProps<"svg">) => (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
role="status"
aria-label="Loading"
data-slot="spinner"
{...props}
class={cn("size-4 animate-spin", props.class)}
>
<path d="M12 2v4" />
<path d="m16.2 7.8 2.9-2.9" />
<path d="M18 12h4" />
<path d="m16.2 16.2 2.9 2.9" />
<path d="M12 18v4" />
<path d="m4.9 19.1 2.9-2.9" />
<path d="M2 12h4" />
<path d="m4.9 4.9 2.9 2.9" />
</svg>
)
export { Spinner }Size
Use the size-* utility class to change the size of the spinner.
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerSize() {
return (
<div class="flex items-center gap-6">
<Spinner class="size-3" />
<Spinner class="size-4" />
<Spinner class="size-6" />
<Spinner class="size-8" />
</div>
)
}Button
Add a spinner to a button to indicate a loading state. Place the <Spinner /> before the label with data-icon="inline-start" for a start position, or after the label with data-icon="inline-end" for an end position.
import { Button } from "~/components/ui/button"
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerButton() {
return (
<div class="flex flex-col items-center gap-4">
<Button disabled size="sm">
<Spinner data-icon="inline-start" />
Loading...
</Button>
<Button disabled size="sm" variant="outline">
<Spinner data-icon="inline-start" />
Please wait
</Button>
<Button disabled size="sm" variant="secondary">
<Spinner data-icon="inline-start" />
Processing
</Button>
</div>
)
}Badge
Add a spinner to a badge to indicate a loading state. Place the <Spinner /> before the label with data-icon="inline-start" for a start position, or after the label with data-icon="inline-end" for an end position.
SyncingUpdatingLoading
import { Badge } from "~/components/ui/badge"
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerBadge() {
return (
<div class="flex items-center gap-2">
<Badge>
<Spinner />
Syncing
</Badge>
<Badge variant="secondary">
<Spinner />
Updating
</Badge>
<Badge variant="outline">
<Spinner />
Loading
</Badge>
</div>
)
}Input Group
Validating...
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupInput,
InputGroupTextarea
} from "~/components/ui/input-group"
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerInputGroup() {
return (
<div class="flex w-full max-w-md flex-col gap-4">
<InputGroup>
<InputGroupInput disabled placeholder="Send a message..." />
<InputGroupAddon align="inline-end">
<Spinner />
</InputGroupAddon>
</InputGroup>
<InputGroup>
<InputGroupTextarea disabled placeholder="Send a message..." />
<InputGroupAddon align="block-end">
<Spinner />
Validating...
<InputGroupButton class="ml-auto" variant="default">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="size-4"
>
<path d="m5 12 7-7 7 7" />
<path d="M12 19V5" />
</svg>
<span class="sr-only">Send</span>
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</div>
)
}Empty
Processing your request
Please wait while we process your request. Do not refresh the page.
import { Button } from "~/components/ui/button"
import {
Empty,
EmptyContent,
EmptyDescription,
EmptyHeader,
EmptyMedia,
EmptyTitle
} from "~/components/ui/empty"
import { Spinner } from "~/components/ui/spinner"
export default function SpinnerEmpty() {
return (
<Empty class="w-full border md:p-6">
<EmptyHeader>
<EmptyMedia variant="icon">
<Spinner />
</EmptyMedia>
<EmptyTitle>Processing your request</EmptyTitle>
<EmptyDescription>
Please wait while we process your request. Do not refresh the page.
</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Button size="sm" variant="outline">
Cancel
</Button>
</EmptyContent>
</Empty>
)
}