IceCubesApp/Packages/DesignSystem/Sources/DesignSystem/Views/ErrorView.swift

51 lines
1.3 KiB
Swift
Raw Normal View History

2023-01-07 17:01:06 +00:00
import SwiftUI
public struct ErrorView: View {
public let title: LocalizedStringKey
public let message: LocalizedStringKey
public let buttonTitle: LocalizedStringKey
2023-01-17 10:36:01 +00:00
public let onButtonPress: () -> Void
public init(title: LocalizedStringKey, message: LocalizedStringKey, buttonTitle: LocalizedStringKey, onButtonPress: @escaping (() -> Void)) {
2023-01-07 17:01:06 +00:00
self.title = title
self.message = message
self.buttonTitle = buttonTitle
self.onButtonPress = onButtonPress
}
2023-01-17 10:36:01 +00:00
2023-01-07 17:01:06 +00:00
public var body: some View {
2023-01-31 07:16:36 +00:00
HStack {
Spacer()
VStack {
Image(systemName: "exclamationmark.triangle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxHeight: 50)
Text(title)
.font(.scaledTitle)
.padding(.top, 16)
Text(message)
.font(.scaledSubheadline)
.multilineTextAlignment(.center)
2023-12-04 14:49:44 +00:00
.foregroundStyle(.secondary)
2023-01-31 07:16:36 +00:00
Button {
onButtonPress()
} label: {
Text(buttonTitle)
}
.buttonStyle(.bordered)
2023-01-07 17:01:06 +00:00
.padding(.top, 16)
}
2023-01-31 07:16:36 +00:00
.padding(.top, 100)
.padding(.layoutPadding)
Spacer()
2023-01-07 17:01:06 +00:00
}
}
}
#Preview {
ErrorView(title: "Error",
message: "Error loading. Please try again",
2024-03-11 08:05:52 +00:00
buttonTitle: "Retry") {}
}