Pārlūkot izejas kodu

feat: implement a show/hide toggle that uses "eye" and "eye.slash" instead of a checkbox

Sam Jaffe 3 nedēļas atpakaļ
vecāks
revīzija
754c9fdd74
2 mainītis faili ar 48 papildinājumiem un 8 dzēšanām
  1. 19 8
      Todos/View/TaskView.swift
  2. 29 0
      Todos/View/VisibilityTapper.swift

+ 19 - 8
Todos/View/TaskView.swift

@@ -10,7 +10,10 @@ import SwiftUI
 struct TaskView: View {
 struct TaskView: View {
   @Binding var task: Task
   @Binding var task: Task
   @State private var showTags: Bool = false
   @State private var showTags: Bool = false
+  @State private var hideTags: Bool = false
+
   @State private var showNotes: Bool = false
   @State private var showNotes: Bool = false
+  @State private var hideNotes: Bool = false
 
 
   var body: some View {
   var body: some View {
     VStack {
     VStack {
@@ -22,19 +25,27 @@ struct TaskView: View {
         }.scaledToFit()
         }.scaledToFit()
         TextField("Task Name", text: $task.name)
         TextField("Task Name", text: $task.name)
       }
       }
+      
       if showTags {
       if showTags {
-        TagBarView(tags: $task.tags)
-          .font(.footnote)
-          .padding(.leading, 30)
+        HStack {
+          TagBarView(tags: $task.tags)
+            .font(.footnote)
+            .padding(.leading, 30)
+          ShowHideTapper(shown: $showTags, hideToggle: $hideTags)
+        }
       }
       }
+      
       if showNotes {
       if showNotes {
-        TextField("Notes", text: $task.notes)
-          .font(.footnote)
-          .padding(.leading, 30)
+        HStack {
+          TextField("Notes", text: $task.notes)
+            .font(.footnote)
+            .padding(.leading, 30)
+          ShowHideTapper(shown: $showNotes, hideToggle: $hideNotes)
+        }
       }
       }
     }.onHover { yes in
     }.onHover { yes in
-      showTags = yes || !task.tags.isEmpty
-      showNotes = yes || !task.notes.isEmpty
+      showTags = yes || !(hideTags || task.tags.isEmpty)
+      showNotes = yes || !(hideNotes || task.notes.isEmpty)
     }
     }
   }
   }
 }
 }

+ 29 - 0
Todos/View/VisibilityTapper.swift

@@ -0,0 +1,29 @@
+//
+//  ShowHideTapper.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 2/28/26.
+//
+
+import SwiftUI
+
+struct ShowHideTapper: View {
+  @Binding var shown: Bool
+  @Binding var hideToggle: Bool
+  
+  var body: some View {
+    Label("", systemImage: hideToggle ? "eye.slash" : "eye")
+      .onTapGesture {
+        hideToggle = !hideToggle
+      }
+      .padding(.leading, -6.5)
+      .padding(.trailing, -6.5)
+      .help("Toggle visibility")
+  }
+}
+
+#Preview {
+  @Previewable @State var shown = false
+  @Previewable @State var hidden = false
+  ShowHideTapper(shown: $shown, hideToggle: $hidden)
+}