import { Button, CloseIconThin, MenuIcon, TFunction } from '@cmsgov/design-system'; import { SyntheticEvent } from 'react'; import classnames from 'classnames'; import { sendHeaderEvent } from './analytics'; import { Link } from './Header'; const menuId = 'hc-c-menu'; export interface ActionMenuProps { t: TFunction; /** Applies the inverse theme styling */ firstName?: string; loggedIn?: boolean; onMenuToggleClick: (event: SyntheticEvent) => any; /** * Indicates the menu is open, which influences the label * and ARIA attribute of the toggle button. */ open?: boolean; /** * These are the links that are visible in the upper left when there * is no menu button present. Currently, these only show up when the * user is logged out */ links: Link[]; } /** * ActionMenu is displayed at the top-right of the header. * There are two variations of this component: One for logged-out * users, which displays a "Log in" & "Espanol" link on desktop. * And another for logged-in users, which includes the user's first * name. The logged-in variation always displays a "Menu" toggle * button, and the logged-out variation only displays it on mobile. */ const ActionMenu = function (props: ActionMenuProps) { function onClick(event) { sendHeaderEvent(props.open ? 'menu closed' : 'menu opened'); props.onMenuToggleClick(event); } const menuButton = ( ); let content; if (props.loggedIn) { content = ( <> {props.firstName && ( {props.firstName} )} {menuButton} ); } else if (props.links.length) { content = ( <> {/* This stuff is hidden on extra-small screens and is duplicately rendered by the Menu 😭 */} {menuButton} ); } else { content = null; } return content; }; export default ActionMenu;