Skip to content

Commit

Permalink
Add multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
JShep-tri committed Aug 8, 2024
1 parent 69af4f2 commit cc28e8e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/components/multiselect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { Menu, MenuHandler, MenuList, MenuItem, Button, Chip } from '@material-tailwind/react';

interface MultiselectProps {
label: string;
options: string[];
selectedOptions: string[];
setSelectedOptions: React.Dispatch<React.SetStateAction<string[]>>;
}

export const Multiselect = ({ label, options, selectedOptions, setSelectedOptions }: MultiselectProps) => {
const handleSelect = (option) => {

Check failure on line 12 in lib/components/multiselect.tsx

View workflow job for this annotation

GitHub Actions / Test Pull Request

Parameter 'option' implicitly has an 'any' type.
if (selectedOptions.includes(option)) {
setSelectedOptions(selectedOptions.filter((item) => item !== option));
} else {
setSelectedOptions([...selectedOptions, option]);
}
};

return (
<div className="w-full">
<Menu>
<MenuHandler>
<Button variant="outlined" color="blue" className="w-full">
{label}
</Button>
</MenuHandler>
<MenuList className="max-w-full">
{options.map((option, index) => (
<MenuItem key={index} onClick={() => handleSelect(option)}>
<div className="flex w-full items-center justify-between">
<span>{option}</span>
{selectedOptions.includes(option) && <Chip value="Selected" color="green" size="sm" className="ml-2" />}
</div>
</MenuItem>
))}
</MenuList>
</Menu>
<div className="mt-2 flex flex-wrap gap-2">
{selectedOptions.map((option, index) => (
<Chip key={index} value={option} color="blue" size="sm" />
))}
</div>
</div>
);
};

0 comments on commit cc28e8e

Please sign in to comment.