Skip to Content
Neshel-UI
Components

Button

Native buttons with variants, responsive sizes, a loading state, icon-only mode and asChild links.

Server-compatible (no "use client")

Purpose

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.tsx
import { Button } from "@neshel-ui/components";

Usage

Preview: button-variants
Preview theme
button-variants.tsx
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

ButtonProps
PropTypeDefaultDescription
asChildboolean—Render the single child element (e.g. a link) with the button styles.
fullWidthboolean—Fill the inline size of the container.
iconOnlyboolean—Square button for a single icon; requires aria-label or aria-labelledby.
loadingboolean—Busy state: keeps focus (aria-disabled), ignores activation and form submission, shows a decorative spinner. Announce progress with your own live region.
refRef<HTMLButtonElement>——
sizeResponsive<ButtonSize>"md"Size, static or per breakpoint (default "md").
variantButtonVariant"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
Preview theme
button-sizes.tsx
"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; requires aria-label or aria-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 is type="button").
  • loading uses aria-disabled so focus is not lost mid-interaction.

Keyboard

KeyAction
TabFocus the button
Enter / SpaceActivate

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

  • onClick navigation on a Button: use asChild with 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.
Edit on GitHub

On this page