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 / Bar.jsx

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

121 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Spinner } from '@wordpress/components';
2 import { useEffect, useRef, useState } from '@wordpress/element';
3 import { __ } from '@wordpress/i18n';
4 import { Icon } from '@wordpress/icons';
5 import classNames from 'classnames';
6 import { Cta } from '../Cta';
7 import {
8 bannerButtonVariables,
9 barVariables,
10 buttonHoverClasses,
11 colorsOf,
12 } from '../colors';
13 import { DismissButton } from '../DismissButton';
14 import { iconFor } from '../icons';
15 import { publishAndReload, publishesSite } from '../publish-site';
16
17 export const Bar = ({
18 notification,
19 href,
20 external,
21 dismissible,
22 onDismiss,
23 onClick,
24 }) => {
25 const { title, content } = notification;
26 const ctaLabel = notification['cta-label'];
27 const icon = iconFor(notification.icon);
28 const colors = colorsOf(notification);
29 const ref = useRef(null);
30 const [publishing, setPublishing] = useState(false);
31 const publishes = publishesSite(notification);
32 const ctaClassName = classNames(
33 'inline-flex h-10 shrink-0 items-center gap-2 rounded-md bg-banner-main px-5 text-sm font-medium text-banner-text no-underline',
34 // Both cursor utilities in one layer would leave the winner to CSS source order.
35 publishing ? 'cursor-not-allowed' : 'cursor-pointer',
36 !publishing && buttonHoverClasses(colors),
37 );
38
39 const publishNow = () => {
40 setPublishing(true);
41 publishAndReload(onClick);
42 };
43
44 // The agent reads this to keep its panel and the scaled page off the bar.
45 useEffect(() => {
46 const root = document.documentElement;
47 const publish = () =>
48 root.style.setProperty(
49 '--extendify-notification-bar-height',
50 // 0 below the breakpoint, where the bar is display:none.
51 `${ref.current.offsetHeight}px`,
52 );
53
54 publish();
55 const observer = new ResizeObserver(publish);
56 observer.observe(ref.current);
57 return () => {
58 observer.disconnect();
59 root.style.removeProperty('--extendify-notification-bar-height');
60 };
61 }, []);
62
63 return (
64 <aside
65 ref={ref}
66 aria-label={
67 // translators: label for the bar reporting whether the site is public.
68 __('Site status', 'extendify-local')
69 }
70 // Below core's admin-bar breakpoint a full-width banner covers the content it reports on.
71 className="fixed bottom-0 left-0 right-0 z-higher hidden items-center gap-4 bg-design-main px-5 py-3.5 text-base text-design-text md:flex"
72 style={barVariables(colors)}
73 data-test="notification-bar"
74 >
75 {icon && (
76 <span
77 className="flex size-10 shrink-0 items-center justify-center rounded-full bg-banner-main text-banner-text"
78 data-test="notification-bar-icon"
79 >
80 <Icon icon={icon} size={24} className="fill-current" />
81 </span>
82 )}
83 <div className="min-w-0 flex-1">
84 <div className="text-[15px] font-bold">{title}</div>
85 <div className="mt-0.5 text-[13px]">{content}</div>
86 </div>
87 {ctaLabel && publishes && (
88 <button
89 type="button"
90 onClick={publishNow}
91 disabled={publishing}
92 aria-busy={publishing}
93 className={ctaClassName}
94 style={bannerButtonVariables(colors)}
95 data-test="notification-bar-publish"
96 >
97 {ctaLabel}
98 {publishing && <Spinner className="m-0 h-4 text-banner-text" />}
99 </button>
100 )}
101 {!publishes && (
102 <Cta
103 notification={notification}
104 href={href}
105 external={external}
106 onClick={onClick}
107 surface="banner"
108 className="inline-flex h-10 shrink-0 cursor-pointer items-center rounded-md bg-banner-main px-5 text-sm font-medium text-banner-text no-underline"
109 />
110 )}
111 {dismissible && (
112 <DismissButton
113 onClick={onDismiss}
114 size={24}
115 className="flex size-8 shrink-0 items-center justify-center rounded-xs text-design-text hover:opacity-80"
116 />
117 )}
118 </aside>
119 );
120 };
121