Skip to content

Conversation

@amoshydra
Copy link

@amoshydra amoshydra commented Jun 5, 2024

Summary

Provide a new prop as allowing container to be switched out to a user provided React.ElementType or React.ComponentType

Related to

Related to #110

How is this tested?

image

Tested with the following code snippet (This is not included in this PR / documentation change)

import React from "react";
import Lottie from "../../../src/components/Lottie";
import groovyWalkAnimation from "../../assets/groovyWalk.json";

const LottieAsExample = () => {
  return (
    <button>
      <Lottie
        animationData={groovyWalkAnimation}
        autoplay={true}
        as="span"
        style={{ display: 'inline-block', width: "2rem" }}
        data-testid="loading-graphic"
      />
      Loading
    </button>
  );
};

export default LottieAsExample;

image

@Xentox-Phil
Copy link

Xentox-Phil commented Nov 7, 2024

i love this addition but i have encountered a type problem with it everything else WORKS absolutely awesome!!!

image

my example involves imbeding it into an existing svg... therefore i also want to set svg props.

If i do this i get the error that y does not exist even tho everything works perfectly fine

image

i tried to fix it but didn't quite get it right

export type LottieOptions<CT extends (ElementType | ComponentType) = "div",T extends RendererType = "svg"> = Omit<
  AnimationConfigWithData<T>,
  "container" | "animationData"
> & {
  animationData: unknown;
  lottieRef?: LottieRef;
  onComplete?: AnimationEventHandler | null;
  onLoopComplete?: AnimationEventHandler | null;
  onEnterFrame?: AnimationEventHandler | null;
  onSegmentStart?: AnimationEventHandler | null;
  onConfigReady?: AnimationEventHandler | null;
  onDataReady?: AnimationEventHandler | null;
  onDataFailed?: AnimationEventHandler | null;
  onLoadedImages?: AnimationEventHandler | null;
  onDOMLoaded?: AnimationEventHandler | null;
  onDestroy?: AnimationEventHandler | null;
  as?: CT;
} & Omit<ComponentPropsWithRef<CT>, "loop" | "as">;

i redefined the LottieOptions to this so you are also able to pass these props

but then i got errors in the useLottie hook:

image

the problem is that the props of the wrapper get now passed to the config aswell...

Maybe you have a solution to this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants