diff --git a/.changeset/gorgeous-kids-dream.md b/.changeset/gorgeous-kids-dream.md new file mode 100644 index 000000000..478abe10b --- /dev/null +++ b/.changeset/gorgeous-kids-dream.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Update footer styling and allow for more than 4 footer groups diff --git a/packages/gitbook/src/components/Footer/Footer.tsx b/packages/gitbook/src/components/Footer/Footer.tsx index 49e03a2e8..083d2fbf6 100644 --- a/packages/gitbook/src/components/Footer/Footer.tsx +++ b/packages/gitbook/src/components/Footer/Footer.tsx @@ -2,6 +2,7 @@ import { CustomizationSettings, SiteCustomizationSettings, Space } from '@gitboo import React from 'react'; import { Image } from '@/components/utils'; +import { partition } from '@/lib/arrays'; import { ContentRefContext } from '@/lib/references'; import { tcls } from '@/lib/tailwind'; @@ -9,6 +10,8 @@ import { FooterLinksGroup } from './FooterLinksGroup'; import { CONTAINER_STYLE } from '../layout'; import { ThemeToggler } from '../ThemeToggler'; +const FOOTER_COLUMNS = 4; + export function Footer(props: { space: Space; context: ContentRefContext; @@ -17,125 +20,115 @@ export function Footer(props: { const { context, customization } = props; return ( -
-
+
+
+ {/* Footer Logo */} +
+ {customization.footer.logo ? ( + Logo + ) : null} +
+ + {/* Mode Switcher */}
- {' '} - {customization.footer.logo ? ( -
- Logo -
- ) : null} -
- {customization.footer.logo || customization.footer.groups?.length > 0 ? ( -
- {customization.footer.groups.map((group, index) => ( - - ))} -
- ) : null} - {customization.footer.copyright ? ( -

- {customization.footer.copyright} -

- ) : null} -
{customization.themes.toggeable ? ( -
+
) : null}
+ + {/* Navigation Groups (split into equal columns) */} + {customization.footer.groups?.length > 0 ? ( +
+ {partition(customization.footer.groups, FOOTER_COLUMNS).map( + (column, columnIndex) => ( +
+ {column.map((group, groupIndex) => ( + + ))} +
+ ), + )} +
+ ) : null} + + {/* Legal */} +
+ {customization.footer.copyright ? ( +

{customization.footer.copyright}

+ ) : null} +
-
+
); } diff --git a/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx b/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx index d0c55c249..bcb12615e 100644 --- a/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx +++ b/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx @@ -16,12 +16,18 @@ export function FooterLinksGroup(props: { const { group, context } = props; return ( -
-

{group.title}

- {group.links.map((link, index) => { - return ; - })} -
+ ); } @@ -37,12 +43,15 @@ async function FooterLink(props: { link: CustomizationContentLink; context: Cont +
- + ); } diff --git a/packages/gitbook/src/lib/arrays.ts b/packages/gitbook/src/lib/arrays.ts new file mode 100644 index 000000000..e87bdcc60 --- /dev/null +++ b/packages/gitbook/src/lib/arrays.ts @@ -0,0 +1,22 @@ +/** + * Partition an array into equal (+ rest items) parts. + * Adapted from https://stackoverflow.com/a/68917937 + */ +export function partition( + /** + * Array to split up + */ + array: any[], + /** + * Amount of parts you want to split into + */ + parts: number, +) { + let rest = array.length % parts; + let size = Math.floor(array.length / parts); + let j = 0; + + return Array.from({ length: Math.min(array.length, parts) }, (_, i) => + array.slice(j, (j += size + (i < rest ? 1 : 0))), + ); +}