From e14d1ad55448b63bf47f34da4e6de4bcd861a1ea Mon Sep 17 00:00:00 2001
From: soheil
Date: Thu, 20 Apr 2023 23:58:20 +0330
Subject: [PATCH 1/3] refactor(staking-template): migrate to chakra
---
src/templates/staking.tsx | 589 +++++++++++++++++++++-----------------
1 file changed, 320 insertions(+), 269 deletions(-)
diff --git a/src/templates/staking.tsx b/src/templates/staking.tsx
index f3c8619106d..ca6a4948ac7 100644
--- a/src/templates/staking.tsx
+++ b/src/templates/staking.tsx
@@ -1,10 +1,24 @@
-import React, { FC } from "react"
+import React from "react"
import { graphql, PageProps } from "gatsby"
import { MDXRenderer } from "gatsby-plugin-mdx"
import { GatsbyImage } from "gatsby-plugin-image"
import { MDXProvider } from "@mdx-js/react"
-import styled from "@emotion/styled"
-import { Badge, Box, BoxProps } from "@chakra-ui/react"
+import {
+ Badge,
+ Box,
+ BoxProps,
+ Flex,
+ Heading,
+ SimpleGrid,
+ Text,
+ useTheme,
+ chakra,
+ calc,
+ Grid,
+ Image,
+ UnorderedList,
+} from "@chakra-ui/react"
+
import ButtonLink from "../components/ButtonLink"
import ButtonDropdown, {
List as ButtonDropdownList,
@@ -13,7 +27,9 @@ import Card from "../components/Card"
import ExpandableCard from "../components/ExpandableCard"
import DocLink from "../components/DocLink"
import Contributors from "../components/Contributors"
-import SharedInfoBanner from "../components/InfoBanner"
+import SharedInfoBanner, {
+ IProps as ISharedInfoBannerProps,
+} from "../components/InfoBanner"
import UpgradeStatus from "../components/UpgradeStatus"
import Link from "../components/Link"
import MarkdownTable from "../components/MarkdownTable"
@@ -27,14 +43,7 @@ import TableOfContents, {
} from "../components/TableOfContents"
import FeedbackCard from "../components/FeedbackCard"
import SectionNav from "../components/SectionNav"
-import {
- Divider,
- Paragraph,
- Header1,
- Header4,
- InfoGrid,
-} from "../components/SharedStyledComponents"
-import Emoji from "../components/OldEmoji"
+import Emoji from "../components/Emoji"
import YouTube from "../components/YouTube"
import Breadcrumbs from "../components/Breadcrumbs"
import StakingLaunchpadWidget from "../components/Staking/StakingLaunchpadWidget"
@@ -49,268 +58,234 @@ import WithdrawalsTabComparison from "../components/Staking/WithdrawalsTabCompar
import Callout from "../components/Callout"
import { isLangRightToLeft, TranslationKey } from "../utils/translations"
-import { Context } from "../types"
import { Lang } from "../utils/languages"
import { getImage } from "../utils/image"
-const Page = styled.div`
- display: flex;
- justify-content: space-between;
- width: 100%;
- margin: 0 auto 4rem;
-
- @media (min-width: ${(props) => props.theme.breakpoints.l}) {
- padding-top: 4rem;
- }
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- flex-direction: column;
- }
-`
-
-const InfoColumn = styled.aside`
- display: flex;
- flex-direction: column;
- position: sticky;
- top: 6.25rem; /* account for navbar */
- height: calc(100vh - 80px);
- flex: 0 1 330px;
- margin: 0 2rem;
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- display: none;
- }
-`
-
-const MobileButton = styled.div`
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- background: ${(props) => props.theme.colors.background};
- box-shadow: 0 -1px 0px ${(props) => props.theme.colors.border};
- width: 100%;
- bottom: 0;
- position: sticky;
- padding: 2rem;
- z-index: 99;
- margin-bottom: 0rem;
- }
-`
+import { ChildOnlyProp, Context } from "../types"
// Apply styles for classes within markdown here
-const ContentContainer = styled.article`
- flex: 1 1 ${(props) => props.theme.breakpoints.l};
- position: relative;
- padding: 2rem;
- padding-top: 0rem;
-
- @media (min-width: ${({ theme }) => theme.breakpoints.l}) {
- h2:first-of-type {
- margin-top: 0;
- }
- }
-
- .featured {
- padding-left: 1rem;
- margin-left: -1rem;
- border-left: 1px dotted ${(props) => props.theme.colors.primary};
- }
-
- .citation {
- p {
- color: ${(props) => props.theme.colors.text200};
- }
- }
-`
-
-const Pre = styled.pre`
- max-width: 100%;
- overflow-x: scroll;
- background-color: ${(props) => props.theme.colors.preBackground};
- border-radius: 0.25rem;
- padding: 1rem;
- border: 1px solid ${(props) => props.theme.colors.preBorder};
- white-space: pre-wrap;
-`
-
-const InfoTitle = styled.h2`
- font-size: 3rem;
- font-weight: 700;
- text-align: right;
- margin-top: 0rem;
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- text-align: left;
- font-size: 2.5rem
- display: none;
- }
-`
-
-const H2 = styled.h2`
- font-size: 2rem;
- font-weight: 700;
- margin-top: 4rem;
-
- a {
- display: none;
- }
-
- /* Anchor tag styles */
-
- a {
- position: relative;
- display: initial;
- opacity: 0;
- margin-left: -1.5em;
- padding-right: 0.5rem;
- font-size: 1rem;
- vertical-align: middle;
- &:hover {
- display: initial;
- fill: ${(props) => props.theme.colors.primary};
- opacity: 1;
- }
- }
-
- &:hover {
- a {
- display: initial;
- fill: ${(props) => props.theme.colors.primary};
- opacity: 1;
- }
- }
-`
-
-const H3 = styled.h3`
- font-size: 1.5rem;
- font-weight: 700;
-
- a {
- display: none;
- }
-
- /* Anchor tag styles */
-
- a {
- position: relative;
- display: initial;
- opacity: 0;
- margin-left: -1.5em;
- padding-right: 0.5rem;
- font-size: 1rem;
- vertical-align: middle;
- &:hover {
- display: initial;
- fill: ${(props) => props.theme.colors.primary};
- opacity: 1;
- }
- }
+const Divider = (props: ChildOnlyProp) => (
+
+)
- &:hover {
- a {
- display: initial;
- fill: ${(props) => props.theme.colors.primary};
- opacity: 1;
- }
- }
-`
+const Paragraph = (props: ChildOnlyProp) => (
+
+)
-const CardGrid = styled.div`
- display: grid;
- grid-template-columns: repeat(3, 1fr);
+const Header1 = (props: ChildOnlyProp) => (
+
+)
- gap: 2rem;
- h3 {
- margin-top: 0;
- }
+const Header4 = (props: ChildOnlyProp) => (
+
+)
- @media (max-width: ${(props) => props.theme.breakpoints.m}) {
- grid-template-columns: repeat(1, 1fr);
- margin: auto;
- }
-`
+const InfoGrid = (props: ChildOnlyProp) => (
+ div": {
+ h: "fit-content",
+ m: 0,
+ "&:hover": {
+ transition: "0.1s",
+ transform: "scale(1.01)",
+ svg: {
+ transition: "0.1s",
+ transform: "scale(1.1)",
+ },
+ },
+ },
+ }}
+ {...props}
+ />
+)
-const Title = styled.h1`
- font-size: 2.5rem;
- font-weight: 700;
- margin-top: 1rem;
-`
+const Pre = (props: ChildOnlyProp) => (
+
+)
-const SummaryPoint = styled.li`
- color: ${(props) => props.theme.colors.text300};
-`
+const InfoTitle = (props: ChildOnlyProp) => (
+
+)
-const StyledButtonDropdown = styled(ButtonDropdown)`
- margin-bottom: 2rem;
- display: flex;
- justify-content: flex-end;
- text-align: center;
- @media (min-width: ${(props) => props.theme.breakpoints.s}) {
- align-self: flex-end;
- }
-`
+const H2 = (props: ChildOnlyProp) => (
+
+)
-const MobileButtonDropdown = styled(StyledButtonDropdown)`
- margin-bottom: 0rem;
- display: none;
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- display: block;
- }
-`
+const H3 = (props: ChildOnlyProp) => (
+
+)
-const Container = styled.div`
- position: relative;
- * {
- scroll-margin-top: 5.5rem;
- }
-`
+const CardGrid = (props: ChildOnlyProp) => (
+
+)
-const HeroContainer = styled.div`
- display: flex;
- align-items: center;
- padding: 2rem;
- --height: 500px;
- max-height: var(--height);
- min-height: var(--height);
- background: ${({ theme }) => theme.colors.layer2Gradient};
- @media (max-width: ${(props) => props.theme.breakpoints.l}) {
- flex-direction: column;
- max-height: 100%;
- padding-left: 0;
- padding-right: 0;
- }
-`
+const Title = (props: ChildOnlyProp) => (
+
+)
-const Image = styled(GatsbyImage)`
- flex: 1 1 100%;
- background-repeat: no-repeat;
- right: 0;
- bottom: 0;
- max-width: 400px;
- @media (max-width: ${({ theme }) => theme.breakpoints.l}) {
- width: 100%;
- height: 100%;
- max-height: 340px;
- max-width: min(400px, 98%);
- overflow: initial;
- align-self: center;
- margin: 0;
- }
-`
+const SummaryPoint = (props: ChildOnlyProp) => (
+
+)
-const MobileTableOfContents = styled(TableOfContents)`
- position: relative;
- z-index: 2;
-`
+const Container = (props: ChildOnlyProp) => (
+
+)
-const TitleCard = styled.div`
- padding: 2rem;
- display: flex;
- flex-direction: column;
- justify-content: flex-start;
- width: 100%;
-`
+const HeroContainer = (props: ChildOnlyProp) => {
+ return (
+
+ )
+}
-const InfoBanner = styled(SharedInfoBanner)`
- margin: 2rem 0;
-`
+const InfoBanner = (props: ISharedInfoBannerProps) => (
+
+)
-const TableContainer: FC = (props) => (
+const TableContainer = (props: BoxProps) => (
-
+
{mdx.frontmatter.title}
-
+
{(summaryPoints || []).map((point, idx) => (
{point}
))}
-
-
+
-
+
-
+
-
-
+
+
{mdx.frontmatter.title}
{tocItems && (
@@ -474,18 +486,57 @@ const StakingPage = ({
maxDepth={mdx.frontmatter.sidebarDepth!}
/>
)}
-
-
+
+
{mdx.body}
-
-
-
-
-
+
+
+
+
+
)
}
From f7698453c13e0ce0981bde60f8653271d2341de1 Mon Sep 17 00:00:00 2001
From: Pablo Pettinari
Date: Wed, 10 May 2023 17:48:07 -0300
Subject: [PATCH 2/3] reuse components from use-cases template and fix layout
for responsive design
---
.../TableOfContents/TableOfContentsMobile.tsx | 6 +-
src/components/TableOfContents/index.tsx | 5 +-
src/templates/staking.tsx | 149 +++++-------------
src/templates/use-cases.tsx | 15 +-
4 files changed, 60 insertions(+), 115 deletions(-)
diff --git a/src/components/TableOfContents/TableOfContentsMobile.tsx b/src/components/TableOfContents/TableOfContentsMobile.tsx
index 93a69034d67..724bf8258bb 100644
--- a/src/components/TableOfContents/TableOfContentsMobile.tsx
+++ b/src/components/TableOfContents/TableOfContentsMobile.tsx
@@ -7,6 +7,7 @@ import {
Icon,
List,
Show,
+ useToken,
} from "@chakra-ui/react"
import React from "react"
import { MdExpandMore } from "react-icons/md"
@@ -20,6 +21,9 @@ export interface IPropsTableOfContentsMobile {
}
const Mobile: React.FC = ({ items, maxDepth }) => {
+ // TODO: Replace with direct token implementation after UI migration is completed
+ const lgBp = useToken("breakpoints", "lg")
+
const { getButtonProps, getDisclosureProps, isOpen } = useDisclosure({
defaultIsOpen: false,
})
@@ -28,7 +32,7 @@ const Mobile: React.FC = ({ items, maxDepth }) => {
}
return (
-
+
{/* TODO: switch `l` to `lg` after UI migration and use `hideBelow` prop */}
= ({
...rest
}) => {
const { isZenMode, handleZenModeChange } = useContext(ZenModeContext)
+ // TODO: Replace with direct token implementation after UI migration is completed
+ const lgBp = useToken("breakpoints", "lg")
const titleIds: Array = []
@@ -81,7 +84,7 @@ const TableOfContents: React.FC = ({
return (
// TODO: Switch to `above="lg"` after completion of Chakra Migration
-
+
(
@@ -254,18 +260,6 @@ const SummaryPoint = (props: ChildOnlyProp) => (
)
-const Container = (props: ChildOnlyProp) => (
-
-)
-
const HeroContainer = (props: ChildOnlyProp) => {
return (
{
)
}
-const InfoBanner = (props: ISharedInfoBannerProps) => (
-
-)
-
const TableContainer = (props: BoxProps) => (
) => {
+ // TODO: Replace with direct token implementation after UI migration is completed
+ const lgBp = useToken("breakpoints", "lg")
+
if (!mdx?.frontmatter)
throw new Error(
"Staking page template query does not return expected values"
@@ -358,7 +351,6 @@ const StakingPage = ({
const isRightToLeft = isLangRightToLeft(mdx.frontmatter.lang as Lang)
const tocItems = mdx.tableOfContents?.items as ItemTableOfContents[]
const { summaryPoints } = mdx.frontmatter
- const theme = useTheme()
const dropdownLinks: ButtonDropdownList = {
text: "Staking Options",
@@ -413,7 +405,7 @@ const StakingPage = ({
}
return (
-
+
@@ -447,97 +439,40 @@ const StakingPage = ({
objectFit="contain"
/>
-
+
-
-
- {mdx.frontmatter.title}
+ {/* // TODO: Switch to `above="lg"` after completion of Chakra Migration */}
+
+
+
+ {mdx.frontmatter.title}
- {tocItems && (
-
- )}
-
-
+ {tocItems && (
+
+ )}
+
+
+
{mdx.body}
-
-
-
-
-
-
+
+ {/* // TODO: Switch to `above="lg"` after completion of Chakra Migration */}
+
+
+
+
+
+
+
)
}
diff --git a/src/templates/use-cases.tsx b/src/templates/use-cases.tsx
index 83111eb650b..aa86ac7d33f 100644
--- a/src/templates/use-cases.tsx
+++ b/src/templates/use-cases.tsx
@@ -191,7 +191,7 @@ const HeroImage = chakra(GatsbyImage, {
},
})
-const Page = (props: FlexProps) => (
+export const Page = (props: FlexProps) => (
(
mb={16}
pt={{ lg: 16 }}
width="full"
+ sx={{ "h2:first-of-type": { mt: { lg: 0 } } }}
{...props}
/>
)
-const InfoColumn = (props: ChildOnlyProp) => (
+export const InfoColumn = (props: ChildOnlyProp) => (
(
type ButtonDropdownProps = Parameters[0]
-const StyledButtonDropdown = (props: FlexProps & ButtonDropdownProps) => (
+export const StyledButtonDropdown = (
+ props: FlexProps & ButtonDropdownProps
+) => (
(
/>
)
-const MobileButtonDropdown = (props: ButtonDropdownProps) => (
+export const MobileButtonDropdown = (props: ButtonDropdownProps) => (
)
-const ContentContainer = (props: Pick) => (
+export const ContentContainer = (props: Pick) => (
) => (
/>
)
-const MobileButton = (props: ChildOnlyProp) => {
+export const MobileButton = (props: ChildOnlyProp) => {
const borderColor = useToken("colors", "border")
return (
Date: Fri, 12 May 2023 15:40:46 -0300
Subject: [PATCH 3/3] refactor the staking page to reuse already existing
components from the use-case template
---
src/pages/staking/index.tsx | 182 ++++++++++--------------------------
src/templates/staking.tsx | 13 +--
src/templates/use-cases.tsx | 60 ++++++------
3 files changed, 82 insertions(+), 173 deletions(-)
diff --git a/src/pages/staking/index.tsx b/src/pages/staking/index.tsx
index 3666a77c402..6dc9ee50d27 100644
--- a/src/pages/staking/index.tsx
+++ b/src/pages/staking/index.tsx
@@ -1,11 +1,9 @@
import React, { ReactNode } from "react"
import { graphql, PageProps } from "gatsby"
import { useTranslation } from "gatsby-plugin-react-i18next"
-import { Box, Flex, Grid, Heading, useToken } from "@chakra-ui/react"
+import { Box, Flex, Grid, Heading, Show, useToken } from "@chakra-ui/react"
-import ButtonDropdown, {
- List as ButtonDropdownList,
-} from "../../components/ButtonDropdown"
+import { List as ButtonDropdownList } from "../../components/ButtonDropdown"
import ButtonLink from "../../components/ButtonLink"
import Card from "../../components/Card"
import Link from "../../components/Link"
@@ -20,12 +18,19 @@ import StakingCommunityCallout from "../../components/Staking/StakingCommunityCa
import UpgradeTableOfContents from "../../components/UpgradeTableOfContents"
import { getImage } from "../../utils/image"
-
+import type { TranslationKey } from "../../utils/translations"
import type { ChildOnlyProp, Context } from "../../types"
-const Content = (props: ChildOnlyProp) => (
-
-)
+// TODO: move these components to a new folder under /components
+import {
+ ContentContainer,
+ InfoColumn,
+ InfoTitle,
+ MobileButton,
+ MobileButtonDropdown,
+ Page,
+ StyledButtonDropdown,
+} from "../../templates/use-cases"
const PageContainer = (props: ChildOnlyProp) => (
@@ -46,105 +51,6 @@ const HeroStatsWrapper = (props: ChildOnlyProp) => (
/>
)
-const Page = (props: ChildOnlyProp) => (
-
-)
-
-const InfoTitle = (props: ChildOnlyProp) => (
-
-)
-
-// InfoColumn shows above xl
-const InfoColumn = (props: ChildOnlyProp) => (
-
-)
-
-const StyledButtonDropdown = ({
- list,
- ...rest
-}: {
- list: ButtonDropdownList
-}) => (
-
-
-
-)
-
-// ButtonDropdown for mobile only
-const MobileButton = ({ list, ...rest }: { list: ButtonDropdownList }) => {
- const borderBoxShadowColor = useToken("colors", "border")
-
- return (
-
-
-
- )
-}
-
-const ContentContainer = (props: { children: ReactNode; id: string }) => {
- const [mdBp, lgBp] = useToken("breakpoints", ["md", "lg"])
-
- return (
- div:first-of-type": {
- mt: 0,
- pt: 0,
- },
- }}
- {...props}
- >
- )
-}
-
const ComparisonGrid = (props: ChildOnlyProp) => {
const gridAreas = {
base: `"solo-title"
@@ -162,7 +68,7 @@ const ComparisonGrid = (props: ChildOnlyProp) => {
"pool-risks"
"pool-reqs"
"pool-cta";`,
- lg: `"solo-title saas-title pool-title"
+ xl: `"solo-title saas-title pool-title"
"solo-rewards saas-rewards pool-rewards"
"solo-risks saas-risks pool-risks"
"solo-reqs saas-reqs pool-reqs"
@@ -172,7 +78,7 @@ const ComparisonGrid = (props: ChildOnlyProp) => {
) => {
const { t } = useTranslation()
+ // TODO: Replace with direct token implementation after UI migration is completed
+ const lgBp = useToken("breakpoints", "lg")
const heroContent = {
title: t("page-staking-hero-title"),
@@ -368,15 +276,18 @@ const StakingPage = ({
-
-
-
-
-
-
-
+ {/* // TODO: Switch to `above="lg"` after completion of Chakra Migration */}
+
+
+
+
+
+
+
+
+
-
+
{tocItems.whatIsStaking.title}
@@ -388,8 +299,8 @@ const StakingPage = ({
-
-
+
+
{tocItems.whyStakeYourEth.title}
@@ -407,8 +318,8 @@ const StakingPage = ({
)
)}
-
-
+
+
{tocItems.howToStakeYourEth.title}
@@ -418,15 +329,15 @@ const StakingPage = ({
-
+
-
+
-
+
-
+
{tocItems.comparisonOfOptions.title}
@@ -619,10 +530,10 @@ const StakingPage = ({
/>
-
+
-
+
{tocItems.faq.title}
@@ -663,8 +574,8 @@ const StakingPage = ({
-
-
+
+
{tocItems.further.title}
-
@@ -738,12 +649,17 @@ const StakingPage = ({
-
-
+
+
-
+
-
+ {/* // TODO: Switch to `above="lg"` after completion of Chakra Migration */}
+
+
+
+
+
)
diff --git a/src/templates/staking.tsx b/src/templates/staking.tsx
index 6ae8678ae35..3fb686614eb 100644
--- a/src/templates/staking.tsx
+++ b/src/templates/staking.tsx
@@ -63,6 +63,7 @@ import { ChildOnlyProp, Context } from "../types"
import {
ContentContainer,
InfoColumn,
+ InfoTitle,
MobileButton,
MobileButtonDropdown,
Page,
@@ -155,18 +156,6 @@ const Pre = (props: ChildOnlyProp) => (
/>
)
-const InfoTitle = (props: ChildOnlyProp) => (
-
-)
-
const H2 = (props: ChildOnlyProp) => (
(
/>
)
-const InfoTitle = (props: ChildOnlyProp) => (
+export const InfoTitle = (props: ChildOnlyProp) => (
(
)
-export const ContentContainer = (props: Pick) => (
-
-)
+export const ContentContainer = (props: Pick) => {
+ const lgBp = useToken("breakpoints", "lg")
+
+ return (
+
+ )
+}
export const MobileButton = (props: ChildOnlyProp) => {
const borderColor = useToken("colors", "border")
@@ -288,6 +292,8 @@ const UseCasePage = ({
pageContext,
}: PageProps) => {
const { t } = useTranslation()
+ // TODO: Replace with direct token implementation after UI migration is completed
+ const lgBp = useToken("breakpoints", "lg")
if (!siteData || !mdx?.frontmatter)
throw new Error(
@@ -347,11 +353,9 @@ const UseCasePage = ({
],
}
- const lgBreakpoint = useToken("breakpoints", "lg")
-
return (
-
+
@@ -393,7 +397,7 @@ const UseCasePage = ({
}}
/>
-
+
-
+
{mdx.frontmatter.title}
@@ -432,7 +436,7 @@ const UseCasePage = ({
-
+