Button
Triggers an action. Native button with solid, line, ghost and danger variants.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on radix-ui/Slot
- Native <button>: Enter and Space activate, Tab focuses.
- loading sets aria-busy and blocks clicks while keeping the label.
- asChild renders a link without losing link semantics.
- Styles in one file:
02-buttons.css
Import
import '@monoline/css';
import {Button} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add button
It needs radix-ui; install it if your project does not have it:
npm install radix-ui
Usage
import {Button} from '@monoline/react';
<div style={{display: 'flex', gap: 'var(--s3)', flexWrap: 'wrap'}}>
<Button variant="solid">Write today</Button>
<Button variant="line">Open folder</Button>
<Button variant="ghost">Show all</Button>
<Button variant="danger">Delete entry</Button>
</div>
Examples
States
Sizes and form rows
Button, Input and NativeSelect share one height at each size (`sm`, `md`, `lg`), so they line up in a row.
Props
ButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "danger" | "line" | "solid" | "ghost" | 'solid' | Default `solid`: the one main action per view. `line` for the rest, `ghost` for inline links, `danger` for destructive. |
size | "sm" | "md" | "lg" | 'md' | `md` (default), `sm` for dense toolbars and table rows, or `lg` for prominent calls to action. Same heights as Input and Select. |
loading | boolean | false | Shows a spinner, sets `aria-busy` and ignores clicks. The label stays so the width does not jump. |
asChild | boolean | false | Render the child element (a link, a router link) with the button styles instead of a `<button>`. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.skeleton | 13-loading.css |
.skeleton-block | 13-loading.css |
.skeleton-hatch | 13-loading.css |
.spinner | 13-loading.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
.btn {
border-color: var(--accent);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
<Button variant="solid">Save changes</Button>
Accessibility
- Native <button>: Enter and Space activate, Tab focuses.
- loading sets aria-busy and blocks clicks while keeping the label.
- asChild renders a link without losing link semantics.
Keyboard
| Keys | Action |
|---|---|
| Enter / Space | Activate |
| Tab | Focuses |