From c1875a8e02e5fc3387237b65075082e5338ca3ab Mon Sep 17 00:00:00 2001 From: PietiKinnunen <106057688+PietiKinnunen@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:52:31 +0200 Subject: [PATCH] Render sub menu items in two columns --- .../DropdownMenu/DropdownSection.module.css | 9 +++ components/DropdownMenu/DropdownSection.tsx | 10 ++- components/DropdownMenu/DropdownSubMenu.tsx | 64 +++++++++++-------- server/sanity-types.ts | 1 + server/sanity.ts | 3 +- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/components/DropdownMenu/DropdownSection.module.css b/components/DropdownMenu/DropdownSection.module.css index 64b13762db..ab4a150027 100644 --- a/components/DropdownMenu/DropdownSection.module.css +++ b/components/DropdownMenu/DropdownSection.module.css @@ -61,3 +61,12 @@ } } } + +.inTwoColumns { + display: grid; + grid-template-columns: 1fr; + column-gap: 4px; + @media (--nav) { + grid-template-columns: 1fr 1fr; + } +} diff --git a/components/DropdownMenu/DropdownSection.tsx b/components/DropdownMenu/DropdownSection.tsx index 14bda7a29f..8d89e8f3d4 100644 --- a/components/DropdownMenu/DropdownSection.tsx +++ b/components/DropdownMenu/DropdownSection.tsx @@ -10,6 +10,7 @@ export interface DropdownMenuProps { isImageLink?: boolean; childLength?: number; isFirst: boolean; + inTwoColumns?: boolean; } const DropdownSection = ({ @@ -22,6 +23,7 @@ const DropdownSection = ({ childLength = 3, isFirst, className, + inTwoColumns = false, ...props }: DropdownMenuProps & React.HTMLAttributes) => { const textExists = title || subtitle ? true : false; @@ -40,7 +42,13 @@ const DropdownSection = ({ {subtitle &&

{subtitle}

} )} -
+
{children}
diff --git a/components/DropdownMenu/DropdownSubMenu.tsx b/components/DropdownMenu/DropdownSubMenu.tsx index d78e41df3f..628fb998f4 100644 --- a/components/DropdownMenu/DropdownSubMenu.tsx +++ b/components/DropdownMenu/DropdownSubMenu.tsx @@ -59,31 +59,45 @@ const DropdownSubMenu = ({ items }: DropdownMenuProps) => { key={`wrapper${submenuTitle}-${i}`} className={cn(styles.wrapper, i === activeTab ? styles.active : "")} > - {submenuSections?.map((section, index) => ( - itemType === "normal" - ) && styles.normal, - index === submenuSections.length - 1 && styles.last - )} - > - {section.sectionItems.map((sectionItemProps, i) => ( - - ))} - - ))} + {submenuSections?.map((section, index) => { + const middleIndex = Math.ceil(section.sectionItems.length / 2); + const items = section.inTwoColumns + ? [ + section.sectionItems.slice(0, middleIndex), + section.sectionItems.slice(middleIndex), + ] + : [section.sectionItems]; + return ( + itemType === "normal" + ) && styles.normal, + index === submenuSections.length - 1 && styles.last + )} + > + {items.map((item, j) => ( +
+ {item.map((sectionItemProps, i) => ( + + ))} +
+ ))} +
+ ); + })} ))} diff --git a/server/sanity-types.ts b/server/sanity-types.ts index a7a03e1286..6ac0a6b99c 100644 --- a/server/sanity-types.ts +++ b/server/sanity-types.ts @@ -26,6 +26,7 @@ type NavSection = { } | null; }; }[]; + inTwoColumns?: boolean | null; }; export type NavigationItem = { title: string; diff --git a/server/sanity.ts b/server/sanity.ts index 8780ff21b9..e4ee83bdf2 100644 --- a/server/sanity.ts +++ b/server/sanity.ts @@ -91,7 +91,8 @@ const navQuery = ` imageDate } } - } + }, + inTwoColumns } } },