Skip to content

Commit a26608a

Browse files
authored
Merge pull request #9631 from soheil555/feat/static-template-to-chakra
migrate `static` template to Chakra
2 parents 46f031e + daac2f6 commit a26608a

File tree

1 file changed

+156
-79
lines changed

1 file changed

+156
-79
lines changed

src/templates/static.tsx

Lines changed: 156 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import React from "react"
2+
import {
3+
Badge,
4+
Box,
5+
Flex,
6+
Text,
7+
Divider as ChakraDivider,
8+
Heading,
9+
Icon,
10+
chakra,
11+
} from "@chakra-ui/react"
212
import { graphql, PageProps } from "gatsby"
313
import { useI18next } from "gatsby-plugin-react-i18next"
414
import { MDXProvider } from "@mdx-js/react"
515
import { MDXRenderer } from "gatsby-plugin-mdx"
6-
import styled from "@emotion/styled"
7-
import { Badge } from "@chakra-ui/react"
816

917
import ButtonLink from "../components/ButtonLink"
1018
import Breadcrumbs from "../components/Breadcrumbs"
@@ -20,101 +28,141 @@ import MeetupList from "../components/MeetupList"
2028
import PageMetadata from "../components/PageMetadata"
2129
import RandomAppList from "../components/RandomAppList"
2230
import ExpandableCard from "../components/ExpandableCard"
23-
import TableOfContents, {
24-
Item as ItemTableOfContents,
25-
} from "../components/TableOfContents"
31+
import TableOfContents from "../components/TableOfContents"
2632
import Translation from "../components/Translation"
2733
import SectionNav from "../components/SectionNav"
2834
import DocLink from "../components/DocLink"
2935
import GhostCard from "../components/GhostCard"
3036
import MatomoOptOut from "../components/MatomoOptOut"
3137
import UpgradeStatus from "../components/UpgradeStatus"
32-
import {
33-
Divider,
34-
Paragraph,
35-
Header1,
36-
Header2,
37-
Header3,
38-
Header4,
39-
ListItem,
40-
CardContainer,
41-
} from "../components/SharedStyledComponents"
42-
import Emoji from "../components/OldEmoji"
38+
import Emoji from "../components/Emoji"
4339
import UpcomingEventsList from "../components/UpcomingEventsList"
44-
import Icon from "../components/Icon"
4540
import SocialListItem from "../components/SocialListItem"
4641
import YouTube from "../components/YouTube"
4742
import TranslationChartImage from "../components/TranslationChartImage"
4843
import PostMergeBanner from "../components/Banners/PostMergeBanner"
4944
import EnergyConsumptionChart from "../components/EnergyConsumptionChart"
5045
import QuizWidget from "../components/Quiz/QuizWidget"
46+
import { Item as ItemTableOfContents } from "../components/TableOfContents/utils"
5147

5248
import { getLocaleTimestamp } from "../utils/time"
5349
import { isLangRightToLeft, TranslationKey } from "../utils/translations"
5450
import { Lang } from "../utils/languages"
55-
import { Context } from "../types"
5651

57-
const Container = styled.div`
58-
width: 100%;
59-
`
52+
import { ChildOnlyProp, Context } from "../types"
6053

61-
const Page = styled.div`
62-
display: flex;
63-
justify-content: space-between;
64-
width: 100%;
65-
margin: 0 auto 4rem;
66-
padding: 2rem;
54+
const Pre = (props: ChildOnlyProp) => (
55+
<Text
56+
as="pre"
57+
maxW="full"
58+
overflowX="scroll"
59+
bgColor="preBackground"
60+
borderRadius="base"
61+
p={4}
62+
border="1px solid"
63+
borderColor="preBorder"
64+
whiteSpace="pre-wrap"
65+
{...props}
66+
/>
67+
)
6768

68-
@media (min-width: ${(props) => props.theme.breakpoints.l}) {
69-
padding-top: 4rem;
70-
}
71-
`
69+
const HR = () => (
70+
<ChakraDivider
71+
mt={8}
72+
mb={4}
73+
display="inline-block"
74+
position="inherit"
75+
bg="border"
76+
/>
77+
)
7278

73-
// Apply styles for classes within markdown here
74-
const ContentContainer = styled.article`
75-
max-width: ${(props) => props.theme.breakpoints.m};
76-
width: 100%;
79+
const Divider = () => <Box my={16} w="10%" h={1} bgColor="homeDivider" />
7780

78-
.featured {
79-
padding-left: 1rem;
80-
margin-left: -1rem;
81-
border-left: 1px dotted ${(props) => props.theme.colors.primary};
82-
}
81+
const Header1 = (props: ChildOnlyProp) => (
82+
<Heading
83+
as="h1"
84+
fontSize={{ base: "2.5rem", md: "5xl" }}
85+
lineHeight={1.4}
86+
fontWeight="bold"
87+
_before={{
88+
content: `""`,
89+
display: "block",
90+
h: "140px",
91+
mt: "-140px",
92+
visibility: "hidden",
93+
}}
94+
sx={{
95+
a: {
96+
display: "none",
97+
},
98+
}}
99+
{...props}
100+
/>
101+
)
83102

84-
.citation {
85-
p {
86-
color: ${(props) => props.theme.colors.text200};
87-
}
88-
}
89-
`
103+
const Header2 = (props: ChildOnlyProp) => (
104+
<Heading
105+
fontSize={{ base: "2xl", md: "2rem" }}
106+
lineHeight={1.4}
107+
fontWeight="bold"
108+
sx={{ position: "inherit !important" }}
109+
_before={{
110+
content: `""`,
111+
display: "block",
112+
h: "120px",
113+
mt: "-120px",
114+
visibility: "hidden",
115+
}}
116+
{...props}
117+
/>
118+
)
90119

