mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-04-11 20:34:31 +00:00
Update heading component
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m8s
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m8s
This commit is contained in:
parent
a1943ebbf3
commit
42a46b93d3
@ -1,4 +1,6 @@
|
||||
import {ElementType, ReactNode} from 'react'
|
||||
'use client'
|
||||
|
||||
import {ElementType, ReactNode, useEffect, useRef} from 'react'
|
||||
import {createSlug} from '@/lib/createSlug'
|
||||
import Link from 'next/link'
|
||||
|
||||
@ -8,13 +10,19 @@ type HeadingProps = {
|
||||
}
|
||||
|
||||
export function Heading({as: Component = 'h1', children = null}: HeadingProps) {
|
||||
let headingText = children ? children.toString() : ''
|
||||
const ref = useRef<HTMLAnchorElement>(null);
|
||||
const headingText = children?.toString() || ''
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.innerHTML = '#'
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Component id={createSlug(headingText)} className="group">
|
||||
<Component id={createSlug(headingText)} className="flex group">
|
||||
{children}
|
||||
<Link className="ml-1.5 group-hover:visible invisible"
|
||||
href={`#${createSlug(headingText)}`}>#</Link>
|
||||
<Link className="sr-only group-hover:not-sr-only !ml-1.5" href={`#${createSlug(headingText)}`} ref={ref}></Link>
|
||||
</Component>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user