84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { useRef } from 'react';
|
|
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
|
|
import { ellipsisVertical } from 'ionicons/icons';
|
|
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
|
import type { AppView } from '../views/viewTypes';
|
|
|
|
interface AppHeaderProps {
|
|
activeView: AppView;
|
|
onNavigate: (view: AppView) => void;
|
|
}
|
|
|
|
export function AppHeader({ activeView, onNavigate }: AppHeaderProps) {
|
|
const popoverRef = useRef<HTMLIonPopoverElement>(null);
|
|
const popover = usePopoverDisclosure();
|
|
|
|
function selectView(view: AppView): void {
|
|
void popoverRef.current?.dismiss();
|
|
onNavigate(view);
|
|
}
|
|
|
|
return (
|
|
<header className="app-header">
|
|
<a
|
|
className="brand"
|
|
href="#studio"
|
|
aria-label="BeatHound home"
|
|
onClick={(event) => {
|
|
event.preventDefault();
|
|
onNavigate('studio');
|
|
}}
|
|
>
|
|
<img
|
|
className="brand-logo"
|
|
src="/logo/logo-horizontal-dark-notagline.svg"
|
|
alt=""
|
|
/>
|
|
</a>
|
|
|
|
<div className="app-header-actions">
|
|
<IonButton
|
|
id="app-menu-trigger"
|
|
className="app-menu-trigger"
|
|
fill="clear"
|
|
aria-label="Open app menu"
|
|
aria-haspopup="dialog"
|
|
aria-expanded={popover.isOpen}
|
|
>
|
|
<IonIcon icon={ellipsisVertical} />
|
|
</IonButton>
|
|
</div>
|
|
|
|
<IonPopover
|
|
className="app-menu-popover"
|
|
ref={popoverRef}
|
|
trigger="app-menu-trigger"
|
|
triggerAction="click"
|
|
side="bottom"
|
|
alignment="end"
|
|
onDidPresent={popover.onDidPresent}
|
|
onDidDismiss={popover.onDidDismiss}
|
|
>
|
|
<nav className="app-menu-options" aria-label="App navigation">
|
|
<IonButton
|
|
className="app-menu-option"
|
|
fill={activeView === 'studio' ? 'solid' : 'clear'}
|
|
aria-current={activeView === 'studio' ? 'page' : undefined}
|
|
onClick={() => selectView('studio')}
|
|
>
|
|
Beat studio
|
|
</IonButton>
|
|
<IonButton
|
|
className="app-menu-option"
|
|
fill={activeView === 'about' ? 'solid' : 'clear'}
|
|
aria-current={activeView === 'about' ? 'page' : undefined}
|
|
onClick={() => selectView('about')}
|
|
>
|
|
About BeatHound
|
|
</IonButton>
|
|
</nav>
|
|
</IonPopover>
|
|
</header>
|
|
);
|
|
}
|