diff --git a/docs/components/Lottie/README.mdx b/docs/components/Lottie/README.mdx index eb72405..470c8a2 100644 --- a/docs/components/Lottie/README.mdx +++ b/docs/components/Lottie/README.mdx @@ -171,6 +171,24 @@ const Example = () => export default Example; ``` +### `as` + +React `ElementType` or `ComponentType` that replaces the default container `
` element. + +```jsx +import Lottie from "lottie-react"; +import fancyLoadingAnimation from "./fancyLoading.json"; + +const Example = () => + +``` + ## Interaction methods These methods are designed to give you more control over the Lottie animation, and fill in the gaps left by the props: diff --git a/src/hooks/useLottie.tsx b/src/hooks/useLottie.tsx index 117da78..e6144c0 100644 --- a/src/hooks/useLottie.tsx +++ b/src/hooks/useLottie.tsx @@ -40,6 +40,8 @@ const useLottie = ( onDOMLoaded, onDestroy, + as: Container = "div", + // Specified here to take them out from the 'rest' lottieRef, renderer, @@ -320,7 +322,11 @@ const useLottie = ( /** * Build the animation view */ - const View =
; + const View = React.createElement(Container, { + style, + ref: animationContainer, + ...rest, + }); return { View, diff --git a/src/types.ts b/src/types.ts index 2e8edc7..1e87a7e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,6 +11,8 @@ import React, { AnimationEventHandler, ReactElement, RefObject, + ComponentType, + ElementType, } from "react"; export type LottieRefCurrentProps = { @@ -51,7 +53,8 @@ export type LottieOptions = Omit< onLoadedImages?: AnimationEventHandler | null; onDOMLoaded?: AnimationEventHandler | null; onDestroy?: AnimationEventHandler | null; -} & Omit, "loop">; + as?: ElementType | ComponentType; +} & Omit, "loop" | "as">; export type PartialLottieOptions = Omit & { animationData?: LottieOptions["animationData"];