Alert

An alert with a title, message, and up to two action buttons.

Note:

All actions in an alert dismiss the alert after the action runs. If no actions are present, a standard “OK” action is included.

Preview

Button Preview

Code Example

let model = AlertVM { alertVM in
  alertVM.title = "My Alert"
  alertVM.message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
  alertVM.primaryButton = .init { buttonVM in
    buttonVM.title = "OK"
    buttonVM.color = .primary
    buttonVM.style = .filled
  }
  alertVM.secondaryButton = .init { buttonVM in
    buttonVM.title = "Cancel"
    buttonVM.style = .light
  }
}

API

AlertVM Props

A model that defines the appearance properties for an alert.

NameTypeDefaultDescription
titleString?nilThe title of the alert.
messageString?nilThe message of the alert.
primaryButtonAlertButtonVM?nilThe model that defines the appearance properties for a primary button in the alert. If it is nil, the primary button will not be displayed.
secondaryButtonAlertButtonVM?nilThe model that defines the appearance properties for a secondary button in the alert. If it is nil, the secondary button will not be displayed.
backgroundColorUniversalColor?nilThe background color of the alert.
borderWidthBorderWidthsmallThe border thickness of the alert.
closesOnOverlayTapBoolfalseA Boolean value indicating whether the alert should close when tapping on the overlay.
contentPaddingsPaddings16The padding applied to the alert's content area.
cornerRadiusContainerRadiusmediumThe corner radius of the alert.
overlayStyleModalOverlayStyledimmedThe style of the overlay displayed behind the alert.
transitionModalTransitionfastThe transition duration of the alert's appearance and dismissal animations.

AlertButtonVM Props

A model that defines the appearance properties for a button in the alert.

NameTypeDefaultDescription
titleString""The text displayed on the button.
animationScaleAnimationScalemediumThe scaling factor for the button's press animation, with a value between 0 and 1.
colorComponentColor?nilThe color of the button.
cornerRadiusComponentRadiusmediumThe corner radius of the button.
styleButtonStylefilledThe visual style of the button.

SUAlert

  • A SwiftUI view modifier that presents an alert with a Boolean value.
public func suAlert(
  isPresented: Binding<Bool>,
  model: AlertVM,
  primaryAction: (() -> Void)? = nil,
  secondaryAction: (() -> Void)? = nil,
  onDismiss: (() -> Void)? = nil
) -> some View
  • A SwiftUI view modifier that presents an alert with an optional Item.
public func suAlert<Item: Identifiable>(
  item: Binding<Item?>,
  model: @escaping (Item) -> AlertVM,
  primaryAction: ((Item) -> Void)? = nil,
  secondaryAction: ((Item) -> Void)? = nil,
  onDismiss: (() -> Void)? = nil
) -> some View

UKAlertController

Initializers

public init(
  model: AlertVM,
  primaryAction: (() -> Void)? = nil,
  secondaryAction: (() -> Void)? = nil
)

Public Properties

NameTypeDescription
modelAlertVMA model that defines the appearance properties for an alert.
primaryAction(() -> Void)?The primary action to be executed when the primary button is tapped.
secondaryAction(() -> Void)?The secondary action to be executed when the secondary button is tapped.

Public Subviews

NameTypeDescription
titleLabelUILabelThe label used to display the title of the alert.
subtitleLabelUILabelThe label used to display the subtitle or message of the alert.
primaryButtonUKButtonThe button representing the primary action in the alert.
secondaryButtonUKButtonThe button representing the secondary action in the alert.
buttonsStackViewUIStackViewA stack view that arranges the primary and secondary buttons.