Files
tuono/apps/documentation/src/components/sidebar/sidebar-link.tsx
T

43 lines
1.0 KiB
TypeScript
Raw Normal View History

import type { JSX, ReactNode } from 'react'
2024-08-15 18:19:40 +02:00
import { NavLink, type NavLinkProps } from '@mantine/core'
2024-12-07 12:06:08 +01:00
import clsx from 'clsx'
2024-08-15 18:19:40 +02:00
import { Link, useRouter } from 'tuono'
import { IconChevronRight } from '@tabler/icons-react'
import styles from './sidebar-link.module.css'
interface SidebarLinkProps {
label: string
href: string
onClick?: () => void
children?: ReactNode
}
export default function SidebarLink(
props: SidebarLinkProps & NavLinkProps,
): JSX.Element {
const { pathname } = useRouter()
2024-12-07 12:06:08 +01:00
const isActive = pathname === props.href
2024-08-15 18:19:40 +02:00
2024-08-15 21:12:02 +02:00
const internalProps = {
2024-12-07 12:06:08 +01:00
active: isActive,
className: clsx(styles.link, isActive && styles.active),
2024-08-15 21:12:02 +02:00
rightSection: props.children && (
<IconChevronRight
size="1.2rem"
stroke={1.5}
className="mantine-rotate-rtl"
/>
),
autoContrast: true,
...props,
}
if (props.href.startsWith('#')) {
return <NavLink component="button" {...internalProps} />
}
return <NavLink component={Link} {...internalProps} />
2024-08-15 18:19:40 +02:00
}