-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.jsx
More file actions
105 lines (93 loc) · 2.77 KB
/
index.jsx
File metadata and controls
105 lines (93 loc) · 2.77 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
102
103
104
105
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 styles from './index.module.css';
const iconMap = {
JSON: CodeBracketIcon,
MD: DocumentIcon,
};
/**
* @typedef MetaBarProps
* @property {Array<import('@vcarl/remark-headings').Heading & { stability: string }>} headings - Array of page headings for table of contents
* @property {string} addedIn - Version or date when feature was added
* @property {string} readingTime - Estimated reading time for the page
* @property {Array<[string, string]>} viewAs - Array of [title, path] tuples for view options
* @property {string} editThisPage - URL for editing the current page
*/
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 {MetaBarProps} props - Component props
*/
export default ({
headings = [],
addedIn,
readingTime,
viewAs = [],
editThisPage,
}) => (
<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': addedIn,
'View As': (
<ol>
{viewAs.map(([title, path]) => {
const Icon = iconMap[title];
return (
<li key={title}>
<a href={path}>
{Icon && <Icon className={styles.icon} />}
{title}
</a>
</li>
);
})}
</ol>
),
Contribute: (
<>
<GitHubIcon className="fill-neutral-700 dark:fill-neutral-100" />
<a href={editThisPage}>Edit this page</a>
</>
),
}}
/>
);