Components
Button
Native buttons with variants, responsive sizes, a loading state, icon-only mode and asChild links.
Server-compatible (no "use client")
import.tsx
button-variants.tsx
button-sizes.tsx
Composition and
Edit on GitHubPurpose
Button triggers an action. It renders a native <button type="button"> by default; with asChild
it styles a link or router link instead.
Import
import { Button } from "@neshel-ui/components";Usage
Preview: button-variants
import { Button } from "@neshel-ui/components";
import { Inline } from "@neshel-ui/layout";
export default function ButtonVariants() {
return (
<Inline space="3" align="center" wrap>
<Button>Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="destructive">Delete</Button>
<Button variant="link">Link</Button>
</Inline>
);
}API
ButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | — | Render the single child element (e.g. a link) with the button styles. |
| fullWidth | boolean | — | Fill the inline size of the container. |
| iconOnly | boolean | — | Square button for a single icon; requires aria-label or aria-labelledby. |
| loading | boolean | — | Busy state: keeps focus (aria-disabled), ignores activation and form submission, shows a
decorative spinner. Announce progress with your own live region. |
| ref | Ref<HTMLButtonElement> | — | — |
| size | Responsive<ButtonSize> | "md" | Size, static or per breakpoint (default "md"). |
| variant | ButtonVariant | "primary" | Visual style (default "primary"). |
Also accepts the props of: React DOM attributes.
ButtonVariant
type ButtonVariant = (typeof buttonVariantNames)[number]ButtonSize
type ButtonSize = (typeof buttonSizeNames)[number]Native button attributes (type, disabled, form, onClick, …) pass through.
Variants, sizes and states
Preview: button-sizes
"use client";
import { Button } from "@neshel-ui/components";
import { Inline, Stack } from "@neshel-ui/layout";
import { Plus } from "lucide-react";
import { useState } from "react";
export default function ButtonSizes() {
const [saving, setSaving] = useState(false);
return (
<Stack space="4">
<Inline space="3" align="center" wrap>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
{/* Responsive: small on phones, medium from md, large from lg. */}
<Button size={{ base: "sm", md: "md", lg: "lg" }}>Responsive</Button>
</Inline>
<Inline space="3" align="center" wrap>
<Button iconOnly aria-label="Add item" variant="outline">
<Plus aria-hidden="true" />
</Button>
<Button
loading={saving}
onClick={() => {
setSaving(true);
setTimeout(() => setSaving(false), 1500);
}}
>
{saving ? "Saving…" : "Save"}
</Button>
<Button asChild variant="link">
<a href="#api-buttonprops">Read the API</a>
</Button>
</Inline>
</Stack>
);
}variant:primary(default),secondary,outline,ghost,destructive,link.size:sm,md(default),lg— responsive:size={{ base: "sm", md: "lg" }}.iconOnly: a square button; requiresaria-labeloraria-labelledby(development warning).fullWidth: fills the inline size of its container.loading: keeps focus (aria-disabled="true",data-loading), ignores clicks and form submission, shows a decorative spinner. Announce progress with your own live region.
Composition and asChild
<Button asChild variant="ghost">
<a href="/docs">Documentation</a>
</Button>The child receives the classes and handlers. asChild with disabled or loading throws: links
cannot be disabled — render a disabled <button> instead.
Accessibility
- A native button: focusable, activated with Enter and Space, announced as "button".
- Use
type="submit"explicitly inside forms when it submits (the default istype="button"). loadingusesaria-disabledso focus is not lost mid-interaction.
Keyboard
| Key | Action |
|---|---|
| Tab | Focus the button |
| Enter / Space | Activate |
Styling
Variants read --neshel-primary, --neshel-secondary, --neshel-destructive, --neshel-border
and their foregrounds; the focus ring uses --neshel-focus. Add utilities with className.
Common mistakes
onClicknavigation on a Button: useasChildwith a link so the browser knows it is navigation.- An icon-only button without
aria-label. - Forgetting
type="submit"and wondering why the form does not submit.