index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 CalendarTodayIcon from '@mui/icons-material/CalendarToday';
  8. import StaticDatePicker from "./StaticDatePicker";
  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 { TLeftIsOpen } from '../../../../typescript/redux/control/types';
  14. import { asyncCurrentUser } from '../../../../redux/authorization/operations';
  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. display: 'flex',
  45. alignContent: 'center',
  46. alignItems:'center',
  47. color: '#b1aeae',
  48. height: '7vh',
  49. padding: 0,
  50. margin:0,
  51. },
  52. activeSearch: {
  53. outline: '2px solid #2184f7',
  54. color: '#2184f7'
  55. },
  56. iconBtn: {
  57. '&:hover': {
  58. transform: 'rotate(180deg)',
  59. transition: 'all 250ms ease-out ',
  60. }
  61. },
  62. iconArrow: {
  63. '&:hover': {
  64. transform: 'rotate(360deg)',
  65. transition: 'all 250ms ease-out ',
  66. }
  67. },
  68. })
  69. const label = { inputProps: { 'aria-label': 'Switch demo' } };
  70. interface ISearchBar {
  71. handleClick:() => void,
  72. handleOpenIsSearch:(e: any) => void,
  73. handleSearch:(e: React.ChangeEvent<HTMLInputElement>) => void,
  74. leftIsOpen: TLeftIsOpen,
  75. value: string,
  76. sort: boolean,
  77. setDate: React.Dispatch<any>,
  78. date:any,
  79. disabled: boolean,
  80. }
  81. const SearchBar = ({ handleClick, handleOpenIsSearch, handleSearch, leftIsOpen,
  82. value, sort, setDate, date, disabled }: ISearchBar) => {
  83. const dispatch = useDispatch()
  84. const handleSort = () => {
  85. updateUser({ sort: !sort })
  86. setTimeout(() => {
  87. dispatch(asyncCurrentUser())
  88. }, 1000);
  89. }
  90. const handleOnOpen = () => setDate('')
  91. const classes = useStyles()
  92. return (
  93. <div className={classes.toolBar}>
  94. <IconButton onClick={handleClick}>
  95. {leftIsOpen ? <ArrowBackIcon className={classes.iconArrow} /> : <MenuIcon className={classes.iconBtn} />}
  96. </IconButton>
  97. <div onFocus={handleOpenIsSearch} style={{display:'flex',width:'100%'}}>
  98. <Search id='search' className={value?classes.activeSearch:undefined}>
  99. <SearchIconWrapper id='search'>
  100. <SearchIcon id='search'/>
  101. </SearchIconWrapper>
  102. <StyledInputBase
  103. id='search'
  104. value={value}
  105. onChange={handleSearch}
  106. placeholder={disabled?'Disabled':'Search'}
  107. inputProps={{ 'aria-label': 'search' }}
  108. disabled={disabled}/>
  109. </Search>
  110. <IconButton aria-label="delete" size="medium" disabled={disabled}>
  111. <StaticDatePicker date={date} disabled={disabled}
  112. changeDate={setDate} handleOnOpen={handleOnOpen} />
  113. <CalendarTodayIcon fontSize='medium'
  114. style={{color:date?'#2184f7':'#b1aeae'}}/>
  115. </IconButton>
  116. <Switch id='sort' onClick={handleSort} checked={sort} {...label} disabled={disabled} />
  117. </div>
  118. </div>
  119. )
  120. }
  121. export default SearchBar