-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathbuildStabilityOverview.mjs
More file actions
49 lines (42 loc) · 1.31 KB
/
buildStabilityOverview.mjs
File metadata and controls
49 lines (42 loc) · 1.31 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
import { h as createElement } from 'hastscript';
import { createJSXElement } from './ast.mjs';
import { JSX_IMPORTS } from '../../web/constants.mjs';
const STABILITY_KINDS = ['error', 'warning', 'default', 'info'];
/**
*
*/
const createBadge = (stabilityIndex, stabilityDescription) => {
const kind = STABILITY_KINDS[stabilityIndex] ?? 'success';
return createJSXElement(JSX_IMPORTS.BadgeGroup.name, {
as: 'span',
size: 'small',
kind,
badgeText: stabilityIndex,
children: stabilityDescription,
});
};
/**
* Builds a static Stability Overview table.
*
* @param {Array<{ api: string, name: string, stabilityIndex: number, stabilityDescription: string }>} entries
* @returns {import('hast').Element}
*/
const buildStabilityOverview = entries => {
const rows = entries.map(
({ api, name, stabilityIndex, stabilityDescription }) =>
createElement('tr', [
createElement('td', createElement('a', { href: `${api}.html` }, name)),
createElement('td', createBadge(stabilityIndex, stabilityDescription)),
])
);
return createElement('table', [
createElement('thead', [
createElement('tr', [
createElement('th', 'API'),
createElement('th', 'Stability'),
]),
]),
createElement('tbody', rows),
]);
};
export default buildStabilityOverview;