Initial Release help-frontend

Dr. Frontend

Search Bar

Google-like search component for finding and linking to external resources.

Implementation

Installation

npx shadcn@latest add showcase-app/search-bar

Basic Usage

import { SearchBar } from '@/components/ui/search-bar';

<SearchBar
  placeholder="Search..."
  results={results}
  onSearch={handleSearch}
  onResultClick={handleClick}
/>

Props

interface SearchBarProps {
  placeholder?: string;
  results?: SearchResult[];
  recentSearches?: string[];
  trendingSearches?: string[];
  onSearch: (query: string) => void;
  onResultClick?: (result) => void;
  onClear?: () => void;
  isLoading?: boolean;
}

SearchResult Interface

interface SearchResult {
  id: string;
  title: string;
  description: string;
  url: string;
  category?: string;
  icon?: ReactNode;
}

Features

  • • Keyboard navigation (↑↓ Enter Esc)
  • • Recent searches history
  • • Trending searches
  • • Loading state indicator
  • • External link handling
  • • Category badges
  • • Custom icons per result

Keyboard Shortcuts

Navigate results↑ ↓
Open selectedEnter
Close dropdownEsc

Best Practices

  • • Debounce search requests
  • • Show loading state for async
  • • Limit results to 5-10 items
  • • Include URL preview
  • • Open external links in new tab