| 1 |
import React, { useMemo } from 'react' |
| 2 |
import { createPortal } from 'react-dom' |
| 3 |
import { __ } from '@wordpress/i18n' |
| 4 |
|
| 5 |
export interface HeadingBadgeProps { |
| 6 |
label: string |
| 7 |
} |
| 8 |
|
| 9 |
/** The page heading, wherever this screen happens to render one. */ |
| 10 |
const findHeading = (): Element | null => |
| 11 |
document.querySelector('.wrap h1.wp-heading-inline') ?? |
| 12 |
document.querySelector('#wpbody-content .wrap h1') ?? |
| 13 |
document.querySelector('#wpbody-content h1') |
| 14 |
|
| 15 |
export const HeadingBadge: React.FC<HeadingBadgeProps> = ({ label }) => { |
| 16 |
const heading = useMemo(findHeading, []) |
| 17 |
|
| 18 |
if (!label || !heading) { |
| 19 |
return null |
| 20 |
} |
| 21 |
|
| 22 |
return createPortal( |
| 23 |
<span |
| 24 |
className="code-snippets-feedback-badge" |
| 25 |
title={__('You are running a pre-release build. Use the Send feedback button if something breaks.', 'code-snippets')} |
| 26 |
> |
| 27 |
<span className="code-snippets-feedback-badge__dot" aria-hidden="true"></span> |
| 28 |
{label} |
| 29 |
</span>, |
| 30 |
heading |
| 31 |
) |
| 32 |
} |
| 33 |
|