Components/AI

AI Search Bar

Intelligent AI search bar with tool selection, model switching, and advanced submission capabilities

Live Preview
Open in

Example

export default function AiSearchBarExample() {
  const handleSubmit = (value: string, options: { 
    selectedTools: number[], 
    thinkMode: boolean, 
    selectedModel: number 
  }) => {
    console.log('Submitted:', value)
    console.log('Selected tools:', options.selectedTools)
    console.log('Think mode:', options.thinkMode)
    console.log('Selected model:', options.selectedModel)
  }

  const handleChange = (value: string) => {
    console.log('Input changed:', value)
  }

  const handleToolsChange = (tools: number[]) => {
    console.log('Tools changed:', tools)
  }

  const handleThinkModeChange = (enabled: boolean) => {
    console.log('Think mode:', enabled)
  }

  const handleModelChange = (modelIndex: number) => {
    console.log('Model changed:', modelIndex)
  }

  const handleStop = () => {
    console.log('Operation stopped')
  }

  return (
    <AiSearchBar
      placeholder="Ask me anything about AI, coding, or design..."
      variant="default"
      onSubmit={handleSubmit}
      onChange={handleChange}
      onToolsChange={handleToolsChange}
      onThinkModeChange={handleThinkModeChange}
      onModelChange={handleModelChange}
      onStop={handleStop}
      className="w-full max-w-2xl"
    />
  )
}

Documentation

PropTypeDefaultDescription
variant"default" | "ghost" | "outline""default"Visual style variant of the search bar
placeholderstring"What can I do for you?"Placeholder text for the input field
onSubmit(value: string, options: { selectedTools: number[], thinkMode: boolean, selectedModel: number }) => voidundefinedCallback when form is submitted
onChange(value: string) => voidundefinedCallback when input value changes
onToolsChange(selectedTools: number[]) => voidundefinedCallback when selected tools change
onThinkModeChange(isEnabled: boolean) => voidundefinedCallback when think mode is toggled
onModelChange(modelIndex: number) => voidundefinedCallback when AI model is changed
classNamestringundefinedAdditional CSS classes for styling
submitLoadingbooleanfalseWhether to show loading state and disable input
submitLoaderComponentReact.ReactNodeundefinedCustom loader component for submit button
onStop() => voidundefinedCallback to stop external operations
isStoppedbooleanfalseExternal control for stopped state
onStoppedChange(stopped: boolean) => voidundefinedCallback when stop state changes

Types

type AI_SearchBarProps = {
  variant?: "default" | "ghost" | "outline"
  placeholder?: string
  onSubmit?: (value: string, options: { selectedTools: number[], thinkMode: boolean, selectedModel: number }) => void
  onChange?: (value: string) => void
  onToolsChange?: (selectedTools: number[]) => void
  onThinkModeChange?: (isEnabled: boolean) => void
  onModelChange?: (modelIndex: number) => void
  className?: string
  submitLoading?: boolean
  submitLoaderComponent?: React.ReactNode
  onStop?: () => void
  isStopped?: boolean
  onStoppedChange?: (stopped: boolean) => void
}

Features

  • Intelligent Tool Selection: Choose from multiple AI tools including web search, image generation, and code interpretation
  • Model Switching: Switch between different AI models (GPT-4, GPT-3.5, Claude-3, Llama-2, Mistral-7B)
  • Think Mode: Enable advanced reasoning mode for complex queries
  • Real-time Input Handling: Responsive textarea with auto-resize and typing indicators
  • Loading States: Built-in loading states with custom loader support
  • Stop Functionality: Ability to stop ongoing operations with external control
  • Responsive Design: Adapts to different screen sizes with mobile-friendly interface
  • Dark Mode Support: Full dark mode compatibility with appropriate color schemes
  • Accessibility Focused: Keyboard navigation and screen reader support