1.5.3 • Published 6 months ago

@adamui/searchbar v1.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@adamui/searchbar

A customizable React search bar component with advanced features, animations, and accessibility.

Features

  • 🔍 Animated search interface with minimizable option
  • 📋 Dropdown suggestions with keyboard navigation
  • ⌨️ Keyboard accessible (arrow keys, enter, escape)
  • 🎨 Customizable styling and appearance
  • 💬 Highlight matched text in suggestions
  • ⏱️ Debounced input for performance
  • 🧩 Custom rendering of suggestion items
  • ♿ Accessible with ARIA attributes
  • 🌓 Dark mode support with system preference detection
  • 📏 Standardized dimensions for consistent UI

Installation

# npm
npm install @adamui/searchbar

# yarn
yarn add @adamui/searchbar

# pnpm
pnpm add @adamui/searchbar

# bun
bun add @adamui/searchbar

Peer Dependencies

This package requires the following peer dependencies:

  • React 17+ or 18+ or 19+
  • Motion 12+
  • TailwindCSS 3+ or 4+ (optional, for styling)

Usage

import { SearchBar } from "@adamui/searchbar";

// Basic usage
const MyComponent = () => {
  const options = [
    { id: 1, label: "Apple" },
    { id: 2, label: "Banana" },
    { id: 3, label: "Cherry" },
    // ...more options
  ];

  return (
    <SearchBar
      dropdownOptions={options}
      placeholder="Search fruits..."
      onSelect={(option) => console.log("Selected:", option)}
      onChange={(value) => console.log("Input value:", value)}
    />
  );
};

// Advanced usage with customization
const AdvancedSearch = () => {
  const options = [
    /* your options */
  ];

  return (
    <SearchBar
      dropdownOptions={options}
      maxSuggestions={10}
      placeholder="Search..."
      onSelect={(option) => console.log("Selected:", option)}
      onChange={(value) => console.log("Input value:", value)}
      minimizable={true}
      showClearButton={true}
      clearOnSelect={false}
      highlightMatches={true}
      highlightMatchesStyles="bg-blue-200 font-medium"
      filterDebounceTime={300}
      noResultsMessage="No matching items found"
      width="500px"
      height="56px"
      darkMode={true}
      renderItem={(item, isSelected) => (
        <div className={`p-2 ${isSelected ? "bg-blue-100" : ""}`}>
          <div className="font-medium">{item.label}</div>
          <div className="text-xs text-gray-500">Item ID: {item.id}</div>
        </div>
      )}
    />
  );
};

Props

PropTypeDefaultDescription
dropdownOptionsArray<{ id: number; label: string }>[]Options to display in the dropdown
maxSuggestionsnumber5Maximum number of suggestions to show
placeholderstring"Search..."Input placeholder text
onSelect(option: Option) => void-Callback when an option is selected
onChange(value: string) => void-Callback when input value changes
disabledbooleanfalseWhether the search bar is disabled
minimizablebooleanfalseWhether the search bar can be minimized to just an icon
showClearButtonbooleanfalseWhether to show a clear button
clearButtonStyleClassstring-Custom class for the clear button
clearOnSelectbooleanfalseWhether to clear input after selection
noResultsMessagestring"No results found"Message shown when no results match
filterDebounceTimenumber100Debounce time in ms for filtering
renderItem(item: Option, isSelected: boolean) => React.ReactNode-Custom render function for list items
highlightMatchesbooleanfalseWhether to highlight matching text
highlightMatchesStylesstring"bg-yellow-200"Tailwind classes for highlighted text
customLoaderReact.ReactNode-Custom loader element
widthstring"400px"Width of the search bar
heightstring"48px"Height of the search bar
darkModebooleanundefinedForce dark mode (true/false) or auto-detect (undefined)

License

MIT © Adam Shelley

1.5.3

6 months ago

1.5.2

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.4.2

6 months ago

1.4.1

6 months ago

1.3.9

6 months ago

1.3.8

6 months ago

1.3.7

6 months ago

1.3.6

6 months ago

1.3.5

6 months ago

1.3.3

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.4.0

6 months ago

1.3.0

6 months ago

1.0.0

6 months ago