PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / FeedbackReporter / HeadingBadge.tsx

HeadingBadge.tsx in Code Snippets 4.0.0-beta.2, at js/components/FeedbackReporter/HeadingBadge.tsx

33 lines 923 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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