// // CategorySettingsView.swift // Todos // // Created by Sam Jaffe on 3/2/26. // import SwiftUI struct CategorySettingsView: View { @AppStorage(UserDefaultsKeys.Category) var allGroups = CodableArray() @State var active = Category() var body: some View { Table(of: Binding.self) { TableColumn("Color") { group in ColorPicker("", selection: group.color, supportsOpacity: false) } TableColumn("Name") { group in TextField("Category Name", text: group.name) .onSubmit(addGroup) } TableColumn("") { group in if group.id != active.id { Button { allGroups.removeAll(where: { $0.id == group.id }) } label: { Label("", systemImage: "trash") } } }.width(max: 20) } rows: { ForEach($allGroups) { group in TableRow(group) } TableRow($active) } } private func addGroup() { if active.valid { allGroups.append(active) active = Category() } } } #Preview { CategorySettingsView() }