Triggers an action. One or two primary buttons per screen, for the view’s main submission; everything else is secondary, outline or ghost.
Status: stable · Components: Button
Import
Section titled “Import”import { Button } from 'nacre'import { Text, View, signal } from 'nsh'import { Button, TEXT_SIZE } from 'nacre'
export function ButtonUsage() { const count = signal(0) return ( <View class="flex-row items-center gap-2"> <Button variant="primary" onPress={() => count.update((n) => n + 1)}> Save </Button> <Text class={`${TEXT_SIZE.small} text-muted-foreground tabular-nums`}>{count()}</Text> </View> )}Examples
Section titled “Examples”Variants
Section titled “Variants”primary is the only solid colored button, for key actions only; secondary is the default; outline is raised; ghost / subtle go in toolbars and rows; destructive is red text on a light red fill; link is for external links only.
import { View } from 'nsh'import { Button } from 'nacre'
export function ButtonVariants() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Button variant="primary">Primary</Button> <Button variant="secondary">Secondary</Button> <Button variant="outline">Outline</Button> <Button variant="ghost">Ghost</Button> <Button variant="subtle">Subtle</Button> <Button variant="destructive">Delete</Button> <Button variant="link">Link</Button> </View> )}tone changes only the color meaning, not the shape: warning is dark yellow text on a light yellow fill (actions to handle soon, like the after-call note); danger with primary is a solid red fill (hang up), and with other variants matches destructive. Only these two; arbitrary color classes are not open.
import { View } from 'nsh'import { Button } from 'nacre'
export function ButtonTones() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Button tone="warning" icon="pencil">Write note 00:42</Button> <Button tone="danger" variant="primary" size="md" icon="phone">Hang up</Button> <Button tone="danger" icon="refresh">Reconnect</Button> </View> )}xs / sm (default) / md / lg. Each label shows its height for the active style and platform. Use one size per row.
import { View, token } from 'nsh'import { Button } from 'nacre'
export function ButtonSizes() { return ( <View class="flex-row flex-wrap items-center gap-2"> {(['xs', 'sm', 'md', 'lg'] as const).map((size) => ( <Button size={size}>{`${size} ${Number(token(`control-h-${size}`))}`}</Button> ))} </View> )}With an icon
Section titled “With an icon”icon goes before the text, trailingIcon after it (the chevron of a disclosure). The icon size follows the button size.
import { View } from 'nsh'import { Button } from 'nacre'
export function ButtonWithIcon() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Button variant="primary" icon="plus"> New category </Button> <Button variant="outline" icon="export" trailingIcon="chevron-down"> Export </Button> <Button variant="secondary" icon="sparkles"> Fill with AI </Button> </View> )}Custom icon
Section titled “Custom icon”icon can also be a render function: the button hands it the size and color to use (following the size, variant and tone), for the app’s own icon set. children can nest another Text (a dimmer timer). The label always uses tabular numbers: timers and countdowns change every second, and proportional digits would make the button width and text position jump; when class narrows the button (flex-1 min-w-0) the label truncates instead of overflowing the row and pushing its neighbors out. align=“start” puts the content of a stretched button on the left, so the text start stays put as its length changes.
import { Text, View } from 'nsh'import { Button, Icon, TEXT_SIZE } from 'nacre'
export function ButtonCustomIcon() { return ( <View class="w-[280px] max-w-full gap-2"> <Button variant="primary" size="md" icon={(state) => ( <View class="items-center justify-center"> <Icon name="phone" size={state.size} color={state.color} /> <View class="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-primary-foreground" /> </View> )} > Answer <Text class={`${TEXT_SIZE.small} text-primary-foreground`}>00:12</Text> </Button> <Button tone="warning" align="start" testID="button-align-start" icon={(state) => <Icon name="pencil" size={state.size} color={state.color} />}> After-call work 01:29 </Button> <Button tone="warning" align="start" class="min-w-0" icon={(state) => <Icon name="pencil" size={state.size} color={state.color} />}> After-call work 01:29 · back to this call to write the note </Button> </View> )}Submitting
Section titled “Submitting”While loading, a loader replaces the leading icon and the button cannot be pressed again; its width does not change.
import { View, signal } from 'nsh'import { Button } from 'nacre'
export function ButtonLoading() { const busy = signal(false) const save = () => { busy.set(true) setTimeout(() => busy.set(false), 1500) } return ( <View class="flex-row items-center gap-2"> <Button variant="primary" loading={busy()} onPress={save}> Save </Button> <Button variant="outline" loading> Syncing </Button> </View> )}Disabled
Section titled “Disabled”A disabled button takes no hover, so no tooltip shows: say why it is disabled next to it (Dialog’s footerHint).
Phone: A disabled button drops to 40% and ignores taps; explain why next to it.
import { View } from 'nsh'import { Button } from 'nacre'
export function ButtonDisabled() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Button variant="primary" disabled> Primary </Button> <Button disabled>Secondary</Button> <Button variant="outline" disabled> Outline </Button> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus the button and show the focus ring |
| Space / Return | Press |
Accessibility
Section titled “Accessibility”- Screen readers read the button text; an icon-only button is an IconButton (label required).
- loading reads as busy; a disclosure button passes expanded, read as expanded / collapsed.
- A disabled button is not in the Tab order.
Do / Don’t
Section titled “Do / Don’t”Do
- One or two primary buttons per view
- Use destructive for dangerous actions, and confirm them
- Name the action on the button (“Save”, “Reassign”)
Don’t
- Use primary for ordinary actions
- Use link for in-page actions
- Mix size steps in one row
Button
Section titled “Button”| Prop | Type | Default | Description |
|---|---|---|---|
variant |
ButtonVariant |
'secondary' |
Visual treatment. Use primary for the main action. The default is secondary. |
size |
ButtonSize |
'sm' |
Control size. The default is sm. Use inline to place an action in a line of text. |
tone |
ButtonTone |
— | Semantic color treatment for the action. |
disabled |
boolean |
— | Prevents activation and exposes the disabled state to assistive technology. |
loading |
boolean |
— | Shows a spinner before the label and prevents another activation during submission. |
onPress |
(event: PressEvent) => void |
— | Receives the press event, including modifier keys. |
round |
boolean |
— | Uses a pill shape. |
testID |
string |
— | Test identifier for the root button. |
labelTestID |
string |
— | Test identifier for the label when its text changes. |
accessibilityLabel |
string |
— | Name of the action announced by assistive technology. |
class |
string |
— | Additional layout classes, such as width or flex sizing. |
align |
'center' | 'start' |
— | Center the contents by default. Use start to keep changing text aligned in a wide button. |
icon |
IconName | IconRender |
— | Leading icon name or render function. The spinner replaces it while loading. |
trailingIcon |
IconName |
— | Icon after the label, such as a disclosure chevron. |
iconColor |
ColorToken |
— | Icon color token. Defaults to the foreground color of the variant. |
tooltip |
TooltipContent | null |
— | Hover content, for example the reason an action is disabled. |
shortcut |
string | null |
— | Keyboard shortcut displayed in the tooltip. |
expanded |
boolean |
— | Open or closed state announced for a disclosure button. |
viewRef |
(node: ViewRef) => void |
— | Provides the root node for restoring focus. |
pressed |
boolean |
— | Keeps the pressed appearance while the attached menu is open. |
children |
JSX.Element |
— | Label or custom contents displayed in the button. |
* required