From c288efe1bbfe584b1a1f91f2b6ca94adf7101ea5 Mon Sep 17 00:00:00 2001 From: KirisameVanilla <118162831+KirisameVanilla@users.noreply.github.com> Date: Sun, 28 Sep 2025 10:03:14 +0800 Subject: [PATCH] misc: swizzle out doccard --- src/theme/DocCard/index.js | 96 +++++++++++++++++++++++++++++ src/theme/DocCard/styles.module.css | 27 ++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/theme/DocCard/index.js create mode 100644 src/theme/DocCard/styles.module.css diff --git a/src/theme/DocCard/index.js b/src/theme/DocCard/index.js new file mode 100644 index 0000000..282b616 --- /dev/null +++ b/src/theme/DocCard/index.js @@ -0,0 +1,96 @@ +import React from 'react'; +import clsx from 'clsx'; +import Link from '@docusaurus/Link'; +import { + useDocById, + findFirstSidebarItemLink, +} from '@docusaurus/plugin-content-docs/client'; +import {usePluralForm} from '@docusaurus/theme-common'; +import isInternalUrl from '@docusaurus/isInternalUrl'; +import {translate} from '@docusaurus/Translate'; +import Heading from '@theme/Heading'; +import styles from './styles.module.css'; +function useCategoryItemsPlural() { + const {selectMessage} = usePluralForm(); + return (count) => + selectMessage( + count, + translate( + { + message: '1 item|{count} items', + id: 'theme.docs.DocCard.categoryDescription.plurals', + description: + 'The default description for a category card in the generated index about how many items this category includes', + }, + {count}, + ), + ); +} +function CardContainer({className, href, children}) { + return ( + + {children} + + ); +} +function CardLayout({className, href, icon, title, description}) { + return ( + + + {icon} {title} + + {description && ( +

+ {description} +

+ )} +
+ ); +} +function CardCategory({item}) { + const href = findFirstSidebarItemLink(item); + const categoryItemsPlural = useCategoryItemsPlural(); + // Unexpected: categories that don't have a link have been filtered upfront + if (!href) { + return null; + } + return ( + + ); +} +function CardLink({item}) { + const icon = isInternalUrl(item.href) ? '📄️' : '🔗'; + const doc = useDocById(item.docId ?? undefined); + return ( + + ); +} +export default function DocCard({item}) { + switch (item.type) { + case 'link': + return ; + case 'category': + return ; + default: + throw new Error(`unknown item type ${JSON.stringify(item)}`); + } +} diff --git a/src/theme/DocCard/styles.module.css b/src/theme/DocCard/styles.module.css new file mode 100644 index 0000000..4f7ad27 --- /dev/null +++ b/src/theme/DocCard/styles.module.css @@ -0,0 +1,27 @@ +.cardContainer { + --ifm-link-color: var(--ifm-color-emphasis-800); + --ifm-link-hover-color: var(--ifm-color-emphasis-700); + --ifm-link-hover-decoration: none; + + box-shadow: 0 1.5px 3px 0 rgb(0 0 0 / 15%); + border: 1px solid var(--ifm-color-emphasis-200); + transition: all var(--ifm-transition-fast) ease; + transition-property: border, box-shadow; +} + +.cardContainer:hover { + border-color: var(--ifm-color-primary); + box-shadow: 0 3px 6px 0 rgb(0 0 0 / 20%); +} + +.cardContainer *:last-child { + margin-bottom: 0; +} + +.cardTitle { + font-size: 1.2rem; +} + +.cardDescription { + font-size: 0.8rem; +}