Files
basecoat/docs/src/components/spinner.mdx
T

136 lines
8.1 KiB
Plaintext
Raw Normal View History

2026-06-17 11:19:31 +08:00
# Spinner
<Callout title="No dedicated component" icon="circle-alert">
There is no dedicated Spinner component in Basecoat.
</Callout>
<Preview class="w-full max-w-xs">
<article class="item bg-muted/50 border-transparent">
<figure><svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg></figure>
<section>
<h3>Processing payment...</h3>
</section>
2026-06-20 13:58:42 +08:00
<aside class="tabular-nums text-sm">$100.00</aside>
2026-06-17 11:19:31 +08:00
</article>
</Preview>
## Usage
Spinners are pure HTML using the `loader-circle` Lucide icon with the `animate-spin` Tailwind utility. Add `role="status"` and `aria-label="Loading"` for accessibility.
```html
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
```
## Examples
### Size
Use the `size-*` utility class to change the size of the spinner.
<Preview>
<div class="flex items-center gap-6">
<svg aria-label="Loading" role="status" class="size-3 animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
<svg aria-label="Loading" role="status" class="size-4 animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
<svg aria-label="Loading" role="status" class="size-6 animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
<svg aria-label="Loading" role="status" class="size-8 animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
</div>
</Preview>
### Button
2026-06-20 13:58:42 +08:00
Add a spinner to a button to indicate a loading state. Place the spinner before or after the label; button spacing is handled automatically.
2026-06-17 11:19:31 +08:00
<Preview>
<div class="flex flex-col items-center gap-4">
2026-06-20 13:58:42 +08:00
<button class="btn" data-size="sm" disabled>
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Loading...
</button>
2026-06-20 13:58:42 +08:00
<button class="btn" data-variant="outline" data-size="sm" disabled>
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Please wait
</button>
2026-06-20 13:58:42 +08:00
<button class="btn" data-variant="secondary" data-size="sm" disabled>
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Processing
</button>
</div>
</Preview>
### Badge
2026-06-20 13:58:42 +08:00
Add a spinner to a badge to indicate a loading state. Place the spinner before or after the label; badge spacing is handled automatically.
2026-06-17 11:19:31 +08:00
<Preview>
<div class="flex items-center gap-4">
<span class="badge">
2026-06-20 13:58:42 +08:00
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Syncing
</span>
2026-06-20 13:58:42 +08:00
<span class="badge">
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Updating
</span>
2026-06-20 13:58:42 +08:00
<span class="badge">
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
2026-06-17 11:19:31 +08:00
Processing
</span>
</div>
</Preview>
2026-06-22 18:19:38 +08:00
### Input group
2026-06-17 11:19:31 +08:00
<Preview class="w-full max-w-md">
<div class="flex w-full max-w-md flex-col gap-4">
<div class="input-group">
2026-06-20 13:58:42 +08:00
<input placeholder="Send a message..." disabled />
2026-06-17 11:19:31 +08:00
<span data-align="inline-end">
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
</span>
</div>
<div class="input-group">
2026-06-20 13:58:42 +08:00
<textarea placeholder="Send a message..." disabled></textarea>
2026-06-17 11:19:31 +08:00
<footer data-align="block-end">
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
Validating...
2026-06-20 13:58:42 +08:00
<button type="button" class="btn ms-auto" data-size="icon-sm">
2026-06-17 11:19:31 +08:00
<svg class="lucide lucide-arrow-up" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
<span class="sr-only">Send</span>
</button>
</footer>
</div>
</div>
</Preview>
### Empty
<Preview class="w-full">
<div class="empty w-full">
<header>
<figure>
<svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
</figure>
<h3>Processing your request</h3>
<p>Please wait while we process your request. Do not refresh the page.</p>
</header>
<section>
2026-06-20 13:58:42 +08:00
<button class="btn" data-variant="outline" data-size="sm">Cancel</button>
2026-06-17 11:19:31 +08:00
</section>
</div>
</Preview>
## RTL
Spinner layout follows document direction. Use logical utilities when surrounding spacing depends on direction.
<Preview class="w-full max-w-xs">
<article class="item bg-muted/50 border-transparent" dir="rtl">
<figure><svg aria-label="Loading" role="status" class="animate-spin lucide lucide-loader-circle" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg></figure>
<section>
<h3>جاري معالجة الدفع...</h3>
</section>
2026-06-20 13:58:42 +08:00
<aside class="tabular-nums text-sm">١٠٠.٠٠ دولار</aside>
2026-06-17 11:19:31 +08:00
</article>
</Preview>