Skip to content

Latest commit

 

History

History
101 lines (83 loc) · 2.99 KB

README.md

File metadata and controls

101 lines (83 loc) · 2.99 KB

Tests codebeat badge License Swift Version Platform

SearchBarKit

Sleek searchbar for iOS and macOS

img

Features

  • 🎯 Focus Callbacks: Receive notifications when the search field gains or loses focus.
  • ✍️ Real-time Text Updates: Get instant updates as the user types.
  • 🎨 Effortless Customization: Easily adjust sizing and color themes via struct injection.
  • 🌐 Cross-Platform Compatibility: Works seamlessly on both iOS and macOS.
  • 🌗 Dark & Light Mode Support: Automatically adapts to the system's appearance.

Example

SearchBar(
      placeholderText: "Search...", // Placeholder text
      onFocus: { isFocused in // Triggered when search field is focused
         print("isFocused: \(isFocused)")
      },
      onTextChange: { text in // Triggered when text changes
         print("text: \(text)")
      }
)

Custom Sizing

let customSizing = SearchBarSizing(
      horizontalPadding: 8,
      verticalPadding: 8,
      leftIconHorizontalPadding: 8,
      clearButtonPadding: 8
)

SearchBar(
      placeholderText: "Search...",
      searchbarSizing: customSizing,
      onFocus: { isFocused in
         // Handle focus change
      },
      onTextChange: { text in
         // Handle text change
      }
)

Custom Theme

let customTheme = SearchBarTheme(
      iconColor: .blue,
      textColor: .black,
      activeBG: .white,
      activeBorder: .blue,
      background: .gray.opacity(0.2),
      borderColor: .blue
)

SearchBar(
      placeholderText: "Search...",
      searchBarTheme: customTheme,
      onFocus: { isFocused in
         // Handle focus change
      },
      onTextChange: { text in
         // Handle text change
      }
)

Installation

Add to your project using Swift Package Manager by adding the following URL:

.package(url: "https://github.com/sentryco/SearchBarKit", branch: "main")

Dependencies:

Todo

  • Maybe not hide close button on focus loss?
  • Add more comments with AI
  • Remove unit test, add uitest
  • It seems placeholder text-color for SearchBar text doesnt work for macOS. Try to fix it
  • Store accessIds in an accissible const
  • Make SearchBar a ViewBuilder and add styling as a textfield modifier?

Future improvments:

  • Add SearchBarIdentifier (injectable accessid) (for now these are hardcoded)
  • Move more metrics to const (later when it makes sense)