39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
import SwiftUI
|
|
|
|
struct CategoryPicker: View {
|
|
@Binding var selectedCategory: String
|
|
|
|
private let columns = [
|
|
GridItem(.adaptive(minimum: 90), spacing: 8)
|
|
]
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("Category")
|
|
.font(.subheadline)
|
|
.fontWeight(.semibold)
|
|
|
|
LazyVGrid(columns: columns, spacing: 8) {
|
|
ForEach(todoCategories, id: \.self) { category in
|
|
let isSelected = selectedCategory == category
|
|
|
|
Button {
|
|
selectedCategory = category
|
|
} label: {
|
|
Text(category)
|
|
.font(.subheadline)
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill(isSelected ? Color.accentColor : Color(.systemGray5))
|
|
)
|
|
.foregroundStyle(isSelected ? .white : .primary)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|