Add DropdownFilter as generic filter to use for tags and categories

This commit is contained in:
Stedoss 2022-10-31 13:28:54 +00:00
parent ae9c59ca2b
commit 1d9ff5d67a

View 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>
);
}