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.
|
/// The body text.
|
||||||
var body: Body
|
var body: Body
|
||||||
/// The primary response.
|
/// The primary response.
|
||||||
var primary: (String, () -> Void)?
|
var primary: (String, Bool, () -> Void)?
|
||||||
/// The secondary response.
|
/// The secondary response.
|
||||||
var secondary: (String, () -> Void)?
|
var secondary: (String, Bool, () -> Void)?
|
||||||
/// The close response.
|
/// The close response.
|
||||||
var close: (String, () -> Void)?
|
var close: (String, () -> Void)?
|
||||||
/// The child view.
|
/// The child view.
|
||||||
@ -114,17 +114,24 @@ public struct ContentDialog: WinUIWidget {
|
|||||||
/// - storage: The view storage.
|
/// - storage: The view storage.
|
||||||
func updateDialogProperties(dialog: WinUI.ContentDialog, storage: ViewStorage) {
|
func updateDialogProperties(dialog: WinUI.ContentDialog, storage: ViewStorage) {
|
||||||
dialog.title = title
|
dialog.title = title
|
||||||
|
let suggested = Application.current.resources.lookup("AccentButtonStyle") as? Style
|
||||||
if let close {
|
if let close {
|
||||||
dialog.closeButtonText = close.0
|
dialog.closeButtonText = close.0
|
||||||
storage.fields["close-action"] = close.1
|
storage.fields["close-action"] = close.1
|
||||||
}
|
}
|
||||||
if let primary {
|
if let primary {
|
||||||
dialog.primaryButtonText = primary.0
|
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 {
|
if let secondary {
|
||||||
dialog.secondaryButtonText = secondary.0
|
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.
|
/// Set the primary response.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - title: The response.
|
/// - title: The response.
|
||||||
|
/// - suggested: Whether it is suggested.
|
||||||
/// - action: The action.
|
/// - action: The action.
|
||||||
public func primaryResponse(
|
public func primaryResponse(
|
||||||
_ title: String,
|
_ title: String,
|
||||||
|
suggested: Bool = false,
|
||||||
action: @escaping () -> Void
|
action: @escaping () -> Void
|
||||||
) -> Self {
|
) -> Self {
|
||||||
modify { $0.primary = (title, action) }
|
modify { $0.primary = (title, suggested, action) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the secondary response.
|
/// Set the secondary response.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - title: The response.
|
/// - title: The response.
|
||||||
|
/// - suggested: Whether it is suggested.
|
||||||
/// - action: The action.
|
/// - action: The action.
|
||||||
public func secondaryResponse(
|
public func secondaryResponse(
|
||||||
_ title: String,
|
_ title: String,
|
||||||
|
suggested: Bool = false,
|
||||||
action: @escaping () -> Void
|
action: @escaping () -> Void
|
||||||
) -> Self {
|
) -> 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")
|
.contentDialog(visible: $dialog, title: "Sample Dialog")
|
||||||
.closeResponse("Close") { dialog = false }
|
.closeResponse("Close") { dialog = false }
|
||||||
.primaryResponse("Delete") { dialog = false }
|
.primaryResponse("Delete", suggested: true) { dialog = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The settings page.
|
/// The settings page.
|
||||||
|
Loading…
Reference in New Issue
Block a user