From c23a5ec0af18f90694931208d9082bb189edac09 Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Fri, 9 Aug 2024 22:57:46 -0400 Subject: [PATCH 01/10] refactor(mdComponents): convert components to ShadCN --- src/components/MdComponents.tsx | 175 ++++++++++++++------------------ src/layouts/Docs.tsx | 43 +++----- src/layouts/Staking.tsx | 14 +-- src/layouts/Static.tsx | 19 ++-- src/layouts/Tutorial.tsx | 28 ++--- src/layouts/Upgrade.tsx | 6 +- tailwind.config.ts | 2 +- 7 files changed, 118 insertions(+), 169 deletions(-) diff --git a/src/components/MdComponents.tsx b/src/components/MdComponents.tsx index 9affa173a57..2b334243302 100644 --- a/src/components/MdComponents.tsx +++ b/src/components/MdComponents.tsx @@ -1,18 +1,11 @@ -import { ComponentProps } from "react" +import { ComponentProps, type HTMLAttributes } from "react" import { Badge, Box, type BoxProps, - chakra, - Divider as ChakraDivider, - Flex, - type FlexProps, - type HeadingProps, ListItem, OrderedList, - Text, UnorderedList, - useToken, } from "@chakra-ui/react" import type { ChildOnlyProp } from "@/lib/types" @@ -23,14 +16,16 @@ import ButtonDropdown, { import { ButtonLink } from "@/components/Buttons" import Contributors from "@/components/Contributors" import MarkdownImage from "@/components/MarkdownImage" -import OldHeading from "@/components/OldHeading" import { mdxTableComponents } from "@/components/Table" import TooltipLink from "@/components/TooltipLink" import YouTube from "@/components/YouTube" +import { cn } from "@/lib/utils/cn" + import ContributorsQuizBanner from "./Banners/ContributorsQuizBanner" import GlossaryTooltip from "./Glossary/GlossaryTooltip" import { StandaloneQuizWidget } from "./Quiz/QuizWidget" +import { Flex } from "./ui/flex" import Card from "./Card" import DocLink from "./DocLink" import Emoji from "./Emoji" @@ -42,90 +37,79 @@ import IssuesList from "./IssuesList" import LocaleDateTime from "./LocaleDateTime" import MainArticle from "./MainArticle" -/** - * Base HTML elements - */ -const headingPropsForAnchor = (id?: string): HeadingProps => { - if (!id) return {} - return { - scrollMarginTop: 28, - id, - "data-group": true, - position: "relative", - } as HeadingProps -} - -export const commonHeadingProps = (id?: string): HeadingProps => ({ - fontWeight: 700, - lineHeight: 1.4, - ...headingPropsForAnchor(id), +export const commonHeadingAttributes = (className: string, id?: string) => ({ + id, + className: cn( + "font-bold leading-xs my-8", + id && "scroll-mt-28 relative", + className + ), + "data-group": !!id || undefined, }) -export const Heading1 = ({ children, ...rest }: HeadingProps) => ( - +type HeadingProps = HTMLAttributes + +export const Heading1 = ({ children, className, ...rest }: HeadingProps) => ( +

{children} - +

) -export const Heading2 = ({ id, children, ...rest }: HeadingProps) => ( - ( +

{children} - +

) -export const Heading3 = ({ id, children, ...rest }: HeadingProps) => ( - +export const Heading3 = ({ + id, + children, + className, + ...rest +}: HeadingProps) => ( +

{children} - +

) -export const Heading4 = ({ id, children, ...rest }: HeadingProps) => ( - ( +

{children} - +

) export const Pre = (props: ChildOnlyProp) => ( - ) export const Paragraph = (props: ChildOnlyProp) => ( - +

) export const HR = () => ( - +


) // All base html element components @@ -150,53 +134,36 @@ export const htmlElements = { /** * Custom React components */ -export const Page = (props: FlexProps) => ( +export const Page = ({ + className, + ...props +}: HTMLAttributes) => ( ) -export const Title = (props: ChildOnlyProp) => +export const Title = (props: ChildOnlyProp) => ( + +) export const ContentContainer = (props: Pick) => { - const lgBp = useToken("breakpoints", "lg") - return ( - ) } export const MobileButton = (props: ChildOnlyProp) => { - const borderColor = useToken("colors", "border") return ( - ) @@ -204,18 +171,24 @@ export const MobileButton = (props: ChildOnlyProp) => { export const StyledButtonDropdown = ({ list, + className, ...rest -}: FlexProps & Pick) => ( - +}: HTMLAttributes & Pick) => ( + ) -export const MobileButtonDropdown = ( - props: ComponentProps -) => +export const MobileButtonDropdown = ({ + className, + ...props +}: ComponentProps) => ( + +) -export const Divider = () => +export const Divider = () => ( +
+) // All custom React components export const reactComponents = { diff --git a/src/layouts/Docs.tsx b/src/layouts/Docs.tsx index 7d6fc32ddf7..7ac9dba2c82 100644 --- a/src/layouts/Docs.tsx +++ b/src/layouts/Docs.tsx @@ -1,4 +1,5 @@ import { useRouter } from "next/router" +import type { HTMLAttributes } from "react" import { Badge, Box, @@ -6,7 +7,6 @@ import { Divider as ChakraDivider, Flex, type FlexProps, - type HeadingProps, type ListProps, OrderedList as ChakraOrderedList, UnorderedList as ChakraUnorderedList, @@ -45,6 +45,7 @@ import TableOfContents from "@/components/TableOfContents" import Translation from "@/components/Translation" import YouTube from "@/components/YouTube" +import { cn } from "@/lib/utils/cn" import { getEditPath } from "@/lib/utils/editPath" const Page = (props: ChildOnlyProp & Pick) => ( @@ -80,47 +81,33 @@ const ContentContainer = (props: ContentContainerProps) => ( /> ) -const baseHeadingStyle: HeadingProps = { - fontFamily: "mono", - textTransform: "uppercase", - fontWeight: "bold", - scrollMarginTop: 40, -} +const baseHeadingClasses = "font-mono uppercase font-bold scroll-mt-40" -const H1 = (props: HeadingProps) => ( +const H1 = (props: HTMLAttributes) => ( ) -const H2 = (props: HeadingProps) => ( +const H2 = (props: HTMLAttributes) => ( ) -const baseSubHeadingStyles: HeadingProps = { - lineHeight: 1.4, - fontWeight: "semibold", -} +const baseSubHeadingClasses = "leading-xs font-semibold" -const H3 = (props: HeadingProps) => ( - +const H3 = (props: HTMLAttributes) => ( + ) -const H4 = (props: HeadingProps) => ( - +const H4 = (props: HTMLAttributes) => ( + ) const UnorderedList = (props: ListProps) => ( diff --git a/src/layouts/Staking.tsx b/src/layouts/Staking.tsx index aabe7c501c2..9236ac5e740 100644 --- a/src/layouts/Staking.tsx +++ b/src/layouts/Staking.tsx @@ -1,11 +1,11 @@ import { useTranslation } from "next-i18next" +import type { HTMLAttributes } from "react" import { Box, type BoxProps, chakra, Flex, Grid, - type HeadingProps, SimpleGrid, Text, UnorderedList, @@ -43,16 +43,12 @@ import WithdrawalsTabComparison from "@/components/Staking/WithdrawalsTabCompari import TableOfContents from "@/components/TableOfContents" import UpgradeStatus from "@/components/UpgradeStatus" -const Heading1 = (props: HeadingProps) => ( - +const Heading1 = (props: HTMLAttributes) => ( + ) -const Heading4 = (props: HeadingProps) => ( - +const Heading4 = (props: HTMLAttributes) => ( + ) const Paragraph = (props: ChildOnlyProp) => ( diff --git a/src/layouts/Static.tsx b/src/layouts/Static.tsx index b111623d0be..870f5776310 100644 --- a/src/layouts/Static.tsx +++ b/src/layouts/Static.tsx @@ -1,5 +1,6 @@ import { useRouter } from "next/router" -import { Box, Flex, type HeadingProps, Icon } from "@chakra-ui/react" +import type { HTMLAttributes } from "react" +import { Box, Flex, Icon } from "@chakra-ui/react" import type { ChildOnlyProp, Lang } from "@/lib/types" import type { MdPageContent, StaticFrontmatter } from "@/lib/interfaces" @@ -38,17 +39,17 @@ import { isLangRightToLeft } from "@/lib/utils/translations" import GuideHeroImage from "@/public/images/heroes/guides-hub-hero.jpg" -const Heading1 = (props: HeadingProps) => ( - +const Heading1 = (props: HTMLAttributes) => ( + ) -const Heading2 = (props: HeadingProps) => ( - +const Heading2 = (props: HTMLAttributes) => ( + ) -const Heading3 = (props: HeadingProps) => ( - +const Heading3 = (props: HTMLAttributes) => ( + ) -const Heading4 = (props: HeadingProps) => ( - +const Heading4 = (props: HTMLAttributes) => ( + ) // Static layout components diff --git a/src/layouts/Tutorial.tsx b/src/layouts/Tutorial.tsx index 4c5a54a0a95..33b20f6f21a 100644 --- a/src/layouts/Tutorial.tsx +++ b/src/layouts/Tutorial.tsx @@ -1,11 +1,11 @@ import { useRouter } from "next/router" +import type { HTMLAttributes } from "react" import { Badge, Box, type BoxProps, Divider, Flex, - type HeadingProps, Kbd, Text, type TextProps, @@ -65,40 +65,30 @@ const ContentContainer = (props: ContentContainerProps) => { ) } -const Heading1 = (props: HeadingProps) => ( +const Heading1 = (props: HTMLAttributes) => ( ) -const Heading2 = (props: HeadingProps) => ( +const Heading2 = (props: HTMLAttributes) => ( ) -const Heading3 = (props: HeadingProps) => ( +const Heading3 = (props: HTMLAttributes) => ( ) -const Heading4 = (props: HeadingProps) => ( +const Heading4 = (props: HTMLAttributes) => ( ) diff --git a/src/layouts/Upgrade.tsx b/src/layouts/Upgrade.tsx index 8978dc5f8e3..c227863f5e3 100644 --- a/src/layouts/Upgrade.tsx +++ b/src/layouts/Upgrade.tsx @@ -1,8 +1,8 @@ import { useTranslation } from "next-i18next" +import type { HTMLAttributes } from "react" import { Box, type BoxProps, - type FlexProps, List, ListItem, Text, @@ -29,7 +29,9 @@ import UpgradeStatus from "@/components/UpgradeStatus" import { getSummaryPoints } from "@/lib/utils/getSummaryPoints" -const Page = (props: FlexProps) => +const Page = (props: HTMLAttributes) => ( + +) type ContainerProps = Pick diff --git a/tailwind.config.ts b/tailwind.config.ts index 17d5794bf52..4685492f175 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -2,7 +2,7 @@ import type { Config } from "tailwindcss" import plugin from "tailwindcss/plugin" const config = { - darkMode: ["class"], + darkMode: ["selector", "[data-theme=dark]"], content: [ "./src/**/*.{ts,tsx}", // TODO: remove after migration From 20fc86e0e5a169f800225efa4826f846ab4e223d Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Sun, 18 Aug 2024 22:40:32 -0400 Subject: [PATCH 02/10] refactor(MdComponents): update imports --- .../index.tsx} | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) rename src/components/{MdComponents.tsx => MdComponents/index.tsx} (85%) diff --git a/src/components/MdComponents.tsx b/src/components/MdComponents/index.tsx similarity index 85% rename from src/components/MdComponents.tsx rename to src/components/MdComponents/index.tsx index 2b334243302..1b4669c8e8e 100644 --- a/src/components/MdComponents.tsx +++ b/src/components/MdComponents/index.tsx @@ -1,19 +1,11 @@ import { ComponentProps, type HTMLAttributes } from "react" -import { - Badge, - Box, - type BoxProps, - ListItem, - OrderedList, - UnorderedList, -} from "@chakra-ui/react" +import { Badge, Box, type BoxProps } from "@chakra-ui/react" import type { ChildOnlyProp } from "@/lib/types" import ButtonDropdown, { type ButtonDropdownProps, } from "@/components/ButtonDropdown" -import { ButtonLink } from "@/components/Buttons" import Contributors from "@/components/Contributors" import MarkdownImage from "@/components/MarkdownImage" import { mdxTableComponents } from "@/components/Table" @@ -22,20 +14,22 @@ import YouTube from "@/components/YouTube" import { cn } from "@/lib/utils/cn" -import ContributorsQuizBanner from "./Banners/ContributorsQuizBanner" -import GlossaryTooltip from "./Glossary/GlossaryTooltip" -import { StandaloneQuizWidget } from "./Quiz/QuizWidget" -import { Flex } from "./ui/flex" -import Card from "./Card" -import DocLink from "./DocLink" -import Emoji from "./Emoji" -import ExpandableCard from "./ExpandableCard" -import FeaturedText from "./FeaturedText" -import IdAnchor from "./IdAnchor" -import InfoBanner from "./InfoBanner" -import IssuesList from "./IssuesList" -import LocaleDateTime from "./LocaleDateTime" -import MainArticle from "./MainArticle" +import ContributorsQuizBanner from "../Banners/ContributorsQuizBanner" +import Card from "../Card" +import DocLink from "../DocLink" +import Emoji from "../Emoji" +import ExpandableCard from "../ExpandableCard" +import FeaturedText from "../FeaturedText" +import GlossaryTooltip from "../Glossary/GlossaryTooltip" +import IdAnchor from "../IdAnchor" +import InfoBanner from "../InfoBanner" +import IssuesList from "../IssuesList" +import LocaleDateTime from "../LocaleDateTime" +import MainArticle from "../MainArticle" +import { StandaloneQuizWidget } from "../Quiz/QuizWidget" +import { ButtonLink } from "../ui/buttons/Button" +import { Flex } from "../ui/flex" +import { ListItem, OrderedList, UnorderedList } from "../ui/list" export const commonHeadingAttributes = (className: string, id?: string) => ({ id, From 5081b56dcd5c08686e0aff314ec1e230c7c2a1bf Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Mon, 19 Aug 2024 19:36:02 -0400 Subject: [PATCH 03/10] feat(MdComponents): create story set --- .../MdComponents/MdComponents.stories.tsx | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/components/MdComponents/MdComponents.stories.tsx diff --git a/src/components/MdComponents/MdComponents.stories.tsx b/src/components/MdComponents/MdComponents.stories.tsx new file mode 100644 index 00000000000..9d101a7334d --- /dev/null +++ b/src/components/MdComponents/MdComponents.stories.tsx @@ -0,0 +1,129 @@ +import pickBy from "lodash/pickBy" +import type { Meta, StoryObj } from "@storybook/react/*" + +import type { List as ButtonDropdownList } from "@/components/ButtonDropdown" + +import { viewportModes } from "../../../.storybook/modes" + +import MdComponentSet from "." + +const meta = { + title: "Molecules / Display Content / MdComponents", + parameters: { + layout: "none", + chromatic: { + modes: pickBy(viewportModes, (args) => + ["md", "lg"].includes(args.viewport) + ), + }, + }, +} satisfies Meta + +export default meta + +const { + ContentContainer, + h1: Heading1, + h2: Heading2, + h3: Heading3, + h4: Heading4, + Title, + p: Paragraph, + FeaturedText, + Divider, + hr: HR, + pre: Pre, + Page, + MobileButton, + MobileButtonDropdown, +} = MdComponentSet + +const Para = () => ( + + Ether (also known by its ticker symbol, ETH) is the native currency + transacted on Ethereum. ETH is needed to pay for usage of the Ethereum + network (in the form of transaction fees). ETH is also used to secure the + network with staking. When people talk about the price of Ethereum, + they're referring to ETH the asset. + +) + +export const MdComponents: StoryObj = { + render: () => ( +
+ + + + + + Heading1 + + Heading2 + + Heading3 + + Heading4 + + Title + + +
Lots of coding here
+
+ Feature Text +
+
+
+ ), +} + +const roadmapDropdownLinks: ButtonDropdownList = { + text: "nav-roadmap-options", + ariaLabel: "nav-roadmap-options-alt", + items: [ + { + text: "nav-roadmap-home", + href: "/roadmap/", + matomo: { + eventCategory: `Roadmap dropdown`, + eventAction: `Clicked`, + eventName: "clicked roadmap home", + }, + }, + { + text: "nav-roadmap-security", + href: "/roadmap/security", + matomo: { + eventCategory: `Roadmap security dropdown`, + eventAction: `Clicked`, + eventName: "clicked roadmap security", + }, + }, + { + text: "nav-roadmap-scaling", + href: "/roadmap/scaling", + matomo: { + eventCategory: `Roadmap scaling dropdown`, + eventAction: `Clicked`, + eventName: "clicked roadmap scaling home", + }, + }, + { + text: "nav-roadmap-user-experience", + href: "/roadmap/user-experience/", + matomo: { + eventCategory: `Roadmap user experience dropdown`, + eventAction: `Clicked`, + eventName: "clicked roadmap user experience home", + }, + }, + { + text: "nav-roadmap-future-proofing", + href: "/roadmap/future-proofing", + matomo: { + eventCategory: `Roadmap future-proofing dropdown`, + eventAction: `Clicked`, + eventName: "clicked roadmap future-proofing home", + }, + }, + ], +} From 7ae010e802486b182a2c2d422a2da83962b83fbd Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Fri, 6 Sep 2024 22:11:03 -0400 Subject: [PATCH 04/10] refactor(layouts/Tutorial): remove margin declaration for Heading1 --- src/layouts/Tutorial.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/Tutorial.tsx b/src/layouts/Tutorial.tsx index 33b20f6f21a..aa599d44653 100644 --- a/src/layouts/Tutorial.tsx +++ b/src/layouts/Tutorial.tsx @@ -67,7 +67,7 @@ const ContentContainer = (props: ContentContainerProps) => { const Heading1 = (props: HTMLAttributes) => ( ) From 2c8988cc5138309b3f5d76844e924b9b8d89eecc Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Fri, 6 Sep 2024 22:11:49 -0400 Subject: [PATCH 05/10] refactor(layouts/Docs): simplify border definition for H2 --- src/layouts/Docs.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/Docs.tsx b/src/layouts/Docs.tsx index 7ac9dba2c82..925b60310c8 100644 --- a/src/layouts/Docs.tsx +++ b/src/layouts/Docs.tsx @@ -94,7 +94,7 @@ const H2 = (props: HTMLAttributes) => ( From fbcee749331c9af26d9fee648791112991e135de Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Fri, 6 Sep 2024 22:13:09 -0400 Subject: [PATCH 06/10] refactor(MdComponents): update background color for `Divider` --- src/components/MdComponents/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MdComponents/index.tsx b/src/components/MdComponents/index.tsx index 1b4669c8e8e..1dbf1c9aeca 100644 --- a/src/components/MdComponents/index.tsx +++ b/src/components/MdComponents/index.tsx @@ -181,7 +181,7 @@ export const MobileButtonDropdown = ({ ) export const Divider = () => ( -
+
) // All custom React components From 32bc6c08b16415bbca1b546cb5e1f76008f25b45 Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Mon, 9 Sep 2024 11:00:58 -0400 Subject: [PATCH 07/10] fix(MdComponents): update top margin for Heading3 --- src/components/MdComponents/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/MdComponents/index.tsx b/src/components/MdComponents/index.tsx index 1dbf1c9aeca..f3664459a58 100644 --- a/src/components/MdComponents/index.tsx +++ b/src/components/MdComponents/index.tsx @@ -70,7 +70,10 @@ export const Heading3 = ({ className, ...rest }: HeadingProps) => ( -

+

{children}

From 50a336a3574f4ee77416779af4c15986267ce983 Mon Sep 17 00:00:00 2001 From: tylerapfledderer Date: Mon, 9 Sep 2024 11:16:36 -0400 Subject: [PATCH 08/10] style(MdComponents): update border and background styles for Pre component --- src/components/MdComponents/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MdComponents/index.tsx b/src/components/MdComponents/index.tsx index f3664459a58..ec7c8fdd079 100644 --- a/src/components/MdComponents/index.tsx +++ b/src/components/MdComponents/index.tsx @@ -96,7 +96,7 @@ export const Heading4 = ({ export const Pre = (props: ChildOnlyProp) => (
 )

From 5ee4ebdaa9960b8c793be8222d15442f3663fc21 Mon Sep 17 00:00:00 2001
From: Pablo Pettinari 
Date: Thu, 12 Sep 2024 09:42:04 +0200
Subject: [PATCH 09/10] use theme defined z-index values

---
 src/components/MdComponents/index.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/components/MdComponents/index.tsx b/src/components/MdComponents/index.tsx
index ec7c8fdd079..2ae07cd4898 100644
--- a/src/components/MdComponents/index.tsx
+++ b/src/components/MdComponents/index.tsx
@@ -160,7 +160,7 @@ export const ContentContainer = (props: Pick) => {
 export const MobileButton = (props: ChildOnlyProp) => {
   return (
     
) From 8bfc8ff950670ba44e5611f7ed4fe94c221146a4 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Thu, 12 Sep 2024 10:01:19 +0200 Subject: [PATCH 10/10] replace custom values with ds tokens --- src/components/MdComponents/index.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/MdComponents/index.tsx b/src/components/MdComponents/index.tsx index 2ae07cd4898..a58550e47c5 100644 --- a/src/components/MdComponents/index.tsx +++ b/src/components/MdComponents/index.tsx @@ -106,7 +106,7 @@ export const Paragraph = (props: ChildOnlyProp) => ( ) export const HR = () => ( -
+
) // All base html element components @@ -150,17 +150,14 @@ export const Title = (props: ChildOnlyProp) => ( export const ContentContainer = (props: Pick) => { return ( - + ) } export const MobileButton = (props: ChildOnlyProp) => { return (
)