diff --git a/src/components/NewSelect.tsx b/src/components/NewSelect.tsx index 32c67c0..968aa81 100644 --- a/src/components/NewSelect.tsx +++ b/src/components/NewSelect.tsx @@ -3,18 +3,26 @@ import ChevronDownIcon from "./icons/ChevronDownIcon"; import ChevronUpIcon from "./icons/ChevronUpIcon"; import clsx from "clsx"; import CloseIcon from "./icons/CloseIcon"; +import Button from "./Button"; +import CheckIcon from "./icons/CheckIcon"; +import { useClickAway } from "@uidotdev/usehooks"; function NewSelect({ data, isGrid, placeholder, + resetTitle, }: { data: T[]; isGrid: boolean; placeholder: string; + resetTitle: string; }) { const [selectedValues, setSelectedValues] = useState([]); const [isSelectVisible, setIsSelectVisible] = useState(false); + const selectRef = useClickAway(() => { + setIsSelectVisible(false); + }); const handleSelectClick = (item: T) => { const isItemSelected = selectedValues.some((val) => val.name === item.name); @@ -41,7 +49,10 @@ function NewSelect({ ) : ( -
+
({ )} onClick={() => setIsSelectVisible(!isSelectVisible)} > -
+
{selectedValues.length > 0 - ? selectedValues.map((value, index) => { - return ( -
- {value.name + - (index !== selectedValues.length - 1 ? ", " : "")} -
- ); - }) + ? selectedValues.map(({ name }) => name).join(", ") : placeholder}
@@ -79,27 +83,39 @@ function NewSelect({ )} >
-
setSelectedValues([])} - > - - - - Выбрать всё +
+
-
+
{data.map((item, index) => (
handleSelectClick(item)} > +
+ {selectedValues + .map((value) => value.name) + .includes(item.name) && ( + + + + )} +
{item.name}
))} diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx index 9edac6a..2cba9de 100644 --- a/src/pages/DashboardPage.tsx +++ b/src/pages/DashboardPage.tsx @@ -76,6 +76,7 @@ function DashboardPage() { ]} isGrid={false} placeholder="Выберите сервер" + resetTitle="Все сервера" />