Add suggested content dialog responses
This commit is contained in:
parent
821ba1f006
commit
8ec85b877f
@ -19,9 +19,9 @@ public struct ContentDialog: WinUIWidget {
|
||||
/// The body text.
|
||||
var body: Body
|
||||
/// The primary response.
|
||||
var primary: (String, () -> Void)?
|
||||
var primary: (String, Bool, () -> Void)?
|
||||
/// The secondary response.
|
||||
var secondary: (String, () -> Void)?
|
||||
var secondary: (String, Bool, () -> Void)?
|
||||
/// The close response.
|
||||
var close: (String, () -> Void)?
|
||||
/// The child view.
|
||||
@ -114,17 +114,24 @@ public struct ContentDialog: WinUIWidget {
|
||||
/// - storage: The view storage.
|
||||
func updateDialogProperties(dialog: WinUI.ContentDialog, storage: ViewStorage) {
|
||||
dialog.title = title
|
||||
let suggested = Application.current.resources.lookup("AccentButtonStyle") as? Style
|
||||
if let close {
|
||||
dialog.closeButtonText = close.0
|
||||
storage.fields["close-action"] = close.1
|
||||
}
|
||||
if let primary {
|
||||
dialog.primaryButtonText = primary.0
|
||||
storage.fields["primary-action"] = primary.1
|
||||
storage.fields["primary-action"] = primary.2
|
||||
if primary.1 {
|
||||
dialog.primaryButtonStyle = suggested
|
||||
}
|
||||
}
|
||||
if let secondary {
|
||||
dialog.secondaryButtonText = secondary.0
|
||||
storage.fields["secondary-action"] = secondary.1
|
||||
storage.fields["secondary-action"] = secondary.2
|
||||
if secondary.1 {
|
||||
dialog.secondaryButtonStyle = suggested
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,23 +149,27 @@ public struct ContentDialog: WinUIWidget {
|
||||
/// Set the primary response.
|
||||
/// - Parameters:
|
||||
/// - title: The response.
|
||||
/// - suggested: Whether it is suggested.
|
||||
/// - action: The action.
|
||||
public func primaryResponse(
|
||||
_ title: String,
|
||||
suggested: Bool = false,
|
||||
action: @escaping () -> Void
|
||||
) -> Self {
|
||||
modify { $0.primary = (title, action) }
|
||||
modify { $0.primary = (title, suggested, action) }
|
||||
}
|
||||
|
||||
/// Set the secondary response.
|
||||
/// - Parameters:
|
||||
/// - title: The response.
|
||||
/// - suggested: Whether it is suggested.
|
||||
/// - action: The action.
|
||||
public func secondaryResponse(
|
||||
_ title: String,
|
||||
suggested: Bool = false,
|
||||
action: @escaping () -> Void
|
||||
) -> Self {
|
||||
modify { $0.secondary = (title, action) }
|
||||
modify { $0.secondary = (title, suggested, action) }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ struct ContentView: View {
|
||||
}
|
||||
.contentDialog(visible: $dialog, title: "Sample Dialog")
|
||||
.closeResponse("Close") { dialog = false }
|
||||
.primaryResponse("Delete") { dialog = false }
|
||||
.primaryResponse("Delete", suggested: true) { dialog = false }
|
||||
}
|
||||
|
||||
/// The settings page.
|
||||
|
Loading…
Reference in New Issue
Block a user