index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import Toolbar from '@mui/material/Toolbar'
  2. import IconButton from '@mui/material/IconButton'
  3. import MenuIcon from '@mui/icons-material/Menu';
  4. import SearchIcon from '@mui/icons-material/Search';
  5. import InputBase from '@mui/material/InputBase';
  6. import ArrowBackIcon from '@mui/icons-material/ArrowBack';
  7. import Switch from '@mui/material/Switch';
  8. import CalendarTodayIcon from '@mui/icons-material/CalendarToday';
  9. import { styled } from '@mui/material/styles';
  10. import { makeStyles } from '@material-ui/core'
  11. import { useDispatch } from 'react-redux';
  12. import { updateUser } from '../../../../api-data';
  13. import { asyncCurrentUser } from '../../../../redux/authorization/operations';
  14. import StaticDatePicker from "./StaticDatePicker";
  15. const Search = styled('div')(({ theme }:any) => ({
  16. position: 'relative',
  17. borderRadius: '20px',
  18. backgroundColor: '#f1f0f0',
  19. width: '100%',
  20. margin:'0 5% 0 5%'
  21. }));
  22. const SearchIconWrapper = styled('div')(({ theme }) => ({
  23. padding: theme.spacing(0, 2),
  24. height: '100%',
  25. position: 'absolute',
  26. pointerEvents: 'none',
  27. display: 'flex',
  28. alignItems: 'center',
  29. justifyContent: 'center',
  30. }));
  31. const StyledInputBase = styled(InputBase)(({ theme }) => ({
  32. color: 'inherit',
  33. '& .MuiInputBase-input': {
  34. fontWeight: 500,
  35. borderRadius: '20px',
  36. padding: theme.spacing(1, 1, 1, 0),
  37. paddingLeft: `calc(1em + ${theme.spacing(4)})`,
  38. transition: theme.transitions.create('width'),
  39. width: '100%',
  40. },
  41. }));
  42. const useStyles = makeStyles({
  43. toolBar: {
  44. color: '#b1aeae',
  45. height: '7vh',
  46. },
  47. activeSearch: {
  48. outline: '2px solid #2184f7',
  49. color: '#2184f7'
  50. },
  51. iconBtn: {
  52. '&:hover': {
  53. transform: 'rotate(180deg)',
  54. transition: 'all 250ms ease-out ',
  55. }
  56. },
  57. iconArrow: {
  58. '&:hover': {
  59. transform: 'rotate(360deg)',
  60. transition: 'all 250ms ease-out ',
  61. }
  62. },
  63. })
  64. const label = { inputProps: { 'aria-label': 'Switch demo' } };
  65. interface ISearchBar {
  66. handleClick:() => void,
  67. handleFocus:() => void,
  68. handleSearch:(e: React.ChangeEvent<HTMLInputElement>) => void,
  69. isSearch: boolean,
  70. value: string,
  71. sort: boolean,
  72. setDate: React.Dispatch<any>,
  73. date:any,
  74. }
  75. const SearchBar = ({ handleClick, handleFocus, handleSearch, isSearch,
  76. value, sort,setDate,date }: ISearchBar) => {
  77. const dispatch = useDispatch()
  78. const handleSort = () => {
  79. updateUser({ sort: !sort })
  80. dispatch(asyncCurrentUser())
  81. }
  82. const handleOnOpen = () => setDate('')
  83. const classes = useStyles()
  84. return (
  85. <Toolbar className={classes.toolBar}>
  86. <IconButton onClick={handleClick}>
  87. {isSearch ? <ArrowBackIcon className={classes.iconArrow} /> : <MenuIcon className={classes.iconBtn} />}
  88. </IconButton>
  89. <Search className={value?classes.activeSearch:undefined}>
  90. <SearchIconWrapper>
  91. <SearchIcon />
  92. </SearchIconWrapper>
  93. <StyledInputBase
  94. value={value}
  95. onFocus={handleFocus}
  96. onChange={handleSearch}
  97. placeholder='Search'
  98. inputProps={{ 'aria-label': 'search' }}
  99. />
  100. </Search>
  101. <IconButton aria-label="delete" size="medium">
  102. <StaticDatePicker date={date}
  103. changeDate={setDate} handleOnOpen={handleOnOpen} />
  104. <CalendarTodayIcon fontSize='medium'
  105. style={{color:date?'#2184f7':'#b1aeae'}}/>
  106. </IconButton>
  107. <Switch onClick={handleSort} checked={sort} {...label} />
  108. </Toolbar>
  109. )
  110. }
  111. export default SearchBar