1
1
import * as VisuallyHidden from '@radix-ui/react-visually-hidden'
2
- import { HTMLAttributes , useContext } from 'react'
2
+ import { ElementType , useContext } from 'react'
3
3
import { useInView } from 'react-intersection-observer'
4
4
import { useDebounce } from 'react-use'
5
5
@@ -10,13 +10,15 @@ import { DocumentContext } from '@/layout/DocumentContext'
10
10
11
11
export type HeadingProps = TextProps & {
12
12
level : 1 | 2 | 3 | 4 | 5 | 6
13
- } & HTMLAttributes < HTMLHeadingElement >
13
+ }
14
14
15
15
const BaseHeading = ( { level, id, children, ...props } : HeadingProps ) => {
16
16
const { markOutlineItem } = useContext ( DocumentContext ) !
17
+
17
18
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
19
20
} )
21
+
20
22
useDebounce (
21
23
( ) => {
22
24
if ( id ) {
@@ -26,17 +28,20 @@ const BaseHeading = ({ level, id, children, ...props }: HeadingProps) => {
26
28
100 ,
27
29
[ id , inOrAboveView , markOutlineItem ] ,
28
30
)
31
+
32
+ const Heading : ElementType = `h${ level } `
33
+
29
34
const { t } = useI18n < any > ( )
30
35
31
36
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 >
34
39
{ id ? (
35
40
< span
36
41
sx = { {
37
42
marginInlineStart : '0.35em' ,
38
43
opacity : Opacity [ '0%' ] ,
39
- [ `h ${ level } :hover &, &:focus-within` ] : { opacity : Opacity [ '100%' ] } ,
44
+ [ `* :hover > &, &:focus-within` ] : { opacity : Opacity [ '100%' ] } ,
40
45
transition : buildTransition ( 'OPACITY' ) ,
41
46
} }
42
47
>
0 commit comments