Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@dotlottie/react-player
Advanced tools
This is a React Component for easily embedding and playing dotLottie animations in your react projects.
dotLottie is an open-source file format that combines one or more Lottie files and their associated resources into a single file. These files are ZIP archives compressed with the Deflate compression method and have the file extension ".lottie".
Read more about dotLottie here!
You can install @dotlottie/react-player
using npm:
npm install @dotlottie/react-player
or yarn:
yarn add @dotlottie/react-player
To use @dotlottie/react-player
in your React project, import the component and use it as follows:
import React from 'react';
import { DotLottiePlayer, Controls } from '@dotlottie/react-player';
import '@dotlottie/react-player/dist/index.css';
const App = () => {
return (
<div>
<DotLottiePlayer
src="/path-to-lottie.lottie"
autoplay
loop
>
<Controls />
</DotLottiePlayer>
</div>
);
};
export default App;
The DotLottiePlayer
component accepts the following props:
Prop | Description | Type | Default |
---|---|---|---|
src (required) | Animation data or URL | Record<string, unknown> | string | undefined |
lottieRef | Get player object | MutableRefObject | undefined |
autoplay | Autoplay animation on load | boolean | false |
background | Background color | string | transparent |
direction | Play direction | 1 | -1 | 1 |
hover | Whether to play on mouse hover | boolean | false |
intermission | Pause between loops | number | 0 |
loop | Whether to loop animation | boolean | false |
playMode | Play mode | 'normal' | 'bounce' | normal |
renderer | How to render | 'svg' | 'html' | 'canvas' | svg |
speed | Play speed | number | 1 |
onEvent | Listen to player events | function | undefined |
The following events are exposed via the onEvent
function:
Name | Description |
---|---|
complete | Animation completed playing |
error | An animation source cannot be parsed, fails to load, or has format errors |
frame | A new frame is entered |
freeze | Animation is frozen |
loopComplete | Loop animation is complete |
pause | Animation is paused |
ready | Animation data is loaded and player is ready |
stop | Animation is stopped |
Listening for events:
import React, { useState } from 'react';
import { DotLottiePlayer, Controls, PlayerEvents } from '@dotlottie/react-player';
import '@dotlottie/react-player/dist/index.css';
const App = () => {
const [loading, setLoading] = useState(true);
return (
<div>
{loading ? (
<div>loading....</div>
) : (
<DotLottiePlayer
src="/path-to-lottie.lottie"
onEvent={(event: PlayerEvents) => {
if (event === PlayerEvents.Ready) {
setLoading(false);
}
}}
autoplay
loop
>
<Controls />
</DotLottiePlayer>
)}
</div>
);
};
export default App;
Getting player instance and calling methods:
import React, { useRef } from 'react';
import { DotLottiePlayer, Controls, PlayerEvents } from '@dotlottie/react-player';
import '@dotlottie/react-player/dist/index.css';
const App = () => {
const lottieRef = useRef<DotLottieRefProps>();
return (
<div>
<DotLottiePlayer
lottieRef={lottieRef}
src="/path-to-lottie.lottie"
onEvent={(event: PlayerEvents) => {
if (event === PlayerEvents.Ready) {
// Play next animation.
lottieRef.current?.next();
}
}}
autoplay
loop
>
<Controls />
</DotLottiePlayer>
</div>
);
};
export default App;
You can access these methods using the player instance:
getLottie: () => AnimationItem | undefined
: Returns the lottie-web instance.getManifest: () => Manifest | undefined
: Returns the .lottie
Manifest.next: (options?: PlaybackOptions) => void
: Plays the next animation in the manifest.play: (indexOrId?: string | number, options?: PlaybackOptions) => void
: Plays the current animation.previous: (options?: PlaybackOptions) => void
: Plays the previous animation in the manifest.reset: () => void
: Goes back to the default/initial animation.We use changesets to maintain a changelog for this repository. When making any changes to the codebase that impact functionality or performance, we require a changeset to be present.
To add a changeset, run:
pnpm changeset add
And select the type of version bump you'd like (major, minor, patch).
You can document the changes in detail and format them properly using Markdown by opening the ".md" file that the "pnpm changeset" command created in the ".changeset" folder. Open the file, and it should look something like this:
---
"@dotlottie/common": minor
"@dotlottie/react-player": 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 teammates and future you can understand the changes and the context of
the change.
Commit your changes and the changeset to your branch, and then create a pull request on the develop branch.
Here are some of our other Lottie-related libraries:
MIT License © LottieFiles.com
FAQs
dotlottie animation player react component.
The npm package @dotlottie/react-player receives a total of 37,274 weekly downloads. As such, @dotlottie/react-player popularity was classified as popular.
We found that @dotlottie/react-player demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.