From 4a77240f1ae81ae9280a9cae7e105b2de3cdd1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20B=C3=A4r?= Date: Fri, 5 Jun 2026 11:51:48 +0200 Subject: [PATCH] fix: improve `@since` tag rendering --- playground/js/src/bar.ts | 3 +++ playground/js/src/foo.ts | 8 ++++++++ src/components/Comment.tsx | 8 -------- src/components/MemberDeclaration.tsx | 10 +++++++++- src/components/MemberSignatureBody.tsx | 14 +++++++++++++- src/components/styles.css | 4 +++- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/playground/js/src/bar.ts b/playground/js/src/bar.ts index 80a0c9d..cefd03e 100644 --- a/playground/js/src/bar.ts +++ b/playground/js/src/bar.ts @@ -13,18 +13,21 @@ export interface BarOptions { * The age of the `Bar` instance. * * @default 0 + * @since Added in 1.2.3 */ age: number; /** * Favourite numbers of the `Bar` instance. * * @default [1, 2, Infinity] + * @since Added in 1.2.0 */ numbers: number[]; /** * Favourite words of the `Bar` instance. * * @default ['foo', 'bar', 'jabberwocky'] + * @since Added in 1.1.0 */ strings: string[]; } diff --git a/playground/js/src/foo.ts b/playground/js/src/foo.ts index 85200bd..600823f 100644 --- a/playground/js/src/foo.ts +++ b/playground/js/src/foo.ts @@ -3,6 +3,12 @@ */ export class Foo { private name: string; + /** + * This is the description of the Foo class. + * + * @since Added in 1.3.0 + */ + public description: string; /** * Constructor of the `Foo` class. */ @@ -21,6 +27,8 @@ export class Foo { /** * Set the name of the class. * @param {string} name + * + * @since Added in 1.2.0 */ setName(name: string | Foo): void { this.name = typeof name === 'string' ? name : name.getName(); diff --git a/src/components/Comment.tsx b/src/components/Comment.tsx index 89caf5d..61199d6 100644 --- a/src/components/Comment.tsx +++ b/src/components/Comment.tsx @@ -72,14 +72,6 @@ export function Comment({ comment, root, hideTags = [] }: CommentProps) { ))} )} - - { - comment.blockTags?.some((tag) => tag.tag === '@since') && ( -
- tag.tag === '@since')?.content)} /> -
- ) - } ); } diff --git a/src/components/MemberDeclaration.tsx b/src/components/MemberDeclaration.tsx index 946642a..d07eb3b 100644 --- a/src/components/MemberDeclaration.tsx +++ b/src/components/MemberDeclaration.tsx @@ -3,9 +3,10 @@ import { useMinimalLayout } from '../hooks/useMinimalLayout'; import { useRequiredReflection } from '../hooks/useReflection'; import { escapeMdx } from '../utils/helpers'; -import { Comment, hasComment } from './Comment'; +import { Comment, displayPartsToMarkdown, hasComment } from './Comment'; import { DefaultValue } from './DefaultValue'; import { Icon } from './Icon'; +import { Markdown } from './Markdown'; import { MemberSources } from './MemberSources'; import { Parameter } from './Parameter'; import { extractDeclarationFromType, Type } from './Type'; @@ -21,6 +22,7 @@ export function MemberDeclaration({ id }: MemberDeclarationProps) { const minimal = useMinimalLayout(); const showTypes = reflection.typeParameters && reflection.typeParameters.length > 0; const showDeclaration = !minimal && extractDeclarationFromType(reflection.type); + const showSince = reflection.comment?.blockTags?.some((tag) => tag.tag === '@since'); return ( <> @@ -61,6 +63,12 @@ export function MemberDeclaration({ id }: MemberDeclarationProps) { )} + + {showSince && ( +
+ tag.tag === '@since')?.content)} /> +
+ )} ); diff --git a/src/components/MemberSignatureBody.tsx b/src/components/MemberSignatureBody.tsx index a887396..6e89cd4 100644 --- a/src/components/MemberSignatureBody.tsx +++ b/src/components/MemberSignatureBody.tsx @@ -7,7 +7,7 @@ import { usePluginData } from '@docusaurus/useGlobalData'; import { useMinimalLayout } from '../hooks/useMinimalLayout'; import type { TSDSignatureReflection } from '../types'; import { ApiDataContext } from './ApiDataContext'; -import { Comment, hasComment } from './Comment'; +import { Comment, displayPartsToMarkdown, hasComment } from './Comment'; import { CommentBadges, isCommentWithModifiers } from './CommentBadges'; import { DefaultValue } from './DefaultValue'; import { Flags } from './Flags'; @@ -15,6 +15,7 @@ import { hasSources, MemberSources } from './MemberSources'; import { Parameter } from './Parameter'; import { extractDeclarationFromType, Type } from './Type'; import { TypeParameters } from './TypeParameters'; +import { Markdown } from './Markdown'; export function hasSigBody( sig: TSDSignatureReflection | undefined, @@ -62,6 +63,7 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro const showTypes = sig.typeParameter && sig.typeParameter.length > 0; const showParams = !minimal && sig.parameters && sig.parameters.length > 0; const showReturn = !minimal && sig.type; + const showSince = sig.comment?.blockTags?.some((tag) => tag.tag === '@since'); const { reflections } = useContext(ApiDataContext); const { isPython } = usePluginData('docusaurus-plugin-typedoc-api') as GlobalData; @@ -214,6 +216,16 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro )} + + { + showSince && ( + <> +
+ tag.tag === '@since')?.content)} /> +
+ + ) + } ); } diff --git a/src/components/styles.css b/src/components/styles.css index cc939a6..a4bbafa 100644 --- a/src/components/styles.css +++ b/src/components/styles.css @@ -194,7 +194,9 @@ html[data-theme='light'] .tsd-panel-content { .tsd-comment-since { font-style: italic; font-size: 90%; - margin-top: 1em; + margin-top: 0.5em; + padding-top: 0.5em; + border-top: 1px solid rgba(0, 0, 0, 0.05); } .tsd-comment-root {