File size: 1,794 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import React from 'react';
import Grow from '@mui/material/Grow';
import TextField from '@mui/material/TextField';
import IconButton from '@mui/material/IconButton';
import ClearIcon from '@mui/icons-material/Clear';
import { withStyles } from "tss-react/mui";
const defaultSearchStyles = theme => ({
main: {
display: 'flex',
flex: '1 0 auto',
},
searchText: {
flex: '0.8 0',
},
clearIcon: {
'&:hover': {
color: theme.palette.error.main,
},
},
});
class CustomSearchRender extends React.Component {
handleTextChange = event => {
this.props.onSearch(event.target.value);
};
componentDidMount() {
document.addEventListener('keydown', this.onKeyDown, false);
}
componentWillUnmount() {
document.removeEventListener('keydown', this.onKeyDown, false);
}
onKeyDown = event => {
if (event.keyCode === 27) {
this.props.onHide();
}
};
render() {
const { classes, options, onHide, searchText } = this.props;
return (
<Grow appear in={true} timeout={300}>
<div className={classes.main} ref={el => (this.rootRef = el)}>
<TextField
placeholder={'Custom TableSearch without search icon'}
className={classes.searchText}
InputProps={{
'aria-label': options.textLabels.toolbar.search,
}}
value={searchText || ''}
onChange={this.handleTextChange}
fullWidth={true}
inputRef={el => (this.searchField = el)}
/>
<IconButton className={classes.clearIcon} onClick={onHide}>
<ClearIcon />
</IconButton>
</div>
</Grow>
);
}
}
export default withStyles(CustomSearchRender, defaultSearchStyles, { name: 'CustomSearchRender' });
|