PluginProbe
Extendify / 3.2.3
Extendify v3.2.3
3.2.3 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 All 129 releases
extendify / src / Notifications / templates / Bar.jsx

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

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