|
| 1 | +import * as React from 'react'; |
| 2 | +import TextField from '@mui/material/TextField'; |
| 3 | +import Autocomplete from '@mui/material/Autocomplete'; |
| 4 | +import Chip from '@mui/material/Chip'; |
| 5 | +import Stack from '@mui/material/Stack'; |
| 6 | + |
| 7 | +export default function CustomSingleValueRendering() { |
| 8 | + return ( |
| 9 | + <Stack spacing={3} sx={{ width: 500 }}> |
| 10 | + <Autocomplete |
| 11 | + options={top100Films} |
| 12 | + getOptionLabel={(option) => option.title} |
| 13 | + renderValue={(value, getItemProps) => ( |
| 14 | + <Chip label={value.title} {...getItemProps()} /> |
| 15 | + )} |
| 16 | + renderInput={(params) => <TextField {...params} label="Movie" />} |
| 17 | + /> |
| 18 | + <Autocomplete |
| 19 | + options={top100Films.map((option) => option.title)} |
| 20 | + freeSolo |
| 21 | + renderValue={(value, getItemProps) => ( |
| 22 | + <Chip label={value} {...getItemProps()} /> |
| 23 | + )} |
| 24 | + renderInput={(params) => <TextField {...params} label="freeSolo" />} |
| 25 | + /> |
| 26 | + </Stack> |
| 27 | + ); |
| 28 | +} |
| 29 | + |
| 30 | +// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top |
| 31 | +const top100Films = [ |
| 32 | + { title: 'The Shawshank Redemption', year: 1994 }, |
| 33 | + { title: 'The Godfather', year: 1972 }, |
| 34 | + { title: 'The Godfather: Part II', year: 1974 }, |
| 35 | + { title: 'The Dark Knight', year: 2008 }, |
| 36 | + { title: '12 Angry Men', year: 1957 }, |
| 37 | + { title: "Schindler's List", year: 1993 }, |
| 38 | + { title: 'Pulp Fiction', year: 1994 }, |
| 39 | + { |
| 40 | + title: 'The Lord of the Rings: The Return of the King', |
| 41 | + year: 2003, |
| 42 | + }, |
| 43 | + { title: 'The Good, the Bad and the Ugly', year: 1966 }, |
| 44 | + { title: 'Fight Club', year: 1999 }, |
| 45 | + { |
| 46 | + title: 'The Lord of the Rings: The Fellowship of the Ring', |
| 47 | + year: 2001, |
| 48 | + }, |
| 49 | + { |
| 50 | + title: 'Star Wars: Episode V - The Empire Strikes Back', |
| 51 | + year: 1980, |
| 52 | + }, |
| 53 | + { title: 'Forrest Gump', year: 1994 }, |
| 54 | + { title: 'Inception', year: 2010 }, |
| 55 | + { |
| 56 | + title: 'The Lord of the Rings: The Two Towers', |
| 57 | + year: 2002, |
| 58 | + }, |
| 59 | + { title: "One Flew Over the Cuckoo's Nest", year: 1975 }, |
| 60 | + { title: 'Goodfellas', year: 1990 }, |
| 61 | + { title: 'The Matrix', year: 1999 }, |
| 62 | + { title: 'Seven Samurai', year: 1954 }, |
| 63 | + { |
| 64 | + title: 'Star Wars: Episode IV - A New Hope', |
| 65 | + year: 1977, |
| 66 | + }, |
| 67 | + { title: 'City of God', year: 2002 }, |
| 68 | + { title: 'Se7en', year: 1995 }, |
| 69 | + { title: 'The Silence of the Lambs', year: 1991 }, |
| 70 | + { title: "It's a Wonderful Life", year: 1946 }, |
| 71 | + { title: 'Life Is Beautiful', year: 1997 }, |
| 72 | + { title: 'The Usual Suspects', year: 1995 }, |
| 73 | + { title: 'Léon: The Professional', year: 1994 }, |
| 74 | + { title: 'Spirited Away', year: 2001 }, |
| 75 | + { title: 'Saving Private Ryan', year: 1998 }, |
| 76 | + { title: 'Once Upon a Time in the West', year: 1968 }, |
| 77 | + { title: 'American History X', year: 1998 }, |
| 78 | + { title: 'Interstellar', year: 2014 }, |
| 79 | +]; |
0 commit comments