diff --git a/src/components/Lottie/Lottie.mdx b/src/components/Lottie/Lottie.mdx index 292caaf2c..b574640fb 100644 --- a/src/components/Lottie/Lottie.mdx +++ b/src/components/Lottie/Lottie.mdx @@ -39,6 +39,8 @@ To use the `Lottie` component, import it and provide the Lottie animation source **Use `lvh` or `svh` units instead of `vh`** as [these units](https://www.w3.org/TR/css-values-4/#large-viewport-size) are more reliable on mobile and other devices where elements such as the address bar appear and disappear and affect the height. +The component also provides a `width` prop to set the width of the Lottie container. While the `width` prop defaults to `fluid`, it allows any `ContainerWidth` value such as `narrower`, `narrow`, `normal`, `wide`, `wider`, `widest`, `fluid`, or a custom CSS width value like `600px` or `80vw`. + If importing the Lottie file directly into a Svelte component, make sure to append **?url** to the import statement (see example below). This ensures that the file is treated as a URL. > 💡TIP: Set `showDebugInfo` prop to `true` to display information about the component state. diff --git a/src/components/Lottie/Lottie.stories.svelte b/src/components/Lottie/Lottie.stories.svelte index 473d90dec..8ecc7da2d 100644 --- a/src/components/Lottie/Lottie.stories.svelte +++ b/src/components/Lottie/Lottie.stories.svelte @@ -40,42 +40,53 @@ let progress = $state(0); - - + + {#snippet children(args)} + + {/snippet} - - + + {#snippet children(args)} + + {/snippet} - - + + {#snippet children(args)} + + {/snippet} - - + + {#snippet children(args)} + + {/snippet} diff --git a/src/components/Lottie/Lottie.svelte b/src/components/Lottie/Lottie.svelte index a49c870f0..f3cae789f 100644 --- a/src/components/Lottie/Lottie.svelte +++ b/src/components/Lottie/Lottie.svelte @@ -11,12 +11,12 @@ isReverseMode, createRenderConfig, isNullish, + isContainerWidth, } from './ts/utils'; import { Tween } from 'svelte/motion'; // Components import Debug from './Debug.svelte'; - import WASM from './lottie/dotlottie-player.wasm?url'; // Types import type { Props } from './ts/types'; @@ -49,7 +49,8 @@ layout = { fit: 'contain', align: [0.5, 0.5] }, animationId = '', lottiePlayer = $bindable(undefined), - height = '100lvh', + width = 'fluid', + height = 'auto', showDebugInfo = false, lottieState = createLottieState(), progress = $bindable(0), @@ -157,8 +158,6 @@ themeId, }); - DotLottie.setWasmUrl(WASM); - lottiePlayer.addEventListener('load', onLoadEvent); lottiePlayer.addEventListener('frame', onRenderEvent); lottiePlayer.addEventListener('complete', onCompleteEvent); @@ -396,7 +395,13 @@ }); -
+
{#if showDebugInfo && lottiePlayer} {/if} @@ -420,15 +425,22 @@ :global(.lottie-block) { position: relative; height: 100%; + width: 100%; + margin: 0 auto; .lottie-container { width: 100%; height: 100%; } + canvas { width: 100%; height: 100%; display: block; } } + + .debug-border { + border: 1px dashed lightgray; + } diff --git a/src/components/Lottie/demo/withScrollerBase.svelte b/src/components/Lottie/demo/withScrollerBase.svelte index c878921ac..5b792e890 100644 --- a/src/components/Lottie/demo/withScrollerBase.svelte +++ b/src/components/Lottie/demo/withScrollerBase.svelte @@ -1,4 +1,5 @@ + + + +