Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct SearchBar: View {
@Binding var text: String
var body: some View {
HStack {
HStack {
Image(systemName: "magnifyingglass")
TextField("Search", text: $text)
.foregroundColor(.primary)
if !text.isEmpty {
Button(action: {
self.text = ""
}) {
Image(systemName: "xmark.circle.fill")
}
} else {
EmptyView()
}
}
.padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8)
.foregroundColor(.secondary)
.background(Color(.secondarySystemBackground))
.cornerRadius(10.0)
}
.padding(.horizontal)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment