index.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import InputBase from '@mui/material/InputBase';
  2. import Toolbar from '@mui/material/Toolbar'
  3. import SearchIcon from '@mui/icons-material/Search';
  4. import CloseIcon from '@mui/icons-material/Close';
  5. import IconButton from '@mui/material/IconButton';
  6. import { styled } from '@mui/material/styles';
  7. import { makeStyles } from '@material-ui/core'
  8. const SearchBar = styled('div')(() => ({
  9. position: 'relative',
  10. borderRadius: '20px',
  11. backgroundColor: '#f1f0f0',
  12. width: '100%',
  13. margin:'0 5% 0 5%'
  14. }));
  15. const SearchIconWrapper = styled('div')(({ theme }) => ({
  16. padding: theme.spacing(0, 2),
  17. height: '100%',
  18. position: 'absolute',
  19. pointerEvents: 'none',
  20. display: 'flex',
  21. alignItems: 'center',
  22. justifyContent: 'center',
  23. }));
  24. const StyledInputBase = styled(InputBase)(({ theme }) => ({
  25. color: 'inherit',
  26. '& .MuiInputBase-input': {
  27. fontWeight: 500,
  28. borderRadius: '20px',
  29. padding: theme.spacing(1, 1, 1, 0),
  30. paddingLeft: `calc(1em + ${theme.spacing(4)})`,
  31. transition: theme.transitions.create('width'),
  32. width: '100%',
  33. },
  34. }));
  35. const useStyles = makeStyles({
  36. toolBar: {
  37. color: '#b1aeae',
  38. height: '7vh',
  39. width:'100%'
  40. },
  41. searchBarActive: {
  42. outline: '2px solid #2184f7',
  43. color: '#2184f7',
  44. },
  45. iconClose: {
  46. '&:hover': {
  47. transform: 'rotate(180deg)',
  48. transition: 'all 250ms ease-out ',
  49. }
  50. },
  51. })
  52. interface IForwardSearch {
  53. handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void,
  54. value: string,
  55. total: string
  56. }
  57. const ForwardSearch = ({handleSearch,value,total}:IForwardSearch) => {
  58. const classes = useStyles()
  59. const disabled = total === '0' ? true : false
  60. return (
  61. <Toolbar className={classes.toolBar} >
  62. <IconButton aria-label="delete" size="medium">
  63. <CloseIcon className={classes.iconClose} fontSize='medium'/>
  64. </IconButton>
  65. <SearchBar className={!value||disabled?undefined:classes.searchBarActive}>
  66. <SearchIconWrapper>
  67. <SearchIcon />
  68. </SearchIconWrapper>
  69. <StyledInputBase
  70. disabled={disabled}
  71. onChange={handleSearch}
  72. placeholder={disabled?'Disabled':'Search'}
  73. value={value}
  74. inputProps={{ 'aria-label': 'search' }}
  75. />
  76. </SearchBar>
  77. </Toolbar>
  78. )
  79. }
  80. export default ForwardSearch