Skip to content

Commit 7c7a830

Browse files
committed
feat: Support ReactJS 18, NextJS
- Support ReactJS 18 - Update README and fix tons of things for supporting NextJS - Change types/interface names - `IAnimation` to `Animation` - `IStyle` to `Style` - `page` props is deprecated. This value will be auto-assign, so you don't have to set it.
1 parent 083ff9c commit 7c7a830

Some content is hidden

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

52 files changed

+1824
-8623
lines changed

README.md

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,47 +27,72 @@ npm install react-scroll-motion
2727
yarn add react-scroll-motion
2828
```
2929

30-
## Code Preview
30+
## Preview
3131

3232
| PC | Mobile |
3333
| ------------------------------------------------------------ | ------------------------------------------------------------ |
3434
| <img src="_readme/example-pc.gif" alt="Preview PC" width=434 height=320/> | <img src="_readme/example-mobile.gif" alt="Preview Mobile" width=148 height=320/> |
3535

3636
- [View on deployed example](https://1000ship.github.io/react-scroll-motion/)
37+
38+
39+
## Import components/functions
40+
41+
### ReactJS
3742

3843
```jsx
39-
import { Animator, ScrollContainer, ScrollPage, batch, Fade, FadeIn, Move, MoveIn, MoveOut, Sticky, StickyIn, ZoomIn } from "react-scroll-motion";
44+
import { Animator, ScrollContainer, ScrollPage, batch, Fade, FadeIn, FadeOut, Move, MoveIn, MoveOut, Sticky, StickyIn, StickyOut, Zoom, ZoomIn, ZoomOut } from "react-scroll-motion";
45+
```
46+
47+
- Support up to 18 version
48+
49+
### NextJS
50+
```jsx
51+
import dynamic from "next/dynamic";
52+
const Animator = dynamic(
53+
import("react-scroll-motion").then((it) => it.Animator),
54+
{ ssr: false }
55+
);
56+
57+
58+
import { ScrollContainer, ScrollPage, batch, Fade, FadeIn, FadeOut, Move, MoveIn, MoveOut, Sticky, StickyIn, StickyOut, Zoom, ZoomIn, ZoomOut } from "react-scroll-motion";
59+
```
60+
- **Check this out especially if you use *NextJS***
61+
- Please import `Animator` component with `next/dynamic` like upper code, when using NextJS
4062

63+
## Example Code
64+
```jsx
4165
const ZoomInScrollOut = batch(StickyIn(), FadeIn(), ZoomIn());
4266
const FadeUp = batch(Fade(), Move(), Sticky());
4367

