suiss/ui · Component
Button
A pill-shaped button that triggers an action, with variants for every level of emphasis.
Button is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Button renders a native button by default. It supports eight visual variants, five text sizes and five icon-only sizes, and an optional block mode that fills the container width.
Use the default variant for the primary action in a view, secondary, tinted or outline for supporting actions, ghost and plain for low-emphasis actions, and destructive for actions that delete or remove. To join several buttons into one control, use Button Group.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/button.tsx:
- Update the import paths to match your project.
Usage
Mark icons with data-icon="inline-start" or data-icon="inline-end" to tighten the padding on that side. Icons without a size class are sized automatically.
Use an icon size, such as icon or icon-sm, for buttons that contain only an icon, and give them an aria-label.
To render a link or a router component with button styling, use the render prop from Base UI. buttonVariants is also exported if you need the classes on another element.
To render a link or a router component with button styling, set asChild and pass it as the child. buttonVariants is also exported if you need the classes on another element.
Button always renders a button. To give a link or a router component button styling, apply the classes from buttonVariants to it.
Examples
Variants
Shows all eight variants side by side.
Sizes
Compares the xs, sm, default and lg sizes.
With icon
Adds leading and trailing icons, and an icon-only button.
Disabled
A disabled button that is skipped in the tab order.
Block
Full-width buttons at each size, whose corner radius scales with size.
API Reference
Button
The interactive button element.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "default" | Visual style: default, outline, secondary, tinted, ghost, plain, destructive or link. |
size | "default" | "xs" | "sm" | "lg" | "xl" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl" | "default" | Height and padding. xs to xl for text buttons; icon-xs to icon-xl for square icon-only buttons. |
block | true | - | When true, the button fills the container width and uses rounded corners instead of a pill shape. |
Also accepts the props of the primitive part it wraps.
Accessibility
- Renders a native
button, soEnterandSpaceactivate it. - A disabled button is removed from the tab order.
- Icon-only buttons need an
aria-label. - Keyboard focus shows a 3px ring in
--ring; thedestructivevariant tints it withring-destructive/20. aria-invalidadds a destructive border and ring, andaria-expandedshows a selected background onoutline,ghostandplainbuttons that open menus or popovers.
Notes
- Styling hook:
data-slot="button". - Colors come from the
primary,secondary,accentanddestructivevariables. Hover uses the same color with an opacity, such ashover:bg-primary/80, and disabled buttons useopacity-50. - Buttons in a group raise the focused one above its neighbors so the whole ring stays visible.
Button is a Pressable with the button role. It supports eight visual variants, five text sizes and five icon-only sizes, and an optional block mode that fills the width of its container.
Use the default variant for the primary action on a screen, secondary, tinted or outline for supporting actions, ghost and plain for low-emphasis actions, and destructive for actions that delete or remove. To join several buttons into one control, use Button Group.