Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(animation-factory): fix Vue3 breaking changes #1579

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
<template>
<div class="animate-modal">
<p>
BREAKING Vue3: `h()` hyperscript doesn't support rendering `'transition'` using strings.
Instead, replace it by `Transition` component of Vue 3 itself `import { Transition } from
'vue'`.
<br />
<a href="https://github.com/vuejs/core/issues/826#issuecomment-598207464">
https://github.com/vuejs/core/issues/826#issuecomment-598207464
</a>
<br />
<a href="https://github.com/vuejs/test-utils/issues/471#issuecomment-804477181">
https://github.com/vuejs/test-utils/issues/471#issuecomment-804477181
</a>
</p>
<p>
BREAKING Vue3: Review Transition Class Change. Replace instances of `.v-enter` to
`.v-enter-from` Replace instances of `.v-leave` to `.v-leave-from`.
<br />
<a href="https://v3-migration.vuejs.org/breaking-changes/transition.html">
https://v3-migration.vuejs.org/breaking-changes/transition.html
</a>
</p>
<p>
BREAKING Vue3: VNodes now have a flat props structure.
<br />
<a
href="https://v3-migration.vuejs.org/breaking-changes/render-function-api.html#vnode-props-format"
>
https://v3-migration.vuejs.org/breaking-changes/render-function-api.html#vnode-props-format
</a>
</p>
<button @click="openWithClipPath">Open modal with CLIP PATH animation</button>
<button @click="openWithScale">Open modal with SCALE animation</button>
<button @click="openWithTranslate">Open modal with TRANSLATE animation</button>
Expand All @@ -49,34 +19,37 @@
</template>

<script setup lang="ts">
import { ref, shallowRef } from 'vue';
import { nextTick, ref, shallowRef } from 'vue';
import BaseModal from '../../../../x-components/src/components/modals/base-modal.vue';
import { animateClipPath } from '../../../../x-components/src/components/animations/animate-clip-path/animate-clip-path.factory';
import { animateScale } from '../../../../x-components/src/components/animations/animate-scale/animate-scale.factory';
import { animateTranslate } from '../../../../x-components/src/components/animations/animate-translate/animate-translate.factory';

const clipPathAnimation = animateClipPath('bottom');
const clipPathAnimation = animateClipPath('left');
const scaleAnimation = animateScale('bottom');
const translateAnimation = animateTranslate('bottom');
const translateAnimation = animateTranslate('right');

const currentAnimation = shallowRef(clipPathAnimation);
const currentAnimation = shallowRef(scaleAnimation);
const open = ref(false);

/** Open modal with ClipPath animation. */
function openWithClipPath() {
async function openWithClipPath() {
currentAnimation.value = clipPathAnimation;
await nextTick();
open.value = true;
}

/** Open modal with Scale animation. */
function openWithScale() {
async function openWithScale() {
currentAnimation.value = scaleAnimation;
await nextTick();
open.value = true;
}

/** Open modal with Translate animation. */
function openWithTranslate() {
async function openWithTranslate() {
currentAnimation.value = translateAnimation;
await nextTick();
open.value = true;
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
}

&--top {
&#{$p}--enter,
&#{$p}--enter-from,
&#{$p}--leave-to {
clip-path: inset(0 0 100% 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
}

&--bottom {
&#{$p}--enter,
&#{$p}--enter-from,
&#{$p}--leave-to {
clip-path: inset(100% 0 0 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
}

&--top-to-bottom {
&#{$p}--enter {
&#{$p}--enter-from {
clip-path: inset(0 0 100% 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
&#{$p}--leave-to {
Expand All @@ -31,7 +31,7 @@
}

&--bottom-to-top {
&#{$p}--enter {
&#{$p}--enter-from {
clip-path: inset(100% 0 0 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
&#{$p}--leave-to {
Expand All @@ -40,21 +40,21 @@
}

&--left {
&#{$p}--enter,
&#{$p}--enter-from,
&#{$p}--leave-to {
clip-path: inset(0 100% 0 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
}

&--right {
&#{$p}--enter,
&#{$p}--enter-from,
&#{$p}--leave-to {
clip-path: inset(0 0 0 100% round var(--x-size-border-radius-animation-clip-path, 0));
}
}

&--left-to-right {
&#{$p}--enter {
&#{$p}--enter-from {
clip-path: inset(0 100% 0 0 round var(--x-size-border-radius-animation-clip-path, 0));
}
&#{$p}--leave-to {
Expand All @@ -63,7 +63,7 @@
}

&--right-to-left {
&#{$p}--enter {
&#{$p}--enter-from {
joseacabaneros marked this conversation as resolved.
Show resolved Hide resolved
clip-path: inset(0 0 0 100% round var(--x-size-border-radius-animation-clip-path, 0));
}
&#{$p}--leave-to {
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking on this "util" and how easy it has become, I don't know if it would be better in an architectural manner, turn clip-path, scale and translate into Vue components. But it would be a breaking change 😢

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, h } from 'vue';
import { defineComponent, h, Transition } from 'vue';

export type AnimationOrigin =
| 'top'
Expand All @@ -19,23 +19,23 @@ export type AnimationOrigin =
*
* @internal
*/
export function createDirectionalAnimationFactory(animationName: string) {
export function createDirectionalAnimationFactory(
animationName: string
): ReturnType<typeof defineComponent> {
return (animationOrigin: AnimationOrigin = 'top') =>
joseacabaneros marked this conversation as resolved.
Show resolved Hide resolved
defineComponent({
name: `transition-${animationName}-${animationOrigin}`,
inheritAttrs: false,
setup(_, { attrs, listeners, slots }) {
setup(_, { attrs, slots }) {
return () =>
h(
'transition',
Transition,
{
props: {
name: `x-${animationName}--${animationOrigin} x-${animationName}-`,
...attrs
},
on: listeners
name: `x-${animationName}--${animationOrigin} x-${animationName}-`,
...attrs
},
joseacabaneros marked this conversation as resolved.
Show resolved Hide resolved
slots.default?.() ?? []
// Vue recommends using function for better performance.
() => slots.default?.() ?? ''
);
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
<script lang="ts">
/* eslint-disable max-len */
import { computed, ComputedRef, defineComponent, provide } from 'vue';
// import { animateClipPath } from '../../components/animations/animate-clip-path/animate-clip-path.factory';
import { animateClipPath } from '../../components/animations/animate-clip-path/animate-clip-path.factory';
// import StaggeredFadeAndSlide from '../../components/animations/staggered-fade-and-slide.vue';
import AutoProgressBar from '../../components/auto-progress-bar.vue';
import BaseDropdown from '../../components/base-dropdown.vue';
Expand Down Expand Up @@ -601,7 +601,7 @@
];
const columnPickerValues = [0, 2, 4];
// const resultsAnimation = StaggeredFadeAndSlide;
// const modalAnimation = animateClipPath();
const modalAnimation = animateClipPath();
const selectedColumns = 4;
const sortValues = ['', 'price asc', 'price desc'];
const isAnyQueryLoadedInPreview = useQueriesPreview().isAnyQueryLoadedInPreview;
Expand Down Expand Up @@ -663,7 +663,7 @@
};
return {
resultsAnimation: undefined,
modalAnimation: undefined,
modalAnimation,
queriesPreviewInfo,
stores,
initialExtraParams,
Expand Down
Loading