Skip to content

Commit 7cb4af6

Browse files
authored
Merge branch 'dev' into stablecoins-redirect
2 parents 94f5cc8 + c90857c commit 7cb4af6

File tree

6 files changed

+58
-38
lines changed

6 files changed

+58
-38
lines changed

src/components/Link.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const BaseLink = forwardRef(function Link(
6767
const isPdf = url.isPdf(href)
6868
const isExternal = url.isExternal(href)
6969
const isInternalPdf = isPdf && !isExternal
70+
const isHash = url.isHash(href)
7071

7172
// Get proper download link for internally hosted PDF's & static files (ex: whitepaper)
7273
// Opens in separate window.
@@ -119,6 +120,27 @@ export const BaseLink = forwardRef(function Link(
119120
)
120121
}
121122

123+
if (isHash) {
124+
return (
125+
<ChakraLink
126+
onClick={(e) => {
127+
e.stopPropagation()
128+
trackCustomEvent(
129+
customEventOptions ?? {
130+
eventCategory: "Link",
131+
eventAction: "Clicked",
132+
eventName: "Clicked on hash link",
133+
eventValue: href,
134+
}
135+
)
136+
}}
137+
{...commonProps}
138+
>
139+
{children}
140+
</ChakraLink>
141+
)
142+
}
143+
122144
return (
123145
<NextLink
124146
locale={locale}

src/components/MainArticle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Box, type BoxProps } from "@chakra-ui/react"
33
import { MAIN_CONTENT_ID } from "@/lib/constants"
44

55
const MainArticle = (props: BoxProps) => (
6-
<Box as="article" id={MAIN_CONTENT_ID} tabIndex={-1} {...props} />
6+
<Box as="article" id={MAIN_CONTENT_ID} scrollMarginTop={24} {...props} />
77
)
88

99
export default MainArticle

src/components/SkipLink.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
import React from "react"
1+
import { useTranslation } from "next-i18next"
22
import { Box } from "@chakra-ui/react"
33

4-
import { BaseLink } from "../components/Link"
4+
import { BaseLink } from "@/components/Link"
55

6-
import Translation from "./Translation"
6+
import { MAIN_CONTENT_ID } from "@/lib/constants"
77

8-
export interface IProps {
9-
hrefId: string
10-
}
11-
12-
export const SkipLink: React.FC<IProps> = ({ hrefId }) => {
8+
export const SkipLink = () => {
9+
const { t } = useTranslation()
1310
return (
1411
<Box bg="primary.base">
1512
<BaseLink
16-
href={hrefId}
13+
href={"#" + MAIN_CONTENT_ID}
1714
lineHeight="taller"
1815
position="absolute"
1916
top="-12"
@@ -23,7 +20,7 @@ export const SkipLink: React.FC<IProps> = ({ hrefId }) => {
2320
_hover={{ textDecoration: "none" }}
2421
_focus={{ position: "static" }}
2522
>
26-
<Translation id="skip-to-main-content" />
23+
{t("skip-to-main-content")}
2724
</BaseLink>
2825
</Box>
2926
)

src/layouts/RootLayout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Root } from "@/lib/types"
88
import FeedbackWidget from "@/components/FeedbackWidget"
99
import Footer from "@/components/Footer"
1010
import Nav from "@/components/Nav"
11+
import { SkipLink } from "@/components/SkipLink"
1112
import TranslationBanner from "@/components/TranslationBanner"
1213
import TranslationBannerLegal from "@/components/TranslationBannerLegal"
1314

@@ -47,6 +48,8 @@ export const RootLayout = ({
4748

4849
return (
4950
<Container mx="auto" maxW={oldTheme.variables.maxPageWidth}>
51+
<SkipLink />
52+
5053
<Nav path={asPath} />
5154

5255
<TranslationBanner

src/layouts/UseCases.tsx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Hide,
88
Icon,
99
ListItem,
10-
Show,
1110
Text,
1211
UnorderedList,
1312
useToken,
@@ -179,17 +178,15 @@ export const UseCasesLayout: React.FC<IProps> = ({
179178

180179
return (
181180
<Box position="relative" width="full">
182-
<Show above={lgBp}>
183-
<BannerNotification shouldShow zIndex="sticky">
184-
<Emoji text=":pencil:" fontSize="2xl" me={4} flexShrink={0} />
185-
<Text m={0}>
186-
{t("template-usecase:template-usecase-banner")}{" "}
187-
<InlineLink href={absoluteEditPath}>
188-
{t("template-usecase-edit-link")}
189-
</InlineLink>
190-
</Text>
191-
</BannerNotification>
192-
</Show>
181+
<BannerNotification shouldShow zIndex="sticky" hideBelow={lgBp}>
182+
<Emoji text=":pencil:" fontSize="2xl" me={4} flexShrink={0} />
183+
<Text m={0}>
184+
{t("template-usecase:template-usecase-banner")}{" "}
185+
<InlineLink href={absoluteEditPath}>
186+
{t("template-usecase-edit-link")}
187+
</InlineLink>
188+
</Text>
189+
</BannerNotification>
193190
<HeroContainer key={frontmatter.title}>
194191
<TitleCard>
195192
<Emoji fontSize="4rem" text={frontmatter.emoji!} />
@@ -233,21 +230,20 @@ export const UseCasesLayout: React.FC<IProps> = ({
233230
}}
234231
/>
235232
</HeroContainer>
236-
<Show above={lgBp}>
237-
<Flex
238-
as={BaseLink}
239-
to={"#" + MAIN_CONTENT_ID}
240-
bg="ednBackground"
241-
justifyContent="center"
242-
p={4}
243-
width="full"
244-
_hover={{
245-
bg: "background.base",
246-
}}
247-
>
248-
<Icon as={MdExpandMore} fontSize="2xl" color="secondary" />
249-
</Flex>
250-
</Show>
233+
<Flex
234+
as={BaseLink}
235+
to={"#" + MAIN_CONTENT_ID}
236+
bg="ednBackground"
237+
justifyContent="center"
238+
p={4}
239+
width="full"
240+
_hover={{
241+
bg: "background.base",
242+
}}
243+
hideBelow={lgBp}
244+
>
245+
<Icon as={MdExpandMore} fontSize="2xl" color="secondary" />
246+
</Flex>
251247
<Page>
252248
{/* TODO: Switch to `above="lg"` after completion of Chakra Migration */}
253249
<LeftNavBar

src/lib/utils/url.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ export const isHrefActive = (
3333
? pathname.startsWith(cleanHref)
3434
: pathname === cleanHref
3535
}
36+
37+
export const isHash = (href: string): boolean => href.startsWith("#")

0 commit comments

Comments
 (0)