Skip to content

Commit eebfa97

Browse files
committed
feat: #274 improve DOM architecture of VFullscreen, VBottomSheet
1 parent 6f1886d commit eebfa97

File tree

13 files changed

+110
-155
lines changed

13 files changed

+110
-155
lines changed

packages/docs/components/content/FullScreen.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const emit = defineEmits<{
88

99
<template>
1010
<VFullscreen
11-
fullscreen-class="p-4 bg-primary-50 dark:bg-gray-800"
11+
content-class="p-4 bg-primary-50 dark:bg-gray-800"
12+
close-direction="RIGHT"
1213
@update:model-value="val => emit('update:modelValue', val)"
1314
>
1415
<h1 class="mb-4 text-2xl">

packages/docs/content/3.api/1.components/2.v-full-screen.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,6 @@ Hide the overlay or not.
3333
- TS: `PropType<boolean>`{lang=ts}
3434
- Default: `true`{lang=ts}
3535

36-
### fullscreenClass
37-
38-
Bind class to `.vfm-fullscreen-content`{lang=ts} element.
39-
- Type:
40-
- JS: `[Object, Array, String]`{lang=ts}
41-
- TS: `[Object, Array, String] as unknown as PropType<any>`{lang=ts}
42-
- Default: `undefined`{lang=ts}
43-
44-
### fullscreenStyle
45-
46-
Bind style to `.vfm-fullscreen-content`{lang=ts} element.
47-
- Type:
48-
- JS: `[String, Object, Array]`{lang=ts}
49-
- TS: `PropType<StyleValue>`{lang=ts}
50-
```ts
51-
export type StyleValue = string | CSSProperties | (string | CSSProperties)[]
52-
```
53-
```ts
54-
import { StyleValue } from 'vue-final-modal'
55-
```
56-
- Default: `undefined`{lang=ts}
57-
5836
### closeDirection
5937

6038
The direction of swiping to close the full screen modal
@@ -69,7 +47,7 @@ Threshold for swipe to close
6947
- Type:
7048
- JS: `Number`{lang=ts}
7149
- TS: `PropType<number>`{lang=ts}
72-
- Default: `30`
50+
- Default: `0`
7351

7452
### showSwipeBanner
7553

packages/docs/content/3.api/1.components/3.v-bottom-sheet.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ It will be helpful for understanding the naming of [props](#props).
2525

2626
`<VBottomSheet>`{lang=ts} also provides the following properties:
2727

28-
### bottomSheetClass
29-
30-
Bind class to `.vfm-bottom-sheet-content`{lang=ts} element.
31-
- Type:
32-
- JS: `[Object, Array, String]`{lang=ts}
33-
- TS: `[Object, Array, String] as unknown as PropType<any>`{lang=ts}
34-
- Default: `undefined`{lang=ts}
35-
36-
### bottomSheetStyle
37-
38-
Bind style to `.vfm-bottom-sheet-content`{lang=ts} element.
39-
- Type:
40-
- JS: `[String, Object, Array]`{lang=ts}
41-
- TS: `PropType<StyleValue>`{lang=ts}
42-
```ts
43-
export type StyleValue = string | CSSProperties | (string | CSSProperties)[]
44-
```
45-
```ts
46-
import { StyleValue } from 'vue-final-modal'
47-
```
48-
- Default: `undefined`{lang=ts}
49-
5028
### closeDirection
5129

5230
The direction of swiping to close the bottom sheet modal
@@ -61,7 +39,7 @@ Threshold for swipe to close
6139
- Type:
6240
- JS: `Number`{lang=ts}
6341
- TS: `PropType<number>`{lang=ts}
64-
- Default: `30`
42+
- Default: `0`
6543

6644
## Events
6745

packages/viteplay/src/components/VBottomSheet/Basic.example.vue

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const bottomSheet = useModal<
1515
component: markRaw(VBottomSheet),
1616
attrs: {
1717
background: 'interactive',
18-
bottomSheetStyle: {
18+
contentStyle: {
1919
backgroundColor: '#fff',
2020
},
2121
},
@@ -51,24 +51,23 @@ function beforeOpen(e: any) {
5151
<VBottomSheet
5252
v-model="show"
5353
:modal-id="theModalId"
54+
content-style="background-color: #fff; border-top-left-radius: 12px; border-top-right-radius: 12px;"
5455
@before-open="beforeOpen"
5556
>
56-
<div style="background-color: #fff; height: 500px; border-top-left-radius: 12px; border-top-right-radius: 12px;">
57-
<div>Direct use vfm</div>
58-
<button @click="() => toggle(theModalId)">
59-
close modal by modal modalId
60-
</button>
61-
<button @click="show = false">
62-
close
63-
</button>
64-
</div>
65-
<!-- <div style="background-color: #fff; height: 500px">
57+
<div>Direct use vfm</div>
58+
<button @click="() => toggle(theModalId)">
59+
close modal by modal modalId
60+
</button>
61+
<button @click="show = false">
62+
close
63+
</button>
64+
<div style="height: 300px">
6665
Direct use vfm
67-
</div> -->
68-
<!-- <div style="background-color: #fff; height: 500px">
66+
</div>
67+
<!-- <div style="min-height: 500px">
6968
Direct use vfm
70-
</div> -->
71-
<!-- <div style="background-color: #fff; height: 500px">
69+
</div>
70+
<div style="min-height: 500px">
7271
Direct use vfm
7372
</div> -->
7473
</VBottomSheet>

packages/viteplay/src/components/VFullScreen/Basic.example.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const fullscreenModal = useModal<
1515
attrs: {
1616
background: 'interactive',
1717
closeDirection: 'RIGHT',
18-
showSwipeBanner: true,
19-
fullscreenStyle: {
18+
// showSwipeBanner: true,
19+
contentStyle: {
2020
backgroundColor: '#fff',
2121
},
2222
},
@@ -50,14 +50,14 @@ const fullscreenModal = useModal<
5050
<VFullscreen
5151
v-model="show"
5252
:modal-id="theModalId"
53-
fullscreen-style="background-color: #fff;"
5453
close-direction="RIGHT"
54+
content-style="background-color: #fff;"
55+
:show-swipe-banner="true"
5556
:prevent-navigation-gestures-on-mobile-webkit="true"
5657
>
57-
<!-- :show-swipe-banner="true" -->
58-
<!-- <template #swipe-banner>
58+
<template #swipe-banner>
5959
<div style="position: absolute; height: 100%; top: 0; left: 0; width: 20px; background-color: pink;" />
60-
</template> -->
60+
</template>
6161
<div style="height: 500px">
6262
<div>Direct use vfm</div>
6363
<button @click="() => toggle(theModalId)">

packages/vue-final-modal/src/components/CoreModal/CoreModal.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ onBeforeUnmount(() => {
132132
focusLast()
133133
openLastOverlay()
134134
})
135+
136+
const vfmContentEl = ref<HTMLDivElement>()
137+
138+
defineExpose({
139+
vfmContentEl,
140+
})
135141
</script>
136142

137143
<template>
@@ -161,10 +167,12 @@ onBeforeUnmount(() => {
161167
<Transition v-bind="contentTransition" v-on="contentListeners">
162168
<div
163169
v-show="contentVisible"
170+
ref="vfmContentEl"
164171
class="vfm__content vfm--outline-none"
165172
:class="[contentClass, { 'vfm--prevent-auto': background === 'interactive' }]"
166173
:style="contentStyle"
167174
tabindex="0"
175+
v-bind="bindContent"
168176
@mousedown="() => onMousedown()"
169177
>
170178
<slot />

packages/vue-final-modal/src/components/CoreModal/CoreModalProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export const coreModalProps = {
104104
type: [String, Object, Array] as PropType<StyleValue>,
105105
default: undefined,
106106
},
107+
bindContent: {
108+
type: Object as PropType<any>,
109+
default: undefined,
110+
},
107111
/**
108112
* @description Is it allow to close the modal by clicking the overlay.
109113
* @default `true`

packages/vue-final-modal/src/components/VBottomSheet/VBottomSheet.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ const contentTransition = computed<undefined | TransitionProps>(() => {
3131
return props.contentTransition
3232
})
3333
34-
const vfmBottomSheetContentEl = ref<HTMLDivElement>()
34+
const VueFinalModalComp = ref<InstanceType<typeof VueFinalModal>>()
35+
const vfmContentEl = computed(() => VueFinalModalComp.value?.vfmContentEl)
3536
36-
const { offset, isSwiping } = useSwipeToClose(vfmBottomSheetContentEl, {
37+
defineExpose({
38+
vfmContentEl,
39+
})
40+
41+
const { offset, isSwiping } = useSwipeToClose(vfmContentEl, {
3742
direction: props.closeDirection,
3843
threshold: props.threshold,
3944
close: () => emit('update:modelValue', false),
@@ -46,24 +51,28 @@ watch(
4651
offset.value = 0
4752
},
4853
)
54+
55+
const bindContent = computed(() => {
56+
if (props.closeDirection === 'NONE')
57+
return {}
58+
return {
59+
class: { 'vfm-bounce-back': !isSwiping.value },
60+
style: isSwiping.value ? { transform: `translateY(${-offset.value}px)` } : '',
61+
}
62+
})
4963
</script>
5064

5165
<template>
5266
<VueFinalModal
67+
ref="VueFinalModalComp"
5368
v-bind="{
5469
...vfmAttrs,
5570
contentTransition,
71+
bindContent,
5672
}"
5773
class="vfm-bottom-sheet"
5874
>
59-
<div
60-
ref="vfmBottomSheetContentEl"
61-
class="vfm-bottom-sheet-content"
62-
:class="[{ 'vfm-bounce-back': !isSwiping }, bottomSheetClass]"
63-
:style="[{ transform: `translateY(${-offset}px)` }, bottomSheetStyle || {}]"
64-
>
65-
<slot />
66-
</div>
75+
<slot />
6776
</VueFinalModal>
6877
</template>
6978

@@ -76,8 +85,6 @@ watch(
7685
flex-direction: column;
7786
width: 100%;
7887
max-height: 90%;
79-
}
80-
.vfm-bottom-sheet-content {
8188
overflow-y: auto;
8289
}
8390
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import type { PropType } from 'vue'
22
import { vueFinalModalProps } from '../VueFinalModal/VueFinalModalProps'
3-
import type { StyleValue } from '~/Modal'
43

54
export const vBottomSheetProps = {
65
...vueFinalModalProps,
7-
/**
8-
* @description Bind class to `vfm-bottom-sheet-content`.
9-
* @default `undefined`
10-
*/
11-
bottomSheetClass: {
12-
type: undefined as unknown as PropType<any>,
13-
default: undefined,
14-
},
15-
/**
16-
* @description Bind style to `vfm-bottom-sheet-content`.
17-
* @default `undefined`
18-
*/
19-
bottomSheetStyle: {
20-
type: [String, Object, Array] as PropType<StyleValue>,
21-
default: undefined,
22-
},
236
/**
247
* @description The direction of swiping to close the bottom sheet modal
258
* @default `DOWN`
@@ -36,10 +19,10 @@ export const vBottomSheetProps = {
3619
},
3720
/**
3821
* @description Threshold for swipe to close
39-
* @default `30`
22+
* @default `0`
4023
*/
4124
threshold: {
4225
type: Number as PropType<number>,
43-
default: 30,
26+
default: 0,
4427
},
4528
} as const

0 commit comments

Comments
 (0)