Gathering detailed insights and metrics for @lottiefiles/react-lottie-player
Gathering detailed insights and metrics for @lottiefiles/react-lottie-player
Gathering detailed insights and metrics for @lottiefiles/react-lottie-player
Gathering detailed insights and metrics for @lottiefiles/react-lottie-player
lottie web player as a react component
npm install @lottiefiles/react-lottie-player
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
729 Stars
179 Commits
80 Forks
12 Watching
35 Branches
21 Contributors
Updated on 19 Nov 2024
TypeScript (60.9%)
JavaScript (26.89%)
CSS (9.29%)
HTML (2.92%)
Cumulative downloads
Total Downloads
Last day
-2.2%
38,019
Compared to previous day
Last week
0.8%
204,582
Compared to previous week
Last month
11%
850,065
Compared to previous month
Last year
81.1%
8,467,087
Compared to previous year
1
1
67
This is a React component for the Lottie Web Player
1npm install --save @lottiefiles/react-lottie-player
1import { Player, Controls } from '@lottiefiles/react-lottie-player';
Clone repo
run yarn install
run yarn storybook
1yarn storybook
Add the element Player
and set the src
prop to a URL pointing to a valid Lottie JSON.
1<Player 2 autoplay 3 loop 4 src="https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json" 5 style={{ height: '300px', width: '300px' }} 6> 7 <Controls visible={true} buttons={['play', 'repeat', 'frame', 'debug']} /> 8</Player>
Prop | Description | Type | Default |
---|---|---|---|
lottieRef | Get lottie animation object | function | undefined |
onEvent | Listen for events | function | undefined |
onStateChange | Play state changes | function | undefined |
onBackgroundChange | Listen for bg changes | function | undefined |
autoplay | Autoplay animation on load. | boolean | false |
background | Background color. | string | undefined |
controls | Show controls. | boolean | false |
direction | Direction of animation. | number | 1 |
hover | Whether to play on mouse hover. | boolean | false |
keepLastFrame | Stop animation on the last frame. Has no effect if loop is true. | boolean | false |
loop | Whether to loop animation. | boolean | false |
renderer | Renderer to use. | `"svg" | "canvas"` |
speed | Animation speed. | number | 1 |
style | The style for the container. | object | undefined |
src (required) | Bodymovin JSON data or URL to JSON. | object | string |
To call methods on the instance of the Player component. you may get a reference to the component and call the methods on ref.current. This is esentially reacts way of doing a document.getElementById(); You may then use this ref ie: player in the example below to call methods that are described in this documentation. See ref in react documentation
1import React from 'react'; 2import { Player } from '@lottiefiles/react-lottie-player'; 3 4class App extends React.Component { 5 constructor(props) { 6 super(props); 7 this.player = React.createRef(); // initialize your ref 8 } 9 render() { 10 return ( 11 <Player 12 ref={this.player} // set the ref to your class instance 13 autoplay={false} 14 loop={true} 15 controls={true} 16 src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json" 17 style={{ height: '300px', width: '300px' }} 18 ></Player> 19 ); 20 } 21} 22 23export default App;
The lottieRef prop returns the Lottie instance which you can use to set data and call methods as described in the bodymovin documentation.
1import React from 'react'; 2import { Player } from '@lottiefiles/react-lottie-player'; 3 4class App extends React.Component { 5 constructor(props) { 6 super(props); 7 this.state = { lottie: null }; // initialize your state 8 } 9 10 render() { 11 return ( 12 <Player 13 lottieRef={instance => { 14 this.setState({ lottie: instance }); // the lottie instance is returned in the argument of this prop. set it to your local state 15 }} 16 autoplay={false} 17 loop={true} 18 controls={true} 19 src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json" 20 style={{ height: '300px', width: '300px' }} 21 ></Player> 22 ); 23 } 24} 25 26export default App;
1import React from 'react'; 2import { Player } from '@lottiefiles/react-lottie-player'; 3 4class App extends React.Component { 5 constructor(props) { 6 super(props); 7 this.player = React.createRef(); 8 } 9 10 doSomething() { 11 this.player.current.play(); // make use of the player and call methods 12 } 13 14 render() { 15 return ( 16 <Player 17 onEvent={event => { 18 if (event === 'load') this.doSomething(); // check event type and do something 19 }} 20 ref={this.player} 21 autoplay={false} 22 loop={true} 23 controls={true} 24 src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json" 25 style={{ height: '300px', width: '300px' }} 26 ></Player> 27 ); 28 } 29} 30 31export default App;
The following events are exposed and can be listened to via addEventListener
calls.
Name | Description |
---|---|
load | Animation data is loaded. |
error | An animation source cannot be parsed, fails to load or has format errors. |
ready | Animation data is loaded and player is ready. |
play | Animation starts playing. |
pause | Animation is paused. |
stop | Animation is stopped. |
freeze | Animation is paused due to player being invisible. |
loop | An animation loop is completed. |
complete | Animation is complete (all loops completed). |
frame | A new frame is entered. |
pause() => void
Pause animation play.
Type: void
play() => void
Start playing animation.
Type: void
setPlayerDirection(direction: 1 | -1 ) => void
Animation play direction.
Name | Type | Description |
---|---|---|
value | number | Direction values. |
Type: void
setPlayerSpeed(speed?: number) => void
Sets animation play speed.
Name | Type | Description |
---|---|---|
value | number | Playback speed. |
Type: void
stop() => void
Stops animation play.
Type: void
setSeeker(frame: number, play: boolean) => void
Seek to a given frame.
Type: void
We use changesets to maintain a changelog for this repository. When making any change to the codebase that impacts functionality or performance we require a changeset to be present.
To add a changeset run:
yarn run changeset
And select the type of version bump you'd like (major, minor, path).
You can document the change in detail and format it properly using Markdown by opening the ".md" file that the "yarn changeset" command created in the ".changeset" folder. Open the file, it should look something like this:
---
"@lottiefiles/pkg1": minor
"@lottiefiles/pkg2": major
---
This is where you document your **changes** using Markdown.
- You can write
- However you'd like
- In as much detail as you'd like
Aim to provide enough details so that team mates and future you can understand the changes and the context of the change.
You can commit your changes and the changeset to your branch and then create a pull request on the develop branch.
MIT License © LottieFiles.com
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
78 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More