From 78ecff907a0992e3ee9d58ce565d59d84c530935 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Fri, 25 Mar 2022 14:17:42 +0300 Subject: [PATCH] refactor(theme-classic): clean up CSS of doc cards (#6950) Co-authored-by: sebastienlorber Co-authored-by: Joshua Chen --- .../src/theme/DocCard/index.tsx | 41 +++++++++++-------- .../src/theme/DocCard/styles.module.css | 25 ++++------- .../src/theme/DocCardList/index.tsx | 17 ++++++-- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx index de65d3d642..15c8ac155d 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx @@ -22,20 +22,15 @@ function CardContainer({ href, children, }: { - href?: string; + href: string; children: ReactNode; }): JSX.Element { - const className = clsx( - 'card margin-bottom--lg padding--lg', - styles.cardContainer, - href && styles.cardContainerLink, - ); - return href ? ( - + return ( + {children} - ) : ( -
{children}
); } @@ -45,7 +40,7 @@ function CardLayout({ title, description, }: { - href?: string; + href: string; icon: ReactNode; title: string; description?: string; @@ -55,17 +50,29 @@ function CardLayout({

{icon} {title}

-
- {description} -
+ {description && ( +

+ {description} +

+ )} ); } -function CardCategory({item}: {item: PropSidebarItemCategory}): JSX.Element { +function CardCategory({ + item, +}: { + item: PropSidebarItemCategory; +}): JSX.Element | null { const href = findFirstCategoryLink(item); + + // Unexpected: categories that don't have a link have been filtered upfront + if (!href) { + return null; + } + return ( { + if (item.type === 'category') { + return !!findFirstCategoryLink(item); + } + return true; + }); +} export default function DocCardList({ items, @@ -17,9 +28,9 @@ export default function DocCardList({ }): JSX.Element { return (
- {items.map((item, index) => ( -
- + {filterItems(items).map((item, index) => ( +
+
))}