diff --git a/public/snapshot2.jpeg b/public/snapshot2.jpeg new file mode 100644 index 0000000..7217829 Binary files /dev/null and b/public/snapshot2.jpeg differ diff --git a/public/snapshot2.png b/public/snapshot2.png new file mode 100644 index 0000000..12ced3a Binary files /dev/null and b/public/snapshot2.png differ diff --git a/src/components/MultiSelect.tsx b/src/components/MultiSelect.tsx index 651c726..11d550e 100644 --- a/src/components/MultiSelect.tsx +++ b/src/components/MultiSelect.tsx @@ -5,11 +5,10 @@ export type Item = { label: string; key: string }; export type IProps = { placeholder?: string; list: Item[]; - // selectedItems: Item[]; - // setselectedItems: any; selectedItems: Item[]; setSelectedItems: any; enableSearch?: boolean; + colorSelectedItem?: { border: string; background: string }; }; function MultiSelect({ @@ -23,18 +22,17 @@ function MultiSelect({ selectedItems, setSelectedItems: setselectedItems, enableSearch = true, + colorSelectedItem = { border: "red", background: "rgb(254 242 242)" }, }: IProps) { - // const [selectedItems, setselectedItems] = useState([]); const [showDropDownBox, setshowDropDownBox] = useState(false); const [filtertext, setFiltertext] = useState(""); const [allItem, setAllItem] = useState(list); + const handleAddItem = (itemToBeAdded: Item) => { const doesItemAlreadyExist = selectedItems.find( (item) => item.key === itemToBeAdded.key ); - if (doesItemAlreadyExist) return; - setselectedItems([...selectedItems, itemToBeAdded]); }; @@ -50,6 +48,10 @@ function MultiSelect({ {selectedItems.length === 0 && (
setshowDropDownBox(!showDropDownBox)} > {placeholder} ...{" "} @@ -59,6 +61,10 @@ function MultiSelect({
handleRemoveItem(item)} > {item.label} x{" "} diff --git a/src/components/README.md b/src/components/README.md index 4e83bb6..1fd5d45 100644 --- a/src/components/README.md +++ b/src/components/README.md @@ -39,3 +39,26 @@ yarn add slick-react-multiselect-dropdown # yarn setSelectedItems={setSelectedItem} /> ``` + +## 💄 Themable + +color values for selected Items could be in all css accepted formats. such as `#cece` `rgb(254 242 242)` `green` + +```ts + + const colorSelectedItem = { + { border: "red", background: "rgb(254 242 242)" } + } + + +``` + +## Result + +!["demo snapshot"](https://github.com/jitunayak/slick-react-multiselect-dropdown/blob/main/public/snapshot2.jpeg?raw=true)