From 59d285bcbdd12b70d7a3fb41d07e7460d76d3bf3 Mon Sep 17 00:00:00 2001 From: sebastien Date: Tue, 24 Dec 2024 17:21:47 +0100 Subject: [PATCH 1/3] Theme: Footer Column/Link should merge provided className instead of overriding default --- packages/docusaurus-theme-classic/src/options.ts | 14 ++++++++------ .../src/theme/Footer/LinkItem/index.tsx | 6 +++--- .../src/theme/Footer/Links/MultiColumn/index.tsx | 5 +++-- .../src/theme/Footer/Links/Simple/index.tsx | 3 ++- .../src/utils/useThemeConfig.ts | 1 + website/docusaurus.config.ts | 5 +++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/options.ts b/packages/docusaurus-theme-classic/src/options.ts index 7bd6253565cf..6827c069bcbb 100644 --- a/packages/docusaurus-theme-classic/src/options.ts +++ b/packages/docusaurus-theme-classic/src/options.ts @@ -308,6 +308,7 @@ const FooterLinkItemSchema = Joi.object({ href: URISchema, html: Joi.string(), label: Joi.string(), + className: Joi.string(), }) .xor('to', 'href', 'html') .with('to', 'label') @@ -317,6 +318,12 @@ const FooterLinkItemSchema = Joi.object({ // attributes like target, aria-role, data-customAttribute...) .unknown(); +const FooterColumnItemSchema = Joi.object({ + title: Joi.string().allow(null).default(null), + className: Joi.string(), + items: Joi.array().items(FooterLinkItemSchema).default([]), +}); + const LogoSchema = Joi.object({ alt: Joi.string().allow(''), src: Joi.string().required(), @@ -384,12 +391,7 @@ export const ThemeConfigSchema = Joi.object({ logo: LogoSchema, copyright: Joi.string(), links: Joi.alternatives( - Joi.array().items( - Joi.object({ - title: Joi.string().allow(null).default(null), - items: Joi.array().items(FooterLinkItemSchema).default([]), - }), - ), + Joi.array().items(FooterColumnItemSchema), Joi.array().items(FooterLinkItemSchema), ) .messages({ diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx index 8f6f09a8753e..ac4f6b488dd3 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx @@ -6,7 +6,7 @@ */ import React, {type ReactNode} from 'react'; - +import clsx from 'clsx'; import Link from '@docusaurus/Link'; import useBaseUrl from '@docusaurus/useBaseUrl'; import isInternalUrl from '@docusaurus/isInternalUrl'; @@ -14,13 +14,13 @@ import IconExternalLink from '@theme/Icon/ExternalLink'; import type {Props} from '@theme/Footer/LinkItem'; export default function FooterLinkItem({item}: Props): ReactNode { - const {to, href, label, prependBaseUrlToHref, ...props} = item; + const {to, href, label, prependBaseUrlToHref, className, ...props} = item; const toUrl = useBaseUrl(to); const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true}); return ( +
{column.title}
    {column.items.map((item, i) => ( diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/Links/Simple/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/Links/Simple/index.tsx index fcb98352e6be..5286cf43049a 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/Links/Simple/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/Links/Simple/index.tsx @@ -6,6 +6,7 @@ */ import React, {type ReactNode} from 'react'; +import clsx from 'clsx'; import LinkItem from '@theme/Footer/LinkItem'; import type {Props} from '@theme/Footer/Links/Simple'; @@ -16,7 +17,7 @@ function Separator() { function SimpleLinkItem({item}: {item: Props['links'][number]}) { return item.html ? ( Date: Thu, 26 Dec 2024 12:39:01 +0100 Subject: [PATCH 2/3] fix typing --- .../src/utils/useThemeConfig.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts index ebbf060e1f9c..4b0c61202e00 100644 --- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts +++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts @@ -82,11 +82,14 @@ export type FooterBase = { copyright?: string; }; +export type FooterColumnItem = { + title: string | null; + className?: string; + items: FooterLinkItem[]; +}; + export type MultiColumnFooter = FooterBase & { - links: { - title: string | null; - items: FooterLinkItem[]; - }[]; + links: FooterColumnItem[]; }; export type SimpleFooter = FooterBase & { From 925b997849151501d1663d40b1dc799b27dbff1c Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 26 Dec 2024 12:39:17 +0100 Subject: [PATCH 3/3] fix typing --- .../src/utils/useThemeConfig.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts index 4b0c61202e00..f9e13eaa1648 100644 --- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts +++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts @@ -74,6 +74,12 @@ export type FooterLinkItem = { prependBaseUrlToHref?: string; } & {[key: string]: unknown}; +export type FooterColumnItem = { + title: string | null; + className?: string; + items: FooterLinkItem[]; +}; + export type FooterLogo = BaseLogo; export type FooterBase = { @@ -82,12 +88,6 @@ export type FooterBase = { copyright?: string; }; -export type FooterColumnItem = { - title: string | null; - className?: string; - items: FooterLinkItem[]; -}; - export type MultiColumnFooter = FooterBase & { links: FooterColumnItem[]; };