Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
asurance committed May 21, 2024
1 parent 20f1fca commit 45a2058
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/guide/Q&A.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 常见问题

## 为什么`openify`打开的组件拿不到`context`
9 changes: 8 additions & 1 deletion docs/guide/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"type": "dir",
"name": "intro",
"label": "介绍"
}
},
{
"type": "dir",
"name": "feature",
"label": "特性"
},
"how-it-works",
"Q&A"
]
1 change: 1 addition & 0 deletions docs/guide/feature/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["static-call", "promisify", "no-dependency"]
3 changes: 3 additions & 0 deletions docs/guide/feature/no-dependency.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 组件库无关

组件库无关则可以轻易的将该工具库应用到你的项目中。
3 changes: 3 additions & 0 deletions docs/guide/feature/promisify.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Promise 化

Promise 化意味着配合 async/await 使用,可以大大简化代码组织
3 changes: 3 additions & 0 deletions docs/guide/feature/static-call.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 静态调用

静态调用意味着调用可以用在任何地方,例如工具脚本,store 中,甚至能配合动态导入使用
1 change: 1 addition & 0 deletions docs/guide/how-it-works.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 实现原理
12 changes: 7 additions & 5 deletions docs/guide/intro/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PackageManagerTabs } from '@theme';

# 快速上手

## 安装

```bash
npm install @mx-space/api-client --save
```
<PackageManagerTabs command="install openify" />

## 开发自定义弹窗组件

Expand All @@ -14,17 +14,19 @@ export type MyModalProps = {
onOk: () => void;
onCancel: () => void;
afterClose: () => void;
/** your props **/
};

export default function MyModal({
visible,
onOk,
onCancel,
afterClose,
/** your props **/
}: MyModalProps) {
// your code here
return <Modal {/*** your props **/}>
{/*** your content here **/}</Modal>;
return <Modal {/** your props **/}>
{/** your content here **/}</Modal>;
}
```

Expand Down
2 changes: 2 additions & 0 deletions docs/guide/intro/welcome.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# 欢迎使用

openify 是一个简化弹窗/抽屉类组件打开的工具库
2 changes: 2 additions & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ hero:

features:
- title: 静态调用
link: /guide/feature/static-call
- title: Promise化
link: /guide/feature/promisify
- title: 组件库无关
---
10 changes: 5 additions & 5 deletions src/openify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OpenifyError } from './openifyError';

export function openify<ModalProps extends object, Value, Reason>(
comp: ComponentType<ModalProps>,
config: OpenifyConfig<ModalProps> & { bindToComponent?: true },
config?: OpenifyConfig<ModalProps> & { bindToComponent?: true },
): ComponentType<ModalProps> & {
open: (openProps: Partial<ModalProps>) => Promise<Value>;
openSafely: (
Expand All @@ -15,7 +15,7 @@ export function openify<ModalProps extends object, Value, Reason>(
};
export function openify<ModalProps extends object, Value, Reason>(
comp: ComponentType<ModalProps>,
config: OpenifyConfig<ModalProps> & { bindToComponent: false },
config?: OpenifyConfig<ModalProps> & { bindToComponent: false },
): {
open: (openProps: Partial<ModalProps>) => Promise<Value>;
openSafely: (
Expand All @@ -24,7 +24,7 @@ export function openify<ModalProps extends object, Value, Reason>(
};
export function openify<ModalProps extends object, Value, Reason>(
comp: ComponentType<ModalProps>,
config: OpenifyConfig<ModalProps> & { bindToComponent?: boolean },
config: OpenifyConfig<ModalProps> & { bindToComponent?: boolean } = {},
) {
const {
bindToComponent = true,
Expand All @@ -42,7 +42,7 @@ export function openify<ModalProps extends object, Value, Reason>(
const getContainer =
typeof container === 'function' ? container : () => container;
const fns = {
open(openProps: Partial<ModalProps>) {
open(openProps?: Partial<ModalProps>) {
return new Promise<Value>((resolve, reject) => {
const element = getContainer();
const currentRenderHook =
Expand Down Expand Up @@ -71,7 +71,7 @@ export function openify<ModalProps extends object, Value, Reason>(
renderComp();
});
},
openSafely(openProps: Partial<ModalProps>) {
openSafely(openProps?: Partial<ModalProps>) {
return new Promise<OpenifyCallabck<Value, Reason>>(resolve => {
const element = getContainer();
const currentRenderHook =
Expand Down

0 comments on commit 45a2058

Please sign in to comment.