generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: close 支持回调外部 props 方法 * test: add unit test * test: add unit test * test: add unit test * feat: 改进默认 TS 类型 * docs: 补充文档 * chore: docs order * chore: update demo
- Loading branch information
Showing
20 changed files
with
2,101 additions
and
1,247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["**/*"] | ||
} |
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,51 @@ | ||
--- | ||
title: 常见问题 | ||
nav: | ||
title: FAQ | ||
order: 3 | ||
--- | ||
|
||
## Q: 普通标签控制台报 `enhancedAction` 错误, [#14](https://github.com/Wxh16144/easy-antd-modal/issues/14) | ||
|
||
```txt | ||
React does not recognize the `enhancedAction` prop on a DOM element. | ||
``` | ||
|
||
### A: 已知(边界)问题,因为 `easy-antd-modal` 会给弹窗内容添加一个 `enhancedAction` props | ||
|
||
```tsx | pure | ||
import Modal from 'easy-antd-modal'; | ||
|
||
const Content = (props) => <div {...props}>root 标签是普通标签</div>; | ||
|
||
export default () => ( | ||
<Modal defaultOpen> | ||
<Content /> | ||
</Modal> | ||
); | ||
``` | ||
|
||
#### 两个解决方法 | ||
|
||
**方案一**: 临时给 `<Content />` 多包装一个 div。 | ||
**方案二**: `<Content >` 组件 omit 掉 enhancedAction。 | ||
|
||
--- | ||
|
||
## Q: antd4.x 中,拖拽弹窗关闭后再打开位置没有重置。 | ||
|
||
### A:预期的 😅 | ||
|
||
antd4.x 没有提供显隐回调,直到 5.3.0 antd 才为 Modal 提供了 `afterOpenChange`方法, 所以不只是 4.x,在 5.3.0 以下存在同样问题。 | ||
|
||
--- | ||
|
||
## Q: 为什么 PC 和 移动端的代码都放在一起,增加依赖体积。[#17](https://github.com/Wxh16144/easy-antd-modal/issues/17) | ||
|
||
### A: 这也是规划错误,没有采用 monorepo 的方式,但是问题不是很大,一般构建工具都会对 js 代码 `tree shaking` | ||
|
||
--- | ||
|
||
## Q: 内部通过 `enhancedAction.close()` 关闭不执行 `onClean/onClose` 方法, [#18](https://github.com/Wxh16144/easy-antd-modal/issues/18) | ||
|
||
### A: 设计缺陷,起初以为关闭即可,但是使用过程中还是难免会遇到这种需求。[1.6.0](./guide/advanced-close.md) 已经通过另外一种方式解决。可以试试看~ |
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,55 @@ | ||
--- | ||
title: 内部关闭(回调) | ||
group: | ||
title: 进阶使用 | ||
order: 1 | ||
order: 5 | ||
--- | ||
|
||
## 快速了解 <Badge>1.6.0+</Badge> | ||
|
||
在 [issue#18](https://github.com/Wxh16144/easy-antd-modal/issues/18) 中,遇到需求是内部关闭操作无法执行`onClean/onClose` 方法。想了几个方案都不太满意。最终绕了一圈解决: | ||
|
||
内部调用的地方传入一个需要触发的回调函数名即可。后面参数则是该函数的执行参数。 | ||
|
||
```tsx | pure | ||
import { Button } from 'antd'; | ||
import type { ModalContentPropsWithEnhanced } from 'easy-antd-modal'; | ||
import React from 'react'; | ||
|
||
const ContentForm: React.FC<ModalContentPropsWithEnhanced> = ({ enhancedAction }) => { | ||
function handleClick(event: React.MouseEvent<HTMLButtonElement>) { | ||
enhancedAction?.close('onCancel', event); // <=== 关键改动 | ||
} | ||
|
||
return <Button onClick={handleClick}>Close</Button>; | ||
}; | ||
|
||
export default ContentForm; | ||
``` | ||
|
||
:::warning | ||
**请注意 `<Modal />` 的关闭回调是 <span style="color:red">onCancel</span>, 而 `<Drawer />` 是 <span style="color:red">onClose</span>.** | ||
::: | ||
|
||
```tsx | pure | ||
import { Button } from 'antd'; | ||
import type { DrawerContentPropsWithEnhanced } from 'easy-antd-modal'; | ||
import React from 'react'; | ||
|
||
const ContentForm: React.FC<DrawerContentPropsWithEnhanced> = ({ enhancedAction }) => { | ||
function handleClick(event: React.MouseEvent<HTMLButtonElement>) { | ||
enhancedAction?.close('onClose', event); // Drawer 的回调是 onClose | ||
} | ||
|
||
return <Button onClick={handleClick}>Close</Button>; | ||
}; | ||
|
||
export default ContentForm; | ||
``` | ||
|
||
### FAQ | ||
|
||
#### Q:为什么我不直接受控,然后将关闭方法传递下去了 🤣? | ||
|
||
条条大路通罗马, 确实直接 props 传递下去更直观(前提是你已经用了受控模式), 但是具体情况需要具体分析 🧐 |
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,7 +1,8 @@ | ||
--- | ||
title: 进阶使用 | ||
title: 内部关闭 | ||
group: | ||
title: 快速上手 | ||
title: 进阶使用 | ||
order: 1 | ||
order: 4 | ||
--- | ||
|
||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ title: 拖拽 Modal | |
group: | ||
title: 快速上手 | ||
order: 0 | ||
order: 3 | ||
order: 4 | ||
--- | ||
|
||
## 推荐示例 | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
title: 静态方法 | ||
group: | ||
title: Legacy | ||
order: 5 | ||
order: 99 | ||
--- | ||
|
||
## 静态方法 | ||
|
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
Oops, something went wrong.