37 lines
848 B
Swift
37 lines
848 B
Swift
|
//
|
||
|
// 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<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)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|