import React, { forwardRef } from 'react'; import { classNames } from '~/utils/classNames'; import { Input } from './Input'; import { motion, AnimatePresence } from 'framer-motion'; interface SearchInputProps extends React.InputHTMLAttributes { /** Function to call when the clear button is clicked */ onClear?: () => void; /** Whether to show the clear button when there is input */ showClearButton?: boolean; /** Additional class name for the search icon */ iconClassName?: string; /** Additional class name for the container */ containerClassName?: string; /** Whether the search is loading */ loading?: boolean; } /** * SearchInput component * * A search input field with a search icon and optional clear button. */ export const SearchInput = forwardRef( ( { className, onClear, showClearButton = true, iconClassName, containerClassName, loading = false, ...props }, ref, ) => { const hasValue = Boolean(props.value); return (
{/* Search icon or loading spinner */}
{loading ? ( ) : ( )}
{/* Input field */} {/* Clear button */} {hasValue && showClearButton && ( )}
); }, ); SearchInput.displayName = 'SearchInput';