From 1e63c5b1b3078f908a06237d6aefe77b495ea024 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Thu, 23 Feb 2023 17:02:26 +0530 Subject: [PATCH] style: added direction for multi-level drop-down (#328) * feat: made new multi-level select listbox * refractor: changeds Multi-level-select component and added direction props * style: added direction for multi-level drop-down --- .../components/core/multi-level-select.tsx | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/apps/app/components/core/multi-level-select.tsx b/apps/app/components/core/multi-level-select.tsx index db74f8bd2..68a76ae91 100644 --- a/apps/app/components/core/multi-level-select.tsx +++ b/apps/app/components/core/multi-level-select.tsx @@ -20,10 +20,11 @@ type TMultipleSelectProps = { selected: TSelectOption | null; setSelected: (value: any) => void; label: string; + direction?: "left" | "right"; }; -export const MultiSelect: React.FC = (props) => { - const { options, selected, setSelected, label } = props; +export const MultiLevelSelect: React.FC = (props) => { + const { options, selected, setSelected, label, direction = "right" } = props; const [openChildFor, setOpenChildFor] = useState(null); @@ -42,7 +43,7 @@ export const MultiSelect: React.FC = (props) => {
setOpenChildFor(null)} - className="relative w-full cursor-default rounded-lg bg-white py-2 pl-3 pr-10 text-left shadow-md focus:outline-none focus-visible:border-indigo-500 focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75 focus-visible:ring-offset-2 focus-visible:ring-offset-orange-300 sm:text-sm" + className="relative w-full cursor-default rounded-lg bg-white py-2 pl-3 pr-10 text-left shadow-md sm:text-sm" > {selected?.label ?? label} @@ -58,35 +59,41 @@ export const MultiSelect: React.FC = (props) => { > {options.map((option) => ( - `relative cursor-default select-none py-2 pl-10 pr-4 ${ - active ? "bg-amber-100 text-amber-900" : "text-gray-900" - }` + className={ + "relative cursor-default select-none py-2 pl-10 pr-4 hover:bg-gray-100 hover:text-gray-900" } onClick={(e: any) => { if (option.children !== null) { e.preventDefault(); setOpenChildFor(option); } + if (option.id === openChildFor?.id) { + e.preventDefault(); + setOpenChildFor(null); + } }} value={option} > {({ selected }) => ( <> {openChildFor?.id === option.id && ( -
+
{option.children?.map((child) => ( - `relative cursor-default select-none py-2 pl-10 pr-4 ${ - active ? "bg-amber-100 text-amber-900" : "text-gray-900" - }` + className={ + "relative cursor-default select-none py-2 pl-10 pr-4 hover:bg-gray-100 hover:text-gray-900" } as="div" value={child} @@ -101,7 +108,7 @@ export const MultiSelect: React.FC = (props) => { {child.label} {selected ? ( - + ) : null} @@ -110,7 +117,13 @@ export const MultiSelect: React.FC = (props) => { ))} -
+
)} = (props) => { {option.label} {selected ? ( - + ) : null}