@mhmmt/react-dotlottie-player 0.1.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 +62 -0
- package/dist/components/DotLottiePlayer.d.ts +3 -0
- package/dist/hooks/useDotLottie.d.ts +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/react-dotlottie-player.cjs.js +2 -0
- package/dist/react-dotlottie-player.cjs.js.map +1 -0
- package/dist/react-dotlottie-player.d.ts +24 -0
- package/dist/react-dotlottie-player.esm.js +2 -0
- package/dist/react-dotlottie-player.esm.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# React DotLottie Player
|
|
2
|
+
|
|
3
|
+
Play Lottie animations in React — supports both `.json` and `.lottie` files.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Play `.json` Lottie animations
|
|
8
|
+
- Play `.lottie` animations (automatically unzips)
|
|
9
|
+
- SSR-safe with dynamic import
|
|
10
|
+
- Full TypeScript support
|
|
11
|
+
- Tree-shakeable exports
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install react-dotlottie-player
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Peer Dependencies
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install react react-dom
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { DotLottiePlayer } from 'react-dotlottie-player';
|
|
29
|
+
|
|
30
|
+
function App() {
|
|
31
|
+
return (
|
|
32
|
+
<DotLottiePlayer
|
|
33
|
+
src="/animation.json"
|
|
34
|
+
loop
|
|
35
|
+
autoplay
|
|
36
|
+
speed={1}
|
|
37
|
+
onLoad={() => console.log('Animation loaded')}
|
|
38
|
+
onError={(error) => console.error('Error:', error)}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Default | Description |
|
|
47
|
+
|------|------|---------|-------------|
|
|
48
|
+
| `src` | `string` | **required** | URL to `.json` or `.lottie` file |
|
|
49
|
+
| `loop` | `boolean` | `false` | Loop animation |
|
|
50
|
+
| `autoplay` | `boolean` | `true` | Auto-play on load |
|
|
51
|
+
| `speed` | `number` | `1` | Playback speed |
|
|
52
|
+
| `direction` | `1 \| -1` | `1` | Playback direction |
|
|
53
|
+
| `backgroundColor` | `string` | `'transparent'` | Background color |
|
|
54
|
+
| `onLoad` | `() => void` | - | Callback when animation loads |
|
|
55
|
+
| `onError` | `(error: Error) => void` | - | Callback on error |
|
|
56
|
+
| `onComplete` | `() => void` | - | Callback when animation completes |
|
|
57
|
+
| `onLoopComplete` | `() => void` | - | Callback when loop completes |
|
|
58
|
+
| `onFrame` | `(frame: number) => void` | - | Callback on each frame |
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AnimationItem } from 'lottie-web';
|
|
2
|
+
interface UseDotLottieOptions {
|
|
3
|
+
src: string;
|
|
4
|
+
loop?: boolean;
|
|
5
|
+
autoplay?: boolean;
|
|
6
|
+
speed?: number;
|
|
7
|
+
direction?: 1 | -1;
|
|
8
|
+
backgroundColor?: string;
|
|
9
|
+
onLoad?: () => void;
|
|
10
|
+
onError?: (error: Error) => void;
|
|
11
|
+
onComplete?: () => void;
|
|
12
|
+
onLoopComplete?: () => void;
|
|
13
|
+
onFrame?: (frame: number) => void;
|
|
14
|
+
onEnterFrame?: (frame: number) => void;
|
|
15
|
+
}
|
|
16
|
+
interface UseDotLottieReturn {
|
|
17
|
+
play: () => void;
|
|
18
|
+
pause: () => void;
|
|
19
|
+
stop: () => void;
|
|
20
|
+
goToFrame: (frame: number, isFrame?: boolean) => void;
|
|
21
|
+
setSpeed: (speed: number) => void;
|
|
22
|
+
setDirection: (direction: 1 | -1) => void;
|
|
23
|
+
setSubframe: (useSubFrame: boolean) => void;
|
|
24
|
+
getDuration: (inFrames?: boolean) => number;
|
|
25
|
+
destroy: () => void;
|
|
26
|
+
isLoaded: boolean;
|
|
27
|
+
isPlaying: boolean;
|
|
28
|
+
currentFrame: number;
|
|
29
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
|
30
|
+
animationData: AnimationItem | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function useDotLottie({ src, loop, autoplay, speed, direction, backgroundColor, onLoad, onError, onComplete, onLoopComplete, onFrame, onEnterFrame, }: UseDotLottieOptions): UseDotLottieReturn;
|
|
33
|
+
export {};
|
package/dist/index.d.ts
ADDED