| 1 |
import { Logo } from '@assist/svg'; |
| 2 |
import { useLayoutEffect, useState } from '@wordpress/element'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
import classNames from 'classnames'; |
| 5 |
import { colord } from 'colord'; |
| 6 |
|
| 7 |
export const Header = () => { |
| 8 |
const [contrastBg, setContrastBg] = useState(); |
| 9 |
const [focusColor, setFocusColor] = useState(); |
| 10 |
|
| 11 |
useLayoutEffect(() => { |
| 12 |
const documentStyles = window.getComputedStyle(document.body); |
| 13 |
const bannerMain = documentStyles.getPropertyValue('--ext-banner-main'); |
| 14 |
const b = colord(bannerMain || '#000000'); |
| 15 |
const contrast = b.isDark() ? b.lighten(0.1) : b.darken(0.1); |
| 16 |
setContrastBg(contrast.toHex()); |
| 17 |
const focus = b.isDark() ? b.lighten(0.3) : b.darken(0.3); |
| 18 |
setFocusColor(focus.toHex()); |
| 19 |
}, []); |
| 20 |
|
| 21 |
return ( |
| 22 |
<header className="flex w-full border-b border-gray-400 bg-banner-main"> |
| 23 |
<div className="mx-auto mt-auto flex w-full max-w-[996px] flex-col px-4"> |
| 24 |
<div className="my-6 flex flex-wrap items-center justify-between gap-x-4 gap-y-6"> |
| 25 |
{window.extSharedData?.partnerLogo && ( |
| 26 |
<div className="flex h-10 max-w-52 overflow-hidden md:max-w-72"> |
| 27 |
<img |
| 28 |
className="max-h-full max-w-full object-contain" |
| 29 |
src={window.extSharedData.partnerLogo} |
| 30 |
alt={window.extSharedData.partnerName} |
| 31 |
/> |
| 32 |
</div> |
| 33 |
)} |
| 34 |
{!window.extSharedData?.partnerLogo && ( |
| 35 |
<Logo className="logo max-h-9 w-32 text-banner-text sm:w-40" /> |
| 36 |
)} |
| 37 |
<div |
| 38 |
id="assist-menu-bar" |
| 39 |
className={classNames( |
| 40 |
'flex-wrap items-center gap-4 lg:flex lg:w-auto', |
| 41 |
)} |
| 42 |
> |
| 43 |
<a |
| 44 |
style={{ |
| 45 |
borderColor: contrastBg, |
| 46 |
'--tw-ring-color': focusColor, |
| 47 |
'--ext-override': focusColor, |
| 48 |
}} |
| 49 |
className="block cursor-pointer rounded-xs border border-gray-500 bg-white px-4 py-2 text-center text-sm text-gray-900 no-underline transition-colors duration-200 hover:bg-gray-100 focus:outline-hidden focus:ring focus:ring-gray-900 focus:ring-offset-1 lg:inline-block lg:rounded-xs" |
| 50 |
href={window.extSharedData.homeUrl} |
| 51 |
target="_blank" |
| 52 |
> |
| 53 |
{__('View site', 'extendify-local')} |
| 54 |
</a> |
| 55 |
</div> |
| 56 |
</div> |
| 57 |
</div> |
| 58 |
</header> |
| 59 |
); |
| 60 |
}; |
| 61 |
|