{"id":13535714,"url":"https://github.com/LottieFiles/lottie-react","last_synced_at":"2025-04-02T02:31:13.969Z","repository":{"id":38172702,"uuid":"263287837","full_name":"LottieFiles/lottie-react","owner":"LottieFiles","description":"lottie web player as a react component","archived":false,"fork":false,"pushed_at":"2025-03-16T01:50:30.000Z","size":4129,"stargazers_count":744,"open_issues_count":47,"forks_count":80,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T07:02:47.055Z","etag":null,"topics":["react","typescript"],"latest_commit_sha":null,"homepage":"https://lottiefiles.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LottieFiles.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-12T09:10:58.000Z","updated_at":"2025-03-21T04:26:08.000Z","dependencies_parsed_at":"2025-01-31T05:31:36.885Z","dependency_job_id":"d70dc1ad-4c70-4316-8d0b-ebc851e5e88c","html_url":"https://github.com/LottieFiles/lottie-react","commit_stats":{"total_commits":143,"total_committers":15,"mean_commits":9.533333333333333,"dds":"0.39860139860139865","last_synced_commit":"b1d32d3ffdf47d59e5054abf84beb09ebe0dfc21"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LottieFiles%2Flottie-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LottieFiles%2Flottie-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LottieFiles%2Flottie-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LottieFiles%2Flottie-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LottieFiles","download_url":"https://codeload.github.com/LottieFiles/lottie-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246743596,"owners_count":20826558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","typescript"],"created_at":"2024-08-01T09:00:23.838Z","updated_at":"2025-04-02T02:31:13.581Z","avatar_url":"https://github.com/LottieFiles.png","language":"TypeScript","funding_links":[],"categories":["Libraries","TypeScript"],"sub_categories":["Creation Tools"],"readme":"## LottiePlayer React Component\n\nThis is a React component for the Lottie Web Player\n\n## Demo\n\n![screencast](https://i.imgur.com/miLzIkJ.gif)\n\n## Documentation\n\n- [View documentation](https://docs.lottiefiles.com/lottie-player/components/lottie-react)\n\n#### In Javascript or TypeScript:\n\n1. Install package using npm or yarn.\n\n```shell\nnpm install --save @lottiefiles/react-lottie-player\n```\n\n2. Import package in your code.\n\n```javascript\nimport { Player, Controls } from '@lottiefiles/react-lottie-player';\n```\n\n## Example/Development\n\n1. Clone repo\n\n2. run yarn install\n\n3. run yarn storybook\n\n```shell\nyarn storybook\n```\n\n## Usage\n\n### Player component\n\nAdd the element `Player` and set the `src` prop to a URL pointing to a valid Lottie JSON.\n\n```javascript\n\u003cPlayer\n  autoplay\n  loop\n  src=\"https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json\"\n  style={{ height: '300px', width: '300px' }}\n\u003e\n  \u003cControls visible={true} buttons={['play', 'repeat', 'frame', 'debug']} /\u003e\n\u003c/Player\u003e\n```\n\n## Props\n\n| Prop                 | Description                                                            | Type               | Default     |\n| -------------------- | ---------------------------------------------------------------------- | ------------------ | ----------- |\n| `lottieRef`          | Get lottie animation object                                            | `function`         | `undefined` |\n| `onEvent`            | Listen for events                                                      | `function`         | `undefined` |\n| `onStateChange`      | Play state changes                                                     | `function`         | `undefined` |\n| `onBackgroundChange` | Listen for bg changes                                                  | `function`         | `undefined` |\n| `autoplay`           | Autoplay animation on load.                                            | `boolean`          | `false`     |\n| `background`         | Background color.                                                      | `string`           | `undefined` |\n| `controls`           | Show controls.                                                         | `boolean`          | `false`     |\n| `direction`          | Direction of animation.                                                | `number`           | `1`         |\n| `hover`              | Whether to play on mouse hover.                                        | `boolean`          | `false`     |\n| `keepLastFrame`      | Stop animation on the last frame.\u003c/br\u003eHas no effect if `loop` is true. | `boolean`          | `false`     |\n| `loop`               | Whether to loop animation.                                             | `boolean`          | `false`     |\n| `renderer`           | Renderer to use.                                                       | `\"svg\" | \"canvas\"` | `'svg'`     |\n| `speed`              | Animation speed.                                                       | `number`           | `1`         |\n| `style`              | The style for the container.                                           | `object`           | `undefined` |\n| `src` _(required)_   | Bodymovin JSON data or URL to JSON.                                    | `object` | `string`| `undefined` |\n\n## Get Player instance\n\nTo call methods on the instance of the Player component. you may get a reference to the component and call the methods\non ref.current. This is esentially reacts way of doing a document.getElementById(); You may then use this ref ie: player\nin the example below to call methods that are described in this documentation. See ref in\n[react documentation](https://reactjs.org/docs/refs-and-the-dom.html)\n\n```javascript\nimport React from 'react';\nimport { Player } from '@lottiefiles/react-lottie-player';\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n    this.player = React.createRef(); // initialize your ref\n  }\n  render() {\n    return (\n      \u003cPlayer\n        ref={this.player} // set the ref to your class instance\n        autoplay={false}\n        loop={true}\n        controls={true}\n        src=\"https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json\"\n        style={{ height: '300px', width: '300px' }}\n      \u003e\u003c/Player\u003e\n    );\n  }\n}\n\nexport default App;\n```\n\n## Get Lottie instance\n\nThe lottieRef prop returns the Lottie instance which you can use to set data and call methods as described in the\n[bodymovin documentation](https://github.com/airbnb/lottie-web).\n\n```javascript\nimport React from 'react';\nimport { Player } from '@lottiefiles/react-lottie-player';\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = { lottie: null }; // initialize your state\n  }\n\n  render() {\n    return (\n      \u003cPlayer\n        lottieRef={instance =\u003e {\n          this.setState({ lottie: instance }); // the lottie instance is returned in the argument of this prop. set it to your local state\n        }}\n        autoplay={false}\n        loop={true}\n        controls={true}\n        src=\"https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json\"\n        style={{ height: '300px', width: '300px' }}\n      \u003e\u003c/Player\u003e\n    );\n  }\n}\n\nexport default App;\n```\n\n## Listening for events\n\n```javascript\nimport React from 'react';\nimport { Player } from '@lottiefiles/react-lottie-player';\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n    this.player = React.createRef();\n  }\n\n  doSomething() {\n    this.player.current.play(); // make use of the player and call methods\n  }\n\n  render() {\n    return (\n      \u003cPlayer\n        onEvent={event =\u003e {\n          if (event === 'load') this.doSomething(); // check event type and do something\n        }}\n        ref={this.player}\n        autoplay={false}\n        loop={true}\n        controls={true}\n        src=\"https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json\"\n        style={{ height: '300px', width: '300px' }}\n      \u003e\u003c/Player\u003e\n    );\n  }\n}\n\nexport default App;\n```\n\n## Events\n\nThe following events are exposed and can be listened to via `addEventListener` calls.\n\n| Name       | Description                                                               |\n| ---------- | ------------------------------------------------------------------------- |\n| `load`     | Animation data is loaded.                                                 |\n| `error`    | An animation source cannot be parsed, fails to load or has format errors. |\n| `ready`    | Animation data is loaded and player is ready.                             |\n| `play`     | Animation starts playing.                                                 |\n| `pause`    | Animation is paused.                                                      |\n| `stop`     | Animation is stopped.                                                     |\n| `freeze`   | Animation is paused due to player being invisible.                        |\n| `loop`     | An animation loop is completed.                                           |\n| `complete` | Animation is complete (all loops completed).                              |\n| `frame`    | A new frame is entered.                                                   |\n\n## Methods\n\n### `pause() =\u003e void`\n\nPause animation play.\n\n#### Returns\n\nType: `void`\n\n### `play() =\u003e void`\n\nStart playing animation.\n\n#### Returns\n\nType: `void`\n\n### `setPlayerDirection(direction: 1 | -1 ) =\u003e void`\n\nAnimation play direction.\n\n#### Parameters\n\n| Name    | Type     | Description       |\n| ------- | -------- | ----------------- |\n| `value` | `number` | Direction values. |\n\n#### Returns\n\nType: `void`\n\n### `setPlayerSpeed(speed?: number) =\u003e void`\n\nSets animation play speed.\n\n#### Parameters\n\n| Name    | Type     | Description     |\n| ------- | -------- | --------------- |\n| `value` | `number` | Playback speed. |\n\n#### Returns\n\nType: `void`\n\n### `stop() =\u003e void`\n\nStops animation play.\n\n#### Returns\n\nType: `void`\n\n### `setSeeker(frame: number, play: boolean) =\u003e void`\n\nSeek to a given frame.\n\n#### Returns\n\nType: `void`\n\n## Contributing\n\nWe 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.\n\nTo add a changeset run:\n\n```\nyarn run changeset\n```\n\nAnd select the type of version bump you'd like (major, minor, path).\n\nYou 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:\n\n```\n---\n\"@lottiefiles/pkg1\": minor\n\"@lottiefiles/pkg2\": major\n---\n\nThis is where you document your **changes** using Markdown.\n\n- You can write\n- However you'd like\n- In as much detail as you'd like\n\nAim to provide enough details so that team mates and future you can understand the changes and the context of the change.\n```\n\nYou can commit your changes and the changeset to your branch and then create a pull request on the develop branch.\n\n## License\n\nMIT License © LottieFiles.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLottieFiles%2Flottie-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLottieFiles%2Flottie-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLottieFiles%2Flottie-react/lists"}