Last active
January 8, 2024 00:19
-
-
Save PatrickJS/007619ac6896272f0dfa370cf5aa69c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { component$, useVisibleTask$, useStore, useSignal, noSerialize } from '@builder.io/qwik'; | |
import lottie from 'lottie-web'; | |
import { Options } from './types'; | |
export interface OptionsProps { | |
options: Options; | |
} | |
export const QwikLottie = component$(({ options }: OptionsProps) => { | |
const store = useStore({ | |
anim: noSerialize({}), | |
}); | |
const canvas = useSignal<Element>(); | |
// eslint-disable-next-line qwik/no-use-visible-task | |
useVisibleTask$(() => { | |
store.anim = noSerialize(lottie.loadAnimation({ | |
container: options.container || canvas.value, | |
renderer: options.renderer || 'svg', | |
loop: options.loop || true, | |
autoplay: options.autoplay || true, | |
animationData: options.animationData, | |
path: options.path, | |
rendererSettings: options.rendererSettings, | |
name: options.name, | |
})); | |
}); | |
return <div ref={canvas}></div>; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type renderer = 'svg'; | |
export interface Options { | |
container?: any; | |
renderer?: renderer; | |
loop?: boolean; | |
autoplay?: boolean; | |
animationData?: object; | |
path?: string; | |
rendererSettings?: object; | |
name?: string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment