Button
Triggers an action. Primary, secondary, ghost and danger styles in three sizes, with a loading state.
Use a button for an action on the current page, such as saving or deleting. To go to another page, use a link, or a button rendered as a link.
import { Button } from "@aloxe/react";
export default function ButtonVariants() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="primary">Publish</Button>
<Button variant="secondary">Save draft</Button>
<Button variant="ghost">Cancel</Button>
<Button variant="danger">Delete project</Button>
</div>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { Button } from "@aloxe/react";
<Button onClick={save}>Save changes</Button>Pick the variant by importance. Keep one primary button per view for the main action. Secondary suits other actions, ghost suits low-priority actions in toolbars and footers, and danger is for actions that delete or can't be undone.
Inside a form, pass type="submit". The default is type="button", so a button never submits a form by accident.
Examples
Sizes
sm (32 px) fits dense toolbars and tables, md (40 px) is the default, lg (48 px) suits a single call to action. The label keeps the same text style at every size.
import { Button } from "@aloxe/react";
export default function ButtonSizes() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</div>
);
}With icons
Place an icon before the label for the object or after it for direction. Icons are 16 px (20 px at lg) and hidden from screen readers.
import { Button } from "@aloxe/react";
import { ArrowRight, Download, Plus } from "lucide-react";
export default function ButtonWithIcons() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button>
<Plus />
New project
</Button>
<Button variant="secondary">
<Download />
Export CSV
</Button>
<Button variant="ghost">
Continue
<ArrowRight />
</Button>
</div>
);
}Loading
loading swaps the label for a spinner and keeps the button's width, so the layout doesn't move. The button stays focusable and announces aria-busy, so keyboard focus isn't lost while a request runs. Select the first button to try it.
"use client";
import { Button } from "@aloxe/react";
import { useState } from "react";
export default function ButtonLoading() {
const [saving, setSaving] = useState(false);
function save() {
setSaving(true);
window.setTimeout(() => setSaving(false), 2000);
}
return (
<div className="flex flex-wrap items-center gap-3">
<Button loading={saving} onClick={save}>
Save changes
</Button>
<Button variant="secondary" loading>
Uploading
</Button>
</div>
);
}Disabled
A disabled button can't be focused or clicked. If people need to know why an action is unavailable, keep it enabled and explain on click, or say why next to it.
import { Button } from "@aloxe/react";
export default function ButtonDisabled() {
return (
<div className="flex flex-wrap items-center gap-3">
<Button disabled>Publish</Button>
<Button variant="secondary" disabled>
Save draft
</Button>
<Button variant="ghost" disabled>
Cancel
</Button>
<Button variant="danger" disabled>
Delete project
</Button>
</div>
);
}As a link
To navigate, render a link with the button styles, here a Next.js Link. Set nativeButton={false} so the element keeps link semantics.
import { Button } from "@aloxe/react";
import { ArrowRight } from "lucide-react";
import Link from "next/link";
export default function ButtonAsLink() {
return (
<Button
variant="secondary"
nativeButton={false}
render={<Link href="/docs/getting-started/installation" />}
>
Read the installation guide
<ArrowRight />
</Button>
);
}Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the button. |
| Enter or Space | Activates the button. |
- The visible label is the accessible name. Write it as a verb that says what happens: "Save changes", not "OK".
- The focus ring is 2 px with a 2 px offset in the focus colour, visible in both themes.
mdandlgbuttons are at least 40 px tall;smis 32 px, above the 24 px minimum target size.- A loading button keeps focus and sets
aria-busy="true". Announce the result separately, for example with a toast.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="button"].
Button
Extends Base UI Button.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "primary" | "secondary" | "ghost" | "danger" | "primary" | Visual weight. Use one primary button per view and danger only for destructive actions. |
| size | "sm" | "md" | "lg" | "md" | Height: 32, 40 or 48 px. The label stays Label Md at every size. |
| loading | boolean | false | Shows a spinner in place of the label, keeps the width, sets aria-busy and blocks clicks. The button stays focusable. |
| disabled | boolean | false | Disables the button. Prefer explaining why an action is unavailable over disabling it silently. |
| render | ReactElement | (props, state) => ReactElement | Renders another element, e.g. a link: render={<a href="/pricing" />} with nativeButton={false}. | |
| nativeButton | boolean | true | Set to false when render is not a <button>, so the right ARIA and keyboard handling is added. |
| className | string | Merged with the default classes; yours win on conflicts. |
Figma
The Button component set has one variant per style: Button/Primary, Button/Secondary, Button/Ghost and Button/Danger map to variant. The Figma Size property (Sm, Md, Lg) maps to size. Hover, pressed and focus are interaction states, not props.
See Figma for where to get the file and how its names map to code.