4468
<ScrollContainer>
45-
<ScrollPage page={0}>
69+
<ScrollPage>
4670
<Animator animation={batch(Fade(), Sticky(), MoveOut(0, -200))}>
4771
<span style={{ fontSize: "30px" }}>Let me show you scroll animation 😀</span>
4872
</Animator>
4973
</ScrollPage>
50-
<ScrollPage page={1}>
74+
<ScrollPage>
5175
<Animator animation={ZoomInScrollOut}>
5276
<span style={{ fontSize: "40px" }}>I'm FadeUpScrollOut ✨</span>
5377
</Animator>
5478
</ScrollPage>
55-
<ScrollPage page={2}>
79+
<ScrollPage>
5680
<Animator animation={FadeUp}>
5781
<span style={{ fontSize: "40px" }}>I'm FadeUp ⛅️</span>
5882
</Animator>
5983
</ScrollPage>
60-
<ScrollPage page={3}>
84+
<ScrollPage>
6185
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "100%" }} >
6286
<span style={{ fontSize: "40px" }}>
6387
<Animator animation={MoveIn(-1000, 0)}>Hello Guys 👋🏻</Animator>
64-
<Animator animation={MoveIn(1000, 0)}>Nice to meet you 🙋🏻‍♀️</Animator>- I'm Seonghyeok -
88+
<Animator animation={MoveIn(1000, 0)}>Nice to meet you 🙋🏻‍♀️</Animator>
89+
- I'm Dante Chun -
6590
<Animator animation={MoveOut(1000, 0)}>Good bye ✋🏻</Animator>
6691
<Animator animation={MoveOut(-1000, 0)}>See you 💛</Animator>
6792
</span>
6893
</div>
6994
</ScrollPage>
70-
<ScrollPage page={4}>
95+
<ScrollPage>
7196
<Animator animation={batch(Fade(), Sticky())}>
7297
<span style={{ fontSize: "40px" }}>Done</span>
7398
<br/>
@@ -79,14 +104,72 @@ const FadeUp = batch(Fade(), Move(), Sticky());
79104
</ScrollContainer>
80105
```
81106

107+
## Make custom animation
108+
109+
Let's make spin animation 😉
110+
111+
<img src="_readme/custom-animation.webp" alt="Custom spinning animation" width="400" height="400" />
112+
113+
114+
### Javascript
115+
```jsx
116+
const Spin = (cycle) =>
117+
({
118+
in: {
119+
style: {
120+
transform: (p) => `rotate(${p * 360 * cycle}deg)`,
121+
},
122+
},
123+
out: {
124+
style: {
125+
transform: (p) => `rotate(${p * 360 * cycle}deg)`,
126+
},
127+
},
128+
});
129+
```
130+
131+
132+
### Typescript
133+
```tsx
134+
import { Animation } from "react-scroll-motion";
135+
136+
const Spin = (cycle: number) =>
137+
({
138+
in: {
139+
style: {
140+
transform: (p) => `rotate(${p * 360 * cycle}deg)`,
141+
},
142+
},
143+
out: {
144+
style: {
145+
transform: (p) => `rotate(${p * 360 * cycle}deg)`,
146+
},
147+
},
148+
} as Animation);
149+
```
150+
151+
```jsx
152+
<ScrollContainer>
153+
<ScrollPage>
154+
// Your custom animation also can be batched!
155+
<Animator animation={batch(Sticky(), Fade(), Spin(3))}>
156+
<h1 style={{ fontSize: 50 }}>Hello!!!</h1>
157+
</Animator>
158+
</ScrollPage>
159+
<ScrollPage>
160+
...
161+
</ScrollPage>
162+
</ScrollContainer>
163+
```
164+
82165
## Notes & References
83166

84-
- [Simple Docs (BETA)](_readme/docs.md)
167+
- [Simple Docs](_readme/docs.md)
85168
- [Update Notes](_readme/update.md)
86169

87170
## Author
88171

89-
👤 **Seonghyeok Chun**
172+
👤 **Dante Chun**
90173

91174
* Website: 1000ship.me
92175
* Github: [@1000ship](https://github.com/1000ship)
@@ -101,8 +184,5 @@ Give a ⭐️ if this project helped you!
101184

102185
## 📝 License
103186

104-
Copyright © 2021 [Seonghyeok Chun](https://github.com/1000ship).<br />
187+
Copyright © 2021 [Dante Chun](https://github.com/1000ship).<br />
105188
This project is [MIT](https://github.com/1000ship/react-scroll-motion/blob/master/LICENSE) licensed.
106-
107-
***
108-
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_

_readme/custom-animation.webp

663 KB
Loading

_readme/docs.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33

44

5-
## Simple Docs
5+
## Docs
66

77
### Markup Example
88

99
```jsx
1010
<ScrollContainer snap="mandatory">
11-
<ScrollPage page={0}>
11+
<ScrollPage>
1212
<Animator animation={batch(Fade(), Sticky(), MoveOut(0, -200))}>
1313
<MediumText>Let't me show you scroll animation 😀</MediumText>
1414
</Animator>
@@ -24,10 +24,6 @@
2424
2525
- `ScrollPage` is `position: relative;` thus, if you want use flexbox, make `div` in `ScrollPage`
2626
27-
- `ScrollPage` has `page` props for integer
28-
29-
*(Honestly, I don't like this way, is there awesome solution?)*
30-
3127
- `Animator` must be in `ScrollPage`
3228
3329
- `Animator` has `animation` props

_readme/update.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@
3030
## version 0.2.6
3131

3232
- Remove unnecessary files on npm.js publishing
33+
34+
## version 0.3.0
35+
36+
- Support ReactJS 18
37+
- Update README and fix tons of things for supporting NextJS
38+
- Change types/interface names
39+
- `IAnimation` to `Animation`
40+
- `IStyle` to `Style`
41+
- `page` props is deprecated. This value will be auto-assign, so you don't have to set it.

examples/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"react/no-unescaped-entities": "off"
5+
}
6+
}

