Components / Button
Button
One action, six variants. A square, monospaced button for the things you want people to do next. Use a button for actions and a link for navigation.
Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.
Usage playground
Configure. Preview. Copy.Icon-only buttons use the label as their accessible name (or “Add item” when blank). Empty or whitespace-only labels always fall back to “Add item”, including leading/trailing icons and no icon. The icon size always displays only an icon.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return (
<Button
variant="default"
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/button#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.
Run this revision-pinned GitHub command in a project configured for shadcn. It installs yads-button, its internal modules and scoped stylesheet, Radix Slot, class-variance-authority and JetBrains Mono. Import { Button, buttonVariants } from @/components/ui/yads-button (adjust the alias to your project). No separate theme install is needed.
Each example’s Copy sample includes the complete React module, even when collapsed. Inline SVG icons and recipe CSS are included: no icon package or Tailwind utilities required. Use a client boundary for interactive examples in React Server Component apps; buttonVariants() also works on the server.
Variants
Compare all six variants. Default is the primary action; secondary, outline, ghost and link offer quieter choices. Reserve destructive for risky actions.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-4 w-full">
<Button variant="default">Default</Button>
Sizes
Small (sm), default and large (lg) adjust height and padding. The square icon size is for a single icon and needs an accessible name.
import { Button } from "@/components/ui/yads-button";
function AddIcon() {
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M12 5v14M5 12h14" />
Leading and trailing icons
Place an icon before or after the visible label. These decorative inline SVGs are hidden from assistive technology and require no icon package.
import { Button } from "@/components/ui/yads-button";
function AddIcon() {
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M12 5v14M5 12h14" />
Icon only
Give an icon-only action a meaningful aria-label. The icon itself is decorative; its shape is not an accessible name.
import { Button } from "@/components/ui/yads-button";
function AddIcon() {
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M12 5v14M5 12h14" />
Full width
Fill the available container with Tailwind’s w-full utility.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return (
<Button variant="secondary" className="w-full">
Create account
Disabled
Native disabled buttons cannot be activated or reached with Tab. Explain why an action is unavailable in nearby text rather than only in a tooltip.
import { Button } from "@/components/ui/yads-button";
function AddIcon() {
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M12 5v14M5 12h14" />
Static loading
loading is a boolean, defaulting to false. Native buttons retain focus, their accessible name and their width while busy. Repeated clicks, Enter and Space are suppressed. Keep children and labels unchanged during the request; announce progress and completion in a separate status region. Spinner motion stops when reduced motion is preferred.
Native disabled still takes precedence, including when combined with loading: it removes the button from the tab order. Composed anchors also support loading: they keep focus and link semantics while navigation is blocked. See Pending links. Use an ordinary button for async actions, not an anchor.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return <Button loading>Save changes</Button>;
}
Interactive loading
Try Save changes. This simulated request completes after 1.5 seconds; the status below reports its outcome. In your app, clear loading on success and failure and report the real result.
Ready to save.
'use client';
import { useState } from "react";
import { Button } from "@/components/ui/yads-button";
export default function Example() {
Link composition
Use asChild with one direct semantic a child for navigation, and a native button for an action. Enabled anchors keep their href, link semantics, child handlers and normal browser navigation. Disabled anchors expose aria-disabled, omit href and leave the tab order (tabIndex=-1); they remain programmatically focusable, unlike natively disabled buttons. Clicks (including child handlers), Enter and Space cannot activate them. No native disabled attribute is sent to the anchor. The disabled and loading guarantees require the direct anchor shown here, not a nested Slot or custom component that could override the blocking props.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return (
<div className="flex flex-wrap gap-4 w-full">
<Button asChild><a href="#button-link-destination">Visit destination</a></Button>
Pending links
A pending anchor retains focus, its accessible name and dimensions, exposes aria-busy and aria-disabled, and stays in the tab order by default (an explicit author tabIndex is respected). Its href is temporarily omitted so pointer, keyboard, auxiliary clicks and context-menu navigation cannot follow it. Child click and activation-key handlers are suppressed too. Clear loading on success and failure to restore the original link. Keep children and labels stable and announce results separately. Explicit disabled wins over loading for tab order. This checkbox simulates external pending state; Button does not start requests or perform routing for you.
'use client';
import { useState } from "react";
import { Button } from "@/components/ui/yads-button";
import { Label } from "@/components/ui/yads-label";
import { Checkbox } from "@/components/ui/yads-checkbox";
className customization
Pass a className and your own CSS to override height, padding, border and letter spacing while keeping YADS colors, square corners and focus styles. The repeated class selector deliberately outranks the component’s base and size classes: stylesheet order alone is not a reliable override. Include the recipe CSS wherever you use the class; no Tailwind or private component variables are needed.
import { Button } from "@/components/ui/yads-button";
export default function Example() {
return (
<>
<style>{`
buttonVariants composition
buttonVariants returns the supported variant and size classes for your own element. Its className option adds recipe styles with the same deliberate specificity. It supplies styling only, not Button behavior: use a native button for actions, set its type, and provide an accessible name.
import { buttonVariants } from "@/components/ui/yads-button";
export default function Example() {
return (
<>
<style>{`
Accessibility
- Name the action. Prefer a clear visible label. Icon-only buttons need
aria-label(oraria-labelledby); hide decorative SVGs witharia-hidden. The playground’s blank-label fallback is an example convenience, not automatic Button behavior. - Keep native semantics. Use buttons for actions and links for navigation. Enter and Space activate native buttons; Enter follows enabled links. Set
type="button"for non-submit actions inside forms. Keep the visible keyboard focus ring. - Explain unavailable actions. Native
disabledbuttons cannot activate, submit or receive focus. Disabled direct links omit href, exposearia-disabledand usetabIndex=-1: skipped by Tab, but still programmatically focusable. Explain the reason in nearby text, not only a tooltip. - Announce progress without renaming. Loading sets
aria-busyandaria-disabled, keeps focus, accessible content and dimensions, and suppresses clicks and Enter/Space activation, including native form submission. Keep children/labels stable; announce progress and results in a separaterole="status"region. Clear pending on success and failure. The decorative spinner stops with reduced motion. - Compose only supported pending links. Use one direct
<a>child withasChild. While loading, href is omitted and child/parent activation handlers are suppressed, blocking pointer, auxiliary and keyboard navigation. The link keeps focus and its name, exposes busy/disabled state, and defaults totabIndex=0(an explicit author tabIndex is respected). Explicit disabled takes precedence. Restore loading to false to restore href and handlers. These guarantees do not cover nested Slot or custom component children that replace props or run their own logic.
Button does not manage requests or routing. Use a native button for asynchronous actions. See Interactive loading and Pending links for complete examples.
API reference
ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> and the CVA variant props. It does not implement a generic polymorphic API. Imports and exports are available from @/components/ui/yads-button.
Omit variant/size for their defaults; CVA also accepts null to omit the respective classes. On narrow screens, scroll the focused table horizontally to read all columns.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "secondary" | "outline" | "ghost" | "link" | "destructive" | null | "default" | Visual hierarchy. Both the playground and component start with default. |
size | "default" | "sm" | "lg" | "icon" | null | "default" | Height and padding; icon is square and needs an accessible name. |
loading | boolean | false | Shows a decorative spinner; sets aria-busy and aria-disabled, retains focus, name and layout, and suppresses activation. Keep children stable. |
asChild | boolean | false | Uses Radix Slot to merge onto one child rather than render a button. Disabled/loading composition requires one direct <a> child; nested Slot and custom children are unsupported for blocking. |
disabled | boolean | false | Native disabled on buttons. Direct anchors omit href, expose aria-disabled and use tabIndex=-1; disabled wins over loading for tab order. |
type | "button" | "submit" | "reset" | Not set | Native browser default applies (normally submit inside a form). Set type="button" for non-submit actions. Put navigation attributes on the direct anchor child. |
className | string | Not set | Adds classes to the variant and size classes. Use ordinary CSS with sufficient specificity, as in the customization recipes. |
children | React.ReactNode | Not set | Button content, or one child with asChild. Provide a visible label or aria-label for icon-only actions. |
ref | React.Ref<HTMLButtonElement> | Not set | Forwarded to the rendered element. The public ref type is button-oriented; asChild does not provide arbitrary element/ref typing. |
Native button attributes
Native button attributes such as id, name, value, form, formAction, title, aria-*, data-*, style and event handlers are forwarded. No type is supplied automatically. Native submit/reset behavior remains the browser’s responsibility; loading blocks activation, not application-driven form submission.
With asChild, put href, target and rel on the direct anchor. Do not pass button-only attributes such as type, form or value to links. Disabled/loading direct anchors receive no native disabled attribute. The blocked state owns href, role, busy/disabled ARIA and activation handlers as described above.
buttonVariants(options)
Returns a class string for variant, size and optional className, with the same default variant/size as Button. It supplies styling only: no loading, disabled, keyboard or link behavior. The public module is server-neutral, so server components can call buttonVariants(); interactive Button behavior stays in its client module. See buttonVariants composition.
Playground defaults
Reset restores default / default, “Add item”, no icon, enabled, not loading and intrinsic width. Full width uses Tailwind’s w-full utility, not a Button prop. Icon placement and label are also playground controls, not public props.