Skip to content

Commit

Permalink
UI: Add SearchBar component
Browse files Browse the repository at this point in the history
Issue #3418
PR #3625
  • Loading branch information
ordabach committed Aug 28, 2023
1 parent 406d907 commit 42bbee1
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import ClearIcon from '@mui/icons-material/Clear';
import {nanoid} from 'nanoid';

const EMPTY_STRING = '';
const DEFAULT_VARIANT = 'standard';
const DEFAULT_PLACEHOLDER = 'Search';
const DEFAULT_LABEL = 'Search';
const SearchBar = (props) => {
const {variant = 'standard', label, placeholder = 'Search', setQuery} = {...props};
const {variant = DEFAULT_VARIANT, label = DEFAULT_LABEL, placeholder = DEFAULT_PLACEHOLDER, setQuery} = {...props};
const [currentValue, setCurrentValue] = useState(EMPTY_STRING);

useEffect(() => {
Expand All @@ -23,28 +26,22 @@ const SearchBar = (props) => {
}

return (
<Box>
<Box className="search-bar-wrapper">
<TextField id={`search-bar-${nanoid()}`}
fullWidth
variant={variant}
label={label}
value={currentValue}
placeholder={placeholder}
onChange={handleValueChange}
InputProps={{
startAdornment: (
<InputAdornment position="start">
startAdornment: (<InputAdornment position="start">
<SearchIcon/>
</InputAdornment>
),
endAdornment: (
currentValue !== '' && (
<InputAdornment position="end">
</InputAdornment>), endAdornment: (currentValue !== '' && (<InputAdornment position="end">
<IconButton onClick={clearValue}>
<ClearIcon/>
</IconButton>
</InputAdornment>
)
)
</InputAdornment>))
}}/>
</Box>
)
Expand Down

0 comments on commit 42bbee1

Please sign in to comment.