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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import ShoppingCartIcon from '@material-ui/icons/ShoppingCart';
import SearchIcon from '@material-ui/icons/Search';
import { AppBar, Toolbar, IconButton, Badge } from '@material-ui/core';
import Cart from '../Cart/Cart';
import styles from './search-jss';
class SearchProduct extends React.Component {
state = {
anchorEl: null,
};
handleClick = event => {
this.setState({ anchorEl: event.currentTarget });
};
handleClose = () => {
this.setState({ anchorEl: null });
};
render() {
const { anchorEl } = this.state;
const {
classes,
dataCart,
removeItem,
checkout,
totalItems,
totalPrice,
search
} = this.props;
return (
<div className={classes.root}>
<AppBar position="static" color="inherit">
<Toolbar>
<div className={classes.flex}>
<div className={classes.wrapper}>
<div className={classes.search}>
<SearchIcon />
</div>
<input className={classes.input} placeholder="Search Product" onChange={(event) => search(event)} />
</div>
</div>
<div>
<IconButton
color="inherit"
aria-owns={anchorEl ? 'simple-menu' : null}
aria-haspopup="true"
onClick={this.handleClick}
>
<Badge badgeContent={totalItems} color="secondary">
<ShoppingCartIcon />
</Badge>
</IconButton>
<Cart
anchorEl={anchorEl}
dataCart={dataCart}
close={this.handleClose}
removeItem={removeItem}
checkout={checkout}
totalPrice={totalPrice}
/>
</div>
</Toolbar>
</AppBar>
</div>
);
}
}
SearchProduct.propTypes = {
classes: PropTypes.object.isRequired,
dataCart: PropTypes.object.isRequired,
removeItem: PropTypes.func.isRequired,
search: PropTypes.func.isRequired,
checkout: PropTypes.func.isRequired,
totalItems: PropTypes.number.isRequired,
totalPrice: PropTypes.number.isRequired,
};
export default withStyles(styles)(SearchProduct);
|