Skip to content

Commit 89d4269

Browse files
committed
feat: duration can be changed;
fix(docs): README;
1 parent 0cbb45b commit 89d4269

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ bun install @douxcode/vue-spring-bottom-sheet
2222

2323
```vue
2424
<script setup>
25-
import BottomSheet from '@douxcode/vue-bottom-sheet'
26-
import '@douxcode/vue-bottom-sheet/dist/style.css'
25+
import BottomSheet from '@douxcode/vue-spring-bottom-sheet'
26+
import '@douxcode/vue-spring-bottom-sheet/dist/style.css'
2727
import { ref } from 'vue'
2828
2929
const bottomSheet = ref(null)
@@ -46,8 +46,8 @@ const close = () => {
4646

4747
```vue
4848
<script setup lang="ts">
49-
import BottomSheet from '@douxcode/vue-bottom-sheet'
50-
import '@douxcode/vue-bottom-sheet/dist/style.css'
49+
import BottomSheet from '@douxcode/vue-spring-bottom-sheet'
50+
import '@douxcode/vue-spring-bottom-sheet/dist/style.css'
5151
import { ref } from 'vue'
5252
5353
const bottomSheet = ref<InstanceType<typeof BottomSheet>>()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"url": "https://github.com/megaarmos/vue-spring-bottom-sheet/issues"
3333
},
3434
"private": false,
35-
"version": "1.1.4",
35+
"version": "1.2.0",
3636
"type": "module",
3737
"exports": {
3838
".": {

playground/nuxt/pages/snap.vue

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

src/BottomSheet.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
1010
import { useSnapPoints } from './composables/useSnapPoints.ts'
1111
1212
interface IProps {
13+
duration?: number
1314
snapPoints?: number[]
1415
defaultBreakpoint?: number
1516
blocking?: boolean
@@ -23,6 +24,7 @@ const props = withDefaults(defineProps<IProps>(), {
2324
canSwipeClose: true,
2425
canBackdropClose: true,
2526
expandOnContentDrag: true,
27+
duration: 250,
2628
})
2729
2830
const emit = defineEmits<{
@@ -61,6 +63,8 @@ const { activate, deactivate } = useFocusTrap([sheet, backdrop], { immediate: fa
6163
const minHeightComputed = computed(() =>
6264
Math.ceil(sheetContentHeight.value + sheetHeaderHeight.value + sheetFooterHeight.value),
6365
)
66+
const transitionVisibility = computed(() => `visibility ${props.duration}ms ease-in-out`)
67+
const transitionOpacity = computed(() => `opacity ${props.duration}ms ease-in-out`)
6468
6569
// Element styling and transforms
6670
const { motionProperties } = useMotionProperties(sheet)
@@ -103,7 +107,12 @@ const open = () => {
103107
height: height.value,
104108
y: height.value,
105109
})
106-
push('y', 0, motionProperties, { type: 'tween', easings: 'easeInOut', bounce: 0, duration: 300 })
110+
push('y', 0, motionProperties, {
111+
type: 'tween',
112+
easings: 'easeInOut',
113+
bounce: 0,
114+
duration: props.duration,
115+
})
107116
showSheet.value = true
108117
isWindowScrollLocked.value = true
109118
isWindowRootScrollLocked.value = true
@@ -116,14 +125,18 @@ const open = () => {
116125
emit('opened')
117126
activate()
118127
}
119-
}, 300)
128+
}, props.duration)
120129
}
121130
}
122131
// Close sheet method
123132
const close = () => {
124133
if (!sheet.value) return
125134
126-
push('y', sheetHeight.value, motionProperties, { type: 'tween', bounce: 0, duration: 300 })
135+
push('y', sheetHeight.value, motionProperties, {
136+
type: 'tween',
137+
bounce: 0,
138+
duration: props.duration,
139+
})
127140
128141
showSheet.value = false
129142
isWindowScrollLocked.value = false
@@ -139,7 +152,7 @@ const close = () => {
139152
if (motionValues.value.y!.get() - sheetHeight.value < 0.1) {
140153
emit('closed')
141154
}
142-
}, 300)
155+
}, props.duration)
143156
}
144157
145158
// Backdrop click handler
@@ -160,7 +173,7 @@ const snapToPoint = (snapPoint: number) => {
160173
type: 'tween',
161174
easings: 'easeInOut',
162175
bounce: 0,
163-
duration: 300,
176+
duration: props.duration,
164177
})
165178
}
166179
@@ -212,7 +225,7 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
212225
type: 'tween',
213226
easings: 'easeInOut',
214227
bounce: 0,
215-
duration: 300,
228+
duration: props.duration,
216229
})
217230
218231
if (translateY.value === height.value) {
@@ -225,7 +238,7 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
225238
type: 'tween',
226239
easings: 'easeInOut',
227240
bounce: 0,
228-
duration: 300,
241+
duration: props.duration,
229242
})
230243
}
231244
@@ -468,7 +481,7 @@ defineExpose({ open, close, snapToPoint })
468481
pointer-events: all;
469482
position: fixed;
470483
right: 0;
471-
transition: visibility 300ms ease-in-out;
484+
transition: v-bind(transitionVisibility);
472485
visibility: hidden;
473486
width: 100%;
474487
will-change: height;
@@ -535,7 +548,7 @@ defineExpose({ open, close, snapToPoint })
535548
536549
.fade-enter-active,
537550
.fade-leave-active {
538-
transition: opacity 300ms ease;
551+
transition: v-bind(transitionOpacity);
539552
}
540553
541554
.fade-enter-from,

0 commit comments

Comments
 (0)