feat: Support @defaultValue (#9363)

This commit is contained in:
Jiralite 2023-04-10 12:56:43 +01:00 committed by GitHub
parent 69cdeb7296
commit 733c96c255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ import { Fragment, useCallback, type ReactNode } from 'react';
import { ItemLink } from '../../ItemLink';
import { SyntaxHighlighter } from '../../SyntaxHighlighter';
import { resolveItemURI } from '../util';
import { DeprecatedBlock, ExampleBlock, RemarksBlock, SeeBlock } from './BlockComment';
import { DefaultValueBlock, DeprecatedBlock, ExampleBlock, RemarksBlock, SeeBlock } from './BlockComment';
export function TSDoc({ item, tsdoc }: { item: ApiItem; tsdoc: DocNode }): JSX.Element {
const createNode = useCallback(
@ -84,6 +84,10 @@ export function TSDoc({ item, tsdoc }: { item: ApiItem; tsdoc: DocNode }): JSX.E
(block) => block.blockTag.tagName.toUpperCase() === StandardTags.example.tagNameWithUpperCase,
);
const defaultValueBlock = comment.customBlocks.find(
(block) => block.blockTag.tagName.toUpperCase() === StandardTags.defaultValue.tagNameWithUpperCase,
);
return (
<div className="flex flex-col space-y-2">
{comment.deprecatedBlock ? (
@ -91,6 +95,9 @@ export function TSDoc({ item, tsdoc }: { item: ApiItem; tsdoc: DocNode }): JSX.E
) : null}
{comment.summarySection ? createNode(comment.summarySection) : null}
{comment.remarksBlock ? <RemarksBlock>{createNode(comment.remarksBlock.content)}</RemarksBlock> : null}
{defaultValueBlock ? (
<DefaultValueBlock>{createNode(defaultValueBlock.content)}</DefaultValueBlock>
) : null}
{exampleBlocks.length
? exampleBlocks.map((block, idx) => <ExampleBlock key={idx}>{createNode(block.content)}</ExampleBlock>)
: null}