SwipeUI

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 button
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.ts and 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 install so versions match your SDK.

Usage

app/settings.tsx
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

app/item.tsx
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>;
app/welcome.tsx
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>;
app/editor.tsx
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

PropTypeDefaultDescription
layout?union—

Optional layout transition for composed controls; derive its values from useMotion.

motion?MotionOverridethe app's feel (`smooth` without a provider)

The app's press character, or a local override. The app's motion feel, or a local override for the press, label and width springs.

haptics?booleantrue

Impact feedback on activation. Disable when a parent already provides feedback. Plays a light impact on press.

childrenReactNode—

The label. Strings are wrapped in Text; other nodes inherit the label colour.

variant?ButtonVariant'solid'

How much the button stands out: solid, tinted (a soft wash of the tone), outline, ghost (no fill until pressed) or plain (text only). The 1.x names default, secondary and destructive still work as solid primary, neutral and destructive.

tone?ButtonTone'primary' for solid, tinted and plain; 'neutral' for outline and ghost

The colour family: primary, neutral, destructive or success.

size?ButtonSize'md'

The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt.

shape?ButtonShape'preset'

preset follows your preset's control radius; pill is a capsule.

block?booleanfalse

Stretches the button to the full width of its container.

leadingIcon?ButtonIcon—

Content before the label: a node, or a function that receives { color, size }.

trailingIcon?ButtonIcon—

Content after the label: a node, or a function that receives { color, size }.

trailingIconNudge?booleanfalse

Slides the trailing icon a little forward while pressed, mirrored in right-to-left layouts.

loading?booleanfalse

Shows a spinner, reports busy and ignores taps.

loadingLabel?string—

Label shown while loading; defaults to the children.

loadingPlacement?ButtonLoadingPlacement'start'

Where the spinner goes: start replaces the leading icon; center hides the label and holds the width.

singleLine?booleanfalse

Keep string labels and loading words on one clipped line.

labelMorph?ButtonLabelMorph'fade'

How a changed text label arrives: fade (the new label rises in as the old one fades), characters (only the changed letters roll in) or none. The width springs to fit either way.

highlight?booleantrue

A faint rim of light along the top edge of solid buttons.

glow?booleanfalse

A soft shadow in the tone's colour under solid buttons.

pressEffect?ButtonPressEffect'both'

Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing.

disabledStyle?ButtonDisabledStyle'muted'

How a disabled button looks: muted mutes its fill and label; dim halves its opacity.

glassStatus?ThemeSurfaceTone—

Keeps a completed or failed action’s Glass status visible when the control is locked.

palette?Partial<ButtonPalette>BUTTON_PALETTE

Colours that belong to the button's material rather than the theme (the top highlight).

className?string—

Classes merged over the style.

textClassName?string—

Classes for the label text.

style?StyleProp<ViewStyle>—

Style escape hatch for the container.

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) or plain (just text). The 1.x names still work: default, secondary and destructive are solid primary, neutral and destructive.
  • tone picks the colour family: primary, neutral, destructive or success. 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) or lg (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' }) and buttonTextVariants(...) return the classes.

Button settings

PropDoesDefault
variantsolid, tinted, outline, ghost or plain (or a 1.x name)solid
toneprimary, neutral, destructive or successprimary; neutral for outline and ghost
sizesm, md or lgmd
shapepreset (your preset's control radius) or pillpreset
blockFills the container's widthfalse
leadingIcon / trailingIconA node, or a function given { color, size }none
trailingIconNudgeThe trailing icon slides forward while pressedfalse
pressEffectboth, scale, wash or noneboth
highlightThe light rim on solid buttonstrue
glowA shadow in the tone's colour under solid buttonsfalse
paletteThe rim's colourBUTTON_PALETTE
labelMorphfade, characters or nonefade
loading / loadingLabelSpinner, busy state and an optional labelfalse
loadingPlacementstart (replaces the leading icon) or center (holds the width)start
disabledStylemuted (muted fill and label) or dim (half opacity)muted
hapticsA light tap on presstrue
motionA local motion feel or overridethe 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.

SettingDefaultBehavior
singleLinefalseKeep 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, morph and press motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items