refactor(ui): 统一资源卡片规范并收敛面板布局与公共组件
This commit is contained in:
@@ -31,7 +31,7 @@ struct PanelTrendChart: View {
|
||||
var expectedInterval: TimeInterval = 2
|
||||
var boundaryDates: Set<Date> = []
|
||||
var intervals: [TimeInterval] = []
|
||||
var plotHeight: CGFloat = 58
|
||||
var plotHeight: CGFloat = PanelStyle.plotHeight
|
||||
var showsLegendValues = true
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@State private var retainedScale: Double = 1
|
||||
@@ -84,7 +84,7 @@ struct PanelTrendChart: View {
|
||||
if showsLegendValues {
|
||||
Text(verbatim: formatted(values.last ?? nil, format: format)).monospacedDigit()
|
||||
}
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.8)
|
||||
}.font(PanelStyle.legend).lineLimit(1).minimumScaleFactor(0.8)
|
||||
}
|
||||
|
||||
private func tooltipRow(_ label: LocalizedStringKey, values: [Double?], tint: Color, format: TrendValueFormat? = nil, index: Int) -> some View {
|
||||
@@ -181,7 +181,7 @@ struct PanelTrendChart: View {
|
||||
if let date = dates.first { Text(date, style: .time) }
|
||||
Spacer(minLength: 0)
|
||||
if let date = dates.last { Text(date, style: .time) }
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(height: 12)
|
||||
}.font(PanelStyle.legend).foregroundStyle(.secondary).frame(height: 12)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.onAppear {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Shared roles for the compact monitoring panel. Micro charts keep their own 8pt role.
|
||||
enum PanelStyle {
|
||||
static let title = Font.system(size: 13, weight: .semibold)
|
||||
static let section = Font.system(size: 11, weight: .semibold)
|
||||
static let label = Font.system(size: 10)
|
||||
static let value = Font.system(size: 10, weight: .medium)
|
||||
static let legend = Font.system(size: 9)
|
||||
static let padding: CGFloat = 10
|
||||
static let gap: CGFloat = 8
|
||||
static let titleHeight: CGFloat = 20
|
||||
static let plotHeight: CGFloat = 58
|
||||
}
|
||||
|
||||
struct CardSeparator: View {
|
||||
var body: some View {
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1)
|
||||
.padding(.vertical, 4)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardField<Content: View>: View {
|
||||
let title: LocalizedStringKey
|
||||
@ViewBuilder var content: () -> Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title)).frame(height: 14)
|
||||
content().font(PanelStyle.value).monospacedDigit().frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardSurface: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content.modifier(PanelCardBackground(radius: 10))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
||||
}
|
||||
}
|
||||
|
||||
struct CardInset: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content.padding(.horizontal, 8).padding(.vertical, 5)
|
||||
.background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
}
|
||||
|
||||
/// Segment widths are proportional to the supplied total, without minimum fills.
|
||||
struct CapacityBar: View {
|
||||
let values: [Double]
|
||||
let colors: [Color]
|
||||
let total: Double
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { bounds in
|
||||
HStack(spacing: 0) {
|
||||
ForEach(values.indices, id: \.self) { index in
|
||||
Rectangle().fill(colors.isEmpty ? Color.clear : colors[index % colors.count])
|
||||
.frame(width: bounds.size.width * min(1, max(0, values[index] / max(1, total))))
|
||||
}
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
||||
}
|
||||
.frame(height: 8)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
struct CapacityField: View {
|
||||
let title: LocalizedStringKey
|
||||
let value: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(color).frame(width: 4, height: 4)
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title))
|
||||
}.frame(height: 14)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
struct CardSectionHeader: View {
|
||||
let title: LocalizedStringKey
|
||||
let valueLabel: LocalizedStringKey
|
||||
let value: String
|
||||
let color: Color
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(title).font(PanelStyle.section)
|
||||
Spacer(minLength: 4)
|
||||
Text(valueLabel).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: value).font(PanelStyle.value).foregroundStyle(color)
|
||||
}.frame(height: 16)
|
||||
}
|
||||
}
|
||||
@@ -16,48 +16,55 @@ struct ResourceCard<Content: View>: View {
|
||||
@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)
|
||||
GeometryReader { bounds in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
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)
|
||||
Label {
|
||||
Text(title).foregroundStyle(statusWarning ? .red : .primary)
|
||||
} icon: {
|
||||
Image(systemName: symbol).frame(width: 16, height: 16).foregroundStyle(statusWarning ? .red : color)
|
||||
}.font(PanelStyle.title).fixedSize()
|
||||
if let status {
|
||||
Text(verbatim: status)
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
.foregroundStyle(statusWarning ? .red : color)
|
||||
.padding(.horizontal, 6).frame(height: 16)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}.foregroundStyle(color).lineLimit(1).minimumScaleFactor(0.65)
|
||||
if let detail {
|
||||
Text(verbatim: detail)
|
||||
.font(.system(size: 10, weight: .medium)).foregroundStyle(.secondary)
|
||||
.padding(.horizontal, 6).frame(height: 16)
|
||||
.background(.primary.opacity(0.06), in: Capsule())
|
||||
.lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
HStack(alignment: .center, spacing: 6) {
|
||||
AnimatedMetricText(value: value)
|
||||
.font(PanelStyle.title)
|
||||
.foregroundStyle(valueColor ?? color)
|
||||
if let secondaryValue {
|
||||
AnimatedMetricText(value: secondaryValue).font(PanelStyle.title)
|
||||
.foregroundStyle(secondaryValueColor ?? color)
|
||||
}
|
||||
}.foregroundStyle(color).lineLimit(1)
|
||||
}
|
||||
.frame(height: PanelStyle.titleHeight)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
content()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
content()
|
||||
.font(PanelStyle.label)
|
||||
.padding(PanelStyle.padding)
|
||||
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
|
||||
}
|
||||
.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)))
|
||||
.modifier(CardSurface())
|
||||
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
|
||||
GeometryReader { proxy in
|
||||
if let tooltip {
|
||||
|
||||
Reference in New Issue
Block a user