|
@ -14,8 +14,6 @@ export interface HeadingProps { |
|
|
as?: any; |
|
|
as?: any; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const anchorClassName = siteConfig.headerIdConfig.className; |
|
|
|
|
|
|
|
|
|
|
|
const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading( |
|
|
const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading( |
|
|
{as: Comp = 'div', className, children, id, isPageAnchor = true, ...props}, |
|
|
{as: Comp = 'div', className, children, id, isPageAnchor = true, ...props}, |
|
|
ref |
|
|
ref |
|
@ -26,8 +24,7 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<> |
|
|
<Comp id={id} {...props} ref={ref} className={cn('mdx-heading', className)}> |
|
|
<Comp id={id} {...props} ref={ref} className={cn('heading', className)}> |
|
|
|
|
|
{children} |
|
|
{children} |
|
|
{isPageAnchor && ( |
|
|
{isPageAnchor && ( |
|
|
<a |
|
|
<a |
|
@ -35,7 +32,7 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading( |
|
|
aria-label={label} |
|
|
aria-label={label} |
|
|
title={label} |
|
|
title={label} |
|
|
className={cn( |
|
|
className={cn( |
|
|
anchorClassName, |
|
|
'mdx-header-anchor', |
|
|
Comp === 'h1' ? 'hidden' : 'inline-block' |
|
|
Comp === 'h1' ? 'hidden' : 'inline-block' |
|
|
)}> |
|
|
)}> |
|
|
<svg |
|
|
<svg |
|
@ -52,45 +49,6 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading( |
|
|
</a> |
|
|
</a> |
|
|
)} |
|
|
)} |
|
|
</Comp> |
|
|
</Comp> |
|
|
<style jsx> |
|
|
|
|
|
{` |
|
|
|
|
|
.heading { |
|
|
|
|
|
scroll-margin-top: 2.5em; |
|
|
|
|
|
/* Space for the anchor */ |
|
|
|
|
|
padding-right: 1em; |
|
|
|
|
|
} |
|
|
|
|
|
.heading:before { |
|
|
|
|
|
height: 6rem; |
|
|
|
|
|
margin-top: -6rem; |
|
|
|
|
|
visibility: hidden; |
|
|
|
|
|
content: ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.heading .${anchorClassName} { |
|
|
|
|
|
/* Prevent the anchor from |
|
|
|
|
|
overflowing to its own line */ |
|
|
|
|
|
height: 0px; |
|
|
|
|
|
width: 0px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.heading .${anchorClassName} svg { |
|
|
|
|
|
display: inline; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.heading .${anchorClassName} svg { |
|
|
|
|
|
visibility: hidden; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.heading:hover .${anchorClassName} svg { |
|
|
|
|
|
visibility: visible; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.heading .${anchorClassName}:focus svg { |
|
|
|
|
|
visibility: visible; |
|
|
|
|
|
} |
|
|
|
|
|
`}
|
|
|
|
|
|
</style> |
|
|
|
|
|
</> |
|
|
|
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|