Skip to content

Commit ad98615

Browse files
70: Migrate from styled-components to emotion
1 parent d5d2e35 commit ad98615

File tree

8 files changed

+317
-209
lines changed

8 files changed

+317
-209
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ This helps us avoid calculating the height ourselves and therefore browsers don'
1010
heavy Recalculate-Style-Phases.
1111
For more information read [here](https://developers.google.com/web/fundamentals/performance/rendering/).
1212

13-
Since it's using [styled-components](https://www.styled-components.com/) internally, it's best to
14-
use it in apps where you already have styled-components in place.
15-
The component is only compatible with styled-components v4 and higher.
13+
Since it's using [emotion](https://emotion.sh) internally, it's best to
14+
use it in apps where you already have emotion in place.
1615

1716
The component is inspired by [react-headroom](https://kyleamathews.github.io/react-headroom/).
1817

demo/demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { createRoot } from 'react-dom/client'
33
import StickyHeadroom from '../src/Headroom'
4-
import styled from 'styled-components'
4+
import styled from '@emotion/styled'
55
import CITIES from './cities'
66

77
const Header = styled.header`

package-lock.json

Lines changed: 302 additions & 193 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"react",
3737
"hide",
3838
"header",
39-
"styled-components",
39+
"emotion",
4040
"typescript"
4141
],
4242
"module": "./index.js",
@@ -64,13 +64,15 @@
6464
],
6565
"peerDependencies": {
6666
"react": "16.x.x || 17.x.x || 18.x.x || 19.x.x",
67-
"styled-components": "4.x.x || 5.x.x || 6.x.x"
67+
"@emotion/react": "11.x.x",
68+
"@emotion/styled": "11.x.x"
6869
},
6970
"devDependencies": {
70-
"@stylelint/postcss-css-in-js": "^0.38.0",
71+
"@emotion/react": "^11.14.0",
72+
"@emotion/styled": "^11.14.0",
7173
"@swc/core": "^1.11.24",
7274
"@swc/jest": "^0.2.38",
73-
"@swc/plugin-styled-components": "^7.1.5",
75+
"@swc/plugin-emotion": "^9.0.4",
7476
"@types/jest": "^29.5.14",
7577
"@types/node": "^22.15.21",
7678
"@types/react-dom": "^19.1.5",
@@ -88,14 +90,12 @@
8890
"jest": "^29.7.0",
8991
"jest-environment-jsdom": "^29.7.0",
9092
"jest-junit": "^16.0.0",
91-
"jest-styled-components": "^7.2.0",
9293
"postcss": "^8.5.3",
9394
"postcss-styled-syntax": "^0.7.1",
9495
"prettier": "^3.5.3",
9596
"raf": "^3.4.1",
9697
"react": "^19.1.0",
9798
"react-dom": "^19.1.0",
98-
"styled-components": "^6.1.18",
9999
"stylelint": "^16.19.1",
100100
"stylelint-config-recommended": "^16.0.0",
101101
"swc-loader": "^0.2.6",

src/Headroom.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, { css, keyframes } from 'styled-components'
2+
import styled from '@emotion/styled'
3+
import { css, keyframes } from '@emotion/react'
34

45
const DIRECTION_UP = 'up'
56
const DIRECTION_DOWN = 'down'

src/__tests__/Headroom.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ describe('Headroom', () => {
99
// TODO: Rewrite tests #37
1010
// import { ReactWrapper, mount } from 'enzyme'
1111
// import Headroom from '../Headroom'
12-
// import 'jest-styled-components'
1312
// import React, { ComponentProps } from 'react'
1413
//
1514
// const pinStart = 10

tools/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function compile(fileNames: string[], options: CompilerOptions): Record<string,
2020
// * index.tsx (a copy of src/Headroom.tsx) - using typescript
2121
// * index.d.ts (which is the typescript declaration) - using typescript
2222
// * index.d.ts.map (the source map for index.d.ts) - using typescript
23-
// * index.js (which strips the typescript annotations and optimizes styled-components) - using swc
23+
// * index.js (which strips the typescript annotations and optimizes emotion) - using swc
2424
// * index.js.map (the source map for index.js) - using swc
2525
// * index.cjs (a CommonJS version of index.js for legacy tooling) - using swc
2626
// * index.cjs.map (the source map for index.cjs) - using swc
@@ -65,7 +65,7 @@ function compile(fileNames: string[], options: CompilerOptions): Record<string,
6565
experimental: {
6666
plugins: [
6767
[
68-
'@swc/plugin-styled-components',
68+
'@swc/plugin-emotion',
6969
{
7070
displayName: false,
7171
ssr: false,
@@ -105,7 +105,7 @@ function compile(fileNames: string[], options: CompilerOptions): Record<string,
105105
experimental: {
106106
plugins: [
107107
[
108-
'@swc/plugin-styled-components',
108+
'@swc/plugin-emotion',
109109
{
110110
displayName: false,
111111
ssr: false,

tools/demo.webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const webpackConfig: webpack.Configuration = {
3030
experimental: {
3131
plugins: [
3232
[
33-
'@swc/plugin-styled-components',
33+
'@swc/plugin-emotion',
3434
{
3535
displayName: false,
3636
ssr: false,

0 commit comments

Comments
 (0)