Button
Flat, raised, and floating actions with the original Material ripple.
Installation
pnpm dlx shadcn@latest add https://react-toolbox.io/r/button.jsonNew here? Set up your project first. Styles, fonts, and required components are included.
Usage
Give IconButton and other icon-only buttons an aria-label. Use asChild with a single ref-forwarding router link to apply button styles and behavior without nesting interactive elements. BrowseButton opens a native file picker.
Composition
Pending actions expose their busy state and prevent repeated submission. The editable example reports success or failure and allows another attempt. Pass your application’s save callback to onSave.
pnpm dlx shadcn@latest add https://react-toolbox.io/r/example-recipes.jsonShow composition code
'use client';
import { LoadingButtonRecipe } from '@/components/ui/examples/recipes';
/** Simulate application work without sending example data. */
function saveChanges() {
return new Promise<void>((resolve) => setTimeout(resolve, 700));
}
export default function ButtonComposition() {
return <LoadingButtonRecipe onSave={saveChanges} />;
}
State and callbacks
BrowseButton reports files through onChange's input event. File selection cannot be set with value; use inputRef to clear the native input.
API reference
Key props and defaults. Full types and inline documentation are included with the source in material/button.
Button
| Property | Type | Default |
|---|---|---|
accent | boolean | false |
asChild | (false) | (true)Merge behavior and styles into one ref-forwarding child, such as a router Link. | false |
floating | boolean | — |
mini | boolean | — |
primary | boolean | false |
raised | boolean | — |
BrowseButton
| Property | Type | Default |
|---|---|---|
accept | string | '*/*' |
multiple | boolean | false |
onChange | ChangeEventHandler<HTMLInputElement> | — |
Material guidelines
- Use flat buttons in dialogs and toolbars. A raised button adds emphasis where the surrounding layout needs a more prominent action.
- The standard text button has a 36px visible height, an 88px minimum width, and a 48px touch target. Use concise action labels and retain the built-in press feedback.
- Reserve a floating action button for the screen’s primary action; give its icon an accessible name.