Add DropdownFilter
as generic filter to use for tags and categories
This commit is contained in:
parent
ae9c59ca2b
commit
1d9ff5d67a
34
frontend/leeds-beer-quest/src/components/dropdown-filter.tsx
Normal file
34
frontend/leeds-beer-quest/src/components/dropdown-filter.tsx
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { ListItemText, MenuItem, Select, SelectChangeEvent } from "@mui/material";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export type TFilter = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TDropdownFilterProps = {
|
||||||
|
filters: TFilter[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DropdownFilter(props: TDropdownFilterProps) {
|
||||||
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
||||||
|
|
||||||
|
const handleChange = (event: SelectChangeEvent<typeof selectedTags>) => {
|
||||||
|
const { value } = event.target;
|
||||||
|
setSelectedTags(typeof value == "string" ? value.split(",") : value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return(
|
||||||
|
<Select
|
||||||
|
multiple
|
||||||
|
value={selectedTags}
|
||||||
|
onChange={handleChange}
|
||||||
|
renderValue={(selected) => selected.join(', ')}>
|
||||||
|
{props.filters.map((filter) => (
|
||||||
|
<MenuItem key={filter.id} value={filter.name}>
|
||||||
|
<ListItemText primary={filter.name} />
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user