PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Notifications / templates / Pill.jsx

Pill.jsx in Extendify 3.2.1, at src/Notifications/templates/Pill.jsx

66 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState } from '@wordpress/element';
2 import { Icon } from '@wordpress/icons';
3 import classNames from 'classnames';
4 import { bannerButtonVariables, buttonHoverClasses, colorsOf } from '../colors';
5 import { iconFor } from '../icons';
6 import { externalLinkProps } from '../notification-link';
7 import { publishAndReload, publishesSite } from '../publish-site';
8
9 export const Pill = ({ notification, href, external, onClick }) => {
10 const ctaLabel = notification['cta-label'];
11 const icon = iconFor(notification.icon);
12 const colors = colorsOf(notification);
13 const [publishing, setPublishing] = useState(false);
14 const publishes = publishesSite(notification);
15 // Core's admin bar is taller below the md breakpoint; the pill matches it.
16 const className = classNames(
17 'inline-flex h-7.5 shrink-0 items-center gap-1 rounded-sm bg-banner-main px-2.5 text-sm leading-none text-banner-text no-underline md:h-6 md:text-[13px]',
18 publishing ? 'cursor-not-allowed' : 'cursor-pointer',
19 !publishing && buttonHoverClasses(colors),
20 );
21 // The pill has no room for a spinner, so the reload is the only feedback.
22 const publishNow = () => {
23 setPublishing(true);
24 publishAndReload(onClick);
25 };
26
27 const shared = {
28 // Without this the pill has no accessible name where CSS hides the label.
29 'aria-label': ctaLabel,
30 className,
31 style: bannerButtonVariables(colors),
32 'data-test': 'notification-pill',
33 };
34 const label = (
35 <>
36 {icon && <Icon icon={icon} size={16} className="fill-current" />}
37 <span className="ext-notification-pill-label">{ctaLabel}</span>
38 </>
39 );
40
41 if (publishes) {
42 return (
43 <button
44 type="button"
45 onClick={publishNow}
46 disabled={publishing}
47 aria-busy={publishing}
48 {...shared}
49 >
50 {label}
51 </button>
52 );
53 }
54
55 return (
56 <a
57 href={href}
58 {...externalLinkProps(external)}
59 onClick={onClick}
60 {...shared}
61 >
62 {label}
63 </a>
64 );
65 };
66