Skip to content

Commit df87cb8

Browse files
authored
Merge pull request #13850 from saurabhburade/shadcn-migrate/GlossaryDefinition
Shadcn migration - GlossaryDefinition
2 parents 489eebc + f84b255 commit df87cb8

File tree

1 file changed

+15
-26
lines changed
  • src/components/Glossary/GlossaryDefinition

1 file changed

+15
-26
lines changed

src/components/Glossary/GlossaryDefinition/index.tsx

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ComponentProps } from "react"
2-
import { type HeadingProps, Text, VStack } from "@chakra-ui/react"
32

4-
import Heading from "@/components/Heading"
53
import IdAnchor from "@/components/IdAnchor"
6-
import InlineLink from "@/components/Link"
74
import Translation from "@/components/Translation"
5+
import { Stack } from "@/components/ui/flex"
6+
import InlineLink from "@/components/ui/Link"
7+
8+
import { cn } from "@/lib/utils/cn"
89

910
import { DEFAULT_GLOSSARY_NS } from "@/lib/constants"
1011

@@ -25,42 +26,30 @@ const GlossaryDefinition = ({
2526
size = "md",
2627
options = { ns: DEFAULT_GLOSSARY_NS },
2728
}: GlossaryDefinitionProps) => {
28-
const textStyles = size === "sm" ? { mb: 0 } : {}
29-
30-
const headingPropsForAnchor = (id?: string): HeadingProps => {
31-
if (!id) return {}
32-
return {
33-
scrollMarginTop: 28,
34-
id,
35-
"data-group": true,
36-
position: "relative",
37-
} as HeadingProps
38-
}
29+
const textClasses = size === "sm" ? "mb-0" : ""
3930

4031
return (
41-
<VStack spacing={4} align="stretch" textAlign="start" mb={8}>
42-
<Heading size="md" {...headingPropsForAnchor(term)}>
32+
<Stack className="mb-8 items-stretch gap-4 text-start">
33+
<h4
34+
className={term ? "relative scroll-mt-28" : ""}
35+
{...(term ? { "data-group": true, id: term } : {})}
36+
>
4337
<IdAnchor id={term} />
4438
<Translation
4539
id={term + "-term"}
4640
options={options}
4741
transform={components}
4842
/>
49-
</Heading>
50-
{/**
51-
* `as="span"` prevents hydration warnings for strings that contain
52-
* elements that cannot be nested inside `p` tags, like `ul` tags
53-
* (found in some Glossary definition).
54-
* TODO: Develop a better solution to handle this case.
55-
*/}
56-
<Text as="span" {...textStyles}>
43+
</h4>
44+
45+
<div className={cn("inline-block", textClasses)}>
5746
<Translation
5847
id={term + "-definition"}
5948
options={options}
6049
transform={components}
6150
/>
62-
</Text>
63-
</VStack>
51+
</div>
52+
</Stack>
6453
)
6554
}
6655

0 commit comments

Comments
 (0)