@redseed/redseed-ui-vue3 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redseed/redseed-ui-vue3",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "RedSeed UI Vue 3 components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
- import { ref, computed, onMounted } from 'vue'
3
- import lottie from 'lottie-web'
2
+ import { ref, computed } from 'vue'
4
3
  import LottieCubes from './LottieCubes.json'
4
+ import { useLottie } from '../../helpers/Lottie'
5
5
 
6
6
  const props = defineProps({
7
7
  primary: {
@@ -41,21 +41,7 @@ const loaderClass = computed(() => [
41
41
 
42
42
  const loaderElement = ref(null)
43
43
 
44
- function load() {
45
- if (!lottie) return
46
- if (!LottieCubes) return
47
- if (!loaderElement.value) return
48
-
49
- lottie.loadAnimation({
50
- container: loaderElement.value,
51
- renderer: 'svg',
52
- loop: true,
53
- autoplay: true,
54
- animationData: LottieCubes
55
- })
56
- }
57
-
58
- onMounted(load)
44
+ useLottie(loaderElement, LottieCubes)
59
45
  </script>
60
46
  <template>
61
47
  <div ref="loaderElement"
@@ -0,0 +1,32 @@
1
+ import { ref, watchEffect } from 'vue'
2
+ import Lottie from 'lottie-web'
3
+
4
+ export function useLottie(elementRef, animationData = null) {
5
+
6
+ const lottieAnimation = ref(null)
7
+
8
+ watchEffect(() => {
9
+ if (!elementRef.value) return
10
+ if (!animationData) return
11
+
12
+ loadLottie()
13
+ })
14
+
15
+ function loadLottie() {
16
+ if (!elementRef.value) return
17
+ if (!animationData) return
18
+
19
+ if (lottieAnimation.value) {
20
+ lottieAnimation.value.destroy()
21
+ lottieAnimation.value = null
22
+ }
23
+
24
+ lottieAnimation.value = Lottie.loadAnimation({
25
+ container: elementRef.value,
26
+ renderer: 'svg',
27
+ loop: true,
28
+ autoplay: true,
29
+ animationData: animationData
30
+ })
31
+ }
32
+ }