import { TransitionOptions, useCurrentStateAndParams, useSrefActive as useUiRouterSrefActive, } from '@uirouter/react'; import clsx from 'clsx'; import { ComponentProps } from 'react'; import Tippy from '@tippyjs/react'; import { AutomationTestingProps } from '@/types'; import 'tippy.js/dist/tippy.css'; 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 th-dark:bg-gray-true-8', params, options, ignorePaths ); const anchor = ( {!!icon && svg]:w-4')} />} {isOpen && {label}} ); if (isOpen) return anchor; return ( {anchor} ); } function useSrefActive( to: string, activeClassName: string, params: Partial> = {}, options: TransitionOptions = {}, ignorePaths: string[] = [] ) { const { state: { name: stateName = '' } = {} } = useCurrentStateAndParams(); const anchorProps = useUiRouterSrefActive( to, params || {}, activeClassName, options ); const className = ignorePaths.some((path) => stateName.includes(path)) ? '' : anchorProps.className; return { ...anchorProps, className, }; }