$npx @dinachi/cli@latest add button
variantdefault
secondary
outline
ghost
link
destructive
sizesm
default
lg
icon
childrendisabledsave-button.tsx
import { Button } from "@/components/ui/button"
export function SaveButton() {
return (
<Button>Save changes</Button>
)
}Usage
import { Button } from "@/components/ui/button"
export function SaveButton() {
return <Button onClick={() => save()}>Save changes</Button>
}Examples
Each visual style, from default to destructive.
import { Button } from '@/components/ui/button';
export function Example() {
return (
<div className="flex gap-2 flex-wrap">
<Button variant="default">Default</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="link">Link</Button>
<Button variant="destructive">Destructive</Button>
</div>
);
}A button with the default style.
import { Button } from '@/components/ui/button';
export function Example() {
return <Button>Click me</Button>;
}Small, default and large.
import { Button } from '@/components/ui/button';
export function Example() {
return (
<div className="flex gap-2 items-center">
<Button size="sm">Small</Button>
<Button size="default">Default</Button>
<Button size="lg">Large</Button>
</div>
);
}Square buttons that hold a single icon.
import { Button } from '@/components/ui/button';
import { Bold, Italic, Plus, Search, Trash2, Underline } from 'lucide-react';
export function Example() {
return (
<div className="flex gap-2 items-center flex-wrap">
<Button variant="outline" size="icon">
<Plus className="h-4 w-4" />
</Button>
<Button variant="outline" size="icon">
<Search className="h-4 w-4" />
</Button>
<Button variant="ghost" size="icon">
<Bold className="h-4 w-4" />
</Button>
<Button variant="ghost" size="icon">
<Italic className="h-4 w-4" />
</Button>
<Button variant="ghost" size="icon">
<Underline className="h-4 w-4" />
</Button>
<Button variant="destructive" size="icon">
<Trash2 className="h-4 w-4" />
</Button>
</div>
);
}Icon buttons with tooltips, through the render prop.
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
import { Bold, Mail, Search, Trash2 } from 'lucide-react';
export function Example() {
return (
<div className="flex gap-2 items-center flex-wrap">
<Tooltip>
<TooltipTrigger render={<Button variant="outline" size="icon" />}>
<Mail className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent>
<p>Send email</p>
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" size="icon" />}>
<Search className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent>
<p>Search</p>
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button variant="ghost" size="icon" />}>
<Bold className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent>
<p>Bold</p>
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button variant="destructive" size="icon" />}>
<Trash2 className="h-4 w-4" />
</TooltipTrigger>
<TooltipContent>
<p>Delete</p>
</TooltipContent>
</Tooltip>
</div>
);
}Notes
Submitting a form
Unlike a native <button>, Button does not submit by default. Pass type="submit".
Rendering another element
- With
render,nativeButtondefaults to false and the element getsrole="button"and keyboard handling. - Pass
nativeButtonwhenrenderis itself a<button>, such as another component's trigger. - For a link, style an
<a>withbuttonVariants(). Rendered through Button, it is announced as a button.
Loading states
Pair disabled with focusableWhenDisabled to keep focus on the button. If its text changes, point aria-labelledby at the text so the change is announced.
Agents
- Not registered with the agent bridge. Inside an
AgentProviderit is read from the page as abutton, named by its text oraria-label, and takespress. - A disabled button refuses.
- Set
data-agent-confirmto a reason to require approval for each press.
API
variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link" = "default"
The visual style.size"default" | "sm" | "lg" | "icon" = "default"
Height and padding. icon is square, for a single icon.renderReactElement | (props, state) => ReactElement
Swap the element, keep the behaviour.nativeButtonboolean = true, or false with render
Whether the rendered element is a real <button>. Set true when render is a button.disabled
Blocks clicks and agent presses.agent
boolean = falsefocusableWhenDisabledboolean = false
Keeps a disabled button in the tab order, for loading states.type"button" | "submit" | "reset" = "button"
Pass "submit" to submit the form.classNamestring
Merged over the variant classes.Accessibility
- A native button, or role="button" when
nativeButtonis false. - Name an icon-only button with aria-label; a tooltip does not name it. The agent reads the same name.
- A disabled button leaves the tab order unless
focusableWhenDisabledis set. - Reduced motion turns off the press animation.
Keyboard
EnterSpaceActivates the button
EnterSpaceActivates the button