diff --git a/Sources/InstantSearchSwiftUI/View/SearchBar.swift b/Sources/InstantSearchSwiftUI/View/SearchBar.swift index c6f7958d..cb1cf7b6 100644 --- a/Sources/InstantSearchSwiftUI/View/SearchBar.swift +++ b/Sources/InstantSearchSwiftUI/View/SearchBar.swift @@ -21,7 +21,13 @@ public struct SearchBar: View { /// Whether the search bar is in the editing state @Binding public var isEditing: Bool + + /// Customizable background color for the main text field + @State public var searchBarBackgroundColor = + Color(.sRGB, red: 239/255, green: 239/255, blue: 240/255, opacity: 1) + @State public var searchBarForegroundColor = Color(.gray) + private let placeholder: String private var onSubmit: () -> Void @@ -47,7 +53,7 @@ public struct SearchBar: View { .overlay( HStack { Image(systemName: "magnifyingglass") - .foregroundColor(.gray) + .foregroundColor(searchBarForegroundColor) .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) .padding(.leading, 8) .disabled(true) @@ -57,7 +63,7 @@ public struct SearchBar: View { }, label: { Image(systemName: "multiply.circle.fill") - .foregroundColor(.gray) + .foregroundColor(searchBarForegroundColor) .padding(.trailing, 8) }) } @@ -66,15 +72,15 @@ public struct SearchBar: View { .onTapGesture { isEditing = true } - .background(Color(.sRGB, red: 239/255, green: 239/255, blue: 240/255, opacity: 1)) + .background(searchBarBackgroundColor) .cornerRadius(10) if isEditing { - Button(action: { - isEditing = false - }, - label: { - Text("Cancel") - }) + + Button { + isEditing = false + } label: { + Text("Cancel") + } .padding(.trailing, 10) .transition(.move(edge: .trailing)) .animation(.default)