TagBarView.swift 674 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // TagBarView.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 2/28/26.
  6. //
  7. import SwiftUI
  8. struct TagBarView: View {
  9. @Binding var tags: [String]
  10. @State private var active: String = ""
  11. var body: some View {
  12. HStack {
  13. TextField("Tag", text: $active)
  14. .onSubmit {
  15. tags.append(active)
  16. active = ""
  17. }
  18. ForEach($tags, id: \.self) { tag in
  19. TextField("", text: tag)
  20. .onSubmit {
  21. tags.removeAll(where: { $0.isEmpty })
  22. }
  23. .scaledToFit()
  24. }
  25. }
  26. }
  27. }
  28. #Preview {
  29. @Previewable @State var tags = Array<String>()
  30. TagBarView(tags: $tags)
  31. }