react-fade-in-view 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/index.css +56 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +74 -0
- package/dist/index.mjs +47 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# react-fade-in-view
|
|
2
|
+
|
|
3
|
+
A lightweight and easy-to-use **React fade-in animation component** using **Intersection Observer API**.
|
|
4
|
+
Perfect for landing pages, portfolios, blogs, or any content-heavy site.
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- ⚡ **Lightweight:** No extra animation libraries
|
|
13
|
+
- 👀 **Intersection Observer:** Animates elements on viewport enter
|
|
14
|
+
- 🎯 **Simple API:** Easy to use, fully customizable
|
|
15
|
+
- 🎨 **Directional animations:** Up, down, left, right
|
|
16
|
+
- 🔁 **Optional repeat:** Animate every time or just once
|
|
17
|
+
- 📦 **React & Next.js compatible**
|
|
18
|
+
- ✅ **TypeScript ready**
|
|
19
|
+
- ❌ **No extra CSS import required**
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install react-fade-in-view
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add react-fade-in-view
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🚀 Basic Usage
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { FadeIn } from "react-fade-in-view";
|
|
41
|
+
|
|
42
|
+
export default function App() {
|
|
43
|
+
return (
|
|
44
|
+
<FadeIn direction="up">
|
|
45
|
+
<h1>Hello World</h1>
|
|
46
|
+
</FadeIn>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default function App() {
|
|
51
|
+
return (
|
|
52
|
+
<FadeIn as="h1" direction="up">
|
|
53
|
+
Hello World
|
|
54
|
+
</FadeIn>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🧭 Animation Directions
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
<FadeIn direction="left">Left Fade</FadeIn>
|
|
65
|
+
<FadeIn direction="right">Right Fade</FadeIn>
|
|
66
|
+
<FadeIn direction="up">Up Fade</FadeIn>
|
|
67
|
+
<FadeIn direction="down">Down Fade</FadeIn>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## ⚙️ Props
|
|
73
|
+
|
|
74
|
+
| Prop | Type | Default | Description |
|
|
75
|
+
| ----------- | ------------------------- | ------- | --------------------------------------------------- | -------- | ---- | --------------------------- |
|
|
76
|
+
| `as` | `React.ElementType` | `div` | Element or component to render instead of div |
|
|
77
|
+
| `direction` | `"up" | "down" | "left" | "right"` | `up` | Fade-in animation direction |
|
|
78
|
+
| `className` | `string` | `""` | Optional custom CSS classes |
|
|
79
|
+
| `immediate` | `boolean` | `false` | Animate immediately instead of waiting for viewport |
|
|
80
|
+
| `children` | `React.ReactNode` | — | Content to animate |
|
|
81
|
+
| `...rest` | `any other element props` | — | Pass extra props to the rendered element |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🕒 Custom Duration & Delay
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<FadeIn duration={800} delay={200}>
|
|
89
|
+
<p>This fades in slowly with a delay</p>
|
|
90
|
+
</FadeIn>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 🔁 Repeat Animation on Scroll
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<FadeIn once={false}>
|
|
99
|
+
<p>This will animate every time it enters the viewport</p>
|
|
100
|
+
</FadeIn>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🔗 Next.js Usage Example
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { FadeIn } from "react-fade-in-view";
|
|
109
|
+
|
|
110
|
+
export default function Page() {
|
|
111
|
+
return (
|
|
112
|
+
<main>
|
|
113
|
+
<FadeIn direction="up">
|
|
114
|
+
<h1>Next.js Page with FadeIn</h1>
|
|
115
|
+
</FadeIn>
|
|
116
|
+
</main>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 📄 License
|
|
124
|
+
|
|
125
|
+
MIT © Aayush Daboriya
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* src/styles.css */
|
|
2
|
+
@keyframes fadeInLeft {
|
|
3
|
+
from {
|
|
4
|
+
opacity: 0;
|
|
5
|
+
transform: translateX(-100px);
|
|
6
|
+
}
|
|
7
|
+
to {
|
|
8
|
+
opacity: 1;
|
|
9
|
+
transform: translateX(0);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
@keyframes fadeInRight {
|
|
13
|
+
from {
|
|
14
|
+
opacity: 0;
|
|
15
|
+
transform: translateX(100px);
|
|
16
|
+
}
|
|
17
|
+
to {
|
|
18
|
+
opacity: 1;
|
|
19
|
+
transform: translateX(0);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
@keyframes fadeInUp {
|
|
23
|
+
from {
|
|
24
|
+
opacity: 0;
|
|
25
|
+
transform: translateY(100px);
|
|
26
|
+
}
|
|
27
|
+
to {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: translateY(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
@keyframes fadeInDown {
|
|
33
|
+
from {
|
|
34
|
+
opacity: 0;
|
|
35
|
+
transform: translateY(-100px);
|
|
36
|
+
}
|
|
37
|
+
to {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
transform: translateY(0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
.fade-in-left {
|
|
43
|
+
animation: fadeInLeft 0.6s ease-out forwards;
|
|
44
|
+
}
|
|
45
|
+
.fade-in-right {
|
|
46
|
+
animation: fadeInRight 0.6s ease-out forwards;
|
|
47
|
+
}
|
|
48
|
+
.fade-in-up {
|
|
49
|
+
animation: fadeInUp 0.6s ease-out forwards;
|
|
50
|
+
}
|
|
51
|
+
.fade-in-down {
|
|
52
|
+
animation: fadeInDown 0.6s ease-out forwards;
|
|
53
|
+
}
|
|
54
|
+
.opacity-0 {
|
|
55
|
+
opacity: 0;
|
|
56
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ElementType, ReactNode, ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type Direction = "left" | "right" | "up" | "down";
|
|
5
|
+
type FadeInProps<T extends ElementType> = {
|
|
6
|
+
as?: T;
|
|
7
|
+
direction?: Direction;
|
|
8
|
+
className?: string;
|
|
9
|
+
immediate?: boolean;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
} & Omit<ComponentPropsWithoutRef<T>, "as" | "className" | "children">;
|
|
12
|
+
declare const FadeIn: <T extends ElementType = "div">({ as, direction, className, immediate, children, ...rest }: FadeInProps<T>) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
export { FadeIn };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ElementType, ReactNode, ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type Direction = "left" | "right" | "up" | "down";
|
|
5
|
+
type FadeInProps<T extends ElementType> = {
|
|
6
|
+
as?: T;
|
|
7
|
+
direction?: Direction;
|
|
8
|
+
className?: string;
|
|
9
|
+
immediate?: boolean;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
} & Omit<ComponentPropsWithoutRef<T>, "as" | "className" | "children">;
|
|
12
|
+
declare const FadeIn: <T extends ElementType = "div">({ as, direction, className, immediate, children, ...rest }: FadeInProps<T>) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
export { FadeIn };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
FadeIn: () => FadeIn_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/useInView.ts
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var useInView = (options) => {
|
|
30
|
+
const ref = (0, import_react.useRef)(null);
|
|
31
|
+
const [isVisible, setIsVisible] = (0, import_react.useState)(false);
|
|
32
|
+
(0, import_react.useEffect)(() => {
|
|
33
|
+
if (!ref.current)
|
|
34
|
+
return;
|
|
35
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
36
|
+
if (entry.isIntersecting) {
|
|
37
|
+
setIsVisible(true);
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
}
|
|
40
|
+
}, options);
|
|
41
|
+
observer.observe(ref.current);
|
|
42
|
+
return () => observer.disconnect();
|
|
43
|
+
}, [options]);
|
|
44
|
+
return { ref, isVisible };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/FadeIn.tsx
|
|
48
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
|
+
var FadeIn = ({
|
|
50
|
+
as,
|
|
51
|
+
direction = "up",
|
|
52
|
+
className = "",
|
|
53
|
+
immediate = false,
|
|
54
|
+
children,
|
|
55
|
+
...rest
|
|
56
|
+
}) => {
|
|
57
|
+
const { ref, isVisible } = useInView();
|
|
58
|
+
const Component = as || "div";
|
|
59
|
+
const animationClass = immediate ? `fade-in-${direction}` : isVisible ? `fade-in-${direction}` : "opacity-0";
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
Component,
|
|
62
|
+
{
|
|
63
|
+
ref,
|
|
64
|
+
className: `${animationClass} ${className}`,
|
|
65
|
+
...rest,
|
|
66
|
+
children
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
var FadeIn_default = FadeIn;
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
FadeIn
|
|
74
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/useInView.ts
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
var useInView = (options) => {
|
|
4
|
+
const ref = useRef(null);
|
|
5
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!ref.current)
|
|
8
|
+
return;
|
|
9
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
10
|
+
if (entry.isIntersecting) {
|
|
11
|
+
setIsVisible(true);
|
|
12
|
+
observer.disconnect();
|
|
13
|
+
}
|
|
14
|
+
}, options);
|
|
15
|
+
observer.observe(ref.current);
|
|
16
|
+
return () => observer.disconnect();
|
|
17
|
+
}, [options]);
|
|
18
|
+
return { ref, isVisible };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/FadeIn.tsx
|
|
22
|
+
import { jsx } from "react/jsx-runtime";
|
|
23
|
+
var FadeIn = ({
|
|
24
|
+
as,
|
|
25
|
+
direction = "up",
|
|
26
|
+
className = "",
|
|
27
|
+
immediate = false,
|
|
28
|
+
children,
|
|
29
|
+
...rest
|
|
30
|
+
}) => {
|
|
31
|
+
const { ref, isVisible } = useInView();
|
|
32
|
+
const Component = as || "div";
|
|
33
|
+
const animationClass = immediate ? `fade-in-${direction}` : isVisible ? `fade-in-${direction}` : "opacity-0";
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Component,
|
|
36
|
+
{
|
|
37
|
+
ref,
|
|
38
|
+
className: `${animationClass} ${className}`,
|
|
39
|
+
...rest,
|
|
40
|
+
children
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
var FadeIn_default = FadeIn;
|
|
45
|
+
export {
|
|
46
|
+
FadeIn_default as FadeIn
|
|
47
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-fade-in-view",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight fade-in animation component using Intersection Observer",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"**/*.css"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup src/index.ts --dts --format esm,cjs --clean",
|
|
16
|
+
"dev": "tsup src/index.ts --watch"
|
|
17
|
+
},
|
|
18
|
+
"author": "Aayush Daboriya",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": ">=17",
|
|
22
|
+
"react-dom": ">=17"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "^19.2.7",
|
|
26
|
+
"@types/react-dom": "^19.2.3",
|
|
27
|
+
"esbuild": "0.17.19",
|
|
28
|
+
"react": "^19.2.3",
|
|
29
|
+
"react-dom": "^19.2.3",
|
|
30
|
+
"tsup": "7.2.0",
|
|
31
|
+
"typescript": "^5.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|