-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrv-sheet.vue
161 lines (145 loc) · 3.27 KB
/
rv-sheet.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
<Teleport :disabled="!toBody" v-if="modalShow">
<Transition appear name="bg">
<div
v-if="show && !hidden && isBg"
class="modal-bg"
@click="emit('update:show', false)"
/>
</Transition>
<div
class="rv-sheet"
ref="RvSheetRef"
>
<div class="rv-sheet__header">
<div class="header-container">
<div class="drag-bar" />
</div>
<slot name="header" />
</div>
<div class="rv-sheet__content" @scroll="emit('scroll', $event)">
<slot />
<div class="spacer"></div>
</div>
</div>
</Teleport>
</template>
<script setup lang="ts">
import { ref, watch, onMounted, onUnmounted } from 'vue'
import { RvSheet, RvSheetProps } from '@reevo-design/sheet'
import '@reevo-design/sheet/style.css'
const props = withDefaults(defineProps<RvSheetProps & { toBody?: boolean; hidden?: boolean; isBg?: boolean }>(), {
allowDragSheetContent: true,
canClose: true,
allowShortSwipes: true,
topOffset: undefined,
toBody: false,
hidden: false,
isBg: false,
hideScrollOnBody: true,
})
const emit = defineEmits(['update:show', 'scroll'])
const RvSheetRef = ref<HTMLElement>()
const sheet = ref<RvSheet>()
const modalShow = ref(props.show)
defineExpose({ sheet })
async function initModal() {
if (props.show) {
modalShow.value = true
requestAnimationFrame(() => {
if (RvSheetRef.value) {
sheet.value = new RvSheet(RvSheetRef.value, { ...props })
sheet.value.on('closed', () => {
if (!props.hidden) {
modalShow.value = false
emit('update:show', false)
sheet.value = undefined
}
})
}
})
} else if (sheet.value) {
sheet.value.canClose = true
if (sheet.value.show) {
sheet.value?.closeSheet()
} else {
modalShow.value = false
emit('update:show', false)
sheet.value = undefined
}
} else {
emit('update:show', false)
}
}
onMounted(() => {
initModal()
})
watch(() => props.show, initModal)
watch(
() => props.hidden,
(v) => {
if (v) {
sheet.value?.closeSheet()
} else {
sheet.value?.showSheet()
}
}
)
</script>
<style scoped>
.rv-sheet {
top: 16px !important;
}
.bg-enter-active,
.bg-leave-active {
transition: opacity 0.25s ease;
}
.bg-enter-from,
.bg-leave-to {
opacity: 0;
}
/* Modal background */
.modal-bg {
background-color: rgba(0, 0, 0, 0.25); /* Transparent dark */
backdrop-filter: blur(8px);
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
cursor: pointer;
z-index: 2000;
}
/* Sheet */
.rv-sheet {
border-radius: 1rem 1rem 0 0; /* Large rounded corners for top-left and top-right */
z-index: 2001;
}
/* Sheet header */
.rv-sheet__header {
position: relative;
}
/* Header container for positioning */
.header-container {
position: absolute;
left: 0;
top: 0;
display: flex;
height: 1rem;
width: 100%;
justify-content: center;
align-items: center;
}
/* Drag bar (style for the handle to drag the sheet) */
.drag-bar {
background-color: rgba(128, 128, 128, 0.25);
border-radius: 2px;
height: 0.25rem;
width: 2.25rem;
cursor: pointer;
}
/* Spacer for spacing at the bottom */
.spacer {
height: 1rem;
}
</style>