-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Drawer): export drawer component (#1030)
* fix(Drawer): export drawer component * fix: fix type --------- Co-authored-by: yaogengzhu <455947455@qq.com>
- Loading branch information
1 parent
ac7edf8
commit dde329e
Showing
5 changed files
with
61 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,15 @@ | ||
import { createApp, App, h, ref, nextTick } from 'vue'; | ||
import vueDrawer from './drawer.vue'; | ||
import { WithInstallType } from '../shared'; | ||
import { TdDrawerProps } from './type'; | ||
import _Drawer from './drawer.vue'; | ||
import { withInstall, WithInstallType } from '../shared'; | ||
|
||
import './style'; | ||
|
||
type DrawerOptions = Omit<TdDrawerProps, 'attach'>; | ||
|
||
const Drawer = (options: DrawerOptions) => { | ||
const root = document.createElement('div'); | ||
document.body.appendChild(root); | ||
const visible = ref(false); | ||
const props = ref({}); | ||
const destroyOnClose = ref(false); | ||
|
||
createApp(() => | ||
h(vueDrawer, { ...options, visible: visible.value, destroyOnClose: destroyOnClose.value, ...props.value }), | ||
).mount(root); | ||
|
||
const handler = { | ||
destroy() { | ||
destroyOnClose.value = true; | ||
nextTick(() => { | ||
visible.value = false; | ||
document.body.removeChild(root); | ||
}); | ||
}, | ||
hide() { | ||
visible.value = false; | ||
}, | ||
show() { | ||
visible.value = true; | ||
}, | ||
update(options: DrawerOptions) { | ||
props.value = options; | ||
}, | ||
}; | ||
|
||
return handler; | ||
}; | ||
|
||
Drawer.install = (app: App, name = '') => { | ||
app.component(name || vueDrawer.name, vueDrawer); | ||
|
||
// 添加插件入口 | ||
app.config.globalProperties.$drawer = Drawer; | ||
app.provide('$drawer', Drawer); | ||
}; | ||
|
||
const _Drawer: WithInstallType<typeof Drawer> = Drawer; | ||
import { TdDrawerProps } from './type'; | ||
|
||
export default _Drawer; | ||
export type DividerProps = TdDrawerProps; | ||
|
||
export * from './type'; | ||
export * from './plugin'; | ||
export { default as DrawerPlugin } from './plugin'; | ||
|
||
const Drawer: WithInstallType<typeof _Drawer> = withInstall(_Drawer); | ||
export default Drawer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createApp, App, h, ref, nextTick } from 'vue'; | ||
import vueDrawer from './drawer.vue'; | ||
import { WithInstallType } from '../shared'; | ||
import { TdDrawerProps } from './type'; | ||
|
||
type DrawerOptions = Omit<TdDrawerProps, 'attach'>; | ||
|
||
const Drawer = (options: DrawerOptions) => { | ||
const root = document.createElement('div'); | ||
document.body.appendChild(root); | ||
const visible = ref(false); | ||
const props = ref({}); | ||
const destroyOnClose = ref(false); | ||
|
||
createApp(() => | ||
h(vueDrawer, { ...options, visible: visible.value, destroyOnClose: destroyOnClose.value, ...props.value }), | ||
).mount(root); | ||
|
||
const handler = { | ||
destroy() { | ||
destroyOnClose.value = true; | ||
nextTick(() => { | ||
visible.value = false; | ||
document.body.removeChild(root); | ||
}); | ||
}, | ||
hide() { | ||
visible.value = false; | ||
}, | ||
show() { | ||
visible.value = true; | ||
}, | ||
update(options: DrawerOptions) { | ||
props.value = options; | ||
}, | ||
}; | ||
|
||
return handler; | ||
}; | ||
|
||
Drawer.install = (app: App): void => { | ||
// 添加插件入口 | ||
app.config.globalProperties.$drawer = Drawer; | ||
}; | ||
|
||
const DrawerPlugin: WithInstallType<typeof Drawer> = Drawer; | ||
|
||
export default DrawerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { DialogPlugin } from './dialog'; | ||
export { MessagePlugin } from './message'; | ||
export { ToastPlugin } from './toast'; | ||
export { DrawerPlugin } from './drawer'; |