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
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
Variants
Use the variant prop to set the level of emphasis. This shows all eight variants side by side.
Sizes
Use the size prop to change the height and padding. This compares the xs, sm, default and lg sizes.
With icon
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. For a button that contains only an icon, use an icon size, such as icon or icon-sm, and give it an aria-label.
Disabled
Set the disabled attribute to dim the button and skip it in the tab order.
Block
Set block to make the button fill its container. Block buttons use rounded corners that scale with size instead of a pill shape.
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.
API Reference
Button
The interactive button element.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "default" |
size | "default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl" | "default" |
block | true | - |
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of the primitive part it wraps.
The xs to xl sizes are for text buttons, and form is a 50px text button that sits beside lg fields and turns into a 12px rounded rectangle with block; icon-xs to icon-xl are square sizes for icon-only buttons. block fills the container width and swaps the pill shape for rounded corners.
To render a link or a router component with button styling, use the render prop. 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.
Hover uses the variant color with an opacity, such as hover:bg-primary/80, and disabled buttons use opacity-50. In a group, the focused button is raised above its neighbors so the whole ring stays visible. Style a button through data-slot="button".
Web preview
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.
Installation
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Variants
All eight variants, plus an icon-only button.
Use the variant prop to set the level of emphasis.
Web preview
Sizes
Compares the text and icon-only sizes.
Use the size prop to change the height and padding.
Web preview
With icon
Leading and trailing icons, and an icon-only button.
Give an icon-only button an icon size and an accessibilityLabel.
Web preview
Disabled
Disabled buttons in every variant.
Set disabled to dim the button and block presses.
Web preview
Block
Full-width buttons at each size, whose corner radius scales with size, ending with the form size.
Web preview
Accessibility
- Renders a
Pressablewithrole="button", so VoiceOver and TalkBack announce it as a button. disabledis announced and blocks presses.- Icon-only buttons need an
accessibilityLabel.
API Reference
Button
The interactive button element.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "default" |
size | "xs" | "sm" | "default" | "lg" | "xl" | "form" | "icon-xs" | "icon-sm" | "icon" | "icon-lg" | "icon-xl" | "default" |
block | boolean | - |
Also accepts the props of PressableProps.
icon sizes are square, for buttons that contain only an icon. form is 50 tall with 15 point semibold text, to sit beside lg fields, and turns into a 12 point rounded rectangle with block. block stretches the button to the full width of its container. Put the label in a Text and icons in an Icon; the button passes its text color and icon size down through context, so children pick them up without extra classes. buttonVariants and buttonTextVariants are also exported if you need the classes on another element. Pressed buttons use opacity-80 and disabled buttons opacity-50, and colors follow the system appearance.
.buttonStyle(.variant)
Style that creates VariantButtonStyle.
| Parameter | Type | Default |
|---|---|---|
_ variant | VariantButtonStyle.Variant: .default | .outline | .secondary | .tinted | .ghost | .plain | .destructive | .link | .default |
size | VariantButtonStyle.Size: .default | .xs | .sm | .lg | .xl | .form | .icon | .iconXs | .iconSm | .iconLg | .iconXl | .default |
block | Bool | false |
ButtonVariant
Values: Default, Outline, Secondary, Tinted, Ghost, Plain, Destructive, Link.
ButtonSize
Values: Default, Xs, Sm, Lg, Xl, Form, Icon, IconXs, IconSm, IconLg, IconXl.
Button
The interactive button element.
| Parameter | Type | Default |
|---|---|---|
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | ButtonVariant: Default | Outline | Secondary | Tinted | Ghost | Plain | Destructive | Link | ButtonVariant.Default |
size | ButtonSize: Default | Xs | Sm | Lg | Xl | Form | Icon | IconXs | IconSm | IconLg | IconXl | ButtonSize.Default |
block | Boolean | false |
enabled | Boolean | true |
content | @Composable RowScope.() -> Unit | - |
text | String | - |
Overloads: Button(onClick, content), Button(text, onClick).