91-
const LastUpdated = styled.p`
92-
color: ${(props) => props.theme.colors.text200};
93-
`
120+
const Header3 = (props: ChildOnlyProp) => (
121+
<Heading
122+
as="h3"
123+
fontSize={{ base: "xl", md: "2xl" }}
124+
lineHeight={1.4}
125+
sx={{ position: "inherit !important" }}
126+
_before={{
127+
content: `""`,
128+
display: "block",
129+
h: "120px",
130+
mt: "-120px",
131+
visibility: "hidden",
132+
}}
133+
{...props}
134+
/>
135+
)
94136

95-
const Pre = styled.pre`
96-
max-width: 100%;
97-
overflow-x: scroll;
98-
background-color: ${(props) => props.theme.colors.preBackground};
99-
border-radius: 0.25rem;
100-
padding: 1rem;
101-
border: 1px solid ${(props) => props.theme.colors.preBorder};
102-
white-space: pre-wrap;
103-
`
137+
const Header4 = (props: ChildOnlyProp) => (
138+
<Heading
139+
as="h4"
140+
fontSize={{ base: "md", md: "xl" }}
141+
lineHeight={1.4}
142+
fontWeight="semibold"
143+
sx={{ position: "unset !important" }}
144+
_before={{
145+
content: `""`,
146+
display: "block",
147+
h: "120px",
148+
mt: "-120px",
149+
visibility: "hidden",
150+
}}
151+
{...props}
152+
/>
153+
)
104154

105-
const MobileTableOfContents = styled(TableOfContents)`
106-
position: relative;
107-
z-index: 2;
108-
`
155+
const Paragraph = (props: ChildOnlyProp) => (
156+
<Text fontSize="md" mt={8} mb={4} color="text300" {...props} />
157+
)
109158

110-
const HR = styled.hr`
111-
width: 100%;
112-
margin: 2rem 0rem;
113-
margin-bottom: 1rem;
114-
display: inline-block;
115-
position: inherit;
116-
background: ${(props) => props.theme.colors.border};
117-
`
159+
const ListItem = (props: ChildOnlyProp) => (
160+
<chakra.li color="text300" {...props} />
161+
)
162+
163+
const CardContainer = (props: ChildOnlyProp) => (
164+
<Flex wrap="wrap" mx={-4} {...props} />
165+
)
118166

119167
// Note: you must pass components to MDXProvider in order to render them in markdown files
120168
// https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#mdxprovider
@@ -190,26 +238,55 @@ const StaticPage = ({
190238
const absoluteEditPath = `${editContentUrl}${relativePath}`
191239

192240
return (
193-
<Container>
241+
<Box w="full">
194242
{showPostMergeBanner && (
195243
<PostMergeBanner
196244
translationString={postMergeBannerTranslationString!}
197245
/>
198246
)}
199-
<Page dir={isRightToLeft ? "rtl" : "ltr"}>
247+
<Flex
248+
justifyContent="space-between"
249+
w="full"
250+
mx="auto"
251+
mb={16}
252+
p={8}
253+
pt={{ base: 8, lg: 16 }}
254+
dir={isRightToLeft ? "rtl" : "ltr"}
255+
>
200256
<PageMetadata
201257
title={mdx.frontmatter.title}
202258
description={mdx.frontmatter.description}
203259
/>
204-
<ContentContainer>
260+
<Box
261+
as="article"
262+
maxW="container.md"
263+
w="full"
264+
sx={{
265+
".featured": {
266+
pl: 4,
267+
ml: -4,
268+
borderLeft: "1px dotted",
269+
borderLeftColor: "primary",
270+
},
271+
272+
".citation": {
273+
p: {
274+
color: "text200",
275+
},
276+
},
277+
}}
278+
>
205279
<Breadcrumbs slug={slug} />
206-
<LastUpdated
280+
<Text
281+
color="text200"
207282
dir={isLangRightToLeft(language as Lang) ? "rtl" : "ltr"}
208283
>
209284
<Translation id="page-last-updated" />:{" "}
210285
{getLocaleTimestamp(language as Lang, lastUpdatedDate)}
211-
</LastUpdated>
212-
<MobileTableOfContents
286+
</Text>
287+
<TableOfContents
288+
position="relative"
289+
zIndex={2}
213290
editPath={absoluteEditPath}
214291
items={tocItems}
215292
isMobile={true}
@@ -220,7 +297,7 @@ const StaticPage = ({
220297
<MDXRenderer>{mdx.body}</MDXRenderer>
221298
</MDXProvider>
222299
<FeedbackCard isArticle />
223-
</ContentContainer>
300+
</Box>
224301
{tocItems && (
225302
<TableOfContents
226303
editPath={absoluteEditPath}
@@ -229,8 +306,8 @@ const StaticPage = ({
229306
hideEditButton={!!mdx.frontmatter.hideEditButton}
230307
/>
231308
)}
232-
</Page>
233-
</Container>
309+
</Flex>
310+
</Box>
234311
)
235312
}
236313

0 commit comments

Comments
 (0)