portfolio/components/ui/Heading.tsx

20 lines
620 B
TypeScript
Raw Normal View History

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}
<Link className='ml-1 group-hover:opacity-100 opacity-0 transition-opacity ease-in'
2024-09-19 15:00:03 +00:00
href={`#${createSlug(headingText)}`}>#</Link>
2024-09-19 08:16:45 +00:00
</Component>
)
}