2023-11-14 15:10:00 +00:00
|
|
|
import { getPagePath } from '@nanostores/router'
|
2023-09-25 06:13:47 +00:00
|
|
|
import { clsx } from 'clsx'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-02-04 11:25:21 +00:00
|
|
|
import { ROUTES, router, useRouter } from '../../../stores/router'
|
2023-09-25 06:13:47 +00:00
|
|
|
import { ConditionalWrapper } from '../../_shared/ConditionalWrapper'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
|
|
|
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
|
2023-10-25 15:04:23 +00:00
|
|
|
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 (
|
2023-10-25 15:04:23 +00:00
|
|
|
<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>
|
|
|
|
)
|
|
|
|
}
|