import type { Meta, StoryObj } from '@storybook/nextjs' import { useState } from 'react' import SearchInput from '.' const meta = { title: 'Base/SearchInput', component: SearchInput, parameters: { layout: 'centered', docs: { description: { component: 'Search input component with search icon, clear button, and IME composition support for Asian languages.', }, }, }, tags: ['autodocs'], argTypes: { value: { control: 'text', description: 'Search input value', }, placeholder: { control: 'text', description: 'Placeholder text', }, white: { control: 'boolean', description: 'White background variant', }, className: { control: 'text', description: 'Additional CSS classes', }, }, } satisfies Meta export default meta type Story = StoryObj // Interactive demo wrapper const SearchInputDemo = (args: any) => { const [value, setValue] = useState(args.value || '') return (
{ setValue(v) console.log('Search value changed:', v) }} /> {value && (
Searching for: {value}
)}
) } // Default state export const Default: Story = { render: args => , args: { placeholder: 'Search...', white: false, }, } // White variant export const WhiteBackground: Story = { render: args => , args: { placeholder: 'Search...', white: true, }, } // With initial value export const WithInitialValue: Story = { render: args => , args: { value: 'Initial search query', placeholder: 'Search...', white: false, }, } // Custom placeholder export const CustomPlaceholder: Story = { render: args => , args: { placeholder: 'Search documents, files, and more...', white: false, }, } // Real-world example - User list search const UserListSearchDemo = () => { const [searchQuery, setSearchQuery] = useState('') const users = [ { id: 1, name: 'Alice Johnson', email: 'alice@example.com', role: 'Admin' }, { id: 2, name: 'Bob Smith', email: 'bob@example.com', role: 'User' }, { id: 3, name: 'Charlie Brown', email: 'charlie@example.com', role: 'User' }, { id: 4, name: 'Diana Prince', email: 'diana@example.com', role: 'Editor' }, { id: 5, name: 'Eve Davis', email: 'eve@example.com', role: 'User' }, ] const filteredUsers = users.filter(user => user.name.toLowerCase().includes(searchQuery.toLowerCase()) || user.email.toLowerCase().includes(searchQuery.toLowerCase()) || user.role.toLowerCase().includes(searchQuery.toLowerCase()), ) return (

Team Members

{filteredUsers.length > 0 ? ( filteredUsers.map(user => (
{user.name}
{user.email}
{user.role}
)) ) : (
No users found matching "{searchQuery}"
)}
Showing {filteredUsers.length} of {users.length} members
) } export const UserListSearch: Story = { render: () => , } // Real-world example - Product search const ProductSearchDemo = () => { const [searchQuery, setSearchQuery] = useState('') const products = [ { id: 1, name: 'Laptop Pro 15"', category: 'Electronics', price: 1299 }, { id: 2, name: 'Wireless Mouse', category: 'Accessories', price: 29 }, { id: 3, name: 'Mechanical Keyboard', category: 'Accessories', price: 89 }, { id: 4, name: 'Monitor 27" 4K', category: 'Electronics', price: 499 }, { id: 5, name: 'USB-C Hub', category: 'Accessories', price: 49 }, { id: 6, name: 'Laptop Stand', category: 'Accessories', price: 39 }, ] const filteredProducts = products.filter(product => product.name.toLowerCase().includes(searchQuery.toLowerCase()) || product.category.toLowerCase().includes(searchQuery.toLowerCase()), ) return (

Product Catalog

{filteredProducts.length > 0 ? ( filteredProducts.map(product => (
{product.name}
{product.category}
${product.price}
)) ) : (
No products found
)}
) } export const ProductSearch: Story = { render: () => , } // Real-world example - Documentation search const DocumentationSearchDemo = () => { const [searchQuery, setSearchQuery] = useState('') const docs = [ { id: 1, title: 'Getting Started', category: 'Introduction', excerpt: 'Learn the basics of our platform' }, { id: 2, title: 'API Reference', category: 'Developers', excerpt: 'Complete API documentation and examples' }, { id: 3, title: 'Authentication Guide', category: 'Security', excerpt: 'Set up OAuth and API key authentication' }, { id: 4, title: 'Best Practices', category: 'Guides', excerpt: 'Tips for optimal performance and security' }, { id: 5, title: 'Troubleshooting', category: 'Support', excerpt: 'Common issues and their solutions' }, ] const filteredDocs = docs.filter(doc => doc.title.toLowerCase().includes(searchQuery.toLowerCase()) || doc.category.toLowerCase().includes(searchQuery.toLowerCase()) || doc.excerpt.toLowerCase().includes(searchQuery.toLowerCase()), ) return (

Documentation

Search our comprehensive guides and API references

{filteredDocs.length > 0 ? ( filteredDocs.map(doc => (

{doc.title}

{doc.category}

{doc.excerpt}

)) ) : (
🔍
No documentation found for "{searchQuery}"
)}
) } export const DocumentationSearch: Story = { render: () => , } // Real-world example - Command palette const CommandPaletteDemo = () => { const [searchQuery, setSearchQuery] = useState('') const commands = [ { id: 1, name: 'Create new document', icon: '📄', shortcut: '⌘N' }, { id: 2, name: 'Open settings', icon: 'âš™ī¸', shortcut: '⌘,' }, { id: 3, name: 'Search everywhere', icon: '🔍', shortcut: '⌘K' }, { id: 4, name: 'Toggle sidebar', icon: '📁', shortcut: '⌘B' }, { id: 5, name: 'Save changes', icon: '💾', shortcut: '⌘S' }, { id: 6, name: 'Undo last action', icon: 'â†Šī¸', shortcut: '⌘Z' }, { id: 7, name: 'Redo last action', icon: 'â†Ēī¸', shortcut: '⌘⇧Z' }, ] const filteredCommands = commands.filter(cmd => cmd.name.toLowerCase().includes(searchQuery.toLowerCase()), ) return (
{filteredCommands.length > 0 ? ( filteredCommands.map(cmd => (
{cmd.icon} {cmd.name}
{cmd.shortcut}
)) ) : (
No commands found
)}
) } export const CommandPalette: Story = { render: () => , } // Real-world example - Live search with results count const LiveSearchWithCountDemo = () => { const [searchQuery, setSearchQuery] = useState('') const items = [ 'React Documentation', 'React Hooks', 'React Router', 'Redux Toolkit', 'TypeScript Guide', 'JavaScript Basics', 'CSS Grid Layout', 'Flexbox Tutorial', 'Node.js Express', 'MongoDB Guide', ] const filteredItems = items.filter(item => item.toLowerCase().includes(searchQuery.toLowerCase()), ) return (

Learning Resources

{searchQuery && ( {filteredItems.length} result{filteredItems.length !== 1 ? 's' : ''} )}
{filteredItems.map((item, index) => (
{item}
))}
) } export const LiveSearchWithCount: Story = { render: () => , } // Size variations const SizeVariationsDemo = () => { const [value1, setValue1] = useState('') const [value2, setValue2] = useState('') const [value3, setValue3] = useState('') return (
) } export const SizeVariations: Story = { render: () => , } // Interactive playground export const Playground: Story = { render: args => , args: { value: '', placeholder: 'Search...', white: false, }, }