Icon button
A square button holding only an icon. The accessible name is required.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native elements
- Native button; aria-label is required by the type.
- Space and Enter activate it.
- Styles in one file:
02-buttons.css
Import
import '@monoline/css';
import {IconButton} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add icon-button
Usage
import {IconButton} from '@monoline/react';
const Plus = () => <svg aria-hidden="true" viewBox="0 0 12 12" width="12" height="12"><path d="M6 1v10M1 6h10" stroke="currentColor" fill="none" /></svg>;
<div style={{display: 'flex', gap: 'var(--s3)'}}>
<IconButton aria-label="Add">
<Plus />
</IconButton>
<IconButton variant="solid" aria-label="Add item">
<Plus />
</IconButton>
<IconButton variant="ghost" size="sm" aria-label="Add row">
<Plus />
</IconButton>
</div>
Examples
Variants
Props
IconButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label required | string | – | Required: what the button does, because there is no visible text. |
children required | ReactNode | – | An inline SVG with `currentColor` and `aria-hidden`. |
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 |
.btn | icon-button.css |
.btn-icon | icon-button.css |
.btn-sm | icon-button.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.
app.css
.btn {
border-color: var(--accent);
}
Accessibility
- Native button; aria-label is required by the type.
- Space and Enter activate it.
Keyboard
| Keys | Action |
|---|---|
| Space / Enter | Activate it |