Layout & primitives
Button
Free12.5 KB gzippedThe library's primary action control. Pill-shaped, bold, with a springy press. Renders a native <button type="button">, or an <a> when href is passed.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space · Full report
Import
import { Button, IconButton, ButtonGroup } from "@vjdesigns/vjdesigns-ui";
Importing only Button adds about 12.5 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Variants
variant sets the visual style; tone sets the color separately, so any style works with any tone.
import { Button, Flex } from "@vjdesigns/vjdesigns-ui";
export function Variants() {
return (
<Flex gap={3} wrap="wrap" justify="center">
<Button variant="solid">Solid</Button>
<Button variant="soft">Soft</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="link">Link</Button>
</Flex>
);
}
Tones
import { Button, Flex } from "@vjdesigns/vjdesigns-ui";
export function Tones() {
return (
<Flex gap={3} wrap="wrap" justify="center">
<Button tone="primary">Primary</Button>
<Button tone="neutral">Neutral</Button>
<Button tone="accent">Accent</Button>
<Button tone="success">Success</Button>
<Button tone="danger">Danger</Button>
</Flex>
);
}
Sizes
import { Button, Flex } from "@vjdesigns/vjdesigns-ui";
export function Sizes() {
return (
<Flex gap={3} align="center" wrap="wrap" justify="center">
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</Flex>
);
}
With icons
Icons passed as startIcon or endIcon are decorative and hidden from screen readers.
import {
ArrowRightIcon,
Button,
Flex,
PlusIcon,
TrashIcon,
} from "@vjdesigns/vjdesigns-ui";
export function WithIcons() {
return (
<Flex gap={3} wrap="wrap" justify="center">
<Button startIcon={<PlusIcon />}>New project</Button>
<Button variant="outline" tone="danger" startIcon={<TrashIcon />}>
Delete
</Button>
<Button variant="soft" endIcon={<ArrowRightIcon />}>
Continue
</Button>
</Flex>
);
}
Loading
While loading, the button keeps its width, sets aria-busy and ignores clicks.
import { useState } from "react";
import { Button } from "@vjdesigns/vjdesigns-ui";
export function Loading() {
const [saving, setSaving] = useState(false);
function save() {
setSaving(true);
setTimeout(() => setSaving(false), 2000);
}
return (
<Button loading={saving} loadingText="Saving…" onClick={save}>
Save changes
</Button>
);
}
Icon buttons
Icon-only buttons need an aria-label; the types require it.
import {
ChevronRightIcon,
Flex,
IconButton,
PlusIcon,
TrashIcon,
} from "@vjdesigns/vjdesigns-ui";
export function IconButtons() {
return (
<Flex gap={3} align="center">
<IconButton aria-label="Add item">
<PlusIcon />
</IconButton>
<IconButton aria-label="Delete item" variant="soft" tone="danger">
<TrashIcon />
</IconButton>
<IconButton aria-label="Next page" variant="outline" tone="neutral">
<ChevronRightIcon />
</IconButton>
</Flex>
);
}
Groups
ButtonGroup passes variant, tone, size and disabled to every button inside. attached joins them edge to edge.
import {
Button,
ButtonGroup,
ChevronLeftIcon,
ChevronRightIcon,
IconButton,
Stack,
} from "@vjdesigns/vjdesigns-ui";
export function Groups() {
return (
<Stack gap={4} align="center">
<ButtonGroup variant="outline" tone="neutral" aria-label="Text alignment">
<Button>Left</Button>
<Button>Center</Button>
<Button>Right</Button>
</ButtonGroup>
<ButtonGroup attached variant="soft" aria-label="Pagination">
<IconButton aria-label="Previous page">
<ChevronLeftIcon />
</IconButton>
<Button compact>1</Button>
<Button compact>2</Button>
<IconButton aria-label="Next page">
<ChevronRightIcon />
</IconButton>
</ButtonGroup>
</Stack>
);
}
As link
Pass href to render a link that looks like a button.
import { ArrowRightIcon, Button } from "@vjdesigns/vjdesigns-ui";
export function AsLink() {
return (
<Button href="https://www.npmjs.com/package/@vjdesigns/vjdesigns-ui" variant="outline" endIcon={<ArrowRightIcon />}>
View on npm
</Button>
);
}
Accessibility
An IconButton requires aria-label in its types, so a missing name is a compile error. loading keeps the button's width and focus and sets aria-busy; loadingText is shown and announced. A disabled link drops its href and gets aria-disabled.
import { Button, Flex, IconButton, TrashIcon } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Flex gap={3} align="center" wrap="wrap">
<IconButton aria-label="Delete draft" variant="ghost" tone="danger">
<TrashIcon />
</IconButton>
<Button loading loadingText="Saving…">
Save
</Button>
<Button href="#example-accessibility" disabled variant="outline" tone="neutral">
Disabled link
</Button>
</Flex>
);
}
Focusable when unavailable
aria-disabled makes a button unavailable but keeps it focusable, so people can still reach it and read why, such as a countdown. It looks disabled and ignores clicks. Use disabled when the button shouldn't be reachable at all.
import { useState } from "react";
import { Button, useInterval } from "@vjdesigns/vjdesigns-ui";
export function FocusableWhenUnavailable() {
const [wait, setWait] = useState(0);
useInterval(() => setWait((seconds) => seconds - 1), wait > 0 ? 1000 : null);
return (
<Button variant="outline" aria-disabled={wait > 0} onClick={() => setWait(15)}>
{wait > 0 ? `Resend code in 0:${String(wait).padStart(2, "0")}` : "Resend code"}
</Button>
);
}
Translated
In Arabic, startIcon sits on the right (the start of the line), and the announcement when loading starts comes from the locale. The labels are your own text.
import {
Button,
Flex,
PlusIcon,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function Translated() {
return (
<LocaleProvider locale="ar" messages={ar}>
<Flex gap={3} align="center" wrap="wrap">
<Button startIcon={<PlusIcon />}>إضافة عنصر</Button>
<Button loading variant="outline" tone="neutral">
حفظ
</Button>
</Flex>
</LocaleProvider>
);
}
API reference
Button
| Prop | Type | Default |
|---|---|---|
childrenThe visible label. | ReactNode | — |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the label. Hidden from assistive technology. | ReactNode | — |
loadingShows an inline spinner, sets | boolean | false |
loadingTextLabel shown (and announced) next to the spinner while | ReactNode | — |
loadingLabelAnnounced to screen readers when | string | "Loading" |
fullWidthStretches the button to fill its container. Inherits from a surrounding | boolean | false |
compactTighter side padding, so a short label (a page number, "OK") makes a button no wider than it is tall. | boolean | false |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
disabledDisables the control. Buttons use the native | boolean | false |
hrefPass a URL to render the control as a link ( | string | — |
asA component to render instead, usually a client-side router link (React Router or Next.js | ElementType | — |
Also accepts native <button> attributes, plus className, style and ref.
IconButton
A square (or circular, by default) button that shows only an icon. aria-label is required. At least 32x32 at every size.
| Prop | Type | Default |
|---|---|---|
sizeControl size. | "sm""md""lg""xs" | "md" |
aria-labelRequiredAccessible name. Required, since an icon button has no visible label. | string | — |
childrenRequiredThe icon. Hidden from assistive technology; | ReactNode | — |
loadingReplaces the icon with a spinner, sets | boolean | false |
disabledDisables the control. Buttons use the native | boolean | false |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
hrefPass a URL to render the control as a link ( | string | — |
asA component to render instead, usually a client-side router link (React Router or Next.js | ElementType | — |
Also accepts native <button> attributes, plus className, style and ref.
ButtonGroup
Groups related buttons (role="group"). Give it an aria-label or aria-labelledby when the group's purpose isn't clear from context.
| Prop | Type | Default |
|---|---|---|
attachedJoins buttons edge to edge, sharing borders, with rounding on the outer corners only. | boolean | false |
orientationLayout direction. | "horizontal""vertical" | "horizontal" |
gapSpace between buttons (a | Space | 2 |
fullWidthStretches the group to fill its container and makes buttons share the space equally. | boolean | false |
childrenThe buttons. | ReactNode | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
disabledDisables the control. Buttons use the native | boolean | false |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Button targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the button. A disabled button is skipped; a loading one stays focusable. |
| EnterSpace | Activates the button. As a link (href), Enter follows it. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<button type="button"> | button | aria-disabled and aria-busy while loading |
<a> (with href) | link | aria-disabled when disabled |
IconButton | button | aria-label (required) |
ButtonGroup | group | aria-label |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |