2024-09-19 08:16:45 +00:00
|
|
|
import {ElementType, ReactNode} from 'react'
|
|
|
|
import {createSlug} from '@/lib/createSlug'
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
type HeadingProps = {
|
|
|
|
as?: ElementType
|
|
|
|
children: ReactNode
|
|
|
|
}
|
|
|
|
|
2024-09-19 15:00:03 +00:00
|
|
|
export function Heading({as: Component = 'h1', children = null}: HeadingProps) {
|
|
|
|
let headingText = children ? children.toString() : ''
|
|
|
|
|
2024-09-19 08:16:45 +00:00
|
|
|
return (
|
2024-09-19 15:00:03 +00:00
|
|
|
<Component id={createSlug(headingText)} className='group'>
|
2024-09-19 08:16:45 +00:00
|
|
|
{children}
|
2024-09-25 20:06:30 +00:00
|
|
|
<Link className='ml-1.5 group-hover:visible invisible'
|
2024-09-19 15:00:03 +00:00
|
|
|
href={`#${createSlug(headingText)}`}>#</Link>
|
2024-09-19 08:16:45 +00:00
|
|
|
</Component>
|
|
|
|
)
|
|
|
|
}
|