Components.swift (2618B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 import SwiftUI 3 4 struct Stars: View { 5 let value: Int 6 var body: some View { 7 HStack(spacing: 1) { 8 ForEach(1...5, id: \.self) { index in 9 Image(systemName: index <= value ? "star.fill" : "star") 10 .foregroundStyle(index <= value ? Color.yellow : Color.secondary.opacity(0.4)) 11 } 12 } 13 .font(.caption) 14 .accessibilityLabel("\(value) of 5") 15 } 16 } 17 18 /// Rating out of 5; tapping the star already selected resets it to zero. 19 struct StarPicker: View { 20 let title: LocalizedStringKey 21 @Binding var value: Int 22 23 var body: some View { 24 HStack { 25 Text(title) 26 Spacer() 27 HStack(spacing: 6) { 28 ForEach(1...5, id: \.self) { index in 29 Image(systemName: index <= value ? "star.fill" : "star") 30 .font(.title3) 31 .foregroundStyle(index <= value ? Color.yellow : Color.secondary.opacity(0.5)) 32 .onTapGesture { value = value == index ? 0 : index } 33 .accessibilityLabel("\(index) of 5") 34 .accessibilityAddTraits(.isButton) 35 } 36 } 37 } 38 } 39 } 40 41 struct Figure: View { 42 let title: LocalizedStringKey 43 let value: String 44 var icon: String? 45 46 var body: some View { 47 VStack(alignment: .leading, spacing: 4) { 48 HStack(spacing: 4) { 49 if let icon { Image(systemName: icon).font(.caption2) } 50 Text(title).font(.caption2) 51 } 52 .foregroundStyle(.secondary) 53 Text(value) 54 .font(.headline.monospacedDigit()) 55 .lineLimit(1) 56 .minimumScaleFactor(0.7) 57 } 58 .frame(maxWidth: .infinity, alignment: .leading) 59 .padding(10) 60 .background(Color(.tertiarySystemGroupedBackground), in: RoundedRectangle(cornerRadius: 10, style: .continuous)) 61 } 62 } 63 64 struct TagChips: View { 65 let tags: [String] 66 var body: some View { 67 ScrollView(.horizontal, showsIndicators: false) { 68 HStack(spacing: 6) { 69 ForEach(tags, id: \.self) { tag in 70 Text(tag) 71 .font(.caption.weight(.medium)) 72 .padding(.horizontal, 10) 73 .padding(.vertical, 4) 74 .background(Color.accentColor.opacity(0.15), in: Capsule()) 75 .foregroundStyle(Color.accentColor) 76 } 77 } 78 } 79 } 80 }