2026-06-18 18:04:59 +03:00
|
|
|
// SourceChips.swift
|
|
|
|
|
// Jarvis — names the first 2 sources, collapses the rest into "+N".
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
struct SourceChips: View {
|
|
|
|
|
/// Source names in display order.
|
|
|
|
|
let names: [String]
|
|
|
|
|
/// Total number of sources (may exceed `names.count`).
|
|
|
|
|
let total: Int
|
|
|
|
|
var maxNamed: Int = 2
|
|
|
|
|
|
|
|
|
|
private var named: [String] { Array(names.prefix(maxNamed)) }
|
|
|
|
|
private var overflow: Int { max(0, total - named.count) }
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
HStack(spacing: 6) {
|
|
|
|
|
ForEach(named, id: \.self) { name in
|
|
|
|
|
chip(name)
|
|
|
|
|
}
|
|
|
|
|
if overflow > 0 {
|
|
|
|
|
chip("+\(overflow)", muted: true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func chip(_ text: String, muted: Bool = false) -> some View {
|
|
|
|
|
Text(text)
|
2026-06-22 02:33:33 +03:00
|
|
|
.font(.system(size: 11, weight: .semibold))
|
|
|
|
|
.foregroundStyle(muted ? Palette.chipMutedText : Palette.chipText)
|
|
|
|
|
.padding(.horizontal, 8)
|
|
|
|
|
.padding(.vertical, 3)
|
|
|
|
|
.background(Palette.chipFill)
|
2026-06-18 18:04:59 +03:00
|
|
|
.clipShape(Capsule())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
|
SourceChips(names: ["Daily Monitor", "NilePost", "The EastAfrican"], total: 7)
|
|
|
|
|
.padding()
|
2026-06-22 02:33:33 +03:00
|
|
|
.background(Palette.background)
|
2026-06-18 18:04:59 +03:00
|
|
|
}
|