Skip to content

Commit 2d3a3b6

Browse files
committed
feat: add dragging events;
docs: update README;
1 parent 85324b8 commit 2d3a3b6

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ Assuming there is `const bottomSheet = ref()`
124124

125125
## Events
126126

127-
| Event | Description | Example |
128-
| ---------- | ------------------------------------------------------------------------------------- | ------------------------- |
129-
| min-height | Fires when the minimum height of the sheet changes. Passes the value as an argument. | `@min-height="(n) => {}"` |
130-
| max-height | Fires when the maximum height of the window changes. Passes the value as an argument. | `@max-height="(n) => {}"` |
131-
| opened | Fires when the bottom sheet is opened | `@opened="() => {}"` |
132-
| closed | Fires when the bottom sheet is closed | `@closed="() => {}"` |
127+
| Event | Description | Example |
128+
| ------------- | ------------------------------------------------------------------------------------ | --------------------------- |
129+
| min-height | Fires when the minimum height of the sheet changes. Passes the value as an argument. | `@min-height="(n) => {}"` |
130+
| dragging-up | Fires when the bottom sheet is being dragged up | `@dragging-up="() => {}"` |
131+
| dragging-down | Fires when the bottom sheet is being dragged down | `@dragging-down="() => {}"` |
132+
| opened | Fires when the bottom sheet is opened | `@opened="() => {}"` |
133+
| closed | Fires when the bottom sheet is closed | `@closed="() => {}"` |
133134

134135
## Acknowledgments
135136

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.0.4",
35+
"version": "1.0.5",
3636
"type": "module",
3737
"exports": {
3838
".": {

src/BottomSheet.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const emit = defineEmits<{
2626
(e: 'opened'): void
2727
(e: 'closed'): void
2828
(e: 'ready'): void
29+
(e: 'dragging-up'): void
30+
(e: 'dragging-down'): void
2931
(e: 'minHeight', minSheetHeight: number): void
3032
(e: 'maxHeight', maxSheetHeight: number): void
3133
}>()
@@ -147,7 +149,7 @@ const snapToPoint = (snapPoint: number) => {
147149
})
148150
}
149151
150-
const handleDrag: Handler<'drag', PointerEvent> | undefined = ({ delta }) => {
152+
const handleDrag: Handler<'drag', PointerEvent> | undefined = ({ delta, direction }) => {
151153
if (!sheet.value) return
152154
153155
if (translateY.value === 0) {
@@ -168,6 +170,12 @@ const handleDrag: Handler<'drag', PointerEvent> | undefined = ({ delta }) => {
168170
set({
169171
height: Math.min(Math.max(rubberbandIfOutOfBounds(height.value, 0, maxSnap.value, 0.25), 0), windowHeight.value),
170172
})
173+
174+
if (direction[1] > 0) {
175+
emit('dragging-down')
176+
} else if (direction[1] < 0) {
177+
emit('dragging-up')
178+
}
171179
}
172180
173181
const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {

0 commit comments

Comments
 (0)