Skip to content

Commit 26bb423

Browse files
authored
Merge pull request #13205 from ethereum/fix-glossary-tooltip-styles
Fix heading styles in Glossary Definition and Tooltip
2 parents 104e6ae + aa21459 commit 26bb423

File tree

4 files changed

+65
-30
lines changed

4 files changed

+65
-30
lines changed

.storybook/i18next.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const baseLocales = {
1313
export const ns = [
1414
"common",
1515
"glossary",
16+
"glossary-tooltip",
1617
"learn-quizzes",
1718
"page-about",
1819
"page-index",

src/components/Glossary/GlossaryDefinition/index.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ComponentProps } from "react"
2-
import { Box, type HeadingProps, Text } from "@chakra-ui/react"
2+
import { Box, type HeadingProps, Text, VStack } from "@chakra-ui/react"
33

4+
import Heading from "@/components/Heading"
45
import IdAnchor from "@/components/IdAnchor"
56
import InlineLink from "@/components/Link"
6-
import OldHeading from "@/components/OldHeading"
77
import Translation from "@/components/Translation"
88

99
import { DEFAULT_GLOSSARY_NS } from "@/lib/constants"
@@ -36,27 +36,17 @@ const GlossaryDefinition = ({
3636
position: "relative",
3737
} as HeadingProps
3838
}
39-
const commonHeadingProps = (id?: string): HeadingProps => ({
40-
fontWeight: 700,
41-
lineHeight: 1.4,
42-
...headingPropsForAnchor(id),
43-
})
44-
const Heading3 = ({ id, children, ...rest }: HeadingProps) => (
45-
<OldHeading as="h3" {...commonHeadingProps(id)} fontSize="2xl" {...rest}>
46-
<IdAnchor id={id} />
47-
{children}
48-
</OldHeading>
49-
)
5039

5140
return (
52-
<Box textAlign="start">
53-
<Heading3 id={term}>
41+
<VStack spacing={4} align="stretch" textAlign="start" mb={8}>
42+
<Heading size="md" {...headingPropsForAnchor(term)}>
43+
<IdAnchor id={term} />
5444
<Translation
5545
id={term + "-term"}
5646
options={options}
5747
transform={components}
5848
/>
59-
</Heading3>
49+
</Heading>
6050
{/**
6151
* `as="span"` prevents hydration warnings for strings that contain
6252
* elements that cannot be nested inside `p` tags, like `ul` tags
@@ -70,7 +60,7 @@ const GlossaryDefinition = ({
7060
transform={components}
7161
/>
7262
</Text>
73-
</Box>
63+
</VStack>
7464
)
7565
}
7666

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
import { Center } from "@chakra-ui/react"
12
import { Meta, StoryObj } from "@storybook/react"
23

34
import GlossaryTooltipComponent from "."
45

56
const meta = {
67
title: "Molecules / Overlay Content / Glossary Tooltip",
78
component: GlossaryTooltipComponent,
9+
args: {
10+
termKey: "bridge",
11+
children: "bridge",
12+
},
13+
decorators: [
14+
(Story) => (
15+
<Center boxSize="md">
16+
<Story />
17+
</Center>
18+
),
19+
],
820
} satisfies Meta<typeof GlossaryTooltipComponent>
921

1022
export default meta
1123

12-
export const GlossaryTooltip: StoryObj<typeof meta> = {
24+
type Story = StoryObj<typeof meta>
25+
26+
export const Basic: Story = {}
27+
28+
// for chromatic story snapshot showing the rendered popover
29+
export const OnOpen: Story = {
1330
args: {
14-
termKey: "big-endian",
15-
children: "big-endian",
31+
isOpen: true,
1632
},
1733
}

src/components/Glossary/GlossaryTooltip/index.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
11
import React, { ReactNode } from "react"
22
import { useRouter } from "next/router"
3-
import { Box, Text } from "@chakra-ui/react"
3+
import { Box, Text, VStack } from "@chakra-ui/react"
44

5-
import GlossaryDefinition from "@/components/Glossary/GlossaryDefinition"
6-
import Tooltip from "@/components/Tooltip"
5+
import Heading from "@/components/Heading"
6+
import InlineLink from "@/components/Link"
7+
import Tooltip, { type TooltipProps } from "@/components/Tooltip"
8+
import Translation from "@/components/Translation"
79

810
import { trackCustomEvent } from "@/lib/utils/matomo"
911
import { cleanPath } from "@/lib/utils/url"
1012

11-
type GlossaryTooltipProps = {
13+
type GlossaryTooltipProps = Omit<TooltipProps, "content"> & {
1214
children: ReactNode
1315
termKey: string
1416
}
1517

16-
const GlossaryTooltip = ({ children, termKey }: GlossaryTooltipProps) => {
18+
const components = {
19+
a: InlineLink,
20+
}
21+
22+
const GlossaryTooltip = ({
23+
children,
24+
termKey,
25+
...props
26+
}: GlossaryTooltipProps) => {
1727
const { asPath } = useRouter()
1828

1929
return (
2030
<Box as="span" display="inline-block">
2131
<Tooltip
32+
{...props}
2233
content={
23-
<GlossaryDefinition
24-
term={termKey}
25-
size="sm"
26-
options={{ ns: "glossary-tooltip" }}
27-
/>
34+
<VStack spacing={2} align="stretch" textAlign="start">
35+
<Heading as="h6">
36+
<Translation
37+
id={termKey + "-term"}
38+
options={{ ns: "glossary-tooltip" }}
39+
transform={components}
40+
/>
41+
</Heading>
42+
{/**
43+
* `as="span"` prevents hydration warnings for strings that contain
44+
* elements that cannot be nested inside `p` tags, like `ul` tags
45+
* (found in some Glossary definition).
46+
* TODO: Develop a better solution to handle this case.
47+
*/}
48+
<Text as="span">
49+
<Translation
50+
id={termKey + "-definition"}
51+
options={{ ns: "glossary-tooltip" }}
52+
transform={components}
53+
/>
54+
</Text>
55+
</VStack>
2856
}
2957
onBeforeOpen={() => {
3058
trackCustomEvent({

0 commit comments

Comments
 (0)