From 1097c0d1b9dd63f9573812b9ddb41b790725b46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20CG?= Date: Wed, 10 Jul 2024 18:46:15 +0200 Subject: [PATCH] feat(create-animation): migrate to composition API (#1553) Co-authored-by: Jose A. Cabaneros Co-authored-by: Diego Pascual --- .../src/components/animations/index.ts | 1 + .../animations/test-animation-factory.vue | 99 +++++++++++++++++++ packages/_vue3-migration-test/src/router.ts | 6 ++ .../create-directional-animation-factory.ts | 54 +++++----- 4 files changed, 132 insertions(+), 28 deletions(-) create mode 100644 packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue diff --git a/packages/_vue3-migration-test/src/components/animations/index.ts b/packages/_vue3-migration-test/src/components/animations/index.ts index f1ee0800dd..b951da74a4 100644 --- a/packages/_vue3-migration-test/src/components/animations/index.ts +++ b/packages/_vue3-migration-test/src/components/animations/index.ts @@ -4,3 +4,4 @@ export { default as TestCollapseWidth } from './test-collapse-width.vue'; export { default as TestCrossFade } from './test-cross-fade.vue'; export { default as TestFade } from './test-fade.vue'; export { default as TestFadeAndSlide } from './test-fade-and-slide.vue'; +export { default as TestAnimationFactory } from './test-animation-factory.vue'; diff --git a/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue b/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue new file mode 100644 index 0000000000..3aa3de66cf --- /dev/null +++ b/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index ff54faabee..c8a2c45f80 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -48,6 +48,7 @@ import { TestExperienceControls, TestTagging, TestRenderlessExtraParam, + TestAnimationFactory, TestIcons } from './'; @@ -292,6 +293,11 @@ const routes = [ name: 'RenderlessExtraParam', component: TestRenderlessExtraParam }, + { + path: '/animation-factory', + name: 'AnimationFactory', + component: TestAnimationFactory + }, { path: '/icons', name: 'Icons', diff --git a/packages/x-components/src/components/animations/create-directional-animation-factory.ts b/packages/x-components/src/components/animations/create-directional-animation-factory.ts index c431a770a1..06969117ef 100644 --- a/packages/x-components/src/components/animations/create-directional-animation-factory.ts +++ b/packages/x-components/src/components/animations/create-directional-animation-factory.ts @@ -1,4 +1,14 @@ -import Vue, { VueConstructor } from 'vue'; +import { defineComponent, h } from 'vue'; + +export type AnimationOrigin = + | 'top' + | 'bottom' + | 'top-to-bottom' + | 'bottom-to-top' + | 'left' + | 'right' + | 'left-to-right' + | 'right-to-left'; /** * Abstract Factory to create animations Factory. The returned animation factory uses the @@ -9,36 +19,24 @@ import Vue, { VueConstructor } from 'vue'; * * @internal */ -export function createDirectionalAnimationFactory( - animationName: string -): (animationOrigin?: AnimationOrigin) => VueConstructor { - return (animationOrigin = 'top') => { - return Vue.extend({ +export function createDirectionalAnimationFactory(animationName: string) { + return (animationOrigin: AnimationOrigin = 'top') => + defineComponent({ name: `transition-${animationName}-${animationOrigin}`, inheritAttrs: false, - render(h) { - return h( - 'transition', - { - props: { - name: `x-${animationName}--${animationOrigin} x-${animationName}-`, - ...this.$attrs + setup(_, { attrs, listeners, slots }) { + return () => + h( + 'transition', + { + props: { + name: `x-${animationName}--${animationOrigin} x-${animationName}-`, + ...attrs + }, + on: listeners }, - on: this.$listeners - }, - this.$slots.default - ); + slots.default?.() ?? [] + ); } }); - }; } - -export type AnimationOrigin = - | 'top' - | 'bottom' - | 'top-to-bottom' - | 'bottom-to-top' - | 'left' - | 'right' - | 'left-to-right' - | 'right-to-left';