forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.jsx
More file actions
101 lines (87 loc) · 2.66 KB
/
index.jsx
File metadata and controls
101 lines (87 loc) · 2.66 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { CodeBracketIcon, DocumentIcon } from '@heroicons/react/24/outline';
import Badge from '@node-core/ui-components/Common/Badge';
import MetaBar from '@node-core/ui-components/Containers/MetaBar';
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
import { editURL } from '#theme/config';
import styles from './index.module.css';
const iconMap = {
JSON: CodeBracketIcon,
MD: DocumentIcon,
};
const STABILITY_KINDS = ['error', 'warning', null, 'info'];
const STABILITY_LABELS = ['D', 'E', null, 'L'];
const STABILITY_TOOLTIPS = ['Deprecated', 'Experimental', null, 'Legacy'];
/**
* Renders a heading value with an optional stability badge
* @param {{ value: string, stability: number }} props
*/
const HeadingValue = ({ value, stability }) => {
if (stability === 2) {
return value;
}
const ariaLabel = STABILITY_TOOLTIPS[stability]
? `Stability: ${STABILITY_TOOLTIPS[stability]}`
: undefined;
return (
<>
{value}
<Badge
size="small"
className={styles.badge}
kind={STABILITY_KINDS[stability]}
data-tooltip={STABILITY_TOOLTIPS[stability]}
aria-label={ariaLabel}
tabIndex={0}
>
{STABILITY_LABELS[stability]}
</Badge>
</>
);
};
/**
* MetaBar component that displays table of contents and page metadata
* @param {{ metadata: import('../../types').SerializedMetadata, headings: Array, readingTime: string }} props
*/
export default ({ metadata, headings = [], readingTime }) => {
const editThisPage = editURL.replace('{path}', metadata.path);
const viewAs = [
['JSON', `${metadata.basename}.json`],
['MD', `${metadata.basename}.md`],
];
return (
<MetaBar
heading="Table of Contents"
headings={{
items: headings.map(({ value, stability, ...heading }) => ({
...heading,
value: <HeadingValue value={value} stability={stability} />,
})),
}}
items={{
'Reading Time': readingTime,
'Added In': metadata.added ?? metadata.introduced_in,
'View As': (
<ol>
{viewAs.map(([viewTitle, path]) => {
const Icon = iconMap[viewTitle];
return (
<li key={viewTitle}>
<a href={path}>
{Icon && <Icon className={styles.icon} />}
{viewTitle}
</a>
</li>
);
})}
</ol>
),
Contribute: (
<>
<GitHubIcon className="fill-neutral-700 dark:fill-neutral-100" />
<a href={editThisPage}>Edit this page</a>
</>
),
}}
/>
);
};