组件

Button

The thing you press. A marker-filled primary, a highlighter secondary, an inked outline, a whisper-box ghost, a solid red destructive and a hand-underlined link, in every shadcn size.

安装

terminal
npx shadcn@latest add @wobko/button

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

示例

Variants

Six ways to hold a pen: marker, red pencil, ink, highlighter, pencil whisper and blue felt.

Sizes

The shadcn heights (24, 32, 36, 40) and the square icon buttons. Icon buttons need an aria-label.

States

Rest, hover, pressed, keyboard focus and disabled, forced with data attributes (data-hover, data-pressed, data-focus-visible) so they can be compared side by side. Hover any button yourself: the drawing tilts and lifts a shadow line.

As a link

asChild draws the button on your own element. The drawing lands inside the anchor; a disabled link is announced as disabled and cannot be followed.

Saving, in three states

A real save button: pressing it disables it while the request runs, says what is happening, and confirms. The label is text; nothing here needs an icon.

With an icon

Icons sit before or after the label. Button tightens its padding when it sees one, sizes the pencilled icon to 16 px (12 px in xs) and keeps the drawing behind both.

Icon buttons

Square buttons for one glyph, in the four icon sizes. Give each an aria-label; the drawing is decorative. The last one is a real toggle that swaps its icon.

Loading, with a spinner

The shadcn pattern: a Spinner in front of the label inside a disabled button. The first and last are the static state (disabled buttons are dashed). Press the second to watch a request go through: it is `aria-disabled` while it works instead of `disabled`, so keyboard focus stays on it.

Text and icon buttons, size by size

Each height comes with its square twin: `sm` and `icon-sm` (32 px), default and `icon` (36 px), `lg` and `icon-lg` (40 px), and our extra `xs` pair at 24 px. Put them side by side and the labels and glyphs line up on one baseline.

API 参考

Button

A real <button> (or, with asChild, any element you hand it) with a hand-drawn layer behind its label. The label stays DOM text in the hand font; the drawing is measured from the element, never from the text.

属性类型默认值说明
variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link""default"default = terracotta marker fill and an ink box; destructive = a solid red fill with paper lettering and a red box; outline = an inked box on paper; secondary = highlighter; ghost = a whisper of pencil that lights up under a highlighter swipe on hover; link = a blue felt underline that gets a second, heavier stroke on hover.
size"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg""default"36, 24, 32 and 40 px high (the shadcn sizes); the icon sizes are squares of 36, 24, 32 and 40. Compact density is one step tighter, calm two (and calm is hairline: a pencil.fine outline, a single-pass fill). In the xs sizes an Icon inside is drawn at the 12 px tier.
asChildbooleanfalseRender the child element instead of a <button> and give it the button's classes, data attributes and drawing (Radix Slot). The drawing is inserted inside the child. A disabled asChild element gets aria-disabled, tabIndex -1 and a swallowed click.
seedstring | number-Pins the hand: the same seed always draws the same button, also across remounts. Default: derived from useId().
classNamestring-Merged last. `rounded-full`, as in upstream, makes a pill: the box is drawn with half-height corners (a hand-drawn circle on a square icon button) and `data-shape="pill"` is set. Other rounded-* classes do nothing, because the box is a drawing, not a border.
disabledbooleanfalseDashed pencil box on a pale wash. A real disabled attribute on buttons, aria-disabled on asChild elements.

buttonVariants

The cva function behind Button, for styling a link or trigger like a button. Layout and typography classes only: the drawing comes from Button.

属性类型默认值说明
variantButtonVariant"default"Same values as Button.
sizeButtonSize"default"Same values as Button.
classNamestring-Merged last.

无障碍

  • Renders a native <button>: Enter and Space activate, Tab focuses, disabled removes it from the tab order.
  • Keyboard focus draws a blue felt ring (3:1 against paper and desk); a plain outline is used until the drawing exists and in Windows high contrast, where the drawn layer is replaced by a real border.
  • The drawing is aria-hidden, pointer-events: none and never focusable. Labels are ink on paper, marker or highlighter (4.6:1 or better).
  • With asChild on a link, the element keeps its own role and href; disabled links are announced with aria-disabled.
  • Reduced motion removes the hover tilt, the fill nudge and the underline swipe.

源码

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

正在加载源码