48 lines
2.0 KiB
Swift
48 lines
2.0 KiB
Swift
import SwiftUI
|
|
|
|
struct ResourceCard<Content: View>: View {
|
|
let title: LocalizedStringKey
|
|
let symbol: String
|
|
let color: Color
|
|
let value: String
|
|
var secondaryValue: String? = nil
|
|
@ViewBuilder var content: () -> Content
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
|
Label { Text(title).foregroundStyle(.primary) } icon: {
|
|
Image(systemName: symbol).foregroundStyle(color)
|
|
}.font(.system(size: 13, weight: .semibold)).fixedSize()
|
|
Spacer(minLength: 0)
|
|
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
|
AnimatedMetricText(value: value)
|
|
.font(.system(size: 13, weight: .semibold))
|
|
if let secondaryValue {
|
|
AnimatedMetricText(value: secondaryValue).font(.system(size: 13, weight: .semibold))
|
|
}
|
|
}.foregroundStyle(color).lineLimit(1).minimumScaleFactor(0.65)
|
|
}
|
|
content()
|
|
}
|
|
.font(.system(size: 11))
|
|
.padding(10)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
|
.modifier(PanelCardBackground(radius: 10))
|
|
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
|
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
|
|
GeometryReader { proxy in
|
|
if let tooltip {
|
|
let plot = proxy[tooltip.plot]
|
|
ChartTooltipLayer(point: CGPoint(x: plot.minX + tooltip.point.x, y: plot.minY + tooltip.point.y)) {
|
|
tooltip.content.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
.frame(width: proxy.size.width, height: proxy.size.height)
|
|
}
|
|
}
|
|
.allowsHitTesting(false)
|
|
.accessibilityHidden(true)
|
|
}
|
|
}
|
|
}
|