Skip to content

Commit 06ea9b5

Browse files
authored
Merge pull request #7179 from ethereum/emotion
Implement emotion & chakra
2 parents 332d868 + 2a57448 commit 06ea9b5

File tree

165 files changed

+2115
-1208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+2115
-1208
lines changed

docs/best-practices.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ export default ComponentName
104104
## Styling
105105

106106
- `src/theme.ts` - Declares site color themes, breakpoints and other constants (try to utilize these colors first)
107-
- We use [styled-components](https://styled-components.com/)
107+
- We use [emotion](https://emotion.sh/)
108108

109109
- Tagged template literals are used to style custom components
110110

111111
```tsx
112-
// Example of styling syntax using styled-components
112+
// Example of styling syntax using emotion
113113
114-
import styled from "styled-components"
114+
import styled from "@emotion/styled"
115115
116116
const GenericButton = styled.div`
117117
width: 200px;
@@ -128,14 +128,12 @@ export default ComponentName
128128
// ie: <PrimaryButton>Text</PrimaryButton>
129129
```
130130

131-
- Recommended VS Code Plugin: `vscode-styled-components` <br>To install: Open VS Code > `Ctrl+P` / `Cmd+P` > Run: <br>`ext install vscode-styled-components`
132-
133131
- Values from `src/theme.ts` are automatically passed as a prop object to styled components
134132

135133
```tsx
136134
// Example of theme.ts usage
137135
138-
import styled from "styled-components"
136+
import styled from "@emotion/styled"
139137
140138
const Container = styled.div`
141139
background: ${(props) => props.theme.colors.background};

gatsby-config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,19 @@ const config: GatsbyConfig = {
185185
},
186186
},
187187
// CSS in JS
188-
`gatsby-plugin-styled-components`,
188+
{
189+
resolve: `gatsby-plugin-emotion`,
190+
options: {
191+
labelFormat: "[filename]--[local]",
192+
},
193+
},
194+
{
195+
resolve: "@chakra-ui/gatsby-plugin",
196+
options: {
197+
resetCSS: false,
198+
isUsingColorMode: true,
199+
},
200+
},
189201
// Source assets
190202
{
191203
resolve: `gatsby-source-filesystem`,

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
"private": false,
1010
"dependencies": {
1111
"@apollo/client": "^3.3.13",
12+
"@chakra-ui/gatsby-plugin": "^3.0.1",
13+
"@chakra-ui/react": "^1.0.0",
14+
"@emotion/react": "^11.9.3",
15+
"@emotion/styled": "^11.9.3",
1216
"@formatjs/intl-locale": "^2.4.14",
1317
"@formatjs/intl-numberformat": "^6.1.4",
1418
"@mdx-js/mdx": "^1.6.5",
1519
"@mdx-js/react": "^1.6.5",
1620
"algoliasearch": "^4.3.0",
1721
"axios": "^0.21.2",
18-
"babel-plugin-styled-components": "^1.10.7",
1922
"browser-lang": "^0.1.0",
2023
"browserslist": "^4.21.0",
2124
"clipboard": "^2.0.6",
@@ -24,8 +27,9 @@
2427
"embla-carousel-react": "^6.2.0",
2528
"ethereum-blockies-base64": "^1.0.2",
2629
"focus-trap-react": "^8.11.2",
27-
"framer-motion": "^4.1.3",
30+
"framer-motion": "^6.5.1",
2831
"gatsby": "^4.15.0",
32+
"gatsby-plugin-emotion": "^7.19.0",
2933
"gatsby-plugin-gatsby-cloud": "^4.3.0",
3034
"gatsby-plugin-image": "^2.0.0",
3135
"gatsby-plugin-manifest": "^4.10.1",
@@ -37,7 +41,6 @@
3741
"gatsby-plugin-react-svg": "^3.1.0",
3842
"gatsby-plugin-sharp": "^4.10.0",
3943
"gatsby-plugin-sitemap": "^5.0.0",
40-
"gatsby-plugin-styled-components": "^5.0.0",
4144
"gatsby-remark-autolink-headers": "^5.0.0",
4245
"gatsby-remark-copy-linked-files": "^5.0.0",
4346
"gatsby-remark-images": "^6.0.0",
@@ -67,7 +70,6 @@
6770
"react-intl": "^3.12.1",
6871
"react-select": "^4.3.0",
6972
"recharts": "^2.1.9",
70-
"styled-components": "^5.1.1",
7173
"styled-system": "^5.1.5",
7274
"unist-util-visit-parents": "^2.1.2"
7375
},
@@ -81,7 +83,6 @@
8183
"@types/react": "^17.0.39",
8284
"@types/react-dom": "^17.0.11",
8385
"@types/react-instantsearch-dom": "^6.12.3",
84-
"@types/styled-components": "^5.1.25",
8586
"@types/styled-system": "^5.1.15",
8687
"babel-preset-gatsby": "^2.14.0",
8788
"github-slugger": "^1.3.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type Colors = typeof colors
2+
3+
const colors = {}
4+
5+
export default colors
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import colors from "./colors"
2+
3+
const foundations = {
4+
colors,
5+
}
6+
7+
export default foundations
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const styles = {
2+
global: (_props) => ({
3+
/**
4+
* Current scenario: we have 2 places where global styles are defined.
5+
* - Our legacy global styles under `src/components/GlobalStyle.ts`
6+
* - Chakra also defines its own global styles. Check them here:
7+
* https://github.com/chakra-ui/chakra-ui/blob/main/packages/theme/src/styles.ts
8+
*
9+
* Having those 2 global styles creates some style conflicts. Here we
10+
* override some of the default Chakra globals in order to keep the same
11+
* styles as we had in the legacy one.
12+
*
13+
* TODO: remove these overrides as we adopt the new Design System and we
14+
* don't need the global styles anymore
15+
*/
16+
body: {
17+
lineHeight: "1.6rem",
18+
},
19+
}),
20+
}
21+
22+
export default styles

src/@chakra-ui/gatsby-plugin/theme.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
extendTheme,
3+
type ThemeConfig,
4+
type ThemeOverride,
5+
} from "@chakra-ui/react"
6+
7+
// Global style overrides
8+
import styles from "./styles"
9+
10+
// Foundational style overrides
11+
import foundations from "./foundations"
12+
13+
const config: ThemeConfig = {
14+
cssVarPrefix: "eth",
15+
initialColorMode: "light",
16+
useSystemColorMode: true,
17+
}
18+
19+
const theme: ThemeOverride = {
20+
config,
21+
styles,
22+
...foundations,
23+
}
24+
25+
export default extendTheme(theme)

src/components/Accordion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from "styled-components"
1+
import styled from "@emotion/styled"
22
// TODO add motion animation
33
// import { motion } from "framer-motion"
44
import { FakeLink } from "./SharedStyledComponents"

src/components/ActionCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactNode } from "react"
2-
import styled from "styled-components"
2+
import styled from "@emotion/styled"
33
import { GatsbyImage } from "gatsby-plugin-image"
44

55
import Link from "./Link"

src/components/AdoptionChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react"
2-
import styled, { useTheme } from "styled-components"
2+
import { useTheme } from "@emotion/react"
3+
import styled from "@emotion/styled"
34

45
const Container = styled.div`
56
display: flex;

0 commit comments

Comments
 (0)