Skip to content

Commit 3a036f0

Browse files
committed
feat: adding easing to the animation and set duration to 300;
1 parent 9ce9079 commit 3a036f0

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const snapToPoint = (index: number) => {
2929
:blocking="true"
3030
:can-overlay-close="true"
3131
:can-swipe-close="true"
32-
:expandOnContentDrag="expandOnContentDrag"
32+
:expand-on-content-drag="expandOnContentDrag"
3333
:snap-points="[maxHeight / 3, maxHeight / 1.5, maxHeight]"
3434
@min-height="(n) => (minHeight = n)"
3535
@max-height="(n) => (maxHeight = n)"

src/components/BottomSheet.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useElementBounding, useWindowSize } from '@vueuse/core'
44
import { type Handler, rubberbandIfOutOfBounds, useGesture } from '@vueuse/gesture'
55
import { useMotionControls, useMotionProperties, useMotionTransitions } from '@vueuse/motion'
66
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
7-
import { useSnapPoints } from '../composables/useSnapPoints'
7+
import { useSnapPoints } from '../composables/useSnapPoints.ts'
88
99
interface IProps {
1010
snapPoints: number[]
@@ -58,7 +58,7 @@ const minHeightComputed = computed(() => Math.ceil(sheetContentHeight.value + sh
5858
// Element styling and transforms
5959
const { motionProperties } = useMotionProperties(sheet)
6060
const { push, stop, motionValues } = useMotionTransitions()
61-
const { set, stop: _stopMotion } = useMotionControls(motionProperties, {}, { push, motionValues, stop })
61+
const { set } = useMotionControls(motionProperties, {}, { push, motionValues, stop })
6262
6363
// Height and translation management
6464
const height = ref<number>(0)
@@ -83,7 +83,7 @@ const open = () => {
8383
height: height.value,
8484
y: height.value,
8585
})
86-
push('y', 0, motionProperties, { type: 'tween', bounce: 0, duration: 250 })
86+
push('y', 0, motionProperties, { type: 'tween', easings: 'easeInOut', bounce: 0, duration: 300 })
8787
showSheet.value = true
8888
8989
window.addEventListener('keydown', handleEscapeKey)
@@ -94,14 +94,14 @@ const open = () => {
9494
emit('opened')
9595
activate()
9696
}
97-
}, 250)
97+
}, 300)
9898
}
9999
}
100100
// Close sheet method
101101
const close = () => {
102102
if (!sheet.value) return
103103
104-
push('y', sheetHeight.value, motionProperties, { type: 'tween', bounce: 0, duration: 250 })
104+
push('y', sheetHeight.value, motionProperties, { type: 'tween', bounce: 0, duration: 300 })
105105
showSheet.value = false
106106
107107
if (props.blocking) {
@@ -114,7 +114,7 @@ const close = () => {
114114
if (motionValues.value.y!.get() - sheetHeight.value < 0.1) {
115115
emit('closed')
116116
}
117-
}, 250)
117+
}, 300)
118118
}
119119
120120
// Overlay click handler
@@ -133,7 +133,12 @@ const snapToPoint = (index: number) => {
133133
if (!sheet.value) return
134134
135135
height.value = snapPoints.value[index]
136-
push('height', height.value, motionProperties, { type: 'tween', bounce: 0, duration: 250 })
136+
push('height', height.value, motionProperties, {
137+
type: 'tween',
138+
easings: 'easeInOut',
139+
bounce: 0,
140+
duration: 300,
141+
})
137142
}
138143
139144
const handleDrag: Handler<'drag', PointerEvent> | undefined = ({ delta }) => {
@@ -165,7 +170,7 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
165170
translateY.value = props.canSwipeClose
166171
? [0, height.value].reduce((prev, curr) => (Math.abs(curr - translateY.value) < Math.abs(prev - translateY.value) ? curr : prev))
167172
: 0
168-
push('y', translateY.value, motionProperties, { type: 'tween', bounce: 0, duration: 250 })
173+
push('y', translateY.value, motionProperties, { type: 'tween', easings: 'easeInOut', bounce: 0, duration: 300 })
169174
170175
if (translateY.value === height.value) {
171176
translateY.value = 0
@@ -175,8 +180,9 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
175180
height.value = snapPoints.value[closestSnapPoint.value]
176181
push('height', height.value, motionProperties, {
177182
type: 'tween',
183+
easings: 'easeInOut',
178184
bounce: 0,
179-
duration: 250,
185+
duration: 300,
180186
})
181187
}
182188
@@ -317,19 +323,19 @@ defineExpose({ open, close, snapToPoint })
317323
</Transition>
318324
<div ref="sheet" :class="{ 'sheet-show': showSheet, 'sheet-shadow': !blocking }" aria-modal="true" class="sheet" tabindex="-1">
319325
<div ref="sheetHeader" class="sheet-header">
320-
<slot name="header"></slot>
326+
<slot name="header" />
321327
</div>
322328

323329
<div ref="sheetScroll" class="sheet-scroll" @touchmove="handleSheetScroll">
324330
<div ref="sheetContentWrapper" class="sheet-content-wrapper">
325331
<div ref="sheetContent" class="sheet-content">
326-
<slot></slot>
332+
<slot />
327333
</div>
328334
</div>
329335
</div>
330336

331337
<div ref="sheetFooter" class="sheet-footer">
332-
<slot name="footer"></slot>
338+
<slot name="footer" />
333339
</div>
334340
</div>
335341
</div>
@@ -376,7 +382,7 @@ defineExpose({ open, close, snapToPoint })
376382
max-height: inherit;
377383
pointer-events: all;
378384
position: absolute;
379-
transition: visibility 250ms ease-in-out;
385+
transition: visibility 300ms ease-in-out;
380386
visibility: hidden;
381387
width: 100%;
382388
max-width: 640px;
@@ -442,7 +448,7 @@ defineExpose({ open, close, snapToPoint })
442448
443449
.fade-enter-active,
444450
.fade-leave-active {
445-
transition: opacity 250ms ease;
451+
transition: opacity 300ms ease;
446452
}
447453
448454
.fade-enter-from,

0 commit comments

Comments
 (0)