-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
CommentBadges.tsx
40 lines (35 loc) · 963 Bytes
/
CommentBadges.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from 'react';
import { JSONOutput } from 'typedoc';
function getModifierClassName(tag: string) {
switch (tag) {
case '@beta':
case '@experimental':
return 'warning';
case '@alpha':
return 'danger';
default:
return 'info';
}
}
export type CommentWithModifiers = Pick<JSONOutput.Comment, 'blockTags' | 'summary'> &
Required<Pick<JSONOutput.Comment, 'modifierTags'>>;
export function isCommentWithModifiers(
comment?: JSONOutput.Comment,
): comment is CommentWithModifiers {
return !!comment && !!comment.modifierTags && comment.modifierTags.length > 0;
}
interface CommentBadgesProps {
comment: CommentWithModifiers;
}
export function CommentBadges({ comment }: CommentBadgesProps) {
const { modifierTags } = comment;
return (
<div className="badge-group">
{modifierTags.map((tag) => (
<span key={tag} className={`badge badge--${getModifierClassName(tag)}`}>
{tag.slice(1)}
</span>
))}
</div>
);
}