Skip to content

Commit

Permalink
Added animation when opening card on click
Browse files Browse the repository at this point in the history
  • Loading branch information
Albermonte committed Sep 8, 2023
1 parent 22c0f39 commit 382addb
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/components/atoms/SheetModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { TransitionPresets, useTransition } from '@vueuse/core'
const props = defineProps({
progress: {
Expand Down Expand Up @@ -98,7 +99,7 @@ function onEnd(event: PointerEvent) {
const isClick = Math.abs(initialY - event.clientY) < 10 && Math.abs(initialX - event.clientX) < 10
if (isClick && !initialOpen) {
open()
open(true)
}
else {
if (initialOpen) {
Expand Down Expand Up @@ -131,8 +132,25 @@ function close() {
emit('update:progress', 0)
}
function open() {
emit('update:progress', 1)
function open(smooth = false) {
if (smooth) {
const source = ref(0)
const output = useTransition(source, {
duration: 500,
transition: TransitionPresets.easeOutQuart,
})
source.value = 1
const stop = watch(output, () => {
emit('update:progress', output.value / 1)
if (output.value >= 1) {
source.value = 0
stop()
}
})
}
else {
emit('update:progress', 1)
}
}
function animateShortly() {
Expand Down

0 comments on commit 382addb

Please sign in to comment.