From 667843d0198f7e5c4faaa7075624c7cd46874b5e Mon Sep 17 00:00:00 2001 From: Lexpeartha Date: Sun, 21 Aug 2022 18:12:53 +0200 Subject: [PATCH 01/19] chore: fix typo in a comment --- src/runtime/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/router.ts b/src/runtime/router.ts index 37237c0d..7a4da026 100644 --- a/src/runtime/router.ts +++ b/src/runtime/router.ts @@ -4,7 +4,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#imports' // @ts-expect-error virtual module import routerOptions from '#build/router.options' -// @ts-expect-error irtual module generated by Nuxt +// @ts-expect-error virtual module generated by Nuxt import routes from '#build/routes' export default defineNuxtPlugin(nuxtApp => { From f7489e0731d376c5894485586e98e4c292361ce8 Mon Sep 17 00:00:00 2001 From: Lexpeartha Date: Sun, 21 Aug 2022 18:13:13 +0200 Subject: [PATCH 02/19] feat: add CreateAnimation component --- src/module.ts | 15 ++-- src/runtime/components.ts | 6 ++ src/runtime/components/CreateAnimation.vue | 87 ++++++++++++++++++++++ 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/runtime/components.ts create mode 100644 src/runtime/components/CreateAnimation.vue diff --git a/src/module.ts b/src/module.ts index 2d043a4e..f487e5df 100644 --- a/src/module.ts +++ b/src/module.ts @@ -58,12 +58,12 @@ export interface ModuleOptions { statusTap?: boolean swipeBackEnabled?: boolean tabButtonLayout?: - | 'icon-top' - | 'icon-start' - | 'icon-end' - | 'icon-bottom' - | 'icon-hide' - | 'label-hide' + | 'icon-top' + | 'icon-start' + | 'icon-end' + | 'icon-bottom' + | 'icon-hide' + | 'label-hide' toastEnter?: AnimationBuilder toastLeave?: AnimationBuilder } @@ -123,6 +123,9 @@ export default defineNuxtModule({ nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [] nuxt.options.vite.optimizeDeps.include.push('@ionic/vue') + // Add Nuxt Vue custom utility components + addPlugin(resolve(runtimeDir, 'components')) + // Add auto-imported components IonicBuiltInComponents.map(name => addComponent({ diff --git a/src/runtime/components.ts b/src/runtime/components.ts new file mode 100644 index 00000000..b6eb8d9a --- /dev/null +++ b/src/runtime/components.ts @@ -0,0 +1,6 @@ +import { defineNuxtPlugin } from '#imports' +import CreateAnimation from './components/CreateAnimation.vue' + +export default defineNuxtPlugin(nuxtApp => { + nuxtApp.vueApp.component('CreateAnimation', CreateAnimation) +}) diff --git a/src/runtime/components/CreateAnimation.vue b/src/runtime/components/CreateAnimation.vue new file mode 100644 index 00000000..c258826d --- /dev/null +++ b/src/runtime/components/CreateAnimation.vue @@ -0,0 +1,87 @@ + + + From 81283d38c79ddb143ac07b78ca60dc7eb8a36516 Mon Sep 17 00:00:00 2001 From: Lexpeartha Date: Sun, 21 Aug 2022 18:13:43 +0200 Subject: [PATCH 03/19] chore(playground): add CreateAnimation as example --- playground/pages/tabs/tab3.vue | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/playground/pages/tabs/tab3.vue b/playground/pages/tabs/tab3.vue index 5f9c164a..59d22a99 100644 --- a/playground/pages/tabs/tab3.vue +++ b/playground/pages/tabs/tab3.vue @@ -11,9 +11,27 @@ Tab 3 - + +
+ +
+ + + + +
+
+ - From bc9d1c750b508754f44d0cca5b748240c08ba5ec Mon Sep 17 00:00:00 2001 From: Lexpeartha <43365376+Lexpeartha@users.noreply.github.com> Date: Sun, 21 Aug 2022 20:56:28 +0200 Subject: [PATCH 04/19] refactor: change animation ref to const Co-authored-by: Daniel Roe --- src/runtime/components/CreateAnimation.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/components/CreateAnimation.vue b/src/runtime/components/CreateAnimation.vue index c258826d..9946a13c 100644 --- a/src/runtime/components/CreateAnimation.vue +++ b/src/runtime/components/CreateAnimation.vue @@ -40,7 +40,7 @@ const props = withDefaults(defineProps(), { const element = ref(null) -let animation = ref(null) +const animation = ref(null) onMounted(() => { animation.value = createAnimation(props.id) From cbcd1abf994cfea77961675b9035a08397604053 Mon Sep 17 00:00:00 2001 From: Lexpeartha Date: Sun, 21 Aug 2022 21:11:00 +0200 Subject: [PATCH 05/19] refactor: utilize `@nuxt/kit` for importing component --- src/module.ts | 3 ++- src/parts/components.ts | 12 ++++++++++++ src/runtime/components.ts | 6 ------ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/parts/components.ts delete mode 100644 src/runtime/components.ts diff --git a/src/module.ts b/src/module.ts index f487e5df..7a367ef9 100644 --- a/src/module.ts +++ b/src/module.ts @@ -7,6 +7,7 @@ import { defineUnimportPreset } from 'unimport' import { runtimeDir } from './utils' +import { setupUtilityComponents } from './parts/components' import { useCSSSetup } from './parts/css' import { setupIcons } from './parts/icons' import { setupMeta } from './parts/meta' @@ -124,7 +125,7 @@ export default defineNuxtModule({ nuxt.options.vite.optimizeDeps.include.push('@ionic/vue') // Add Nuxt Vue custom utility components - addPlugin(resolve(runtimeDir, 'components')) + setupUtilityComponents() // Add auto-imported components IonicBuiltInComponents.map(name => diff --git a/src/parts/components.ts b/src/parts/components.ts new file mode 100644 index 00000000..195e48ac --- /dev/null +++ b/src/parts/components.ts @@ -0,0 +1,12 @@ +import { addComponent } from '@nuxt/kit' +import { resolve } from 'path' +import { runtimeDir } from '../utils' + +export const setupUtilityComponents = () => { + // const nuxt = useNuxt() + + addComponent({ + name: 'CreateAnimation', + filePath: resolve(runtimeDir, 'components', 'CreateAnimation.vue'), + }) +} diff --git a/src/runtime/components.ts b/src/runtime/components.ts deleted file mode 100644 index b6eb8d9a..00000000 --- a/src/runtime/components.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { defineNuxtPlugin } from '#imports' -import CreateAnimation from './components/CreateAnimation.vue' - -export default defineNuxtPlugin(nuxtApp => { - nuxtApp.vueApp.component('CreateAnimation', CreateAnimation) -}) From ab02a93be84486f2e9994b89a79009706cf0c9fa Mon Sep 17 00:00:00 2001 From: Lexpeartha Date: Sun, 21 Aug 2022 21:22:49 +0200 Subject: [PATCH 06/19] chore: ignore annoying non-null assertion eslint warning --- src/parts/router.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parts/router.ts b/src/parts/router.ts index 40449ebc..2023e96a 100644 --- a/src/parts/router.ts +++ b/src/parts/router.ts @@ -6,6 +6,7 @@ import { runtimeDir } from '../utils' export const setupRouter = () => { const nuxt = useNuxt() const pagesDirs = nuxt.options._layers.map(layer => + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion resolve(layer.config?.srcDir || layer.cwd!, layer.config?.dir?.pages || 'pages') ) From d9c2d01ab7216b2d447b663f7eaba3a76cd0bcb3 Mon Sep 17 00:00:00 2001 From: Aleksa Date: Tue, 23 Aug 2022 10:58:31 +0200 Subject: [PATCH 07/19] refactor: rename component to `IonAnimation` --- src/parts/components.ts | 4 ++-- .../components/{CreateAnimation.vue => IonAnimation.vue} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename src/runtime/components/{CreateAnimation.vue => IonAnimation.vue} (100%) diff --git a/src/parts/components.ts b/src/parts/components.ts index 195e48ac..d1a9a923 100644 --- a/src/parts/components.ts +++ b/src/parts/components.ts @@ -6,7 +6,7 @@ export const setupUtilityComponents = () => { // const nuxt = useNuxt() addComponent({ - name: 'CreateAnimation', - filePath: resolve(runtimeDir, 'components', 'CreateAnimation.vue'), + name: 'IonAnimation', + filePath: resolve(runtimeDir, 'components', 'IonAnimation.vue'), }) } diff --git a/src/runtime/components/CreateAnimation.vue b/src/runtime/components/IonAnimation.vue similarity index 100% rename from src/runtime/components/CreateAnimation.vue rename to src/runtime/components/IonAnimation.vue From 389d9a206b6dc3a259df1c61631063fa90e6dcb1 Mon Sep 17 00:00:00 2001 From: Aleksa Date: Tue, 23 Aug 2022 11:13:47 +0200 Subject: [PATCH 08/19] chore: update playground animations example --- playground/pages/tabs.vue | 5 +++ playground/pages/tabs/tab3.vue | 20 ----------- playground/pages/tabs/tab4.vue | 64 ++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 playground/pages/tabs/tab4.vue diff --git a/playground/pages/tabs.vue b/playground/pages/tabs.vue index fbf4d6dd..09f81420 100644 --- a/playground/pages/tabs.vue +++ b/playground/pages/tabs.vue @@ -24,6 +24,11 @@ useHead({ Tab 3 + + + + Animation examples + diff --git a/playground/pages/tabs/tab3.vue b/playground/pages/tabs/tab3.vue index 59d22a99..e49db7fb 100644 --- a/playground/pages/tabs/tab3.vue +++ b/playground/pages/tabs/tab3.vue @@ -11,26 +11,6 @@ Tab 3 - -
- -
- - - - -
-
- diff --git a/playground/pages/tabs/tab4.vue b/playground/pages/tabs/tab4.vue new file mode 100644 index 00000000..5dd8e2d9 --- /dev/null +++ b/playground/pages/tabs/tab4.vue @@ -0,0 +1,64 @@ + + + From 735026e372a92283ab5fb73b632eb7876724ab16 Mon Sep 17 00:00:00 2001 From: Aleksa Date: Thu, 25 Aug 2022 00:21:34 +0200 Subject: [PATCH 09/19] feat: add `playOnVisible` prop --- src/runtime/components/IonAnimation.vue | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/runtime/components/IonAnimation.vue b/src/runtime/components/IonAnimation.vue index 9946a13c..5ca9744b 100644 --- a/src/runtime/components/IonAnimation.vue +++ b/src/runtime/components/IonAnimation.vue @@ -13,6 +13,11 @@ interface AnimationFromToObject { toValue: string } +// interface KeyframeObject { +// offset: number +// [key: string]: string +// } + interface AnimationOptions { id?: string duration?: number @@ -22,8 +27,10 @@ interface AnimationOptions { direction?: AnimationDirection from?: AnimationFromObject | AnimationFromObject[] fromTo?: AnimationFromToObject | AnimationFromToObject[] + keyframes?: any[] playOnMount?: boolean - // playOnVisible?: boolean + playOnVisible?: boolean + // keyframes } const props = withDefaults(defineProps(), { @@ -36,6 +43,7 @@ const props = withDefaults(defineProps(), { from: null, fromTo: null, playOnMount: false, + playOnVisible: false, }) const element = ref(null) @@ -73,7 +81,27 @@ onMounted(() => { } } - props.playOnMount && animation.value.play() + if (props.playOnVisible && !props.playOnMount) { + const observer = new IntersectionObserver( + () => { + // Play animation + animation.value.play() + // Disconnect observer - making animation always trigger ONLY ONCE + observer.disconnect() + }, + { + // Use viewport as root element + root: null, + rootMargin: '0px', + threshold: 0.5, + } + ) + // Start observing for animation element + observer.observe(element.value) + + // Disconnect observer when component is about to be unmounted + onBeforeUnmount(() => observer.disconnect()) + } else if (props.playOnMount) animation.value.play() }) onBeforeUnmount(() => { animation.value.destroy() From 3f848e7bbb4db6e7735f119e2f6b2afa3a40f158 Mon Sep 17 00:00:00 2001 From: Aleksa Date: Thu, 25 Aug 2022 00:48:15 +0200 Subject: [PATCH 10/19] feat: add keyframes --- src/runtime/components/IonAnimation.vue | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/runtime/components/IonAnimation.vue b/src/runtime/components/IonAnimation.vue index 5ca9744b..7daa8b39 100644 --- a/src/runtime/components/IonAnimation.vue +++ b/src/runtime/components/IonAnimation.vue @@ -1,6 +1,12 @@ +``` + +You can delegate all that logic to the component: + +```vue + +``` ## Icons Icons are auto-imported from `ionicons/icons` by default, following the pattern of camel case naming with `ionicons` in front of the original icon name from the [official icons website](https://ionic.io/ionicons). -For example, instead of this +For example, instead of this: ```vue [component.vue] From 527da62ab9403c6c98aed85d22986c7b086d7142 Mon Sep 17 00:00:00 2001 From: Aleksa Date: Fri, 26 Aug 2022 16:32:18 +0200 Subject: [PATCH 17/19] chore(playground): add more animation examples --- playground/pages/tabs/tab4.vue | 239 +++++++++++++++++++++++++-------- 1 file changed, 186 insertions(+), 53 deletions(-) diff --git a/playground/pages/tabs/tab4.vue b/playground/pages/tabs/tab4.vue index b365e06f..5cf4f111 100644 --- a/playground/pages/tabs/tab4.vue +++ b/playground/pages/tabs/tab4.vue @@ -13,68 +13,201 @@
- -
- - - - -
- - -
- - - - -
- - -
- - - - -
+
+ + Basic animation + + +
+ +
+ Play + Pause + Stop +
+
+
+ +
+ + Keyframes animation + + +
+ +
+ Play + Pause + Stop +
+
+
+ +
+ + Animation that repeats forever + + +
+ +
+ Play + Pause + Stop +
+
+
+ +
+ + Animation with style hooks + + +
+ +
+ Play + Pause + Stop +
+
+
+ +
+ + Animation with specific easing + + +
+ +
+ Play + Pause + Stop +
+
+
+ +
+ + Reversed animation direction + + +
+ +
+ Play + Pause + Stop +
+
+