11import * as VisuallyHidden from '@radix-ui/react-visually-hidden'
2- import { HTMLAttributes , useContext } from 'react'
2+ import { ElementType , useContext } from 'react'
33import { useInView } from 'react-intersection-observer'
44import { useDebounce } from 'react-use'
55
@@ -10,13 +10,15 @@ import { DocumentContext } from '@/layout/DocumentContext'
1010
1111export type HeadingProps = TextProps & {
1212 level : 1 | 2 | 3 | 4 | 5 | 6
13- } & HTMLAttributes < HTMLHeadingElement >
13+ }
1414
1515const BaseHeading = ( { level, id, children, ...props } : HeadingProps ) => {
1616 const { markOutlineItem } = useContext ( DocumentContext ) !
17+
1718 const { ref, inView : inOrAboveView } = useInView ( {
18- rootMargin : '99999px 0px -90 % 0px' , // consider it "in or above view" if it's anywhere above 10 % from the top of the viewport
19+ rootMargin : '99999px 0px -80 % 0px' , // consider it "in or above view" if it's anywhere above 20 % from the top of the viewport
1920 } )
21+
2022 useDebounce (
2123 ( ) => {
2224 if ( id ) {
@@ -26,17 +28,20 @@ const BaseHeading = ({ level, id, children, ...props }: HeadingProps) => {
2628 100 ,
2729 [ id , inOrAboveView , markOutlineItem ] ,
2830 )
31+
32+ const Heading : ElementType = `h${ level } `
33+
2934 const { t } = useI18n < any > ( )
3035
3136 return (
32- < Text ref = { ref } as = { `h ${ level } ` } id = { id } weight = "SEMIBOLD" color = "White" { ...props } >
33- { children }
37+ < Text ref = { ref } id = { id } weight = "SEMIBOLD" color = "White" { ...props } >
38+ < Heading sx = { { display : 'inline' } } > { children } </ Heading >
3439 { id ? (
3540 < span
3641 sx = { {
3742 marginInlineStart : '0.35em' ,
3843 opacity : Opacity [ '0%' ] ,
39- [ `h ${ level } :hover &, &:focus-within` ] : { opacity : Opacity [ '100%' ] } ,
44+ [ `* :hover > &, &:focus-within` ] : { opacity : Opacity [ '100%' ] } ,
4045 transition : buildTransition ( 'OPACITY' ) ,
4146 } }
4247 >
0 commit comments