Starts an action.
import { Button } from "@usememos/ui";
import { Plus } from "lucide-react";
<Button variant="primary" icon={<Plus />}>New note</Button>interface ButtonProps extends BaseButton.Props {
variant?: "primary" | "neutral" | "ghost" | "danger"; // default "neutral"
size?: Size;
shape?: "default" | "pill"; // default "default"; icon-only pills are circular
icon?: IconElement; // before the label
iconEnd?: IconElement; // after the label: "Show more" with a chevron, "Next" with an arrow
loading?: boolean;
loadingLabel?: string; // accessible loading description; icon-only buttons use it as their name
}
function buttonClasses(options?: { variant?: ButtonVariant; size?: Size; shape?: ControlShape; iconOnly?: boolean }): string;Wraps Base UI's Button: disabled, focusableWhenDisabled, render, nativeButton and native button attributes pass through. Renders <button type="button">.
-
Label with a verb in sentence case ("Save", "Copy link"). With only an
icon, passaria-labeland add a Tooltip with the same text. -
primary: the one action a view exists for, at most one per view.neutral: every other action.ghost: toolbars, dense rows, the "More actions" trigger.danger: confirming a destructive action inside a dialog, never as a first click. -
Use
loadingfor any action that waits on a server (loading={saving}). An idle button looks the same whether or not the prop is supplied. -
loadingLabeldescribes the pending action ("Saving") to assistive technology while a text button keeps its original accessible name. On icon-only buttons it supplies the accessible name during loading. It never replaces visible text. -
iconEndsays where the action leads or that it opens something (a chevron, an arrow). Don't put an icon inchildren: the label is one text span, so it would wrap. Useiconfor what the action is. -
A link that should look like a button stays an
<a>withbuttonClasses(); Base UI doesn't render links through Button:<a className={buttonClasses({ variant: "primary" })} href="/start">Get started</a>
-
Prefer saying why an action is unavailable over disabling it.
-
Over a photo or video (an image viewer's close and arrows, a cover's edit button), use
neutralButtons inside an element withdata-theme="dark", so they are dark keys whatever the app's theme. There is no media variant. See the recipe.
- A flat control: 20, 24 or 32px tall.
primaryis an ink key withon-primarytext;neutralakeywith a quietedgeboundary;ghostflattext-secondarywithhoveron hover;dangeradanger-keywithon-dangertext. - A neutral button keeps its quiet
edgeon hover; itskey-hoverfill provides feedback. Keyboard focus changes the 1px edge to ink; filled actions retain their contrasting focus edge. shape="pill"usesradius-fulland equal size-row horizontal padding, even with an icon beside a label. Default shape and padding stay unchanged.- Only an icon: square (circular with
shape="pill"). With the default shape, the side with an icon (iconat the start,iconEndat the end) has 2px less padding. - Hover and press reuse one immediate highlight:
key-hoverfor neutral,hoverfor ghost,primary-hoverfor primary; danger retainsdanger-key. Holding the pointer adds no new boundary. Keyboard focus owns the contrasting edge. No color fade, translation, scale or brightness filter. loadingimmediately setsaria-busyandaria-disabled, ignores presses and stays focusable. After 300ms a Spinner replaces the leading icon, or the trailing icon when there is no leading icon. An icon-only button shows just the Spinner; a button with text keeps its original label. A button with icons keeps its width, height, padding and label position. A text-only button has no icon to swap, so the Spinner goes before its label with the icon-side padding and the button widens by one icon; it reserves no space while idle. Finishing cancels the delay and removes the Spinner immediately, restoring the idle width.- Disabled: every variant uses
text-disabledtext, awellfill and a quietedge, including ghost buttons. This keeps disabled toolbar actions distinct from enabled ghost actions without dimming the text. Opacity stays 1.