/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React, {type ReactNode} from 'react'; import { useDocById, findFirstSidebarItemLink, } from '@docusaurus/plugin-content-docs/client'; import { extractLeadingEmoji, useDocCardDescriptionCategoryItemsPlural, } from '@docusaurus/theme-common/internal'; import isInternalUrl from '@docusaurus/isInternalUrl'; import Layout from '@theme/DocCard/Layout'; import type {Props} from '@theme/DocCard'; import type { PropSidebarItemCategory, PropSidebarItemLink, } from '@docusaurus/plugin-content-docs'; function getFallbackEmojiIcon( item: PropSidebarItemLink | PropSidebarItemCategory, ): string { if (item.type === 'category') { return '🗃'; } return isInternalUrl(item.href) ? '📄️' : '🔗'; } function getIconTitleProps( item: PropSidebarItemLink | PropSidebarItemCategory, ): {icon: ReactNode; title: string} { const extracted = extractLeadingEmoji(item.label); const emoji = extracted.emoji ?? getFallbackEmojiIcon(item); return { icon: emoji, title: extracted.rest.trim(), }; } function CardCategory({item}: {item: PropSidebarItemCategory}): ReactNode { const href = findFirstSidebarItemLink(item); const categoryItemsPlural = useDocCardDescriptionCategoryItemsPlural(); // Unexpected: categories that don't have a link have been filtered upfront if (!href) { return null; } return ( ); } function CardLink({item}: {item: PropSidebarItemLink}): ReactNode { const doc = useDocById(item.docId ?? undefined); return ( ); } export default function DocCard({item}: Props): ReactNode { switch (item.type) { case 'link': return ; case 'category': return ; default: throw new Error(`unknown item type ${JSON.stringify(item)}`); } }