Impressia/Vernissage/ViewModifiers/ClearButton.swift

35 lines
837 B
Swift

//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the Apache License 2.0.
//
import Foundation
import SwiftUI
public extension View {
func clearButton(text: Binding<String>) -> 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)
}
}
}
}