examples/.gitignore

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88
# testing
99
/coverage
1010

11+
# next.js
12+
/.next/
13+
/out/
14+
1115
# production
1216
/build
1317

1418
# misc
1519
.DS_Store
16-
.env.local
17-
.env.development.local
18-
.env.test.local
19-
.env.production.local
20+
*.pem
2021

22+
# debug
2123
npm-debug.log*
2224
yarn-debug.log*
2325
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel

examples/README.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
1-
# Getting Started with Create React App
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
3+
## Getting Started
44

5-
## Available Scripts
5+
First, run the development server:
66

7-
In the project directory, you can run:
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
812

9-
### `yarn start`
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
1014

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
15+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
1316

14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
1618

17-
### `yarn test`
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
1820

19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `yarn build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `yarn eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
21+
## Learn More
3522

36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
23+
To learn more about Next.js, take a look at the following resources:
3724

38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
3927

40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
4129

42-
## Learn More
30+
## Deploy on Vercel
4331

44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
4533

46-
To learn React, check out the [React documentation](https://reactjs.org/).
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

examples/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

examples/package.json

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,22 @@
22
"name": "examples",
33
"version": "0.1.0",
44
"private": true,
5-
"dependencies": {
6-
"@testing-library/jest-dom": "^5.14.1",
7-
"@testing-library/react": "^12.0.0",
8-
"@testing-library/user-event": "^13.2.1",
9-
"@types/jest": "^27.0.1",
10-
"@types/node": "^16.7.13",
11-
"@types/react": "^17.0.20",
12-
"@types/react-dom": "^17.0.9",
13-
"react": "^17.0.2",
14-
"react-dom": "^17.0.2",
15-
"react-scripts": "5.0.0",
16-
"react-scroll-motion": "../",
17-
"typescript": "^4.4.2",
18-
"web-vitals": "^2.1.0"
19-
},
205
"scripts": {
21-
"start": "react-scripts start",
22-
"build": "react-scripts build",
23-
"test": "react-scripts test",
24-
"eject": "react-scripts eject"
6+
"reinstall": "rm yarn.lock && rm -rf node_modules && yarn install",
7+
"dev": "next dev",
8+
"build": "next build",
9+
"start": "next start",
10+
"lint": "next lint"
2511
},
26-
"eslintConfig": {
27-
"extends": [
28-
"react-app",
29-
"react-app/jest"
30-
]
12+
"dependencies": {
13+
"next": "12.1.6",
14+
"react": "18.1.0",
15+
"react-dom": "18.1.0",
16+
"react-scroll-motion": "../"
3117
},
32-
"browserslist": {
33-
"production": [
34-
">0.2%",
35-
"not dead",
36-
"not op_mini all"
37-
],
38-
"development": [
39-
"last 1 chrome version",
40-
"last 1 firefox version",
41-
"last 1 safari version"
42-
]
18+
"devDependencies": {
19+
"@types/node": "^17.0.39",
20+
"eslint": "8.17.0",
21+
"eslint-config-next": "12.1.6"
4322
}
4423
}

0 commit comments

Comments
 (0)