Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-linked headers on glossary page [Fixes #12393] #12455

Merged
merged 10 commits into from
May 24, 2024
43 changes: 34 additions & 9 deletions src/components/Glossary/GlossaryDefinition/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentProps } from "react"
import { Box, Text } from "@chakra-ui/react"

import { ComponentProps, useState } from "react"
import { VscLink } from "react-icons/vsc"
import { Box, Flex, Link, Text } from "@chakra-ui/react"
import InlineLink from "@/components/Link"
import OldHeading from "@/components/OldHeading"
import Translation from "@/components/Translation"
Expand All @@ -24,22 +24,47 @@ const GlossaryDefinition = ({
size = "md",
options = { ns: DEFAULT_GLOSSARY_NS },
}: GlossaryDefinitionProps) => {
const [showLink, setShowLink] = useState(false)
const headingStyles =
size === "sm"
? { fontSize: "md", mt: 0, mb: 2 }
: { fontSize: { base: "xl", md: "2xl" } }

const textStyles = size === "sm" ? { mb: 0 } : {}

const linkStyles = {
color: "inherit",
textDecoration: "none",
}

const linkIconStyles = {
left: "-1.5em",
top: "0.8em",
fontSize: "0.5em",
color: "var(--eth-colors-primary-base)",
display: showLink ? "" : "none",
cursor: "pointer",
}

return (
<Box textAlign="start">
<Box textAlign="start" onMouseEnter={() => setShowLink(true)} onMouseLeave={() => setShowLink(false)}>
<OldHeading as="h3" lineHeight={1.4} id={term} {...headingStyles}>
<Translation
id={term + "-term"}
options={options}
transform={components}
/>
<Link href={`#${term}`} {...linkStyles} _hover={{ border: 'none', textDecoration: 'none' }}>
<Flex pos="relative">
<Box pos="absolute" _hover={{ opacity: '0.8' }} {...linkIconStyles}>
<VscLink />
</Box>
<Box>
<Translation
id={term + "-term"}
options={options}
transform={components}
/>
</Box>
</Flex>
</Link>
</OldHeading>

<Text {...textStyles}>
checkomkar marked this conversation as resolved.
Show resolved Hide resolved
<Translation
id={term + "-definition"}
Expand Down
Loading