// // https://mczachurski.dev // Copyright © 2023 Marcin Czachurski and the repository contributors. // Licensed under the MIT License. // import Foundation import SwiftUI public extension View { func clearButton(text: Binding) -> some View { modifier(ClearButton(text: text)) } } private struct ClearButton: ViewModifier { @Binding var text: String func body(content: Content) -> some View { ZStack(alignment: .trailing) { content if !text.isEmpty { Button { text = "" } label: { Image(systemName: "delete.backward.fill") .foregroundStyle(Color.accentColor.opacity(0.8)) } .padding(.trailing, 8) } } } }