Button

Interactive element used for single-step actions

Available from v7.0.0

BB.Button

BB.Button is a customizable SwiftUI button component with various appearances, layouts, and functionalities.


Platform availability: iOS 17.0+


When to use:

  • Use BB.Button when you need interactive elements that trigger actions, such as form submissions, confirmations, or navigation.
  • Consider BB.Link for text-based navigation or BB.IconButton when space is limited and an icon alone suffices.

Import


                                                        
                                                        
                                                            import SwiftUI
                                                        import BackbaseDesignSystem
                                                        
                                                            

Visual reference

 

 

 

 

 

 

 

API reference

Enumerations

Appearance

Represents different visual styles of the button.

  • primary
  • onColorPrimary
  • secondary
  • onColorSecondary
  • tertiary
  • onColorTertiary
  • success
  • danger

Layout

Defines the size variants of the button.

  • small
  • medium

Initializers

init(text:appearance:layout:action:)

Initializes a new button instance.

Parameter

Type

Description

text

String

The text displayed on the button

appearance

Appearance

The visual style of the button (default: .primary)

layout

Layout

The size of the button (default: .medium)

action

@escaping () -> Void

The action to execute when the button is tapped

Methods

expanded(_:)

Controls whether the button should expand to fill its container.

Parameter

Type

Description

expanded

Bool

Determines if the button is expanded or not

Returns: BB.Button - The modified button view

showIndicator(_:)

Toggles the visibility of a loading indicator on the button.

Parameter

Type

Description

show

Bool

Indicates whether to show the loading indicator

Returns: BB.Button - The modified button view

icon(_:)

Sets an icon to be displayed next to the button text.

Parameter

Type

Description

image

Image?

The icon image to display (optional)

Returns: BB.Button - The modified button view

Usage

Basic usage

Create a simple button with a tap action.


                                                        
                                                        
                                                            import SwiftUI
                                                        import BackbaseDesignSystem
                                                        
                                                        struct ContentView: View {
                                                            var body: some View {
                                                                BB.Button(text: "Click Me") {
                                                                    print("Button tapped!")
                                                                }
                                                            }
                                                        }
                                                        
                                                            

Advanced usage

Combine multiple modifiers for a fully customized button.


                                                        
                                                        
                                                            import SwiftUI
                                                        import BackbaseDesignSystem
                                                        
                                                        struct ContentView: View {
                                                            var body: some View {
                                                                BB.Button(text: "Submit", appearance: .success, layout: .small) {
                                                                    // Handle submission
                                                                }
                                                                .expanded(true)
                                                                .showIndicator(true)
                                                                .icon(Image(systemName: "checkmark"))
                                                                .disabled(true)
                                                            }
                                                        }
                                                        
                                                            

States and variants

Appearance variants

Appearance

Description

.primary

Primary call-to-action with filled brand background

.onColorPrimary

Primary button for use on colored backgrounds

.secondary

Secondary action with brand border

.onColorSecondary

Secondary button for use on colored backgrounds

.tertiary

Tertiary action with minimal styling

.onColorTertiary

Tertiary button for use on colored backgrounds

.success

Success-themed button for confirmations

.danger

Danger-themed button for destructive actions

Layout variants

Layout

Description

.small

Compact button for constrained spaces

.medium

Standard button size (default)

Button states

State

Description

Default

Normal interactive state

Pressed

Visual feedback when button is being pressed

Disabled

Non-interactive state with reduced opacity

Loading

Shows activity indicator, button is disabled

Customization

Best practices

  • Use the primary appearance for the most important action in a view.
  • Reserve the danger appearance for actions that are irreversible or could result in data loss.
  • Choose the button layout that fits best with your layout and design considerations.
  • Always provide a meaningful title that clearly indicates the action the button performs.

Accessibility

This component can be configured with accessibility features at the integration level. Use the standard SwiftUI accessibility modifiers to ensure a fully accessible experience for all users.

Accessibility configuration

Modifier

Description

.accessibilityLabel(_:)

Sets the accessibility label for screen readers

.accessibilityHint(_:)

Provides additional context for the action

.accessibilityValue(_:)

Sets the current value for the element

Best practices

  • Provide meaningful accessibility labels that describe the element's purpose.
  • Use accessibility hints to provide additional context when needed.
  • Ensure all interactive elements are accessible.

                                                        
                                                        
                                                            BB.Button(text: "Submit") {
                                                            // Handle action
                                                        }
                                                        .accessibilityLabel("Submit form")
                                                        .accessibilityHint("Double tap to submit your information")
                                                        
                                                            

Dependencies

  • External dependencies: None
  • Internal dependencies: BackbaseDesignSystem

Design tokens

Component styling is applied automatically through the design system's theming infrastructure.

JSON tokens

Tokens are defined in defaultTokens.json, which is integrated in the bundle of the framework, and can be customized by providing your own theme JSON file.
Token groups used by Button:

  • theme.color.button.primary: Primary button variant colors
  • theme.color.button.secondary: Secondary button variant colors
  • theme.color.button.tertiary: Tertiary button variant colors
  • theme.color.button.success: Success button variant colors
  • theme.color.button.danger: Danger button variant colors

Default state tokens (primary example):

Token

JSON Path

Default Value

Background

theme.color.button.primary.default.background

{theme.color.background.brand}

Foreground

theme.color.button.primary.default.foreground

{theme.color.on-background.brand}

Border

theme.color.button.primary.default.border

{theme.color.border.none}

Pressed state tokens:

Token

JSON Path

Default Value

Background

theme.color.button.primary.pressed.background

{theme.color.background.brand-pressed}

Foreground

theme.color.button.primary.pressed.foreground

{theme.color.on-background.brand}

Dimension tokens:

Token

JSON Path

Default Value

Radius

theme.dimension.radius.button.default

99 (fully rounded)

Height (small)

theme.dimension.height.button.sm

32

Height (medium)

theme.dimension.height.button.md

44

Semantic tokens

These tokens are accessed via the public DesignSystem.shared API.

Token

API Reference

Description

Colors

Theme.colors

Button foreground and background colors

Typography

DesignSystem.shared.typography

Button text styling

Corner Radius

DesignSystem.shared.cornerRadius

Button corner radius

See also

  • BB.Chip - Compact interactive element for filtering
  • BB.Badge - Non-interactive status indicator