BusinessCard/BusinessCardClip/Views/Components/ClipErrorView.swift

51 lines
1.5 KiB
Swift

import SwiftUI
import Bedrock
/// Error state shown when card fetch or save fails.
struct ClipErrorView: View {
let message: String
let onRetry: () -> Void
var body: some View {
VStack(spacing: ClipDesign.Spacing.xLarge) {
Image(systemName: "exclamationmark.triangle.fill")
.resizable()
.scaledToFit()
.frame(width: ClipDesign.Size.avatar, height: ClipDesign.Size.avatar)
.foregroundStyle(Color.Clip.error)
VStack(spacing: ClipDesign.Spacing.small) {
Text(String(localized: "Something went wrong"))
.styled(.title2)
.foregroundStyle(Color.Clip.text)
Text(message)
.styled(.subheading)
.foregroundStyle(Color.Clip.secondaryText)
.multilineTextAlignment(.center)
}
ClipPrimaryButton(
title: String(localized: "Try Again"),
systemImage: "arrow.clockwise",
action: onRetry
)
.padding(.horizontal, ClipDesign.Spacing.xLarge)
.padding(.top, ClipDesign.Spacing.large)
}
.padding(ClipDesign.Spacing.xLarge)
.accessibilityElement(children: .combine)
.accessibilityLabel(Text("Error: \(message)"))
}
}
#Preview {
ZStack {
Color.Clip.background
.ignoresSafeArea()
ClipErrorView(message: "This card has expired") {
print("Retry tapped")
}
}
}