Skip to content

Commit 66100fb

Browse files
authored
Merge pull request #13947 from ethereum/shadcn-docs
Shadcn migration - docs layout
2 parents e40a201 + 0de1cc5 commit 66100fb

File tree

1 file changed

+15
-89
lines changed

1 file changed

+15
-89
lines changed

src/layouts/Docs.tsx

Lines changed: 15 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +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-
type FlexProps,
9-
type ListProps,
10-
OrderedList as ChakraOrderedList,
11-
UnorderedList as ChakraUnorderedList,
12-
useToken,
13-
} from "@chakra-ui/react"
3+
import { Badge } from "@chakra-ui/react"
144

155
import { ChildOnlyProp } from "@/lib/types"
166
import type { DocsFrontmatter, MdPageContent } from "@/lib/interfaces"
@@ -27,51 +17,26 @@ import FeedbackCard from "@/components/FeedbackCard"
2717
import FileContributors from "@/components/FileContributors"
2818
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
2919
import InfoBanner from "@/components/InfoBanner"
30-
import Link from "@/components/Link"
3120
import MainArticle from "@/components/MainArticle"
3221
import {
3322
Heading1 as MdHeading1,
3423
Heading2 as MdHeading2,
3524
Heading3 as MdHeading3,
3625
Heading4 as MdHeading4,
37-
Paragraph,
3826
} from "@/components/MdComponents"
3927
import RollupProductDevDoc from "@/components/RollupProductDevDoc"
4028
import SideNav from "@/components/SideNav"
4129
import SideNavMobile from "@/components/SideNavMobile"
4230
import TableOfContents from "@/components/TableOfContents"
4331
import Translation from "@/components/Translation"
4432
import { Divider } from "@/components/ui/divider"
33+
import InlineLink from "@/components/ui/Link"
4534
import { mdxTableComponents } from "@/components/ui/Table"
4635
import YouTube from "@/components/YouTube"
4736

4837
import { cn } from "@/lib/utils/cn"
4938
import { getEditPath } from "@/lib/utils/editPath"
5039

51-
const Page = (props: ChildOnlyProp & Pick<FlexProps, "dir">) => (
52-
<Flex
53-
direction="column"
54-
w="full"
55-
borderBottom="1px"
56-
borderColor="border"
57-
{...props}
58-
/>
59-
)
60-
61-
type ContentContainerProps = Pick<BoxProps, "children" | "dir">
62-
63-
const ContentContainer = (props: ContentContainerProps) => (
64-
<Flex
65-
justify={"space-between"}
66-
w="full"
67-
py={0}
68-
ps={0}
69-
pe={{ base: 0, lg: 8 }}
70-
backgroundColor="ednBackground"
71-
{...props}
72-
/>
73-
)
74-
7540
const baseHeadingClasses = "font-mono uppercase font-bold scroll-mt-40"
7641

7742
const H1 = (props: HTMLAttributes<HTMLHeadingElement>) => (
@@ -101,61 +66,19 @@ const H4 = (props: HTMLAttributes<HTMLHeadingElement>) => (
10166
<MdHeading4 className={baseSubHeadingClasses} {...props} />
10267
)
10368

104-
const UnorderedList = (props: ListProps) => (
105-
<ChakraUnorderedList ms="1.45rem" {...props} />
106-
)
107-
const OrderedList = (props: ListProps) => (
108-
<ChakraOrderedList ms="1.45rem" {...props} />
109-
)
110-
111-
// Apply styles for classes within markdown here
112-
const Content = (props: ChildOnlyProp) => {
113-
const mdBreakpoint = useToken("breakpoints", "md")
114-
115-
return (
116-
<Box
117-
as={MainArticle}
118-
flex={`1 1 ${mdBreakpoint}`}
119-
w={{ base: "full", lg: "0" }}
120-
pt={{ base: 8, md: 12 }}
121-
pb={{ base: 8, md: 16 }}
122-
px={{ base: 8, md: 16 }}
123-
m="0 auto"
124-
sx={{
125-
".citation": {
126-
p: {
127-
color: "text200",
128-
},
129-
},
130-
}}
131-
{...props}
132-
/>
133-
)
134-
}
135-
13669
const BackToTop = (props: ChildOnlyProp) => (
137-
<Flex
138-
display={{ lg: "none" }}
139-
mt={12}
140-
pt={8}
141-
borderTop="1px"
142-
borderColor="border"
143-
{...props}
144-
>
145-
<Link href="#top">
70+
<div className="display-none mt-12 flex border-t pt-8" {...props}>
71+
<InlineLink href="#top">
14672
<Translation id="back-to-top" />
147-
</Link>
148-
</Flex>
73+
</InlineLink>
74+
</div>
14975
)
15076

15177
export const docsComponents = {
15278
h1: H1,
15379
h2: H2,
15480
h3: H3,
15581
h4: H4,
156-
p: Paragraph,
157-
ul: UnorderedList,
158-
ol: OrderedList,
15982
pre: Codeblock,
16083
...mdxTableComponents,
16184
Badge,
@@ -197,16 +120,19 @@ export const DocsLayout = ({
197120
const absoluteEditPath = getEditPath(relativePath)
198121

199122
return (
200-
<Page>
123+
<div className="flex w-full flex-col border-b">
201124
<SideNavMobile path={relativePath} />
202125
{isPageIncomplete && (
203126
<BannerNotification shouldShow={isPageIncomplete}>
204127
<Translation id="page-developers-docs:banner-page-incomplete" />
205128
</BannerNotification>
206129
)}
207-
<ContentContainer dir={contentNotTranslated ? "ltr" : "unset"}>
130+
<div
131+
className="flex justify-between bg-background-highlight lg:pe-8"
132+
dir={contentNotTranslated ? "ltr" : "unset"}
133+
>
208134
<SideNav path={relativePath} />
209-
<Content>
135+
<MainArticle className="min-w-0 flex-1 px-8 pb-8 pt-8 md:px-16 md:pb-16 md:pt-12">
210136
<H1 id="top">{frontmatter.title}</H1>
211137
<FileContributors
212138
contributors={contributors}
@@ -224,7 +150,7 @@ export const DocsLayout = ({
224150
<BackToTop />
225151
<FeedbackCard isArticle />
226152
<DocsNav contentNotTranslated={contentNotTranslated} />
227-
</Content>
153+
</MainArticle>
228154
{tocItems && (
229155
<TableOfContents
230156
editPath={absoluteEditPath}
@@ -234,7 +160,7 @@ export const DocsLayout = ({
234160
pt={isPageIncomplete ? "5rem" : "3rem"}
235161
/>
236162
)}
237-
</ContentContainer>
238-
</Page>
163+
</div>
164+
</div>
239165
)
240166
}

0 commit comments

Comments
 (0)