Caps-iOS/Caps/Views/FancyTextField.swift

48 lines
1.4 KiB
Swift
Raw Normal View History

2022-06-11 11:27:56 +02:00
import SwiftUI
import SFSafeSymbols
struct FancyTextField: View {
@Binding
var text: String
let icon: SFSymbol
let placeholder: String
let showClearButton: Bool = true
var body: some View {
TextField("Search", text: $text, prompt: Text(placeholder))
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray5))
.cornerRadius(8)
.overlay(
HStack {
Image(systemSymbol: icon)
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)
if showClearButton && text != "" {
Button(action: {
self.text = ""
}) {
Image(systemSymbol: .multiplyCircleFill)
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
}
}
struct FancyTextField_Previews: PreviewProvider {
static var previews: some View {
FancyTextField(text: .constant("Text"),
icon: .magnifyingglass,
placeholder: "Enter text")
}
}