From cc28e8e93965b7d7401a258a14d8025f68dc7f92 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 8 Aug 2024 11:50:57 -0700 Subject: [PATCH] Add multiselect --- lib/components/multiselect.tsx | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/components/multiselect.tsx diff --git a/lib/components/multiselect.tsx b/lib/components/multiselect.tsx new file mode 100644 index 0000000..3a8c005 --- /dev/null +++ b/lib/components/multiselect.tsx @@ -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>; +} + +export const Multiselect = ({ label, options, selectedOptions, setSelectedOptions }: MultiselectProps) => { + const handleSelect = (option) => { + if (selectedOptions.includes(option)) { + setSelectedOptions(selectedOptions.filter((item) => item !== option)); + } else { + setSelectedOptions([...selectedOptions, option]); + } + }; + + return ( +
+ + + + + + {options.map((option, index) => ( + handleSelect(option)}> +
+ {option} + {selectedOptions.includes(option) && } +
+
+ ))} +
+
+
+ {selectedOptions.map((option, index) => ( + + ))} +
+
+ ); +};