import React from 'react'; import { Box, IconButton, InputAdornment, TextField } from…
- User
import React from 'react'; import { Box, IconButton, InputAdornment, TextField } from '@mui/material'; import { Search, Clear } from '@mui/icons-material';
interface SearchBarProps { placeholder?: string; onSearch: (searchTerm: string) => void; }
export const SearchBar: React.FC = ({placeholder = 'Поиск...', onSearch}) => { const [searchTerm, setSearchTerm] = React.useState("");
codeconst handleSearch = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { setSearchTerm(event.target.value); onSearch(searchTerm); }; const handleClearSearch = () => { setSearchTerm(''); onSearch(''); }; return ( <Box sx={{display: 'flex', alignItems: 'center'}}> <TextField value={searchTerm} onChange={(e) => handleSearch(e)} placeholder={placeholder} InputProps={{ startAdornment: ( <InputAdornment position='start'> <Search /> </InputAdornment> ), endAdornment: ( <InputAdornment position='end'> {searchTerm && ( <IconButton onClick={handleClearSearch}> <Clear /> </IconButton> )} </InputAdornment> ), }} sx={{ width: '100%' }} /> </Box> );}
Assistant