import * as React from "react"; import { Search, X, Mic } from "lucide-react"; import { cn } from "@/lib/cn"; export interface MobileSearchProps extends Omit, "size"> { /** Show the clear (X) button when there is a value. Default: true. */ clearable?: boolean; /** Show the mic button for voice input. Default: false. */ showMic?: boolean; /** Handler when the mic button is pressed. */ onMicClick?: () => void; /** Handler when the clear button is pressed. */ onClear?: () => void; } /** * MobileSearch - search bar with a search icon, clear button, and optional mic. */ const MobileSearch = React.forwardRef( ( { className, value, onChange, clearable = true, showMic = false, onMicClick, onClear, placeholder = "Search...", ...props }, ref ) => { const hasValue = value !== undefined && String(value).length > 0; const handleClear = () => { onClear?.(); if (onChange) { const event = { target: { value: "" }, } as React.ChangeEvent; onChange(event); } }; return (
{clearable && hasValue && ( )} {showMic && ( )}
); } ); MobileSearch.displayName = "MobileSearch"; export { MobileSearch };