Error Button
A reusable button component with various styles and states
Preview
Code
1import SwiftUI23struct ErrorButtonView: View {4 @State private var showError = false5 6 var body: some View {7 VStack {8 Button("Trigger Error") {9 showError = true10 DispatchQueue.main.asyncAfter(deadline: .now() + 2) {11 showError = false12 }13 }14 .padding()15 .background(showError ? Color.red : Color.gray)16 .foregroundColor(.white)17 .cornerRadius(10)18 19 if showError {20 Text("Error occurred!")21 .foregroundColor(.red)22 .font(.caption)23 }24 }25 }26}2728struct ErrorButtonView_Previews: PreviewProvider {29 static var previews: some View {30 ErrorButtonView()31 }32}