Icon button
The Button palette in an icon target with selection morphs, badge counts and three shapes.
npx @swipeui/cli add icon-buttonWhen 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.tsand 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 installso versions match your SDK.
Usage
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
| Setting | Default | Behavior |
|---|---|---|
children | undefined | Existing icon node; primitive glyphs remain supported. |
icon | undefined | Node or color/size render function, preferred over children. |
accessibilityLabel | absent | Required spoken action name. |
shape | 'circle' | Circular by default; preset follows theme corners, square has none. |
selected | undefined | Controlled toggle selection. |
defaultSelected | false | Initial uncontrolled selection; providing it enables toggle semantics. |
onSelectedChange | undefined | Receives selection requests. |
selectedIcon | undefined | Alternate icon node/render function for selection, crossfaded on morph role. |
morph | undefined | Authored icon pair scrubbed by selection, preferred over swapping nodes. |
effects | true | Morph one-shot effects independent of icon transition. |
badge | undefined | Dot (true) or numeric count; undefined hides it. |
badgeCap | 99 | Maximum printed badge count; higher values append +. |
badgeTone | 'destructive' | Badge status tone. |
announceBadge | true | Include 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 ghost | The colour family: primary, neutral, destructive or success. |
size | 'md' | The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt. |
loading | false | Shows a spinner, reports busy and ignores taps. |
loadingLabel | absent | Label 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. |
highlight | true | A faint rim of light along the top edge of solid buttons. |
glow | false | A 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. |
palette | BUTTON_PALETTE | Colours that belong to the button's material rather than the theme (the top highlight). |
haptics | true | Plays a light impact on press. |
motion | the app's feel (smooth without a provider) | The app's motion feel, or a local override for the press, label and width springs. |
className | absent | Classes merged over the style. |
textClassName | absent | Classes for the label text. |
style | absent | Style escape hatch for the container. |
disabled | false | Prevent activation and expose unavailable state. |
testID | undefined | Root 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
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,morphandnumbermotion roles, so it follows your app's feel. Passmotionto 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 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.