import React, { useState } from 'react'; import classNames from 'classnames'; import './Search.scss'; import Icon from '../Icon'; import { colors } from '../../colors/colorConstants'; import Input from '../Input'; export interface SearchProps { /** * Placeholder for the input field */ placeholder?: string; /** * Callback function to be called when the search button is clicked or enter key is pressed */ onSearch: (query: string) => void; /** * Additional styles for the button */ className?: string; /** * Pass true for transparentBackground button */ style?: React.CSSProperties; /** * If true, the search input field will be disabled */ disabled?: boolean; height: string; width: string; value: string; onChange: (event: React.ChangeEvent) => void; } const Search = ({ placeholder = 'Search', onSearch, className = '', style = {}, disabled = false, height = '100%', width = '100%', value, onChange, }: SearchProps) => { const [isExpanded, setIsExpanded] = useState(false); const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter') { onSearch(value); } }; const handleIconClick = () => { setIsExpanded(true); }; const handleClear = () => { value = ''; setIsExpanded(false); }; return (
{isExpanded ? (
onSearch(value)} >
) : (
)}
); }; export default Search;