Button
The registry button on Base UI, restyled by foundation to the 30px control and the radius ladder.
Variants
import { Button } from "@/components/ui/button"
export default function ButtonVariants() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button>Save changes</Button>
<Button variant="outline">Export</Button>
<Button variant="secondary">Duplicate</Button>
<Button variant="ghost">Cancel</Button>
<Button variant="destructive">Delete project</Button>
<Button variant="link">View history</Button>
</div>
)
}
Sizes
import { Button } from "@/components/ui/button"
export default function ButtonSizes() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button size="xs" variant="outline">
Extra small
</Button>
<Button size="sm" variant="outline">
Small
</Button>
<Button variant="outline">Default</Button>
<Button size="lg" variant="outline">
Large
</Button>
</div>
)
}
With icon
import { ArrowRightIcon, PlusIcon } from "@keyline-icons/react"
import { Button } from "@/components/ui/button"
export default function ButtonWithIcon() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button>
<PlusIcon data-icon="inline-start" />
New project
</Button>
<Button variant="outline">
Continue
<ArrowRightIcon data-icon="inline-end" />
</Button>
</div>
)
}
Icon only
import { ArchiveIcon, DownloadIcon, PlusIcon, SearchIcon } from "@keyline-icons/react"
import { Button } from "@/components/ui/button"
export default function ButtonIconOnly() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button size="icon-xs" variant="ghost" aria-label="Add a row">
<PlusIcon />
</Button>
<Button size="icon-sm" variant="ghost" aria-label="Search projects">
<SearchIcon />
</Button>
<Button size="icon" variant="outline" aria-label="Download the report">
<DownloadIcon />
</Button>
<Button size="icon-lg" variant="outline" aria-label="Archive the project">
<ArchiveIcon />
</Button>
</div>
)
}
States
import { Button } from "@/components/ui/button"
export default function ButtonStates() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button disabled>Disabled</Button>
<Button variant="outline" disabled>
Disabled
</Button>
<Button variant="outline" aria-invalid>
Invalid
</Button>
</div>
)
}
Pending
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"
export default function ButtonPending() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button disabled>
<Spinner data-icon="inline-start" aria-hidden />
Saving
</Button>
<Button variant="outline" disabled>
<Spinner data-icon="inline-start" aria-hidden />
Exporting
</Button>
</div>
)
}
As a link
import { ArrowUpRightIcon } from "@keyline-icons/react"
import { Button } from "@/components/ui/button"
export default function ButtonAsALink() {
return (
<div className="flex flex-wrap items-center gap-2">
<Button variant="outline" nativeButton={false} render={<a href="https://ui.khaeli.com/r/button.json" />}>
Open the Registry JSON
<ArrowUpRightIcon data-icon="inline-end" />
</Button>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/buttonbunx --bun shadcn@latest add @khaeli/buttonInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @base-ui/react ^1.7.0
- class-variance-authority ^0.7.1
Keyboard
EnterSpace- Activates the button.
Tab- Moves focus to the button. A
disabledbutton is a native disabled button: it leaves the tab order and cannot be activated.
Accessible name
- The name is the button's text. Keep it a verb that says what happens: Save changes, not OK.
- An icon-only button has no text, so give it an
aria-labelthat says what it does. An icon beside text is decorative and needs no name. - A pending button keeps a name that says what is happening, such as Saving, and hides the spinner from assistive technology with
aria-hidden. - Rendered as a link with
nativeButton={false}andrender, the anchor takesrole="button": it is announced as a button, and Enter and Space both follow it.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/button.json