| 1 |
import { useRouter } from '@help-center/hooks/useRouter'; |
| 2 |
import { useGlobalSyncStore } from '@help-center/state/globals-sync'; |
| 3 |
import { useActivityStore } from '@shared/state/activity'; |
| 4 |
import { __, isRTL } from '@wordpress/i18n'; |
| 5 |
import { |
| 6 |
chevronLeft, |
| 7 |
chevronRight, |
| 8 |
closeSmall, |
| 9 |
Icon, |
| 10 |
reset, |
| 11 |
} from '@wordpress/icons'; |
| 12 |
import classNames from 'classnames'; |
| 13 |
|
| 14 |
const { partnerLogo, partnerName } = window.extSharedData; |
| 15 |
|
| 16 |
export const Topbar = () => { |
| 17 |
const { visibility, setVisibility } = useGlobalSyncStore(); |
| 18 |
const { incrementActivity } = useActivityStore(); |
| 19 |
const { current, history } = useRouter(); |
| 20 |
const handleClose = () => { |
| 21 |
incrementActivity(`hc-close-button-when-${visibility}`); |
| 22 |
setVisibility('closed'); |
| 23 |
}; |
| 24 |
const isMinimized = visibility === 'minimized'; |
| 25 |
const toggleMinimized = () => { |
| 26 |
const nextState = isMinimized ? 'open' : 'minimized'; |
| 27 |
incrementActivity(`hc-toggle-button-${nextState}`); |
| 28 |
setVisibility(nextState); |
| 29 |
}; |
| 30 |
|
| 31 |
return ( |
| 32 |
<div className="relative flex items-center justify-end gap-x-2 bg-banner-main p-4"> |
| 33 |
{/* biome-ignore lint: soon to be removed anyway */} |
| 34 |
<div |
| 35 |
role={isMinimized ? 'button' : 'heading'} |
| 36 |
onClick={isMinimized ? toggleMinimized : undefined} |
| 37 |
aria-label={ |
| 38 |
isMinimized ? __('Show Help Center', 'extendify-local') : undefined |
| 39 |
} |
| 40 |
aria-expanded={isMinimized ? 'false' : 'true'} |
| 41 |
className={classNames('flex w-full justify-between bg-banner-main', { |
| 42 |
'cursor-pointer': isMinimized, |
| 43 |
})} |
| 44 |
> |
| 45 |
<div |
| 46 |
className={classNames('flex w-full gap-3', { |
| 47 |
'gap-3': history.length === 1, |
| 48 |
})} |
| 49 |
> |
| 50 |
<LogoOrBackButton /> |
| 51 |
{current?.title && ( |
| 52 |
<span className="border-banner-text text-base font-medium text-banner-text"> |
| 53 |
{current.title} |
| 54 |
</span> |
| 55 |
)} |
| 56 |
</div> |
| 57 |
</div> |
| 58 |
<div className="flex items-center justify-end gap-2.5"> |
| 59 |
<button |
| 60 |
className="m-0 border-0 bg-transparent fill-banner-text p-0 text-banner-text" |
| 61 |
type="button" |
| 62 |
data-test="help-center-toggle-minimize-button" |
| 63 |
onClick={toggleMinimized} |
| 64 |
> |
| 65 |
{isMinimized ? ( |
| 66 |
<> |
| 67 |
<Icon |
| 68 |
className="rotate-90 fill-current" |
| 69 |
icon={chevronLeft} |
| 70 |
size={24} |
| 71 |
/> |
| 72 |
<span className="sr-only"> |
| 73 |
{__('Show Help Center', 'extendify-local')} |
| 74 |
</span> |
| 75 |
</> |
| 76 |
) : ( |
| 77 |
<> |
| 78 |
<Icon className="fill-current" icon={reset} size={24} /> |
| 79 |
<span className="sr-only"> |
| 80 |
{__('Minimize Help Center', 'extendify-local')} |
| 81 |
</span> |
| 82 |
</> |
| 83 |
)} |
| 84 |
</button> |
| 85 |
<button |
| 86 |
className="m-0 border-0 bg-transparent fill-banner-text p-0 text-banner-text" |
| 87 |
type="button" |
| 88 |
data-test="help-center-close-button" |
| 89 |
onClick={handleClose} |
| 90 |
> |
| 91 |
<Icon icon={closeSmall} size={24} /> |
| 92 |
<span className="sr-only">{__('close', 'extendify-local')}</span> |
| 93 |
</button> |
| 94 |
</div> |
| 95 |
</div> |
| 96 |
); |
| 97 |
}; |
| 98 |
|
| 99 |
const LogoOrBackButton = () => { |
| 100 |
const { goBack, history } = useRouter(); |
| 101 |
const { visibility } = useGlobalSyncStore(); |
| 102 |
|
| 103 |
if (history.length > 1 && visibility === 'open') { |
| 104 |
return ( |
| 105 |
<button |
| 106 |
className="m-0 border-0 bg-transparent fill-banner-text p-0 text-banner-text" |
| 107 |
type="button" |
| 108 |
onClick={goBack} |
| 109 |
> |
| 110 |
<Icon icon={isRTL() ? chevronRight : chevronLeft} /> |
| 111 |
<span className="sr-only">{__('Go back', 'extendify-local')}</span> |
| 112 |
</button> |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
return partnerLogo ? ( |
| 117 |
<div className="flex h-6 justify-center bg-banner-main after:relative after:-right-2.5 after:top-1 after:mr-2 after:text-banner-text after:opacity-40 after:content-['|'] rtl:after:-right-0"> |
| 118 |
<div className="flex h-6 max-w-[9rem] overflow-hidden"> |
| 119 |
<img |
| 120 |
className="max-h-full max-w-full object-contain" |
| 121 |
src={partnerLogo} |
| 122 |
alt={partnerName} |
| 123 |
/> |
| 124 |
</div> |
| 125 |
</div> |
| 126 |
) : null; |
| 127 |
}; |
| 128 |
|