1
- import { Box , Flex , Link , Text } from "@chakra-ui/react"
2
- import { ComponentProps , useState } from "react"
1
+ import { ComponentProps } from "react"
2
+ import { CiLink } from "react-icons/ci"
3
+ import { Box , type HeadingProps , Icon , Link , Text } from "@chakra-ui/react"
3
4
4
- import { DEFAULT_GLOSSARY_NS } from "@/lib/constants"
5
5
import InlineLink from "@/components/Link"
6
6
import OldHeading from "@/components/OldHeading"
7
7
import Translation from "@/components/Translation"
8
- import { VscLink } from "react-icons/vsc"
8
+
9
+ import { DEFAULT_GLOSSARY_NS } from "@/lib/constants"
9
10
10
11
interface GlossaryDefinitionProps {
11
12
term : string
@@ -24,46 +25,55 @@ const GlossaryDefinition = ({
24
25
size = "md" ,
25
26
options = { ns : DEFAULT_GLOSSARY_NS } ,
26
27
} : GlossaryDefinitionProps ) => {
27
- const [ showLink , setShowLink ] = useState ( false )
28
- const headingStyles =
29
- size === "sm"
30
- ? { fontSize : "md" , mt : 0 , mb : 2 }
31
- : { fontSize : { base : "xl" , md : "2xl" } }
32
-
33
28
const textStyles = size === "sm" ? { mb : 0 } : { }
34
29
35
- const linkStyles = {
36
- color : "inherit" ,
37
- textDecoration : "none" ,
30
+ const IdAnchor = ( { id } : { id ?: string } ) => {
31
+ if ( ! id ) return null
32
+ return (
33
+ < Link
34
+ href = { "#" + id }
35
+ position = "absolute"
36
+ insetInlineEnd = "100%"
37
+ aria-label = { id . replaceAll ( "-" , " " ) + " permalink" }
38
+ opacity = { 0 }
39
+ _groupHover = { { opacity : 1 } }
40
+ _focus = { { opacity : 1 } }
41
+ transition = "opacity 0.1s ease-in-out"
42
+ >
43
+ < Icon as = { CiLink } fontSize = "xl" me = "1" />
44
+ </ Link >
45
+ )
38
46
}
39
-
40
- const linkIconStyles = {
41
- left : "-1.5em" ,
42
- top : "0.8em" ,
43
- fontSize : "0.5em" ,
44
- color : "var(--eth-colors-primary-base)" ,
45
- display : showLink ? "" : "none " ,
46
- cursor : "pointer" ,
47
+ const headingPropsForAnchor = ( id ?: string ) : HeadingProps => {
48
+ if ( ! id ) return { }
49
+ return {
50
+ scrollMarginTop : 28 ,
51
+ id ,
52
+ "data-group" : true ,
53
+ position : "relative " ,
54
+ } as HeadingProps
47
55
}
56
+ const commonHeadingProps = ( id ?: string ) : HeadingProps => ( {
57
+ fontWeight : 700 ,
58
+ lineHeight : 1.4 ,
59
+ ...headingPropsForAnchor ( id ) ,
60
+ } )
61
+ const Heading3 = ( { id, children, ...rest } : HeadingProps ) => (
62
+ < OldHeading as = "h3" { ...commonHeadingProps ( id ) } fontSize = "2xl" { ...rest } >
63
+ < IdAnchor id = { id } />
64
+ { children }
65
+ </ OldHeading >
66
+ )
48
67
49
68
return (
50
- < Box textAlign = "start" onMouseEnter = { ( ) => setShowLink ( true ) } onMouseLeave = { ( ) => setShowLink ( false ) } >
51
- < OldHeading as = "h3" lineHeight = { 1.4 } id = { term } { ...headingStyles } >
52
- < Link href = { `#${ term } ` } { ...linkStyles } _hover = { { border : 'none' , textDecoration : 'none' } } >
53
- < Flex pos = "relative" >
54
- < Box pos = "absolute" _hover = { { opacity : '0.8' } } { ...linkIconStyles } >
55
- < VscLink />
56
- </ Box >
57
- < Box >
58
- < Translation
59
- id = { term + "-term" }
60
- options = { options }
61
- transform = { components }
62
- />
63
- </ Box >
64
- </ Flex >
65
- </ Link >
66
- </ OldHeading >
69
+ < Box textAlign = "start" >
70
+ < Heading3 id = { term } >
71
+ < Translation
72
+ id = { term + "-term" }
73
+ options = { options }
74
+ transform = { components }
75
+ />
76
+ </ Heading3 >
67
77
68
78
< Text { ...textStyles } >
69
79
< Translation
0 commit comments