Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Render navigation submenu items in two columns #509

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/DropdownMenu/DropdownSection.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@
}
}
}

.inTwoColumns {
display: grid;
grid-template-columns: 1fr;
column-gap: 4px;
@media (--nav) {
grid-template-columns: 1fr 1fr;
}
}
10 changes: 9 additions & 1 deletion components/DropdownMenu/DropdownSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DropdownMenuProps {
isImageLink?: boolean;
childLength?: number;
isFirst: boolean;
inTwoColumns?: boolean;
}

const DropdownSection = ({
Expand All @@ -22,6 +23,7 @@ const DropdownSection = ({
childLength = 3,
isFirst,
className,
inTwoColumns = false,
...props
}: DropdownMenuProps & React.HTMLAttributes<HTMLDivElement>) => {
const textExists = title || subtitle ? true : false;
Expand All @@ -40,7 +42,13 @@ const DropdownSection = ({
{subtitle && <p className={styles.subtitle}>{subtitle}</p>}
</div>
)}
<div className={cn(styles.sectionBox, textExists && styles.hasText)}>
<div
className={cn(
styles.sectionBox,
textExists && styles.hasText,
inTwoColumns && styles.inTwoColumns
)}
>
{children}
</div>
</div>
Expand Down
64 changes: 39 additions & 25 deletions components/DropdownMenu/DropdownSubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,45 @@ const DropdownSubMenu = ({ items }: DropdownMenuProps) => {
key={`wrapper${submenuTitle}-${i}`}
className={cn(styles.wrapper, i === activeTab ? styles.active : "")}
>
{submenuSections?.map((section, index) => (
<DropdownSection
key={`drsection${section.title}-${index}`}
titleLink={false}
isImageLink={false}
title={section.title || undefined}
subtitle={section.subtitle}
isFirst={index === 0}
className={cn(
styles.dropdownSection,
section.sectionItems.find(
({ itemType }) => itemType === "normal"
) && styles.normal,
index === submenuSections.length - 1 && styles.last
)}
>
{section.sectionItems.map((sectionItemProps, i) => (
<DropdownMenuItem
key={`${sectionItemProps.title}-item${i}`}
title={sectionItemProps.title || undefined}
{...sectionItemProps}
/>
))}
</DropdownSection>
))}
{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 (
<DropdownSection
key={`drsection${section.title}-${index}`}
titleLink={false}
isImageLink={false}
title={section.title || undefined}
subtitle={section.subtitle}
isFirst={index === 0}
inTwoColumns={section?.inTwoColumns}
className={cn(
styles.dropdownSection,
section.sectionItems.find(
({ itemType }) => itemType === "normal"
) && styles.normal,
index === submenuSections.length - 1 && styles.last
)}
>
{items.map((item, j) => (
<div key={`submenu-items-${item[0]?.title}-${j}`}>
{item.map((sectionItemProps, i) => (
<DropdownMenuItem
title={sectionItemProps?.title || undefined}
key={`${sectionItemProps?.title}-item${i}`}
{...sectionItemProps}
/>
))}
</div>
))}
</DropdownSection>
);
})}
</div>
))}
</div>
Expand Down
1 change: 1 addition & 0 deletions server/sanity-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type NavSection = {
} | null;
};
}[];
inTwoColumns?: boolean | null;
};
export type NavigationItem = {
title: string;
Expand Down
3 changes: 2 additions & 1 deletion server/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const navQuery = `
imageDate
}
}
}
},
inTwoColumns
}
}
},
Expand Down
Loading