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.
84 lines
2.6 KiB
84 lines
2.6 KiB
//
|
|
// RowButtonView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 03/03/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
fileprivate let defaultConfirmationMessage = "Êtes-vous sûr de vouloir faire cela ?"
|
|
|
|
struct RowButtonView: View {
|
|
var role: ButtonRole? = nil
|
|
let title: String
|
|
var systemImage: String? = nil
|
|
var image: String? = nil
|
|
var animatedProgress: Bool = false
|
|
let confirmationMessage: String
|
|
let action: () -> ()
|
|
@State private var askConfirmation: Bool = false
|
|
|
|
init(_ title: String, role: ButtonRole? = nil, systemImage: String? = nil, image: String? = nil, animatedProgress: Bool = false, confirmationMessage: String? = nil, action: @escaping () -> Void) {
|
|
self.role = role
|
|
self.title = title
|
|
self.systemImage = systemImage
|
|
self.image = image
|
|
self.animatedProgress = animatedProgress
|
|
self.confirmationMessage = confirmationMessage ?? defaultConfirmationMessage
|
|
self.action = action
|
|
}
|
|
|
|
var body: some View {
|
|
Button(role: role) {
|
|
if role == .destructive {
|
|
askConfirmation = true
|
|
} else {
|
|
action()
|
|
}
|
|
} label: {
|
|
HStack {
|
|
if animatedProgress {
|
|
Spacer()
|
|
ProgressView()
|
|
} else {
|
|
if let systemImage {
|
|
Image(systemName: systemImage)
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(height: 24)
|
|
}
|
|
if let image {
|
|
Image(image)
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 32, height: 32)
|
|
}
|
|
Spacer()
|
|
Text(title)
|
|
.foregroundColor(.white)
|
|
.frame(height: 32)
|
|
}
|
|
Spacer()
|
|
}
|
|
.font(.headline)
|
|
}
|
|
.disabled(animatedProgress)
|
|
.frame(maxWidth: .infinity)
|
|
.buttonStyle(.borderedProminent)
|
|
.tint(role == .destructive ? Color.red : Color.master)
|
|
.listRowBackground(Color.clear)
|
|
.listRowInsets(EdgeInsets(.zero))
|
|
.confirmationDialog("Confirmation",
|
|
isPresented: $askConfirmation,
|
|
titleVisibility: .visible) {
|
|
Button("OK") {
|
|
action()
|
|
}
|
|
Button("Annuler", role: .cancel) {}
|
|
} message: {
|
|
Text(confirmationMessage)
|
|
}
|
|
|
|
}
|
|
}
|
|
|