You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
974 B
40 lines
974 B
//
|
|
// ConfirmButtonView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by razmig on 21/08/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ConfirmButtonView<T:View>: View {
|
|
@State private var showingConfirmDialog = false
|
|
@State private var actionConfirmed = false
|
|
|
|
var shouldConfirm: Bool
|
|
var message: String
|
|
var confirmButtonText: String = "OK"
|
|
var cancelButtonText: String = "Annuler"
|
|
var onConfirm: () -> Void
|
|
var label: () -> T
|
|
|
|
var body: some View {
|
|
Button {
|
|
if shouldConfirm {
|
|
showingConfirmDialog = true
|
|
} else {
|
|
onConfirm()
|
|
}
|
|
} label: {
|
|
label()
|
|
}
|
|
.confirmationDialog("Attention", isPresented: $showingConfirmDialog) {
|
|
Button(confirmButtonText, role: .destructive) {
|
|
onConfirm()
|
|
}
|
|
Button(cancelButtonText, role: .cancel) { }
|
|
} message: {
|
|
Text(message)
|
|
}
|
|
}
|
|
}
|
|
|