Button
A pressable button in five styles and four tones, with a light rim on solid fills, an optional glow, a press wash, labels that morph while the width springs, and loading in place.
npx @swipeui/cli add buttonWhen to use it
- The main action on a screen or form, such as Continue, Save or Sign in, as a solid button.
- Quieter choices next to it, such as Cancel, Skip or Edit, as tinted, outline, ghost or plain buttons.
- Destructive or confirming actions, such as Delete or Approve, in the destructive or success tone.
- Actions that call a server: loading blocks double taps, and the label can change to the result.
- A hero call to action at the bottom of a screen, as a large pill with a glow, or full width with block.
When not to use it
- Icon-only actions. Icon button requires a spoken label and sizes the icon for you.
- One save or submit that ends in a success tick or an error. Action button runs that whole lifecycle.
- On/off settings. Use Switch; for Follow and Following style states, use Toggle button.
- Delete actions that need a second step. Confirm morph adds confirmation and undo.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add button- Adds
components/swipeui/ui/button.tsx,components/swipeui/ui/button-styles.ts,components/swipeui/ui/button-palette.ts,components/swipeui/ui/button-spinner.tsx,components/swipeui/ui/use-button-press.tsand 8 shared helpers. - Installs class-variance-authority, react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Button } from '@/components/swipeui/ui/button';
<Button onPress={save}>Save changes</Button>
<Button variant="ghost" onPress={cancel}>Cancel</Button>String children are wrapped in Text. Other children inherit the label colour through TextClassContext.
Examples
import { Trash } from '@/components/icons'; // any SVG icon set
import { Button } from '@/components/swipeui/ui/button';
// A destructive action that doesn't shout: a soft red wash with a red label.
<Button
variant="tinted"
tone="destructive"
leadingIcon={({ color, size }) => <Trash color={color} size={size} />}
onPress={remove}
>
Delete
</Button>;import { ArrowRight } from '@/components/icons';
import { Button } from '@/components/swipeui/ui/button';
// A hero call to action: large pill, a glow in the tone's colour, an arrow that nudges forward.
<Button
size="lg"
shape="pill"
glow
trailingIcon={({ color, size }) => <ArrowRight color={color} size={size} />}
trailingIconNudge
onPress={start}
>
Get started
</Button>;import { Button } from '@/components/swipeui/ui/button';
// Loading in place, then the result in the same spot.
<Button
variant={saved ? 'tinted' : 'outline'}
tone={saved ? 'success' : undefined}
loading={saving}
loadingLabel="Saving"
onPress={save}
>
{saved ? 'Saved' : 'Save draft'}
</Button>;Icons can be any node. Pass a function instead and it receives { color, size }: the label colour for the button's style, tone and state, and 16, 18 or 20 points for sm, md and lg. That suits SVG icon sets, which can't inherit a text colour.
API reference
The other Pressable props, such as onLongPress and accessibilityHint, pass through.
Composition and behavior
- variant picks how much the button stands out:
solid(a filled call to action),tinted(a soft wash of the tone with a tone-coloured label),outline(a hairline),ghost(no fill until pressed) orplain(just text). The 1.x names still work:default,secondaryanddestructiveare solid primary, neutral and destructive. - tone picks the colour family:
primary,neutral,destructiveorsuccess. It defaults to primary for solid, tinted and plain, and to neutral for outline and ghost. - size is
sm(36pt, with a 44pt touch area),md(44pt) orlg(52pt). Corners follow your preset's control radius; shape="pill" makes a capsule. block fills the width. - Pressing scales the button on your feel's press spring and fades a soft wash over the surface; a plain button dims its label instead. The trailing icon can nudge forward while pressed.
- When the label changes, the new one rises in while the width springs to fit. labelMorph="characters" rolls only the letters that changed, which suits short swaps like Follow → Following.
- loading shows a thin ring spinner (drawn the same on iOS, Android and the web, and still under Reduce Motion) and ignores taps; loadingPlacement="center" hides the label and keeps the width so nothing around it moves.
- Solid buttons carry a faint rim of light along the top. Its colour is a material colour rather than a theme colour, so it lives in
button-palette.ts; change it with palette. - The style helpers live in
button-styles.ts, so your own pressables can match:buttonVariants({ variant: 'tinted', tone: 'success' })andbuttonTextVariants(...)return the classes.
Button settings
| Prop | Does | Default |
|---|---|---|
| variant | solid, tinted, outline, ghost or plain (or a 1.x name) | solid |
| tone | primary, neutral, destructive or success | primary; neutral for outline and ghost |
| size | sm, md or lg | md |
| shape | preset (your preset's control radius) or pill | preset |
| block | Fills the container's width | false |
| leadingIcon / trailingIcon | A node, or a function given { color, size } | none |
| trailingIconNudge | The trailing icon slides forward while pressed | false |
| pressEffect | both, scale, wash or none | both |
| highlight | The light rim on solid buttons | true |
| glow | A shadow in the tone's colour under solid buttons | false |
| palette | The rim's colour | BUTTON_PALETTE |
| labelMorph | fade, characters or none | fade |
| loading / loadingLabel | Spinner, busy state and an optional label | false |
| loadingPlacement | start (replaces the leading icon) or center (holds the width) | start |
| disabledStyle | muted (muted fill and label) or dim (half opacity) | muted |
| haptics | A light tap on press | true |
| motion | A local motion feel or override | the app's feel |
singleLine defaults to false. Set it to true for compact string and loading labels; their text clips on one line while the frame changes width. Native motion timing is unchanged.
| Setting | Default | Behavior |
|---|---|---|
singleLine | false | Keep string/loading labels on one clipped line. |
Behavior and gestures
- Pressing scales the button on the press spring and fades a soft wash over its surface; pressEffect chooses both, scale, wash or none. Text-only (plain) buttons dim their label instead.
- A light haptic tap plays on press; haptics={false} turns it off.
- With trailingIconNudge, the trailing icon slides a few points forward while pressed, mirrored in right-to-left layouts.
- When the label changes, the new one rises in as the old one fades (labelMorph="fade"), or only the changed letters roll in ("characters"); the width springs to fit. "none" swaps it at once.
- While loading, a thin ring spinner (the same on iOS, Android and the web) replaces the leading icon (loadingPlacement="start") or sits in the centre with the label hidden and the width held ("center"); loadingLabel can swap the text, and taps are ignored.
- Disabled buttons mute their fill and label (disabledStyle="muted") or halve their opacity ("dim"), and ignore taps.
- highlight draws a faint rim of light along the top of solid buttons, glow adds a soft shadow in the tone's colour, and palette changes the rim's colour.
- Small buttons look 36 points tall but respond to a 44-point touch area.
Accessibility
- Announced as a button with its text as the name; pass accessibilityLabel when the content isn't plain text.
- Disabled and loading states are reported, and loading is announced as busy.
- Icons, the wash, the light rim and the spinner are decorative and skipped by screen readers; a label that morphs letter by letter is still read as one word.
- Every size keeps at least a 44-point touch target, and labels grow with Dynamic Type and wrap instead of clipping.
- Label colours come from your preset for each style and tone, so contrast holds in light and dark.
Motion
- Uses the
ambient,morphandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Press: the scale and the trailing-icon nudge use the press spring and your feel's press scale; the wash fades on the press role's fade and exit timings.
- Morph: label changes and the width use the morph spring; characters mode staggers only the letters that changed.
- Labels already on screen when the button mounts don't animate in, so screens open quietly.
- Reduce Motion removes the scale, the nudge, the rise and the width spring; labels cross-fade, the wash still shows, and the loading ring holds still while busy is announced.
- Ambient: the loading ring turns twice per ambient period at a steady speed.
- A button that unmounts (say, when a screen changes) leaves at once; only a label that changes inside a mounted button animates out.
Performance
- Press feedback runs on the UI thread with shared values and never re-renders the label.
- Styles are class strings; changing variant or tone costs nothing at runtime.
- characters mode renders one view per letter, so keep it for a few buttons rather than long lists.
Notes for AI
- Use one solid primary button per area; make the rest tinted, outline, ghost or plain.
- Use tone for meaning: destructive for Delete, success for Approve. Prefer tinted destructive over solid unless the action is the screen's main one.
- Pass icons as render functions so they get the right colour and size: leadingIcon={({ color, size }) => <Plus color={color} size={size} />}.
- Set loading during async work instead of disabling and re-enabling manually; use Action button for a full success/error lifecycle.
- Give icon-only content an accessibilityLabel, or use Icon button.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.