Skip to content

Commit 52e1c30

Browse files
authored
Merge pull request #16 from valbertVieira/feat/vmodel
feat: include v-model
2 parents 0e2a7e3 + f8ce5b5 commit 52e1c30

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ const close = () => {
7272
</template>
7373
```
7474

75+
## Usage with v-model
76+
77+
```vue
78+
<script setup lang="ts">
79+
import { ref } from "vue";
80+
81+
import BottomSheet from "@douxcode/vue-spring-bottom-sheet";
82+
import "@douxcode/vue-spring-bottom-sheet/dist/style.css";
83+
84+
const sheet = ref(false);
85+
86+
</script>
87+
88+
<template>
89+
<button type="button" @click="sheet = true"> Open bottom sheet </button>
90+
<BottomSheet v-model="sheet"> Your content </BottomSheet>
91+
</template>
92+
```
93+
94+
7595
## Usage in Nuxt 3
7696

7797
For Nuxt 3, just wrap component in `<ClientOnly>`

packages/vue-spring-bottom-sheet/src/BottomSheet.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { BottomSheetProps } from './types'
44
import { Motion, AnimatePresence, useMotionValue, animate } from 'motion-v'
55
import type { PanInfo } from 'motion-v'
66
7-
import { computed, nextTick, onUnmounted, ref, toRefs, watch } from 'vue'
8-
import { useElementBounding, useScrollLock, useWindowSize } from '@vueuse/core'
7+
import { computed, nextTick, onUnmounted, ref, toRefs, watch , defineModel, onMounted } from 'vue'
8+
import { useElementBounding, useScrollLock, useVModel, useWindowSize } from '@vueuse/core'
99
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
1010
import { useSnapPoints } from './composables/useSnapPoints'
1111
import { clamp, funnel } from 'remeda'
@@ -27,9 +27,25 @@ const emit = defineEmits<{
2727
(e: 'dragging-up'): void
2828
(e: 'dragging-down'): void
2929
(e: 'instinctHeight', instinctHeight: number): void
30+
(e: 'update:modelValue'): void
3031
}>()
3132
32-
const showSheet = ref(false)
33+
const showSheet = useVModel(props, 'modelValue', emit, {
34+
passive: true,
35+
})
36+
37+
watch(showSheet, (value) => {
38+
if (value) {
39+
open()
40+
}
41+
})
42+
43+
onMounted(() => {
44+
if (showSheet.value) {
45+
open()
46+
}
47+
})
48+
3349
const sheet = ref()
3450
const sheetHeader = ref<HTMLElement | null>(null)
3551
const sheetFooter = ref<HTMLElement | null>(null)

packages/vue-spring-bottom-sheet/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface BottomSheetProps {
66
canSwipeClose?: boolean
77
canBackdropClose?: boolean
88
expandOnContentDrag?: boolean
9+
modelValue?: boolean
910
}

0 commit comments

Comments
 (0)