@hacline/ui/buttonButton
Button component built on @ui-sdk/react/button with native async double-submit prevention, accessible focus management, and polymorphic link rendering.
Import
import { Button } from "@/components/ui/hacline/components/button";Variants
Switch the visual hierarchy of the button with variant. Defaults to primary.
import { Button } from "@/components/ui/hacline/components/button";
export function ButtonVariants() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary">Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="danger">Danger</Button>
<Button variant="link">Link</Button>
</div>
);
}Sizes
Adjust the button size using size, supporting sm, md, lg, and icon sizes icon-sm, icon, and icon-lg. Always provide an aria-label when rendering an icon-only button.
import { Button } from "@/components/ui/hacline/components/button";
import { PlusIcon } from "lucide-react";
export function ButtonSizes() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button size="sm">Small</Button>
<Button size="md">Default</Button>
<Button size="lg">Large</Button>
<Button aria-label="Small icon button" size="icon-sm" variant="outline">
<PlusIcon aria-hidden="true" />
</Button>
<Button aria-label="Default icon button" size="icon" variant="outline">
<PlusIcon aria-hidden="true" />
</Button>
<Button aria-label="Large icon button" size="icon-lg" variant="outline">
<PlusIcon aria-hidden="true" />
</Button>
</div>
);
}Async Loading State
When onClick returns a Promise, the button automatically enters the data-pending state, retains focus, blocks duplicate clicks, and announces pendingAnnouncement to screen readers if the operation exceeds 1 second. Use data-show="idle" and data-show="pending" to swap icons or content automatically.
"use client";
import { Button } from "@/components/ui/hacline/components/button";
import { ArrowDownToLineIcon, LoaderCircleIcon } from "lucide-react";
export function ButtonPending() {
return (
<Button
onClick={async () => {
await saveChanges();
}}
pendingAnnouncement="Saving changes"
>
<ArrowDownToLineIcon aria-hidden="true" data-show="idle" />
<LoaderCircleIcon
aria-hidden="true"
className="animate-spin"
data-show="pending"
/>
Save changes
</Button>
);
}Disabled and Focusable State
Setting disabled blocks activation and removes the button from the Tab order. Combine with focusableWhenDisabled to use aria-disabled and keep keyboard focusability, making it easy to pair with helper text or a Tooltip explaining why the action is unavailable.
import { Button } from "@/components/ui/hacline/components/button";
export function ButtonDisabled() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button disabled>Disabled</Button>
<Button disabled focusableWhenDisabled variant="outline">
Focusable when disabled
</Button>
</div>
);
}Render as Link
Use the render prop to render the button as an <a> or router link component (such as Next.js Link), preserving link semantics and disabled interception behavior.
import { Button } from "@/components/ui/hacline/components/button";
export function ButtonLink() {
return (
<Button
render={(props) => (
<a {...props} href="#props">
Jump to props
</a>
)}
variant="outline"
/>
);
}Props
Also inherits all native <button> HTML attributes and ref.
Data Attributes
The component exposes the following state attributes for custom styling and animations:
| Attribute | Description |
|---|---|
data-slot="button" | Identifies the button root element |
data-pending | Present while the Promise returned by onClick is pending |
data-disabled | Present when the button is disabled |
data-show="idle" | "pending" | Placed on child elements to toggle visibility automatically with data-pending |