76 lines
3.4 KiB
Swift
76 lines
3.4 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
|
|
var valueColor: Color? = nil
|
|
var secondaryValueColor: Color? = nil
|
|
var status: String? = nil
|
|
var statusWarning = false
|
|
var statusHelp: Text? = nil
|
|
var warningText: Text? = nil
|
|
var detail: String? = nil
|
|
@ViewBuilder var content: () -> Content
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
HStack(alignment: .center, spacing: 6) {
|
|
Label { Text(title).foregroundStyle(statusWarning ? .red : .primary) } icon: {
|
|
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
|
|
}.font(.system(size: 13, weight: .semibold)).fixedSize()
|
|
if let status {
|
|
Text(verbatim: status)
|
|
.font(.system(size: 10, weight: .medium))
|
|
.foregroundStyle(statusWarning ? .red : color)
|
|
.padding(.horizontal, 6).padding(.vertical, 2)
|
|
.background((statusWarning ? Color.red : color).opacity(0.14), in: Capsule())
|
|
.help(statusHelp ?? Text(verbatim: status))
|
|
if let warningText {
|
|
warningText
|
|
.font(.system(size: 10)).foregroundStyle(.red).lineLimit(1).minimumScaleFactor(0.7)
|
|
}
|
|
}
|
|
if let detail {
|
|
Text(verbatim: detail)
|
|
.font(.system(size: 9, weight: .medium)).foregroundStyle(.secondary)
|
|
.padding(.horizontal, 5).padding(.vertical, 2)
|
|
.background(.primary.opacity(0.06), in: Capsule())
|
|
.lineLimit(1).minimumScaleFactor(0.7)
|
|
}
|
|
Spacer(minLength: 0)
|
|
HStack(alignment: .center, spacing: 6) {
|
|
AnimatedMetricText(value: value)
|
|
.font(.system(size: 13, weight: .semibold))
|
|
.foregroundStyle(valueColor ?? color)
|
|
if let secondaryValue {
|
|
AnimatedMetricText(value: secondaryValue).font(.system(size: 13, weight: .semibold))
|
|
.foregroundStyle(secondaryValueColor ?? color)
|
|
}
|
|
}.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)
|
|
}
|
|
}
|
|
}
|