|
1 | 1 | import React from 'react';
|
2 | 2 | import TextField from '@material-ui/core/TextField';
|
3 | 3 | import Autocomplete from '@material-ui/lab/Autocomplete';
|
4 |
| -import useNavBarStyles from "../../../styles/materialUI/navBarStyles"; |
5 | 4 | import CloseIcon from '@material-ui/icons/Close';
|
| 5 | +import ArrowBackIcon from '@material-ui/icons/ArrowBack'; |
| 6 | +import {Grid} from "@material-ui/core"; |
| 7 | +import SearchIcon from '@material-ui/icons/Search'; |
6 | 8 |
|
7 |
| -export default function SearchBar(props) { |
| 9 | +function SearchBar(props) { |
8 | 10 | const [value, setValue] = React.useState(null);
|
9 |
| - const classes = useNavBarStyles(); |
10 | 11 |
|
11 | 12 | const handleClose = () => {
|
12 | 13 | if (props.handleClose) {
|
13 | 14 | props.handleClose();
|
14 | 15 | }
|
15 | 16 | }
|
16 | 17 |
|
| 18 | + const renderDesktopTextField = (params) => { |
| 19 | + return <TextField {...params} label="Search for products, brands and more" variant="outlined"/> |
| 20 | + } |
| 21 | + |
| 22 | + const renderMobileTextField = (params) => { |
| 23 | + return ( |
| 24 | + <TextField |
| 25 | + style={{position: "absolute", left: 0, top: 15}} |
| 26 | + label="Search for products, brands and more" |
| 27 | + variant="outlined" |
| 28 | + {...params} |
| 29 | + InputProps={{ |
| 30 | + ...params.InputProps, |
| 31 | + startAdornment: <ArrowBackIcon onClick={props.handleClose} fontSize="large"/>, |
| 32 | + endAdornment: <SearchIcon fontSize="large"/> |
| 33 | + }} |
| 34 | + /> |
| 35 | + ) |
| 36 | + } |
| 37 | + |
17 | 38 | return (
|
18 |
| - <Autocomplete |
19 |
| - value={value} |
20 |
| - autoHighlight |
21 |
| - onChange={(event, newValue) => { |
22 |
| - if (typeof newValue === 'string') { |
23 |
| - setValue({ |
24 |
| - title: newValue, |
25 |
| - }); |
26 |
| - } else if (newValue && newValue.inputValue) { |
27 |
| - // Create a new value from the user input |
28 |
| - setValue({ |
29 |
| - title: newValue.inputValue, |
30 |
| - }); |
31 |
| - } else { |
32 |
| - setValue(newValue); |
33 |
| - } |
34 |
| - }} |
35 |
| - selectOnFocus |
36 |
| - clearOnBlur |
37 |
| - handleHomeEndKeys |
38 |
| - closeIcon={<CloseIcon/>} |
39 |
| - id="free-solo-with-text-demo" |
40 |
| - options={top100Films} |
41 |
| - getOptionLabel={(option) => { |
42 |
| - // Value selected with enter, right from the input |
43 |
| - if (typeof option === 'string') { |
44 |
| - return option; |
45 |
| - } |
46 |
| - // Add "xxx" option created dynamically |
47 |
| - if (option.inputValue) { |
48 |
| - return option.inputValue; |
49 |
| - } |
50 |
| - // Regular option |
51 |
| - return option.title; |
52 |
| - }} |
53 |
| - renderOption={(option) => option.title} |
54 |
| - freeSolo |
55 |
| - fullWidth |
56 |
| - onClose={handleClose} |
57 |
| - size={props.size} |
58 |
| - classes={{root: classes.autoCompleteSearchBarRoot}} |
59 |
| - renderInput={(params) => ( |
60 |
| - <TextField {...params} label="Search for products, brands and more" variant="outlined"/> |
61 |
| - )} |
62 |
| - /> |
| 39 | + <Grid container alignItems="center"> |
| 40 | + <Autocomplete |
| 41 | + value={value} |
| 42 | + autoHighlight |
| 43 | + onChange={(event, newValue) => { |
| 44 | + if (typeof newValue === 'string') { |
| 45 | + setValue({ |
| 46 | + title: newValue, |
| 47 | + }); |
| 48 | + } else if (newValue && newValue.inputValue) { |
| 49 | + // Create a new value from the user input |
| 50 | + setValue({ |
| 51 | + title: newValue.inputValue, |
| 52 | + }); |
| 53 | + } else { |
| 54 | + setValue(newValue); |
| 55 | + } |
| 56 | + }} |
| 57 | + selectOnFocus |
| 58 | + clearOnBlur |
| 59 | + handleHomeEndKeys |
| 60 | + closeIcon={<CloseIcon/>} |
| 61 | + id="free-solo-with-text-demo" |
| 62 | + options={top100Films} |
| 63 | + getOptionLabel={(option) => { |
| 64 | + // Value selected with enter, right from the input |
| 65 | + if (typeof option === 'string') { |
| 66 | + return option; |
| 67 | + } |
| 68 | + // Add "xxx" option created dynamically |
| 69 | + if (option.inputValue) { |
| 70 | + return option.inputValue; |
| 71 | + } |
| 72 | + // Regular option |
| 73 | + return option.title; |
| 74 | + }} |
| 75 | + renderOption={(option) => option.title} |
| 76 | + freeSolo |
| 77 | + fullWidth |
| 78 | + onClose={handleClose} |
| 79 | + size={props.size} |
| 80 | + renderInput={(params) => |
| 81 | + props.device ? renderMobileTextField(params): renderDesktopTextField(params)} |
| 82 | + /> |
| 83 | + </Grid> |
63 | 84 | );
|
64 | 85 | }
|
65 | 86 |
|
66 | 87 | // Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
|
67 | 88 | const top100Films = [
|
68 |
| - {title: 'The Shawshank Redemption', year: 1994}, |
69 |
| - {title: 'The Godfather', year: 1972}, |
70 |
| - {title: 'The Godfather: Part II', year: 1974}, |
71 |
| - {title: 'The Dark Knight', year: 2008}, |
72 |
| - {title: '12 Angry Men', year: 1957}, |
73 |
| - {title: "Schindler's List", year: 1993}, |
74 |
| - {title: 'Léon: The Professional', year: 1994}, |
75 |
| - {title: 'Like Stars on Earth', year: 2007}, |
76 |
| - {title: 'Taxi Driver', year: 1976}, |
77 |
| - {title: 'Lawrence of Arabia', year: 1962}, |
78 |
| - {title: 'Double Indemnity', year: 1944}, |
79 |
| - {title: 'Eternal Sunshine of the Spotless Mind', year: 2004}, |
80 |
| - {title: 'Amadeus', year: 1984}, |
81 |
| - {title: 'To Kill a Mockingbird', year: 1962}, |
82 |
| - {title: 'Toy Story 3', year: 2010}, |
83 |
| - {title: 'Logan', year: 2017}, |
84 |
| - {title: 'Full Metal Jacket', year: 1987}, |
85 |
| - {title: 'Dangal', year: 2016}, |
86 |
| - {title: 'The Sting', year: 1973}, |
87 |
| - {title: '2001: A Space Odyssey', year: 1968}, |
88 |
| - {title: "Singin' in the Rain", year: 1952}, |
89 |
| - {title: 'Toy Story', year: 1995}, |
90 |
| - {title: 'Bicycle Thieves', year: 1948}, |
91 |
| - {title: 'The Kid', year: 1921}, |
92 |
| - {title: 'Inglourious Basterds', year: 2009}, |
93 |
| - {title: 'Snatch', year: 2000}, |
94 |
| - {title: '3 Idiots', year: 2009}, |
95 |
| - {title: 'Monty Python and the Holy Grail', year: 1975}, |
| 89 | + {title: 'Not Working Right Now', year: 1994}, |
| 90 | + |
96 | 91 | ];
|
| 92 | + |
| 93 | +export default SearchBar; |
0 commit comments