PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 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 All 128 releases
← All changes | src/Notifications/templates/Pill.jsx +45 -11 3.2.0 → 3.2.2 View file →
@@ -1,31 +1,65 @@
1 +import { useState } from '@wordpress/element';
1 2 import { Icon } from '@wordpress/icons';
2 3 import classNames from 'classnames';
3 4 import { bannerButtonVariables, buttonHoverClasses, colorsOf } from '../colors';
4 5 import { iconFor } from '../icons';
5 6 import { externalLinkProps } from '../notification-link';
7 +import { publishAndReload, publishesSite } from '../publish-site';
6 8
7 9 export const Pill = ({ notification, href, external, onClick }) => {
8 10 const ctaLabel = notification['cta-label'];
9 11 const icon = iconFor(notification.icon);
10 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 + };
11 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 +
12 55 return (
13 56 <a
14 57 href={href}
15 58 {...externalLinkProps(external)}
16 59 onClick={onClick}
17 - // Without this the pill has no accessible name where CSS hides the label.
18 - aria-label={ctaLabel}
19 - // Core's admin bar is taller below the md breakpoint; the pill matches it.
20 - className={classNames(
21 - 'inline-flex h-7.5 shrink-0 cursor-pointer 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]',
22 - buttonHoverClasses(colors),
23 - )}
24 - style={bannerButtonVariables(colors)}
25 - data-test="notification-pill"
60 + {...shared}
26 61 >
27 - {icon && <Icon icon={icon} size={16} className="fill-current" />}
28 - <span className="ext-notification-pill-label">{ctaLabel}</span>
62 + {label}
29 63 </a>
30 64 );
31 65 };