| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // TagBarView.swift
- // Todos
- //
- // Created by Sam Jaffe on 2/28/26.
- //
- import SwiftUI
- import SwiftData
- struct TagBarView: View {
- @Binding var tags: [Tag]
- @AppStorage(UserDefaultsKeys.UrlHints) var allHints = URLHintArray()
- @State private var active: String = ""
- @FocusState private var isFocused: Bool
-
- var body: some View {
- HStack {
- ForEach($tags) { tag in
- let url = allHints.filter({ $0.matches(tag.wrappedValue) })
- .first?.url(tag.wrappedValue)
- if url != nil {
- Link(destination: url!) {
- Label("", systemImage: "link")
- }
- .padding(.leading, -8)
- .padding(.trailing, -10)
- }
- TextField("", text: tag.id)
- .focused($isFocused)
- .onChange(of: isFocused) {
- tags.removeAll(where: { $0.id.isEmpty })
- }
- }
- .scaledToFit()
- TextField("Tag", text: $active)
- .onSubmit {
- if !active.isEmpty && !tags.contains(where: { $0.like(active) }) {
- tags.append(Tag(id: active))
- }
- active = ""
- }
- }
- }
- }
- #Preview {
- @Previewable @State var tags = Array<Tag>()
- @Previewable @State var allHints = URLHintArray([
- URLHint(prefix: "RPD:", replacement: "http://localhost/")
- ])
- TagBarView(tags: $tags)
- }
|