diff --git a/docs/best-practices.md b/docs/best-practices.md index 560704e6d70..985e5dc1891 100644 --- a/docs/best-practices.md +++ b/docs/best-practices.md @@ -104,14 +104,14 @@ export default ComponentName ## Styling - `src/theme.ts` - Declares site color themes, breakpoints and other constants (try to utilize these colors first) -- We use [styled-components](https://styled-components.com/) +- We use [emotion](https://emotion.sh/) - Tagged template literals are used to style custom components ```tsx - // Example of styling syntax using styled-components + // Example of styling syntax using emotion - import styled from "styled-components" + import styled from "@emotion/styled" const GenericButton = styled.div` width: 200px; @@ -128,14 +128,12 @@ export default ComponentName // ie: Text ``` - - Recommended VS Code Plugin: `vscode-styled-components`
To install: Open VS Code > `Ctrl+P` / `Cmd+P` > Run:
`ext install vscode-styled-components` - - Values from `src/theme.ts` are automatically passed as a prop object to styled components ```tsx // Example of theme.ts usage - import styled from "styled-components" + import styled from "@emotion/styled" const Container = styled.div` background: ${(props) => props.theme.colors.background}; diff --git a/gatsby-config.ts b/gatsby-config.ts index 677a2ea77ca..1596923a6bc 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -185,7 +185,19 @@ const config: GatsbyConfig = { }, }, // CSS in JS - `gatsby-plugin-styled-components`, + { + resolve: `gatsby-plugin-emotion`, + options: { + labelFormat: "[filename]--[local]", + }, + }, + { + resolve: "@chakra-ui/gatsby-plugin", + options: { + resetCSS: false, + isUsingColorMode: true, + }, + }, // Source assets { resolve: `gatsby-source-filesystem`, diff --git a/package.json b/package.json index 5a954786e19..5aa07bc916d 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,16 @@ "private": false, "dependencies": { "@apollo/client": "^3.3.13", + "@chakra-ui/gatsby-plugin": "^3.0.1", + "@chakra-ui/react": "^1.0.0", + "@emotion/react": "^11.9.3", + "@emotion/styled": "^11.9.3", "@formatjs/intl-locale": "^2.4.14", "@formatjs/intl-numberformat": "^6.1.4", "@mdx-js/mdx": "^1.6.5", "@mdx-js/react": "^1.6.5", "algoliasearch": "^4.3.0", "axios": "^0.21.2", - "babel-plugin-styled-components": "^1.10.7", "browser-lang": "^0.1.0", "browserslist": "^4.21.0", "clipboard": "^2.0.6", @@ -24,8 +27,9 @@ "embla-carousel-react": "^6.2.0", "ethereum-blockies-base64": "^1.0.2", "focus-trap-react": "^8.11.2", - "framer-motion": "^4.1.3", + "framer-motion": "^6.5.1", "gatsby": "^4.15.0", + "gatsby-plugin-emotion": "^7.19.0", "gatsby-plugin-gatsby-cloud": "^4.3.0", "gatsby-plugin-image": "^2.0.0", "gatsby-plugin-manifest": "^4.10.1", @@ -37,7 +41,6 @@ "gatsby-plugin-react-svg": "^3.1.0", "gatsby-plugin-sharp": "^4.10.0", "gatsby-plugin-sitemap": "^5.0.0", - "gatsby-plugin-styled-components": "^5.0.0", "gatsby-remark-autolink-headers": "^5.0.0", "gatsby-remark-copy-linked-files": "^5.0.0", "gatsby-remark-images": "^6.0.0", @@ -67,7 +70,6 @@ "react-intl": "^3.12.1", "react-select": "^4.3.0", "recharts": "^2.1.9", - "styled-components": "^5.1.1", "styled-system": "^5.1.5", "unist-util-visit-parents": "^2.1.2" }, @@ -81,7 +83,6 @@ "@types/react": "^17.0.39", "@types/react-dom": "^17.0.11", "@types/react-instantsearch-dom": "^6.12.3", - "@types/styled-components": "^5.1.25", "@types/styled-system": "^5.1.15", "babel-preset-gatsby": "^2.14.0", "github-slugger": "^1.3.0", diff --git a/src/@chakra-ui/gatsby-plugin/foundations/colors.ts b/src/@chakra-ui/gatsby-plugin/foundations/colors.ts new file mode 100644 index 00000000000..747ebd8f907 --- /dev/null +++ b/src/@chakra-ui/gatsby-plugin/foundations/colors.ts @@ -0,0 +1,5 @@ +export type Colors = typeof colors + +const colors = {} + +export default colors diff --git a/src/@chakra-ui/gatsby-plugin/foundations/index.ts b/src/@chakra-ui/gatsby-plugin/foundations/index.ts new file mode 100644 index 00000000000..c358f7b91a8 --- /dev/null +++ b/src/@chakra-ui/gatsby-plugin/foundations/index.ts @@ -0,0 +1,7 @@ +import colors from "./colors" + +const foundations = { + colors, +} + +export default foundations diff --git a/src/@chakra-ui/gatsby-plugin/styles.ts b/src/@chakra-ui/gatsby-plugin/styles.ts new file mode 100644 index 00000000000..aef4806b0c8 --- /dev/null +++ b/src/@chakra-ui/gatsby-plugin/styles.ts @@ -0,0 +1,22 @@ +const styles = { + global: (_props) => ({ + /** + * Current scenario: we have 2 places where global styles are defined. + * - Our legacy global styles under `src/components/GlobalStyle.ts` + * - Chakra also defines its own global styles. Check them here: + * https://github.com/chakra-ui/chakra-ui/blob/main/packages/theme/src/styles.ts + * + * Having those 2 global styles creates some style conflicts. Here we + * override some of the default Chakra globals in order to keep the same + * styles as we had in the legacy one. + * + * TODO: remove these overrides as we adopt the new Design System and we + * don't need the global styles anymore + */ + body: { + lineHeight: "1.6rem", + }, + }), +} + +export default styles diff --git a/src/@chakra-ui/gatsby-plugin/theme.ts b/src/@chakra-ui/gatsby-plugin/theme.ts new file mode 100644 index 00000000000..6f09fbc4590 --- /dev/null +++ b/src/@chakra-ui/gatsby-plugin/theme.ts @@ -0,0 +1,25 @@ +import { + extendTheme, + type ThemeConfig, + type ThemeOverride, +} from "@chakra-ui/react" + +// Global style overrides +import styles from "./styles" + +// Foundational style overrides +import foundations from "./foundations" + +const config: ThemeConfig = { + cssVarPrefix: "eth", + initialColorMode: "light", + useSystemColorMode: true, +} + +const theme: ThemeOverride = { + config, + styles, + ...foundations, +} + +export default extendTheme(theme) diff --git a/src/components/Accordion.tsx b/src/components/Accordion.tsx index af7313bbbea..b8c7b36338f 100644 --- a/src/components/Accordion.tsx +++ b/src/components/Accordion.tsx @@ -1,4 +1,4 @@ -import styled from "styled-components" +import styled from "@emotion/styled" // TODO add motion animation // import { motion } from "framer-motion" import { FakeLink } from "./SharedStyledComponents" diff --git a/src/components/ActionCard.tsx b/src/components/ActionCard.tsx index 89c6aeec1d1..54ffe10196b 100644 --- a/src/components/ActionCard.tsx +++ b/src/components/ActionCard.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { GatsbyImage } from "gatsby-plugin-image" import Link from "./Link" diff --git a/src/components/AdoptionChart.tsx b/src/components/AdoptionChart.tsx index b15b228cc12..b383d988a86 100644 --- a/src/components/AdoptionChart.tsx +++ b/src/components/AdoptionChart.tsx @@ -1,5 +1,6 @@ import React from "react" -import styled, { useTheme } from "styled-components" +import { useTheme } from "@emotion/react" +import styled from "@emotion/styled" const Container = styled.div` display: flex; diff --git a/src/components/AssetDownload.tsx b/src/components/AssetDownload.tsx index cd70401518a..1a477c88af0 100644 --- a/src/components/AssetDownload.tsx +++ b/src/components/AssetDownload.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { GatsbyImage, getImage, getSrc } from "gatsby-plugin-image" import Translation from "../components/Translation" diff --git a/src/components/BannerGrid/index.tsx b/src/components/BannerGrid/index.tsx index 9f070162204..574bc9c511c 100644 --- a/src/components/BannerGrid/index.tsx +++ b/src/components/BannerGrid/index.tsx @@ -1,4 +1,4 @@ -import styled from "styled-components" +import styled from "@emotion/styled" export const Banner = styled.div` width: 100%; diff --git a/src/components/BannerNotification.tsx b/src/components/BannerNotification.tsx index 794894e108f..11f6503d62d 100644 --- a/src/components/BannerNotification.tsx +++ b/src/components/BannerNotification.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" export interface IStyledBanner { shouldShow: boolean diff --git a/src/components/BeaconChainActions.tsx b/src/components/BeaconChainActions.tsx index d7710ee4f21..51cdca046ca 100644 --- a/src/components/BeaconChainActions.tsx +++ b/src/components/BeaconChainActions.tsx @@ -1,7 +1,7 @@ import React from "react" import { useStaticQuery, graphql } from "gatsby" import { getImage } from "gatsby-plugin-image" -import styled from "styled-components" +import styled from "@emotion/styled" import { useIntl } from "react-intl" import { translateMessageId } from "../utils/translations" diff --git a/src/components/BoxGrid.tsx b/src/components/BoxGrid.tsx index 8c8bb329ecc..a64ec7663ed 100644 --- a/src/components/BoxGrid.tsx +++ b/src/components/BoxGrid.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import Emoji from "./Emoji" export interface IBoxItem { diff --git a/src/components/Breadcrumbs.tsx b/src/components/Breadcrumbs.tsx index f2b4b4dabf6..607a4bdfe6d 100644 --- a/src/components/Breadcrumbs.tsx +++ b/src/components/Breadcrumbs.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { useIntl } from "react-intl" import Link from "./Link" diff --git a/src/components/BugBountyCards.tsx b/src/components/BugBountyCards.tsx index b084c10fd9c..50daca7cdb0 100644 --- a/src/components/BugBountyCards.tsx +++ b/src/components/BugBountyCards.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { TranslationKey } from "../utils/translations" import ButtonLink from "./ButtonLink" diff --git a/src/components/BugBountyPoints.tsx b/src/components/BugBountyPoints.tsx index 490492e255e..19d12668418 100644 --- a/src/components/BugBountyPoints.tsx +++ b/src/components/BugBountyPoints.tsx @@ -1,8 +1,8 @@ import React, { useContext, useState, useEffect } from "react" -import { ThemeContext } from "styled-components" +import { useTheme } from "@emotion/react" import { useStaticQuery, graphql } from "gatsby" import { GatsbyImage, getImage } from "gatsby-plugin-image" -import styled from "styled-components" +import styled from "@emotion/styled" import axios from "axios" import Emoji from "./Emoji" @@ -103,8 +103,8 @@ const BugBountyPoints: React.FC = () => { currentDAIPriceUSD: 1, hasError: false, }) - const themeContext = useContext(ThemeContext) - const isDarkTheme = themeContext.isDark + const theme = useTheme() + const isDarkTheme = theme.isDark useEffect(() => { axios diff --git a/src/components/ButtonDropdown.tsx b/src/components/ButtonDropdown.tsx index 957fee6cc5f..803caa62705 100644 --- a/src/components/ButtonDropdown.tsx +++ b/src/components/ButtonDropdown.tsx @@ -1,6 +1,6 @@ // Libraries import React, { useState, createRef } from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { useIntl } from "react-intl" import { motion } from "framer-motion" diff --git a/src/components/ButtonLink.tsx b/src/components/ButtonLink.tsx index b5cd8ac16c3..d852bff3bfd 100644 --- a/src/components/ButtonLink.tsx +++ b/src/components/ButtonLink.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { margin, MarginProps } from "styled-system" import { scrollIntoView } from "../utils/scrollIntoView" diff --git a/src/components/CallToContribute.tsx b/src/components/CallToContribute.tsx index 5acf63c4f4e..c22f9ad8e33 100644 --- a/src/components/CallToContribute.tsx +++ b/src/components/CallToContribute.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import Link from "./Link" import ButtonLink from "./ButtonLink" import Icon from "./Icon" diff --git a/src/components/Callout.tsx b/src/components/Callout.tsx index 1831d1cd56d..c693df91968 100644 --- a/src/components/Callout.tsx +++ b/src/components/Callout.tsx @@ -1,6 +1,6 @@ // Libraries import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { GatsbyImage } from "gatsby-plugin-image" import Translation from "./Translation" import { TranslationKey } from "../utils/translations" diff --git a/src/components/CalloutBanner.tsx b/src/components/CalloutBanner.tsx index 45b99715c87..25cac746bb5 100644 --- a/src/components/CalloutBanner.tsx +++ b/src/components/CalloutBanner.tsx @@ -1,5 +1,5 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { GatsbyImage } from "gatsby-plugin-image" import Translation from "./Translation" diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 706d6f56b96..bba088be74c 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import Emoji from "./Emoji" const StyledCard = styled.div` diff --git a/src/components/CardList.tsx b/src/components/CardList.tsx index 7d3e5243841..e9b30893093 100644 --- a/src/components/CardList.tsx +++ b/src/components/CardList.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from "react" -import styled from "styled-components" +import styled from "@emotion/styled" import { GatsbyImage } from "gatsby-plugin-image" import Link from "./Link" diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx index fa11d530c85..07a63007991 100644 --- a/src/components/Checkbox.tsx +++ b/src/components/Checkbox.tsx @@ -1,12 +1,12 @@ import React from "react" -import styled from "styled-components" +import styled from "@emotion/styled" const CheckboxContainer = styled.div` display: inline-block; vertical-align: middle; ` -const HiddenCheckbox = styled.input.attrs({ type: "checkbox" })` +const HiddenCheckbox = styled.input` border: 0; clip: rect(0 0 0 0); height: 1px; @@ -76,7 +76,7 @@ const Checkbox: React.FC = ({ } return ( - +