Skip to content

Commit c7980b3

Browse files
authored
feat(drawer): [drawer] Add drag listening event (#1701)
* feat(drawer): [drawer] Add drag listening event * feat(drawer): [drawer] Modify version number
1 parent 0ba1db2 commit c7980b3

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

examples/sites/demos/pc/app/drawer/dragable-composition-api.vue

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
<tiny-button @click="openDrawer('width')" type="primary"> 宽度拖拽 </tiny-button>
44
<tiny-button @click="openDrawer('height')" type="primary"> 高度拖拽 </tiny-button>
55

6-
<tiny-drawer :placement="placement" title="标题" dragable :visible="visible" @update:visible="visible = $event">
6+
<tiny-drawer
7+
:placement="placement"
8+
title="标题"
9+
dragable
10+
:visible="visible"
11+
@update:visible="visible = $event"
12+
@drag="drag"
13+
>
714
<div class="content">
815
<p v-if="placement === 'right'">横向拖拽左边框可改变抽屉主体宽度。</p>
916
<p v-else>竖向拖拽上边框可改变抽屉主体高度。</p>
@@ -14,15 +21,19 @@
1421

1522
<script setup>
1623
import { ref } from 'vue'
17-
import { Drawer as TinyDrawer, Button as TinyButton } from '@opentiny/vue'
24+
import { Drawer as TinyDrawer, Button as TinyButton, Modal } from '@opentiny/vue'
1825
1926
const visible = ref(false)
2027
const placement = ref('right')
2128
22-
function openDrawer(target) {
29+
const openDrawer = (target) => {
2330
visible.value = true
2431
placement.value = target === 'width' ? 'right' : 'bottom'
2532
}
33+
34+
const drag = ({ width, height }) => {
35+
Modal.message({ message: `抽屉的宽为${width},高为${height}`, status: 'info' })
36+
}
2637
</script>
2738

2839
<style scoped>

examples/sites/demos/pc/app/drawer/dragable.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
<tiny-button @click="openDrawer('width')" type="primary"> 宽度拖拽 </tiny-button>
44
<tiny-button @click="openDrawer('height')" type="primary"> 高度拖拽 </tiny-button>
55

6-
<tiny-drawer :placement="placement" title="标题" dragable :visible="visible" @update:visible="visible = $event">
6+
<tiny-drawer
7+
:placement="placement"
8+
title="标题"
9+
dragable
10+
:visible="visible"
11+
@update:visible="visible = $event"
12+
@drag="drag"
13+
>
714
<div class="content">
815
<p v-if="placement === 'right'">横向拖拽左边框可改变抽屉主体宽度。</p>
916
<p v-else>竖向拖拽上边框可改变抽屉主体高度。</p>
@@ -13,7 +20,7 @@
1320
</template>
1421

1522
<script>
16-
import { Drawer, Button } from '@opentiny/vue'
23+
import { Drawer, Button, Modal } from '@opentiny/vue'
1724
1825
export default {
1926
components: {
@@ -30,6 +37,9 @@ export default {
3037
openDrawer(target) {
3138
this.visible = true
3239
this.placement = target === 'width' ? 'right' : 'bottom'
40+
},
41+
drag({ width, height }) {
42+
Modal.message({ message: `抽屉的宽为${width},高为${height}`, status: 'info' })
3343
}
3444
}
3545
}

packages/renderless/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@opentiny/vue-renderless",
33
"private": true,
4-
"version": "3.17.0",
4+
"version": "3.17.1",
55
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
66
"homepage": "https://opentiny.design/tiny-vue",
77
"keywords": [

packages/renderless/src/drawer/index.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import debounce from '../common/deps/debounce'
22
import { addClass, removeClass } from '../common/deps/dom'
3-
import type {
4-
IDrawerState,
5-
IDrawerProps,
6-
IDrawerApi,
7-
IDrawerCT,
8-
ISharedRenderlessParamUtils,
9-
IDrawerRenderlessParams
10-
} from '@/types'
3+
import type { IDrawerState, IDrawerApi, IDrawerCT, ISharedRenderlessParamUtils, IDrawerRenderlessParams } from '@/types'
114

125
export const computedWidth =
136
({
@@ -88,7 +81,7 @@ export const mousedown =
8881
state.dragEvent.offsetHeight = drawerBox.offsetHeight
8982
}
9083

91-
export const mousemove = ({ state, props }: { state: IDrawerState; props: IDrawerProps }) =>
84+
export const mousemove = ({ state, props, emit }: Pick<IDrawerRenderlessParams, 'state' | 'props' | 'emit'>) =>
9285
debounce(1, (event) => {
9386
if (!state.dragEvent.isDrag) {
9487
return
@@ -118,6 +111,8 @@ export const mousemove = ({ state, props }: { state: IDrawerState; props: IDrawe
118111
const height = offsetHeight - offsetY
119112
state.height = height > 10 ? height : 10
120113
}
114+
115+
emit('drag', { width: state.width, height: state.height })
121116
}) as Parameters<Document['removeEventListener']>['1']
122117

123118
export const mouseup =

packages/renderless/src/drawer/vue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const renderless = (
4747
close: close({ api }),
4848
handleClose: handleClose({ emit, props, state }),
4949
mousedown: mousedown({ state, vm }),
50-
mousemove: mousemove({ state, props }),
50+
mousemove: mousemove({ state, props, emit }),
5151
mouseup: mouseup({ state }),
5252
addDragEvent: addDragEvent({ api: api as IDrawerApi, vm }),
5353
removeDragEvent: removeDragEvent({ api: api as IDrawerApi, vm }),

packages/vue/src/drawer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/vue-drawer",
3-
"version": "3.17.0",
3+
"version": "3.17.1",
44
"description": "",
55
"main": "lib/index.js",
66
"module": "index.ts",

packages/vue/src/drawer/src/pc.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default defineComponent({
167167
'tipsProps',
168168
'customSlots'
169169
],
170-
emits: ['update:visible', 'open', 'close', 'confirm'],
170+
emits: ['update:visible', 'open', 'close', 'confirm', 'drag'],
171171
setup(props, context) {
172172
return setup({ props, context, renderless, api })
173173
}

0 commit comments

Comments
 (0)