Skip to content

Commit e40a201

Browse files
authored
Merge pull request #13949 from ethereum/shadcn-tutorials
Shadcn migration - tutorials layout
2 parents 032e66d + 239634b commit e40a201

File tree

1 file changed

+39
-93
lines changed

1 file changed

+39
-93
lines changed

src/layouts/Tutorial.tsx

Lines changed: 39 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { useRouter } from "next/router"
22
import type { HTMLAttributes } from "react"
3-
import {
4-
Badge,
5-
Box,
6-
type BoxProps,
7-
Flex,
8-
Kbd,
9-
Text,
10-
type TextProps,
11-
useToken,
12-
} from "@chakra-ui/react"
3+
import { Badge } from "@chakra-ui/react"
134

145
import type { ChildOnlyProp } from "@/lib/types"
156
import type { MdPageContent, TutorialFrontmatter } from "@/lib/interfaces"
@@ -22,7 +13,6 @@ import Emoji from "@/components/Emoji"
2213
import EnvWarningBanner from "@/components/EnvWarningBanner"
2314
import FeedbackCard from "@/components/FeedbackCard"
2415
import FileContributors from "@/components/FileContributors"
25-
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
2616
import InfoBanner from "@/components/InfoBanner"
2717
import MainArticle from "@/components/MainArticle"
2818
import {
@@ -34,37 +24,11 @@ import {
3424
import TableOfContents from "@/components/TableOfContents"
3525
import TooltipLink from "@/components/TooltipLink"
3626
import TutorialMetadata from "@/components/TutorialMetadata"
37-
import { Divider } from "@/components/ui/divider"
3827
import { mdxTableComponents } from "@/components/ui/Table"
3928
import YouTube from "@/components/YouTube"
4029

4130
import { getEditPath } from "@/lib/utils/editPath"
4231

43-
type ContentContainerProps = Pick<BoxProps, "children" | "dir">
44-
45-
const ContentContainer = (props: ContentContainerProps) => {
46-
const boxShadow = useToken("colors", "tableBoxShadow")
47-
48-
return (
49-
<Box
50-
as={MainArticle}
51-
maxW="1000px"
52-
minW={0}
53-
background="background.base"
54-
boxShadow={{ base: "none", lg: boxShadow }}
55-
m={{ base: "2.5rem 0rem", lg: "2rem 2rem 6rem" }}
56-
p={{ base: "3rem 2rem", lg: 16 }}
57-
borderRadius="4px"
58-
{...props}
59-
sx={{
60-
".citation": {
61-
p: { color: "text200" },
62-
},
63-
}}
64-
/>
65-
)
66-
}
67-
6832
const Heading1 = (props: HTMLAttributes<HTMLHeadingElement>) => (
6933
<MdHeading1
7034
className="font-monospace uppercase max-lg:text-[1.75rem]"
@@ -93,25 +57,16 @@ const Heading4 = (props: HTMLAttributes<HTMLHeadingElement>) => (
9357
/>
9458
)
9559

96-
const StyledDivider = (props) => <Divider {...props} />
97-
98-
const Paragraph = (props: TextProps) => (
99-
<Text as="p" mt={8} mb={4} mx={0} color="text300" fontSize="md" {...props} />
60+
const Paragraph = (props: HTMLAttributes<HTMLParagraphElement>) => (
61+
<p className="mx-0 mb-4 mt-8" {...props} />
10062
)
10163

102-
const KBD = (props) => {
103-
const borderColor = useToken("colors", "primary.base")
104-
105-
return (
106-
<Kbd
107-
verticalAlign="middle"
108-
p="0.15rem 0.45rem"
109-
borderRadius="2px"
110-
border={`1px solid ${borderColor}`}
111-
{...props}
112-
/>
113-
)
114-
}
64+
const KBD = (props: HTMLAttributes<HTMLElement>) => (
65+
<kbd
66+
className="rounded-sm border-2 border-primary px-2 py-0.5 align-middle"
67+
{...props}
68+
/>
69+
)
11570

11671
export const tutorialsComponents = {
11772
a: TooltipLink,
@@ -129,9 +84,7 @@ export const tutorialsComponents = {
12984
Card,
13085
Emoji,
13186
EnvWarningBanner,
132-
GlossaryTooltip,
13387
InfoBanner,
134-
StyledDivider,
13588
YouTube,
13689
}
13790
type TutorialLayoutProps = ChildOnlyProp &
@@ -153,44 +106,37 @@ export const TutorialLayout = ({
153106
const { asPath: relativePath } = useRouter()
154107
const absoluteEditPath = getEditPath(relativePath)
155108

156-
const borderColor = useToken("colors", "border")
157-
158109
return (
159-
<>
160-
<Flex
161-
w="100%"
162-
borderBottom={`1px solid ${borderColor}`}
163-
m={{ base: "2rem 0rem", lg: "0 auto" }}
164-
p={{ base: "0", lg: "0 2rem 0 0" }}
165-
background={{ base: "background.base", lg: "ednBackground" }}
110+
<div className="flex w-full gap-8 border-b bg-background p-8 lg:mx-auto lg:bg-background-highlight lg:shadow">
111+
<MainArticle
112+
className="min-w-0 max-w-[1000px] rounded bg-background p-0 lg:p-16 lg:shadow"
113+
dir={contentNotTranslated ? "ltr" : "unset"}
166114
>
167-
<ContentContainer dir={contentNotTranslated ? "ltr" : "unset"}>
168-
<Heading1>{frontmatter.title}</Heading1>
169-
<TutorialMetadata frontmatter={frontmatter} timeToRead={timeToRead} />
170-
<TableOfContents
171-
items={tocItems}
172-
maxDepth={frontmatter.sidebarDepth!}
173-
editPath={absoluteEditPath}
174-
isMobile
175-
pt={8}
176-
/>
177-
{children}
178-
<FileContributors
179-
contributors={contributors}
180-
lastEditLocaleTimestamp={lastEditLocaleTimestamp}
181-
/>
182-
<FeedbackCard />
183-
</ContentContainer>
184-
{tocItems && (
185-
<TableOfContents
186-
items={tocItems}
187-
maxDepth={frontmatter.sidebarDepth!}
188-
editPath={absoluteEditPath}
189-
hideEditButton={!!frontmatter.hideEditButton}
190-
pt={16}
191-
/>
192-
)}
193-
</Flex>
194-
</>
115+
<Heading1>{frontmatter.title}</Heading1>
116+
<TutorialMetadata frontmatter={frontmatter} timeToRead={timeToRead} />
117+
<TableOfContents
118+
items={tocItems}
119+
maxDepth={frontmatter.sidebarDepth!}
120+
editPath={absoluteEditPath}
121+
isMobile
122+
pt={8}
123+
/>
124+
{children}
125+
<FileContributors
126+
contributors={contributors}
127+
lastEditLocaleTimestamp={lastEditLocaleTimestamp}
128+
/>
129+
<FeedbackCard />
130+
</MainArticle>
131+
{tocItems && (
132+
<TableOfContents
133+
items={tocItems}
134+
maxDepth={frontmatter.sidebarDepth!}
135+
editPath={absoluteEditPath}
136+
hideEditButton={!!frontmatter.hideEditButton}
137+
pt={8}
138+
/>
139+
)}
140+
</div>
195141
)
196142
}

0 commit comments

Comments
 (0)