webapp/src/components/Nav/Header/Link.tsx

41 lines
1.2 KiB
TypeScript
Raw Normal View History

import { getPagePath } from '@nanostores/router'
2023-09-25 06:13:47 +00:00
import { clsx } from 'clsx'
import { router, ROUTES, useRouter } from '../../../stores/router'
2023-09-25 06:13:47 +00:00
import { ConditionalWrapper } from '../../_shared/ConditionalWrapper'
import styles from './Header.module.scss'
2023-09-25 06:13:47 +00:00
type Props = {
onMouseOver: (event?: MouseEvent, time?: number) => void
onMouseOut: (event?: MouseEvent, time?: number) => void
routeName?: keyof typeof ROUTES
body: string
active?: boolean
onClick?: (event: MouseEvent) => void
2023-09-25 06:13:47 +00:00
}
export const Link = (props: Props) => {
const { page } = useRouter()
const isSelected = page().route === props.routeName
return (
<li
onClick={props.onClick}
classList={{ 'view-switcher__item--selected': page().route === props.routeName }}
>
2023-09-25 06:13:47 +00:00
<ConditionalWrapper
condition={!isSelected && Boolean(props.routeName)}
wrapper={(children) => <a href={getPagePath(router, props.routeName)}>{children}</a>}
>
<span
2023-09-29 06:46:15 +00:00
class={clsx('cursorPointer linkReplacement', { [styles.mainNavigationItemActive]: props.active })}
2023-09-25 06:13:47 +00:00
onMouseOver={props.onMouseOver}
onMouseOut={props.onMouseOut}
>
{props.body}
</span>
</ConditionalWrapper>
</li>
)
}