From 651a25116c26637fdd4f47c382168d7128ed6a6f Mon Sep 17 00:00:00 2001 From: varodv <72568818+alvarodE@users.noreply.github.com> Date: Tue, 14 May 2024 09:38:05 +0200 Subject: [PATCH 1/7] feat: Replace DisableAnimationMixin by useDisableAnimation composable --- ....spec.ts => use-disable-animation.spec.ts} | 48 ++++++--------- .../animations/disable-animation.mixin.ts | 36 ------------ .../components/animations/fade-and-slide.vue | 58 +++++++++---------- .../src/components/animations/index.ts | 2 +- .../animations/staggered-fade-and-slide.vue | 53 +++++++++-------- .../animations/use-disable-animation.ts | 30 ++++++++++ 6 files changed, 108 insertions(+), 119 deletions(-) rename packages/x-components/src/components/animations/__tests__/{disable-animation-mixin.spec.ts => use-disable-animation.spec.ts} (60%) delete mode 100644 packages/x-components/src/components/animations/disable-animation.mixin.ts create mode 100644 packages/x-components/src/components/animations/use-disable-animation.ts diff --git a/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts b/packages/x-components/src/components/animations/__tests__/use-disable-animation.spec.ts similarity index 60% rename from packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts rename to packages/x-components/src/components/animations/__tests__/use-disable-animation.spec.ts index c3bc5bf904..b2d1bac74d 100644 --- a/packages/x-components/src/components/animations/__tests__/disable-animation-mixin.spec.ts +++ b/packages/x-components/src/components/animations/__tests__/use-disable-animation.spec.ts @@ -1,36 +1,33 @@ -import { mount, Wrapper } from '@vue/test-utils'; -import { Component, Prop, Provide } from 'vue-property-decorator'; -import Vue, { ComponentOptions, CreateElement, VNode } from 'vue'; -import DisableAnimationMixin from '../disable-animation.mixin'; +import { mount } from '@vue/test-utils'; +import { defineComponent, provide } from 'vue'; import { DISABLE_ANIMATIONS_KEY } from '../../decorators/injection.consts'; +import { useDisableAnimation } from '../use-disable-animation'; -@Component -class Provider extends Vue { - @Prop() - @Provide(DISABLE_ANIMATIONS_KEY as string) - public disableAnimation!: boolean; - - render(h: CreateElement): VNode { +const Provider = defineComponent({ + props: { + disableAnimation: Boolean + }, + setup(props) { + provide(DISABLE_ANIMATIONS_KEY as string, props.disableAnimation); + }, + render(h) { return this.$slots.default?.[0] ?? h(); } -} +}); /** * Animation component. */ -const Animation: ComponentOptions = { - mixins: [DisableAnimationMixin], +const Animation = defineComponent({ + setup() { + return useDisableAnimation('x-animation'); + }, template: `

Animation

- `, - data() { - return { - animationName: 'x-animation' - }; - } -}; + ` +}); /** * Function that returns an Animation wrapper. @@ -38,9 +35,7 @@ const Animation: ComponentOptions = { * @param disableAnimation - Flag to disable the animation. * @returns Animation wrapper. */ -function renderDisableAnimation({ - disableAnimation = true -}: DisableAnimationOptions = {}): DisableAnimationAPI { +function renderDisableAnimation({ disableAnimation = true }: DisableAnimationOptions = {}) { const wrapper = mount({ template: ` @@ -78,8 +73,3 @@ interface DisableAnimationOptions { /** Flag to disable the animation. */ disableAnimation?: boolean; } - -interface DisableAnimationAPI { - /** The wrapper of the mounted component. */ - wrapper: Wrapper; -} diff --git a/packages/x-components/src/components/animations/disable-animation.mixin.ts b/packages/x-components/src/components/animations/disable-animation.mixin.ts deleted file mode 100644 index 9581fa47cf..0000000000 --- a/packages/x-components/src/components/animations/disable-animation.mixin.ts +++ /dev/null @@ -1,36 +0,0 @@ -import Vue from 'vue'; -import { Component, Inject } from 'vue-property-decorator'; -import { DISABLE_ANIMATIONS_KEY } from '../decorators/injection.consts'; - -/** - * Mixin to ease disabling animations. - * - * @public - */ -@Component -export default class DisableAnimationMixin extends Vue { - /** - * The name of the animation. - * - * @public - */ - protected animationName!: string; - - /** - * Flag to disable the animation. - * - * @public - */ - @Inject({ from: DISABLE_ANIMATIONS_KEY as string, default: false }) - public disableAnimation!: boolean; - - /** - * The animation's name based on the {@link DisableAnimationMixin.disableAnimation} flag. - * - * @returns The animation name. - * @internal - */ - protected get name(): string { - return this.disableAnimation ? '__no-animation__' : this.animationName; - } -} diff --git a/packages/x-components/src/components/animations/fade-and-slide.vue b/packages/x-components/src/components/animations/fade-and-slide.vue index 727d14dd87..120918734f 100644 --- a/packages/x-components/src/components/animations/fade-and-slide.vue +++ b/packages/x-components/src/components/animations/fade-and-slide.vue @@ -13,9 +13,8 @@