import { TransitionOptions, useCurrentStateAndParams, useSrefActive as useUiRouterSrefActive, } from '@uirouter/react'; import clsx from 'clsx'; import { ComponentProps } from 'react'; import { AutomationTestingProps } from '@/types'; import { Link } from '@@/Link'; import { IconProps, Icon } from '@@/Icon'; import { useSidebarState } from '../useSidebarState'; interface Props extends IconProps, ComponentProps, AutomationTestingProps { label: string; ignorePaths?: string[]; } export function Head({ to, options, params = {}, label, icon, ignorePaths = [], 'data-cy': dataCy, }: Props) { const { isOpen } = useSidebarState(); const anchorProps = useSrefActive( to, 'bg-blue-8 be:bg-gray-8', params, options, ignorePaths ); return (
{!!icon && ( svg]:w-4')} /> )} {isOpen && {label}}
); } function useSrefActive( to: string, activeClassName: string, params: Partial> = {}, options: TransitionOptions = {}, ignorePaths: string[] = [] ) { const { state } = useCurrentStateAndParams(); const anchorProps = useUiRouterSrefActive( to, params || {}, activeClassName, options ); const className = ignorePaths.includes(state.name || '') ? '' : anchorProps.className; return { ...anchorProps, className, }; }