portico/Sources/Portico/Presentation/AlertResponse.swift

41 lines
1.4 KiB
Swift

import Adw
/// One response button on an ``AlertDialog``.
///
/// `AdwAlertDialog` shows no buttons until responses are added, so an alert
/// without at least one response can only be dismissed with Escape. The
/// `defaultResponse` and `closeResponse` identifiers passed to
/// ``View/alert(isPresented:heading:body:defaultResponse:closeResponse:responses:_:extraChild:)``
/// must name a response added beforehand.
public struct AlertResponse {
/// The response identifier reported to the response handler.
public let id: String
/// The button label. An underscore marks the mnemonic character.
public let label: String
/// The button's visual appearance.
public let appearance: ResponseAppearance
/// Whether the button is clickable.
public let isEnabled: Bool
/// Creates a response button.
///
/// - Parameters:
/// - id: The response identifier reported to the response handler.
/// - label: The button label. An underscore marks the mnemonic character.
/// - appearance: Visual appearance. Defaults to ``ResponseAppearance/default``.
/// - isEnabled: Whether the button is clickable. Defaults to `true`.
public init(
id: String,
label: String,
appearance: ResponseAppearance = .default,
isEnabled: Bool = true
) {
self.id = id
self.label = label
self.appearance = appearance
self.isEnabled = isEnabled
}
}