|
| 1 | +import clsx from 'clsx' |
| 2 | +import React, { useContext, useState } from 'react' |
| 3 | + |
| 4 | +import { fade, makeStyles, Button, Tooltip, InputBase } from '@material-ui/core' |
| 5 | + |
| 6 | +import { |
| 7 | + MoreVert as IconMore, |
| 8 | + Tune as IconFilter, |
| 9 | + // ArrowDropDown as IconDropDown, |
| 10 | + Add as IconNew, |
| 11 | + Search as IconSearch, |
| 12 | + Clear as IconClear, |
| 13 | +} from '@material-ui/icons' |
| 14 | + |
| 15 | +// import usersListContext from './usersListContext' |
| 16 | + |
| 17 | +const DashboardActions = () => { |
| 18 | + const classes = useStyles() |
| 19 | + const [search, setSearch] = useState('') |
| 20 | + // const { filter } = useContext(usersListContext) |
| 21 | + |
| 22 | + const handleChangeSearchInput = event => { |
| 23 | + setSearch(event.target.value) |
| 24 | + } |
| 25 | + |
| 26 | + const handelClickSearchClearButton = () => { |
| 27 | + setSearch('') |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <div className={classes.root}> |
| 32 | + <div className={classes.search}> |
| 33 | + <div className={classes.searchIcon}> |
| 34 | + <IconSearch /> |
| 35 | + </div> |
| 36 | + <InputBase |
| 37 | + placeholder="Search users…" |
| 38 | + classes={{ |
| 39 | + root: classes.searchInputRoot, |
| 40 | + input: clsx(classes.searchInputInput, search && '-active'), |
| 41 | + }} |
| 42 | + inputProps={{ 'aria-label': 'search' }} |
| 43 | + value={search} |
| 44 | + onChange={handleChangeSearchInput} |
| 45 | + /> |
| 46 | + {search && ( |
| 47 | + <div className={classes.searchButtonClear}> |
| 48 | + <Tooltip title="Clear search"> |
| 49 | + <Button color="secondary" onClick={handelClickSearchClearButton}> |
| 50 | + <IconClear /> |
| 51 | + </Button> |
| 52 | + </Tooltip> |
| 53 | + </div> |
| 54 | + )} |
| 55 | + </div> |
| 56 | + <Tooltip title="Create new user"> |
| 57 | + <Button color="secondary"> |
| 58 | + <IconNew className={classes.iconNew} /> |
| 59 | + New |
| 60 | + </Button> |
| 61 | + </Tooltip> |
| 62 | + <Tooltip title="Filter users"> |
| 63 | + <Button color="secondary"> |
| 64 | + <IconFilter /> |
| 65 | + </Button> |
| 66 | + </Tooltip> |
| 67 | + <Tooltip title="More actions"> |
| 68 | + <Button color="secondary"> |
| 69 | + <IconMore /> |
| 70 | + </Button> |
| 71 | + </Tooltip> |
| 72 | + </div> |
| 73 | + ) |
| 74 | +} |
| 75 | + |
| 76 | +const useStyles = makeStyles(theme => ({ |
| 77 | + root: { |
| 78 | + // color: theme.palette.secondary.main, |
| 79 | + color: theme.palette.grey[600], |
| 80 | + }, |
| 81 | + iconNew: { |
| 82 | + marginRight: 5, |
| 83 | + }, |
| 84 | + search: { |
| 85 | + position: 'relative', |
| 86 | + display: 'inline-block', |
| 87 | + borderRadius: theme.shape.borderRadius, |
| 88 | + backgroundColor: fade(theme.palette.common.white, 0), |
| 89 | + '&:hover': { |
| 90 | + // backgroundColor: fade(theme.palette.common.white, 0.5), |
| 91 | + backgroundColor: 'rgba(140, 209, 54, 0.04)', |
| 92 | + }, |
| 93 | + marginLeft: 0, |
| 94 | + width: '100%', |
| 95 | + [theme.breakpoints.up('sm')]: { |
| 96 | + marginLeft: theme.spacing(1), |
| 97 | + width: 'auto', |
| 98 | + }, |
| 99 | + }, |
| 100 | + searchIcon: { |
| 101 | + padding: theme.spacing(0, 2), |
| 102 | + height: '100%', |
| 103 | + position: 'absolute', |
| 104 | + pointerEvents: 'none', |
| 105 | + display: 'flex', |
| 106 | + alignItems: 'center', |
| 107 | + justifyContent: 'center', |
| 108 | + }, |
| 109 | + searchButtonClear: { |
| 110 | + position: 'absolute', |
| 111 | + height: '100%', |
| 112 | + top: 0, |
| 113 | + right: 0, |
| 114 | + display: 'flex', |
| 115 | + alignItems: 'center', |
| 116 | + justifyContent: 'center', |
| 117 | + }, |
| 118 | + searchInputRoot: { |
| 119 | + color: 'inherit', |
| 120 | + }, |
| 121 | + searchInputInput: { |
| 122 | + padding: theme.spacing(1, 1, 1, 0), |
| 123 | + // vertical padding + font size from searchIcon |
| 124 | + paddingLeft: `calc(1em + ${theme.spacing(4)}px)`, |
| 125 | + paddingRight: '2.2em', |
| 126 | + transition: theme.transitions.create('width'), |
| 127 | + width: '100%', |
| 128 | + [theme.breakpoints.up('sm')]: { |
| 129 | + width: '12ch', |
| 130 | + '&:focus, &.-active': { |
| 131 | + width: '20ch', |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | +})) |
| 136 | + |
| 137 | +export default DashboardActions |
0 commit comments