-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
432 additions
and
35 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## $ModalDrawer 示例用法 | ||
|
||
```tsx | ||
const inst = window.$ModalDrawer.create({ | ||
blockScroll: false, | ||
title: '测试标题', | ||
placement: 'left', | ||
width: '70vw', | ||
render: () => { | ||
return <div> | ||
<p>点击遮罩/右上角关闭按钮触发 onAsyncMaskClick</p> | ||
<n-button onClick={() => inst.hide()}>直接关闭</n-button> | ||
</div> | ||
}, | ||
renderFooter: () => { | ||
return <n-space> | ||
<n-button | ||
type='primary' | ||
onClick={() => inst.hide()} | ||
> | ||
直接关闭 | ||
</n-button> | ||
</n-space> | ||
}, | ||
onAsyncMaskClick () { | ||
// 异步处理 | ||
const loading = window.$ModalMessage.loading('异步关闭中') | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
loading.destroy() | ||
resolve() | ||
}, 1000) | ||
}) | ||
} | ||
}) | ||
``` |
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,4 @@ | ||
import type { InjectionKey } from 'vue' | ||
import { DrawerApiInjection } from './type' | ||
|
||
export const drawerProviderInjectionKey: InjectionKey<DrawerApiInjection> = Symbol() |
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,111 @@ | ||
import { | ||
type DrawerProps, | ||
NDrawer, | ||
NDrawerContent, | ||
drawerProps | ||
} from 'naive-ui' | ||
|
||
interface DrawerExtraTypes { | ||
/** | ||
* 抽屉标题 | ||
*/ | ||
title: string | ||
|
||
/** | ||
* 抽屉内容渲染 VNode | ||
* @example render: () => h(NButton) | ||
*/ | ||
render?: () => VNode | ||
|
||
/** | ||
* 抽屉底部内容渲染 VNode | ||
* @example renderFooter: () => h(NButton) | ||
*/ | ||
renderFooter?: () => VNode | ||
|
||
/** | ||
* 点击遮罩/右上角关闭按钮触发的异步关闭回调 | ||
*/ | ||
onAsyncMaskClick?: () => Promise<void> | void | ||
} | ||
|
||
const propsDrawerExtraTypes = { | ||
internalKey: { | ||
type: String, | ||
default: '' | ||
}, | ||
title: { | ||
type: String, | ||
default: '' | ||
}, | ||
render: { | ||
type: Function as PropType<() => VNode>, | ||
default() { | ||
return () => <div></div> | ||
} | ||
}, | ||
renderFooter: { | ||
type: Function as PropType<() => VNode> | ||
}, | ||
onAsyncMaskClick: { | ||
type: Function | ||
}, | ||
onInternalAfterLeave: { | ||
type: Function, | ||
required: true | ||
} | ||
} | ||
|
||
|
||
export type DrawerCreateOptions = DrawerProps & DrawerExtraTypes | ||
|
||
export const DrawerEnvironment = defineComponent({ | ||
name: 'DrawerEnvironment', | ||
props: { | ||
...drawerProps, | ||
...propsDrawerExtraTypes | ||
}, | ||
setup(props) { | ||
|
||
const visible = ref(false) | ||
setTimeout(() => { | ||
visible.value = true | ||
}) | ||
|
||
const hideDrawer = async () => { | ||
visible.value = false | ||
Promise.resolve(() => { | ||
props.onInternalAfterLeave!(props.internalKey) | ||
}) | ||
} | ||
|
||
return { | ||
visible, | ||
hideDrawer | ||
} | ||
}, | ||
render() { | ||
|
||
return <NDrawer | ||
{...this.$props} | ||
show={this.visible} | ||
autoFocus={false} | ||
onUpdateShow={async () => { | ||
await this.onAsyncMaskClick?.() | ||
this.hideDrawer() | ||
}} | ||
> | ||
<NDrawerContent | ||
title={this.title} | ||
closable | ||
> | ||
{{ | ||
default: () => this.render(), | ||
footer: this.renderFooter | ||
? () => this.renderFooter?.() | ||
: undefined | ||
}} | ||
</NDrawerContent> | ||
</NDrawer> | ||
} | ||
}) |
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,6 @@ | ||
import { drawerProviderInjectionKey } from './context' | ||
|
||
export function useDrawer() { | ||
const drawerInstance = inject(drawerProviderInjectionKey) | ||
return drawerInstance! | ||
} |
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,3 @@ | ||
export * from './context' | ||
export * from './hook' | ||
export * from './provider' |
Oops, something went wrong.