Skip to content

Commit 468b6ce

Browse files
committed
fixup!
1 parent cbf00f0 commit 468b6ce

5 files changed

Lines changed: 68 additions & 4 deletions

File tree

src/generators/web/constants.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const JSX_IMPORTS = {
4949
name: 'AlertBox',
5050
source: '@node-core/ui-components/Common/AlertBox',
5151
},
52+
Badge: {
53+
name: 'Badge',
54+
source: '@node-core/ui-components/Common/Badge',
55+
},
5256
Blockquote: {
5357
name: 'Blockquote',
5458
source: '@node-core/ui-components/Common/Blockquote',

src/generators/web/utils/synthetic/404.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ export const buildNotFoundPage = () => {
1818
{
1919
type: 'text',
2020
value:
21-
'The page you requested could not be found. Use the navigation to find the documentation you are looking for.',
21+
'The page you requested could not be found. Use the navigation to find the documentation you are looking for, or return to the ',
22+
},
23+
{
24+
type: 'link',
25+
url: 'index.html',
26+
children: [{ type: 'text', value: 'API index' }],
27+
},
28+
{
29+
type: 'text',
30+
value: '.',
2231
},
2332
],
2433
},

src/generators/web/utils/synthetic/__tests__/404.test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('buildNotFoundPage', () => {
2424

2525
assert.ok(paragraph, 'expected a paragraph node in the content tree');
2626
assert.match(paragraph.children[0].value, /could not be found/);
27+
28+
const link = paragraph.children.find(child => child.type === 'link');
29+
30+
assert.equal(link.url, 'index.html');
31+
assert.equal(link.children[0].value, 'API index');
2732
});
2833

2934
it('places the head heading at the start of the content tree', () => {

src/generators/web/utils/synthetic/__tests__/index.test.mjs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,34 @@ describe('buildStabilityOverview', () => {
3737
assert.equal(findChild(table, 'tbody').children.length, 2);
3838
});
3939

40-
it('formats the stability cell as `(index) <first sentence>`', () => {
40+
it('formats the stability cell with a colored badge and first sentence', () => {
4141
const table = buildStabilityOverview([fakeHead('fs', 'fs', 1)]);
4242

4343
const row = findChild(table, 'tbody').children[0];
4444
const stabilityCell = row.children[1];
45+
const badge = stabilityCell.children[0];
4546

46-
assert.equal(stabilityCell.children[0].value, '(1) fs stable');
47+
assert.equal(badge.name, 'Badge');
48+
assert.deepEqual(
49+
badge.attributes.map(({ name, value }) => [name, value]),
50+
[
51+
['size', 'small'],
52+
['kind', 'warning'],
53+
['aria-label', 'Stability: 1'],
54+
]
55+
);
56+
assert.equal(badge.children[0].value, '1');
57+
assert.equal(stabilityCell.children[1].value, ' fs stable');
58+
});
59+
60+
it('uses a default badge for stable entries', () => {
61+
const table = buildStabilityOverview([fakeHead('fs', 'fs', 2)]);
62+
63+
const row = findChild(table, 'tbody').children[0];
64+
const badge = row.children[1].children[0];
65+
const kind = badge.attributes.find(attr => attr.name === 'kind');
66+
67+
assert.equal(kind.value, 'default');
4768
});
4869

4970
it('builds a relative link to the module HTML page', () => {

src/generators/web/utils/synthetic/index.mjs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
import { h as createElement } from 'hastscript';
44

55
import { createSyntheticHead, wrapAsEntry } from './synthetic.mjs';
6+
import { createJSXElement } from '../../../jsx-ast/utils/ast.mjs';
7+
import { JSX_IMPORTS } from '../../constants.mjs';
8+
9+
const STABILITY_BADGE_KINDS = [
10+
'error',
11+
'warning',
12+
'default',
13+
'info',
14+
'neutral',
15+
'neutral',
16+
];
17+
18+
/**
19+
* Maps a Node.js stability index to a UI badge kind.
20+
*
21+
* @param {string} index
22+
*/
23+
const getStabilityBadgeKind = index =>
24+
STABILITY_BADGE_KINDS[parseInt(index, 10)] ?? 'neutral';
625

726
/**
827
* Builds the Stability Overview table from module heads that declare a
@@ -28,7 +47,13 @@ export const buildStabilityOverview = headEntries =>
2847
),
2948
createElement(
3049
'td',
31-
`(${stability.data.index}) ${stability.data.description.split('. ')[0]}`
50+
createJSXElement(JSX_IMPORTS.Badge.name, {
51+
size: 'small',
52+
kind: getStabilityBadgeKind(stability.data.index),
53+
'aria-label': `Stability: ${stability.data.index}`,
54+
children: stability.data.index,
55+
}),
56+
` ${stability.data.description.split('. ')[0]}`
3257
),
3358
])
3459
)

0 commit comments

Comments
 (0)