Skip to content

Commit 440e17f

Browse files
authored
fix: improve @since tag rendering (#80)
1 parent 68278ae commit 440e17f

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

playground/js/src/bar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ export interface BarOptions<NameType extends string> {
1313
* The age of the `Bar` instance.
1414
*
1515
* @default 0
16+
* @since Added in 1.2.3
1617
*/
1718
age: number;
1819
/**
1920
* Favourite numbers of the `Bar` instance.
2021
*
2122
* @default [1, 2, Infinity]
23+
* @since Added in 1.2.0
2224
*/
2325
numbers: number[];
2426
/**
2527
* Favourite words of the `Bar` instance.
2628
*
2729
* @default ['foo', 'bar', 'jabberwocky']
30+
* @since Added in 1.1.0
2831
*/
2932
strings: string[];
3033
}

playground/js/src/foo.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
*/
44
export class Foo {
55
private name: string;
6+
/**
7+
* This is the description of the Foo class.
8+
*
9+
* @since Added in 1.3.0
10+
*/
11+
public description: string;
612
/**
713
* Constructor of the `Foo` class.
814
*/
@@ -21,6 +27,8 @@ export class Foo {
2127
/**
2228
* Set the name of the class.
2329
* @param {string} name
30+
*
31+
* @since Added in 1.2.0
2432
*/
2533
setName(name: string | Foo): void {
2634
this.name = typeof name === 'string' ? name : name.getName();

src/components/Comment.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ export function Comment({ comment, root, hideTags = [] }: CommentProps) {
7272
))}
7373
</dl>
7474
)}
75-
76-
{
77-
comment.blockTags?.some((tag) => tag.tag === '@since') && (
78-
<div className="tsd-comment-since">
79-
<Markdown content={displayPartsToMarkdown(comment.blockTags?.find((tag) => tag.tag === '@since')?.content)} />
80-
</div>
81-
)
82-
}
8375
</div>
8476
);
8577
}

src/components/MemberDeclaration.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import { useMinimalLayout } from '../hooks/useMinimalLayout';
44
import { useRequiredReflection } from '../hooks/useReflection';
55
import { escapeMdx } from '../utils/helpers';
6-
import { Comment, hasComment } from './Comment';
6+
import { Comment, displayPartsToMarkdown, hasComment } from './Comment';
77
import { DefaultValue } from './DefaultValue';
88
import { Icon } from './Icon';
9+
import { Markdown } from './Markdown';
910
import { MemberSources } from './MemberSources';
1011
import { Parameter } from './Parameter';
1112
import { extractDeclarationFromType, Type } from './Type';
@@ -21,6 +22,7 @@ export function MemberDeclaration({ id }: MemberDeclarationProps) {
2122
const minimal = useMinimalLayout();
2223
const showTypes = reflection.typeParameters && reflection.typeParameters.length > 0;
2324
const showDeclaration = !minimal && extractDeclarationFromType(reflection.type);
25+
const showSince = reflection.comment?.blockTags?.some((tag) => tag.tag === '@since');
2426

2527
return (
2628
<>
@@ -61,6 +63,12 @@ export function MemberDeclaration({ id }: MemberDeclarationProps) {
6163
<Parameter param={extractDeclarationFromType(reflection.type)} />
6264
</div>
6365
)}
66+
67+
{showSince && (
68+
<div className="tsd-comment-since">
69+
<Markdown content={displayPartsToMarkdown(reflection.comment?.blockTags?.find((tag) => tag.tag === '@since')?.content)} />
70+
</div>
71+
)}
6472
</div>
6573
</>
6674
);

src/components/MemberSignatureBody.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { usePluginData } from '@docusaurus/useGlobalData';
77
import { useMinimalLayout } from '../hooks/useMinimalLayout';
88
import type { TSDSignatureReflection } from '../types';
99
import { ApiDataContext } from './ApiDataContext';
10-
import { Comment, hasComment } from './Comment';
10+
import { Comment, displayPartsToMarkdown, hasComment } from './Comment';
1111
import { CommentBadges, isCommentWithModifiers } from './CommentBadges';
1212
import { DefaultValue } from './DefaultValue';
1313
import { Flags } from './Flags';
1414
import { hasSources, MemberSources } from './MemberSources';
1515
import { Parameter } from './Parameter';
1616
import { extractDeclarationFromType, Type } from './Type';
1717
import { TypeParameters } from './TypeParameters';
18+
import { Markdown } from './Markdown';
1819

1920
export function hasSigBody(
2021
sig: TSDSignatureReflection | undefined,
@@ -62,6 +63,7 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
6263
const showTypes = sig.typeParameter && sig.typeParameter.length > 0;
6364
const showParams = !minimal && sig.parameters && sig.parameters.length > 0;
6465
const showReturn = !minimal && sig.type;
66+
const showSince = sig.comment?.blockTags?.some((tag) => tag.tag === '@since');
6567

6668
const { reflections } = useContext(ApiDataContext);
6769
const { isPython } = usePluginData('docusaurus-plugin-typedoc-api') as GlobalData;
@@ -214,6 +216,16 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
214216
<Parameter param={extractDeclarationFromType(sig.type)} />
215217
</>
216218
)}
219+
220+
{
221+
showSince && (
222+
<>
223+
<div className="tsd-comment-since">
224+
<Markdown content={displayPartsToMarkdown(sig.comment.blockTags?.find((tag) => tag.tag === '@since')?.content)} />
225+
</div>
226+
</>
227+
)
228+
}
217229
</>
218230
);
219231
}

src/components/styles.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ html[data-theme='light'] .tsd-panel-content {
194194
.tsd-comment-since {
195195
font-style: italic;
196196
font-size: 90%;
197-
margin-top: 1em;
197+
margin-top: 0.5em;
198+
padding-top: 0.5em;
199+
border-top: 1px solid rgba(0, 0, 0, 0.05);
198200
}
199201

200202
.tsd-comment-root {

0 commit comments

Comments
 (0)