组件

Spinner

A pencil that will not stop scribbling: a hand-wound spiral whose line is drawn and undrawn round and round, in the color of the text around it. Still, and whole, when motion is reduced. Stubby can write instead, in three frames like a flip book.

安装

terminal
npx shadcn@latest add @wobko/spinner

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Sizes and colors

Size it with size-*; the scribble is redrawn for the size (fewer, wider turns when it is small). It draws in whatever text color it sits in. With reduced motion on, every one of these stands still, whole.

In buttons and badges

A spinner in front of a label is shadcn's pattern. The button is disabled while the request runs and says what is happening; press it to see a save go through.

Stubby is writing

For a page or a panel that is loading rather than a button: Stubby writes in three frames, flipped like a flip book, and the words say what they are waiting for. The role=status carries the name. With reduced motion he holds still with the scribble finished.

Demo

Official `spinner-demo`: a muted row that reads "Processing payment..." with a spinner as its media and the amount at the end. The scribble is a hand-wound spiral whose line is drawn and undrawn round and round; with reduced motion it stands still, whole.

Basic

Official `spinner-basic`: the bare `<Spinner />`, 16 px by default. It is `role="status"` with the name "Loading", and it draws in the current text color.

Button

Official `spinner-button`: a spinner as the first child of a disabled small button, in the default, outline and secondary variants. The button dashes itself when disabled, so the wait shows in the outline as well as in the scribble.

Badge

Official `spinner-badge`: Syncing, Updating and Processing badges in the default, secondary and outline variants, each with a spinner in front of the word.

Input group

Official `spinner-input-group`: a disabled field with a spinner at its end, and a disabled textarea whose footer says "Validating..." beside a send button. The group draws itself dashed because its control is disabled. Only change: the controls get an `aria-label`.

Empty

Official `spinner-empty`: an Empty state whose icon slip holds a spinner, with a title, a sentence and a Cancel button. For a whole page or panel that is waiting, `variant="write"` on the Spinner has Stubby writing instead.

Color

Official `spinner-color`: five 24 px spinners, each in its own text color. shadcn uses the palette's red, green, blue, yellow and purple; here they are red felt-tip, green pencil, blue biro, orange marker and grape marker (yellow highlighter is too pale to read as a line on paper).

Custom

Official `spinner-custom`: a spinner is nothing more than a status role around an icon that turns, so you can build one from any glyph. Here the hand-drawn `loader-circle` spins with `animate-spin` (and stops for reduced motion, which Tailwind's utility alone does not do). A drawn icon must stay decorative, so the role and the name sit on a span around it instead of on the icon, as they do on the original's lucide svg.

Size

Official `spinner-size`: `size-3`, `size-4`, `size-6` and `size-8`. The scribble is redrawn for each size (fewer, wider turns when it is small) rather than scaled, so the pencil line keeps its weight.

Item

Official `spinner-item`: an outlined row for a download, with the spinner as icon media, a title and sizes, a Cancel button that appears from the `sm` breakpoint up, and a progress bar in the footer. The bar carries an `aria-label`, which the original lacks.

API 参考

Spinner

A role=status span (shadcn's is the svg itself, so its props are the span's) with an accessible name, wrapping an aria-hidden drawing. Size it with size-* like shadcn's (default size-4); the scribble is redrawn for the size, thinner and tighter when small. The line is a filled pen drawing hidden behind a mask whose stroke is dashed, and the dash slides round the line (Stubby is his own three drawings, shown one after the other); nothing is measured, so the whole thing renders on the server.

属性类型默认值说明
variant"scribble" | "loops" | "write""scribble"scribble = the spiral, for buttons and badges. loops = a line of cursive loops written on and off, four times as wide as it is tall, for a wide inline wait. write = Stubby, the pencil-stub mascot, in three frames flipped like a flip book while he writes: for a page or a panel that is loading.
sizenumber-Pixels, if you would rather not use a size-* class: the side of a scribble, the height of the loops (their width is four times that), the height of Stubby. Default: the size-N in className, else 16 (Stubby: 64).
aria-labelstring"Loading"The accessible name. Say what is loading ("Saving your page") when the surrounding text does not.
seedstring | number-Pins the hand: the same seed always draws the same scribble. Default: derived from useId().

无障碍

  • Like shadcn's, it is role=status with aria-label="Loading": a polite live region that announces its name when it appears. Put a visible word next to it when you can ("Saving...").
  • The drawing is aria-hidden. It uses the current text color, so it is as visible as the text next to it (in a disabled button that is the disabled text color).
  • Reduced motion (the OS setting, or the in-app calm-ink setting) stops the slide and shows the whole scribble, standing still; Stubby holds his last frame, the finished scribble.
  • In Windows high contrast the drawing is kept (it is art, not a border) and takes the system text color.

源码

CLI 会复制进你项目的文件。

正在加载源码