index.tsx 3.9 KB

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