Reuse card content across macOS and iOS with platform-sized icons and matching card heights. Add the shared Color field below Package and preserve selection, drag, and execution behavior. Migrate stored snippets to V51 and write color in Vault V2 while retaining V1 decoding and guarding against lossy V1 writes. Validation: macOS focused snippet, migration, architecture, and localization tests pass; 30 iOS focused tests pass; Swift format and localization checks pass. Full macOS testing also reports failures in unchanged KeyExport, MCP, and Agent suites.
42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
import SwiftUI
|
|
|
|
public struct LibraryCardChip: View {
|
|
private let text: Text
|
|
private let symbol: String?
|
|
private let tint: Color
|
|
|
|
public init(text: String, symbol: String? = nil, tint: Color = .secondary) {
|
|
self.text = Text(verbatim: text)
|
|
self.symbol = symbol
|
|
self.tint = tint
|
|
}
|
|
|
|
public init(title: LocalizedStringResource, symbol: String? = nil, tint: Color = .secondary) {
|
|
text = Text(title)
|
|
self.symbol = symbol
|
|
self.tint = tint
|
|
}
|
|
|
|
#if os(macOS)
|
|
private let font = Font.caption2
|
|
private let horizontalPadding: CGFloat = 6
|
|
private let verticalPadding: CGFloat = 2
|
|
#else
|
|
private let font = Font.caption
|
|
private let horizontalPadding: CGFloat = 8
|
|
private let verticalPadding: CGFloat = 4
|
|
#endif
|
|
|
|
public var body: some View {
|
|
HStack(spacing: 4) {
|
|
if let symbol { Image(systemName: symbol) }
|
|
text
|
|
}
|
|
.font(font).foregroundStyle(tint)
|
|
.padding(.horizontal, horizontalPadding).padding(.vertical, verticalPadding)
|
|
.background(tint.opacity(0.12), in: .capsule)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
}
|
|
}
|