2025-05-08 21:19:04 +02:00

40 lines
1019 B
Swift

import SwiftUI
public struct CardView<Content: View>: View {
public let content: () -> Content
public let backgroundColor: Color?
public init(backgroundColor: Color? = nil, @ViewBuilder content: @escaping () -> Content) {
self.backgroundColor = backgroundColor
self.content = content
}
public var body: some View {
VStack(spacing: .zero) {
content()
.padding()
}
.frame(maxWidth: .infinity)
.background(backgroundColor)
/* Corner radius is duplicated to assure even with a background color it will
keep the corner radius */
.cornerRadius(HACornerRadius.standard)
.overlay(
RoundedRectangle(cornerRadius: HACornerRadius.standard)
.stroke(
Color.onSurface, lineWidth: 1
)
)
}
}
#Preview {
VStack {
CardView {
Text("abc")
}
.padding()
}
.background(Color.yellow)
}