import { Spinner } from '@wordpress/components'; import { useEffect, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Icon } from '@wordpress/icons'; import classNames from 'classnames'; import { Cta } from '../Cta'; import { bannerButtonVariables, barVariables, buttonHoverClasses, colorsOf, } from '../colors'; import { DismissButton } from '../DismissButton'; import { iconFor } from '../icons'; import { publishAndReload, publishesSite } from '../publish-site'; export const Bar = ({ notification, href, external, dismissible, onDismiss, onClick, }) => { const { title, content } = notification; const ctaLabel = notification['cta-label']; const icon = iconFor(notification.icon); const colors = colorsOf(notification); const ref = useRef(null); const [publishing, setPublishing] = useState(false); const publishes = publishesSite(notification); const ctaClassName = classNames( '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', // Both cursor utilities in one layer would leave the winner to CSS source order. publishing ? 'cursor-not-allowed' : 'cursor-pointer', !publishing && buttonHoverClasses(colors), ); const publishNow = () => { setPublishing(true); publishAndReload(onClick); }; // The agent reads this to keep its panel and the scaled page off the bar. useEffect(() => { const root = document.documentElement; const publish = () => root.style.setProperty( '--extendify-notification-bar-height', // 0 below the breakpoint, where the bar is display:none. `${ref.current.offsetHeight}px`, ); publish(); const observer = new ResizeObserver(publish); observer.observe(ref.current); return () => { observer.disconnect(); root.style.removeProperty('--extendify-notification-bar-height'); }; }, []); return ( ); };