| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //
- // CategoryGroupView.swift
- // Todos
- //
- // Created by Sam Jaffe on 3/2/26.
- //
- import SwiftUI
- struct CategoryGroupView: View {
- @State var allGroups = [Group]()
- @State var active = Group()
-
- var body: some View {
- Table(of: Binding<Group>.self) {
- TableColumn("Color") { group in
- ColorPicker("", selection: group.color, supportsOpacity: false)
- }
- TableColumn("Name") { group in
- TextField("", 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 = Group()
- }
- }
- }
- #Preview {
- CategoryGroupView()
- }
|