SwipeUI

Icon button

The Button palette in an icon target with selection morphs, badge counts and three shapes.

npx @swipeui/cli add icon-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

  • Give a compact action a required accessible name.
  • Toggle an authored morph pair or a caller-supplied selected icon.

When not to use it

  • Hide an important action behind an unexplained symbol.
  • Use a label and total in a checkout flow; use Checkout button.

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 icon-button
  • Adds components/swipeui/ui/icon-button.tsx, components/swipeui/ui/use-icon-button.ts and 13 shared helpers.
  • Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/actions.tsx
import { IconButton } from '@/components/swipeui/ui/icon-button';

<IconButton accessibilityLabel="Save" morph="bookmark-filled" badge={3} variant="tinted" />;

Examples

styles, toggles, badges. The app and public preview use the same content and variant names. Demo settings sit outside the component and outcome feedback stays on the action.

Settings

SettingDefaultBehavior
childrenundefinedExisting icon node; primitive glyphs remain supported.
iconundefinedNode or color/size render function, preferred over children.
accessibilityLabelabsentRequired spoken action name.
shape'circle'Circular by default; preset follows theme corners, square has none.
selectedundefinedControlled toggle selection.
defaultSelectedfalseInitial uncontrolled selection; providing it enables toggle semantics.
onSelectedChangeundefinedReceives selection requests.
selectedIconundefinedAlternate icon node/render function for selection, crossfaded on morph role.
morphundefinedAuthored icon pair scrubbed by selection, preferred over swapping nodes.
effectstrueMorph one-shot effects independent of icon transition.
badgeundefinedDot (true) or numeric count; undefined hides it.
badgeCap99Maximum printed badge count; higher values append +.
badgeTone'destructive'Badge status tone.
announceBadgetrueInclude the badge in the accessible name.
variant'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'primary' for solid, tinted and plain; 'neutral' for outline and ghostThe colour family: primary, neutral, destructive or success.
size'md'The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt.
loadingfalseShows a spinner, reports busy and ignores taps.
loadingLabelabsentLabel shown while loading; defaults to the children.
loadingPlacement'center'Where the spinner goes: center replaces the glyph in the middle of the button; start puts it beside the glyph.
labelMorph'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.
highlighttrueA faint rim of light along the top edge of solid buttons.
glowfalseA soft shadow in the tone's colour under solid buttons.
pressEffect'both'Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing.
disabledStyle'muted'How a disabled button looks: muted mutes its fill and label; dim halves its opacity.
paletteBUTTON_PALETTEColours that belong to the button's material rather than the theme (the top highlight).
hapticstruePlays a light impact on press.
motionthe app's feel (smooth without a provider)The app's motion feel, or a local override for the press, label and width springs.
classNameabsentClasses merged over the style.
textClassNameabsentClasses for the label text.
styleabsentStyle escape hatch for the container.
disabledfalsePrevent activation and expose unavailable state.
testIDundefinedRoot identifier; parts append suffixes.

Composition and behavior

Use icon for a themed color/size render function, children for existing nodes, or morph for a built-in pair such as bookmark-filled. Keep the accessible name meaningful. Badge tone, announcement, effects, selection and surface styling are independent.

Shared styles, tones, sizes and press feedback retain legacy variant names. circle is the new default; preset and square remain explicit choices.

selected/defaultSelected/onSelectedChange enable toggle use. morph drives an authored IconMorph pair; selectedIcon crossfades an alternate node or render function.

badge accepts a dot or count, caps printed counts through badgeCap and optionally includes the uncapped total in the spoken name.

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.

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.

loading?booleanfalse

Shows a spinner, reports busy and ignores taps.

loadingLabel?string—

Label shown while loading; defaults to the children.

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.

loadingPlacement?ButtonLoadingPlacement'center'

Where the spinner goes while loading. An icon button has no room beside its glyph, so the spinner replaces it in the centre.

children?ReactNodeundefined

Existing icon node; primitive glyphs remain supported.

icon?ButtonIconundefined

Node or color/size render function, preferred over children.

accessibilityLabelstring—

Required spoken action name.

shape?"circle" | "preset" | "square"'circle'

Circular by default; preset follows theme corners, square has none.

selected?booleanundefined

Controlled toggle selection.

defaultSelected?booleanfalse

Initial uncontrolled selection; providing it enables toggle semantics.

onSelectedChange?((selected: boolean) => void)undefined

Receives selection requests.

selectedIcon?ButtonIconundefined

Alternate icon node/render function for selection, crossfaded on morph role.

morph?unionundefined

Authored icon pair scrubbed by selection, preferred over swapping nodes.

effects?booleantrue

Morph one-shot effects independent of icon transition.

badge?number | booleanundefined

Dot (true) or numeric count; undefined hides it.

badgeCap?number99

Maximum printed badge count; higher values append +.

badgeTone?ButtonTone'destructive'

Badge status tone.

announceBadge?booleantrue

Include the badge in the accessible name.

Review gates

Founder app and existing pnpm-dev visual acceptance remains open. Native runtime, VoiceOver/TalkBack, haptics, motion, Dynamic Type, RTL and recordings remain pending founder-scheduled 7.9. Source, bundle and unit checks do not establish visual or native acceptance.

Styles demonstrate an authored plus-check morph. Caller-supplied selectedIcon nodes crossfade in persistent layers. Badges anchor to the whole 36/44/52pt frame; capped counts such as 99+ stay horizontal. The full count remains in the accessible name.

Behavior and gestures

  • Shared styles, tones, sizes and press feedback retain legacy variant names. circle is the new default; preset and square remain explicit choices.
  • selected/defaultSelected/onSelectedChange enable toggle use. morph drives an authored IconMorph pair; selectedIcon crossfades an alternate node or render function.
  • badge accepts a dot or count, caps printed counts through badgeCap and optionally includes the uncapped total in the spoken name.
  • Styles use authored plus-check path morphs. Badges anchor to the full control frame; capped counts stay on one line, with unchanged full-count spoken labels.

Accessibility

  • Named controls expose unavailable, busy and selected/progress state where applicable. Decorative layers are excluded from interaction.
  • Meaningful outcome/availability announcements are distinct from clocks and decorative effects. Native VoiceOver/TalkBack, Dynamic Type, RTL and touch evidence remain pending for 7.9.

Motion

  • Uses the press, morph and number motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Every decorative duration/spring comes from the shared role helpers. Content clocks remain independent of motion feel.
  • Reduce Motion retains readable outcome/progress feedback. Native motion/performance review remains pending.

Performance

  • No new package, network service, telemetry or proprietary source.
  • Async results and content timers clean up or invalidate after unmount; UI animation values stay on the UI thread.

Notes for AI

  • Use icon for a themed color/size render function, children for existing nodes, or morph for a built-in pair such as bookmark-filled. Keep the accessible name meaningful. Badge tone, announcement, effects, selection and surface styling are independent.
  • Founder app/web acceptance and all native runtime, accessibility, haptics, motion and recordings remain pending for 7.9.

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