@@ -21,6 +21,38 @@ const iconMap = {
2121
2222const STABILITY_KINDS = [ 'error' , 'warning' , null , 'info' ] ;
2323const STABILITY_LABELS = [ 'D' , 'E' , null , 'L' ] ;
24+ const STABILITY_TOOLTIPS = [ 'Deprecated' , 'Experimental' , null , 'Legacy' ] ;
25+
26+ /**
27+ * Renders a heading value with an optional stability badge
28+ * @param {{ value: string, stability: number } } props
29+ */
30+ const HeadingValue = ( { value, stability } ) => {
31+ if ( stability === 2 ) {
32+ return value ;
33+ }
34+
35+ const ariaLabel = STABILITY_TOOLTIPS [ stability ]
36+ ? `Stability: ${ STABILITY_TOOLTIPS [ stability ] } `
37+ : undefined ;
38+
39+ return (
40+ < >
41+ { value }
42+
43+ < Badge
44+ size = "small"
45+ className = { styles . badge }
46+ kind = { STABILITY_KINDS [ stability ] }
47+ data-tooltip = { STABILITY_TOOLTIPS [ stability ] }
48+ aria-label = { ariaLabel }
49+ tabIndex = { 0 }
50+ >
51+ { STABILITY_LABELS [ stability ] }
52+ </ Badge >
53+ </ >
54+ ) ;
55+ } ;
2456
2557/**
2658 * MetaBar component that displays table of contents and page metadata
@@ -38,21 +70,7 @@ export default ({
3870 headings = { {
3971 items : headings . map ( ( { value, stability, ...heading } ) => ( {
4072 ...heading ,
41- value :
42- stability !== 2 ? (
43- < >
44- { value }
45- < Badge
46- size = "small"
47- className = { styles . badge }
48- kind = { STABILITY_KINDS [ stability ] }
49- >
50- { STABILITY_LABELS [ stability ] }
51- </ Badge >
52- </ >
53- ) : (
54- value
55- ) ,
73+ value : < HeadingValue value = { value } stability = { stability } /> ,
5674 } ) ) ,
5775 } }
5876 items = { {
@@ -62,10 +80,12 @@ export default ({
6280 < ol >
6381 { viewAs . map ( ( [ title , path ] ) => {
6482 const Icon = iconMap [ title ] ;
83+
6584 return (
6685 < li key = { title } >
6786 < a href = { path } >
6887 { Icon && < Icon className = { styles . icon } /> }
88+
6989 { title }
7090 </ a >
7191 </ li >
@@ -76,6 +96,7 @@ export default ({
7696 Contribute : (
7797 < >
7898 < GitHubIcon className = "fill-neutral-700 dark:fill-neutral-100" />
99+
79100 < a href = { editThisPage } > Edit this page</ a >
80101 </ >
81102 ) ,
0 commit comments