Button
Buttons and links with six looks, six sizes, and joined actions
import { Button, ButtonGroup, ButtonLink, SplitButton } from "@nyte-ai/ui/button";Button acts. ButtonLink navigates with a native <a href>.
Usage
- An icon-only control needs
iconOnlyandaria-label. A control with visible text omitsaria-label. - The icon-only label doubles as the native
title. Inside a Tooltip, passtitle={undefined}to keep one tooltip on screen. - Reserve
disabledfor an impossible action. Give the reason withdisabledReasonor nearby text. Buttondefaults totype="button". Passtype="submit"to submit a form.- In a popup trigger's
render, put the text inside theButton, as in<Popover.Trigger render={<Button>Open</Button>} />. - Give every
ButtonGrouppart the same size.SplitButton.MenuTriggerneeds a label that names the action and its target.
Examples
Looks and tones
<Button>Ghost</Button>
<Button variant="outline">Outline</Button>
<Button variant="solid" tone="primary">Solid</Button>
<Button variant="solid" tone="danger">Danger</Button>
<Button variant="plain">Plain</Button>
<Button variant="text">Text</Button>Sizes
<Button variant="outline" size="lg">Large</Button>
<Button variant="outline">Medium</Button>
<Button variant="outline" size="sm">Small</Button>
<Button iconOnly icon="plus" aria-label="Add" />
<Button size="sm" iconOnly icon="plus" aria-label="Add" />
<Button size="2xs" iconOnly icon="x" aria-label="Remove" />Glyph, pill, chip, and disabled
<Button variant="outline" icon="refresh">Refresh</Button>
<Button variant="pill">Pill</Button>
<Button variant="chip">Chip</Button>
<Button variant="outline" disabled disabledReason="No changes to save">Save Changes</Button>Navigation and loading
<ButtonLink href="/settings" variant="text">Settings</ButtonLink>
<Button variant="solid" tone="primary" loading={saving} onClick={save}>Save Changes</Button>Joined actions
<SplitButton.Root>
<SplitButton.Main variant="solid" tone="primary">
Commit and Push
</SplitButton.Main>
<Menu>
<MenuTrigger
render={
<SplitButton.MenuTrigger variant="solid" tone="primary" aria-label="More commit actions" />
}
/>
<MenuContent align="end">
<MenuItem onClick={commit}>Commit</MenuItem>
<MenuItem onClick={push}>Push</MenuItem>
</MenuContent>
</Menu>
</SplitButton.Root>Props
Button and ButtonLink
Button takes every Base UI Button prop. className and style take plain values, not functions
of state. ButtonLink takes native <a> attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "ghost" | "pill" | "chip" | "outline" | "solid" | "plain" | "text" | "ghost" | |
tone | "neutral" | "primary" | "success" | "warning" | "danger" | "primary" for text, otherwise "neutral" | |
size | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "md" | 16, 20, 24, 28, 32, or 36px tall. |
iconOnly | boolean | false | Square control. |
icon | IconName | Leading or standalone glyph. | |
children | ReactNode | Required for visible-text controls. | |
xstyle | ButtonLayout | Position, inset, margin, flex, grid, order, and width. | |
className, style | See Theming | Applied to the control. | |
loading | boolean | false | Button only. Disables activation but stays focusable. |
disabledReason | string | Button only. Shown as the title while disabled. | |
href | string | Required for ButtonLink |
The reference table below comes from Base UI, MIT, © Material-UI SAS.
A button component that can be used to trigger actions.
Renders a <button> element.
Button Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| focusableWhenDisabled | boolean | false | Whether the button should be focusable when disabled. |
| nativeButton | boolean | true | Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>). |
| className | string | ((state: Button.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Button.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Button.State) => ReactElement) | - | Allows you to replace the component's HTML element
with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render. |
Button Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-disabled | - | Present when the button is disabled. |
ButtonGroup and SplitButton
ButtonGroup and SplitButton.Root render a <div role="group"> with native <div> attributes
plus xstyle, className, and style. SplitButton.Main is a Button.
SplitButton.MenuTrigger is an icon-only Button that requires aria-label, takes no children,
and defaults icon to chevron-down.
The exported types include ButtonProps, ButtonVariant, ButtonSize, and ButtonLayout.
Accessibility
- Enter and Space activate
Button. Enter followsButtonLink. - A disabled
Buttonsets the nativedisabledattribute and leaves the tab order. loadinganddisabledReasonsetaria-disabledinstead, so the button keeps focus.loadingsetsaria-busyand keeps the accessible name.- Name a group with
aria-labelwhen its parts do not name it. Every part keeps its own tab stop.