feat(components): [drawer] enable open event (#1527)

* feat(drawer): enable open event

* docs(drawer): enable open event

* perf(drawer): enable open event

* style(drawer): enable open event

* perf(drawer): enable open event

* perf(drawer): enable open event
This commit is contained in:
betavs 2024-06-11 09:20:52 +08:00 committed by GitHub
parent b72b21da0d
commit e7d9dd9e04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 102 additions and 2 deletions

View File

@ -182,9 +182,21 @@ export default {
}
],
events: [
{
name: 'open',
type: '() => void',
defaultValue: '',
desc: {
'zh-CN': '打开抽屉事件',
'en-US': ''
},
mode: ['pc', 'mobile-first'],
pcDemo: 'open-event',
mfDemo: ''
},
{
name: 'close',
type: '()=> void',
type: '() => void',
defaultValue: '',
desc: {
'zh-CN': '关闭抽屉事件',
@ -196,7 +208,7 @@ export default {
},
{
name: 'confirm',
type: '()=> void',
type: '() => void',
defaultValue: '',
desc: {
'zh-CN': '确认事件,设置 :show-footer="true" 时有效',

View File

@ -0,0 +1,27 @@
<template>
<div>
<tiny-button @click="fn" type="primary"> 打开事件示例 </tiny-button>
<tiny-drawer title="标题" :show-footer="true" :visible="visible" @update:visible="visible = $event" @open="open">
<div style="height: 200px; text-align: center">
<br />
<br />
<span>内容区域</span>
</div>
</tiny-drawer>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { Drawer as TinyDrawer, Button as TinyButton, Modal } from '@opentiny/vue'
const visible = ref(false)
function fn() {
visible.value = true
}
function open() {
Modal.message('打开事件')
}
</script>

View File

@ -0,0 +1,11 @@
import { test, expect } from '@playwright/test'
test('打开事件', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('drawer#open-event')
const message = page.locator('.tiny-modal.type__message').filter({ hasText: '打开事件' }).first()
await page.getByRole('button', { name: '打开事件示例' }).click()
await expect(message).toBeVisible()
})

View File

@ -0,0 +1,36 @@
<template>
<div>
<tiny-button @click="fn" type="primary"> 打开事件示例 </tiny-button>
<tiny-drawer title="标题" :show-footer="true" :visible="visible" @update:visible="visible = $event" @open="open">
<div style="height: 200px; text-align: center">
<br />
<br />
<span>内容区域</span>
</div>
</tiny-drawer>
</div>
</template>
<script>
import { Drawer, Button, Modal } from '@opentiny/vue'
export default {
components: {
TinyDrawer: Drawer,
TinyButton: Button
},
data() {
return {
visible: false
}
},
methods: {
fn() {
this.visible = true
},
open() {
Modal.message('打开事件')
}
}
}
</script>

View File

@ -186,6 +186,18 @@ export default {
},
codeFiles: ['footer-slot.vue']
},
{
demoId: 'open-event',
name: {
'zh-CN': '打开事件',
'en-US': ''
},
desc: {
'zh-CN': '<p>打开抽屉事件。</p>',
'en-US': ''
},
codeFiles: ['open-event.vue']
},
{
demoId: 'close-event',
name: {

View File

@ -38,6 +38,7 @@ export const watchToggle =
(bool: boolean) => {
setTimeout(() => {
emit('update:visible', bool)
bool && emit('open')
}, 0)
}

View File

@ -144,6 +144,7 @@ export default defineComponent({
'beforeClose',
'tipsProps'
],
emits: ['update:visible', 'open', 'close', 'confirm'],
setup(props, context) {
return setup({ props, context, renderless, api })
}