Components/AI
AI Search Bar
Intelligent AI search bar with tool selection, model switching, and advanced submission capabilities
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
Prop | Type | Default | Description |
---|---|---|---|
variant | "default" | "ghost" | "outline" | "default" | Visual style variant of the search bar |
placeholder | string | "What can I do for you?" | Placeholder text for the input field |
onSubmit | (value: string, options: { selectedTools: number[], thinkMode: boolean, selectedModel: number }) => void | undefined | Callback when form is submitted |
onChange | (value: string) => void | undefined | Callback when input value changes |
onToolsChange | (selectedTools: number[]) => void | undefined | Callback when selected tools change |
onThinkModeChange | (isEnabled: boolean) => void | undefined | Callback when think mode is toggled |
onModelChange | (modelIndex: number) => void | undefined | Callback when AI model is changed |
className | string | undefined | Additional CSS classes for styling |
submitLoading | boolean | false | Whether to show loading state and disable input |
submitLoaderComponent | React.ReactNode | undefined | Custom loader component for submit button |
onStop | () => void | undefined | Callback to stop external operations |
isStopped | boolean | false | External control for stopped state |
onStoppedChange | (stopped: boolean) => void | undefined | Callback 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