index.tsx 4.0 KB

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