2023-09-25 06:13:47 +00:00
|
|
|
import { clsx } from 'clsx'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
import { ROUTES } from '../../../config/routes'
|
2023-09-25 06:13:47 +00:00
|
|
|
import { ConditionalWrapper } from '../../_shared/ConditionalWrapper'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
import { A, useMatch } from '@solidjs/router'
|
|
|
|
import { createMemo } from 'solid-js'
|
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) => {
|
2024-06-24 17:50:27 +00:00
|
|
|
const matchRoute = useMatch(() => props.routeName || '')
|
|
|
|
const isSelected = createMemo(() => Boolean(matchRoute()))
|
2023-09-25 06:13:47 +00:00
|
|
|
return (
|
2024-06-24 17:50:27 +00:00
|
|
|
<li onClick={props.onClick} classList={{ 'view-switcher__item--selected': isSelected() }}>
|
2023-09-25 06:13:47 +00:00
|
|
|
<ConditionalWrapper
|
|
|
|
condition={!isSelected && Boolean(props.routeName)}
|
2024-06-24 17:50:27 +00:00
|
|
|
wrapper={(children) => <A href={props.routeName || ''}>{children}</A>}
|
2023-09-25 06:13:47 +00:00
|
|
|
>
|
|
|
|
<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>
|
|
|
|
)
|
|
|
|
}
|