From 194a70ae9b421dd1cbc0ce58d88f3f66a09fd63e Mon Sep 17 00:00:00 2001 From: witt Date: Wed, 15 Jul 2020 18:11:11 +0800 Subject: [PATCH] feat(modal): use Button to reconstrust Modal.Action (#332) * feat(modal): use Button to reconstrust Modal.Action * docs(modal): add example for action loading * test: update snapshots --- .../__snapshots__/index.test.tsx.snap | 168 +++++++++++++----- components/modal/modal-action.tsx | 140 +++++++++------ components/modal/modal-actions.tsx | 2 +- pages/en-us/components/modal.mdx | 31 +++- pages/zh-cn/components/modal.mdx | 43 +++-- 5 files changed, 261 insertions(+), 123 deletions(-) diff --git a/components/modal/__tests__/__snapshots__/index.test.tsx.snap b/components/modal/__tests__/__snapshots__/index.test.tsx.snap index f574ca5..928d38d 100644 --- a/components/modal/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/modal/__tests__/__snapshots__/index.test.tsx.snap @@ -103,53 +103,129 @@ exports[`Modal should render correctly 1`] = ` .content > :global(*:last-child) { margin-bottom: 0; } -
- - ) -} +type ModalActionComponent = React.ForwardRefExoticComponent< + PropsWithoutRef

& RefAttributes +> -export default withDefaults(ModalAction, defaultProps) +type ComponentProps = Partial & + Omit & + Partial> + +ModalAction.defaultProps = defaultProps + +export default ModalAction as ModalActionComponent diff --git a/components/modal/modal-actions.tsx b/components/modal/modal-actions.tsx index 0c2d088..443c3ac 100644 --- a/components/modal/modal-actions.tsx +++ b/components/modal/modal-actions.tsx @@ -22,7 +22,7 @@ const ModalActions: React.FC> = ({ children, ...prop border-bottom-right-radius: ${theme.layout.radius}; } - footer > :global(button + button) { + footer > :global(button.btn + button.btn) { border-left: 1px solid ${theme.palette.border}; } diff --git a/pages/en-us/components/modal.mdx b/pages/en-us/components/modal.mdx index 0084f53..808e43f 100644 --- a/pages/en-us/components/modal.mdx +++ b/pages/en-us/components/modal.mdx @@ -159,6 +159,30 @@ Display popup content that requires attention or provides additional information `} /> + { + const { visible, setVisible, bindings } = useModal() + return ( + <> + + + Modal + This is a modal + +

Some content contained within the modal.

+ + setVisible(false)}>Cancel + Submit + + + ) +} +`} +/> + Modal.Props @@ -190,12 +214,6 @@ Display popup content that requires attention or provides additional information | --------- | ------------ | ---------------- | ------------------------ | ------- | | ... | native props | `HTMLAttributes` | `'id', 'className', ...` | - | -Modal.Actions.Props - -| Attribute | Description | Type | Accepted values | Default | -| --------- | ----------- | ---- | --------------- | ------- | -| - | - | - | - | - | - Modal.Action.Props | Attribute | Description | Type | Accepted values | Default | @@ -203,6 +221,7 @@ Display popup content that requires attention or provides additional information | **passive** | display passive mode | `boolean` | - | `false` | | **disabled** | disable current action | `boolean` | - | `false` | | **onClick** | click handler | [(event: ModalActionEvent) => void](#modalactionevent) | - | - | +| **loading** | show loading | `boolean` | - | `false` | | ... | native props | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | useModal diff --git a/pages/zh-cn/components/modal.mdx b/pages/zh-cn/components/modal.mdx index 1c16072..f4ade63 100644 --- a/pages/zh-cn/components/modal.mdx +++ b/pages/zh-cn/components/modal.mdx @@ -40,8 +40,8 @@ export const meta = {

yield 关键字通常不能在箭头函数中使用(除非是嵌套在允许使用的函数内)。因此,箭头函数不能用作函数生成器。

- 放弃使用 - 明白了 + close()}>放弃使用 + close()}>明白了 ) @@ -69,8 +69,8 @@ export const meta = {

yield 关键字通常不能在箭头函数中使用(除非是嵌套在允许使用的函数内)。因此,箭头函数不能用作函数生成器。

- 放弃使用 - 明白了 + setVisible(false)}>放弃使用 + setVisible(false)}>明白了 ) @@ -127,8 +127,8 @@ export const meta = {

yield 关键字通常不能在箭头函数中使用(除非是嵌套在允许使用的函数内)。因此,箭头函数不能用作函数生成器。

- 继续学习 - 尝试箭头函数 + close()}>继续学习 + close()}>尝试箭头函数 ) @@ -158,6 +158,30 @@ export const meta = { `} /> + { + const { visible, setVisible, bindings } = useModal() + return ( + <> + + + 箭头函数 + 它不能用作构造函数 + +

yield 关键字通常不能在箭头函数中使用(除非是嵌套在允许使用的函数内)。因此,箭头函数不能用作函数生成器。

+
+ setVisible(false)}>取消 + 提交 +
+ + ) +} +`} +/> + Modal.Props @@ -189,12 +213,6 @@ export const meta = { | ---- | -------- | ---------------- | ------------------------ | ---- | | ... | 原生属性 | `HTMLAttributes` | `'id', 'className', ...` | - | -Modal.Actions.Props - -| 属性 | 描述 | 类型 | 推荐值 | 默认 | -| ---- | ---- | ---- | ------ | ---- | -| - | - | - | - | - | - Modal.Action.Props | 属性 | 描述 | 类型 | 推荐值 | 默认 | @@ -202,6 +220,7 @@ export const meta = { | **passive** | 以消极的状态显示按钮 | `boolean` | - | `false` | | **disabled** | 禁用按钮 | `boolean` | - | `false` | | **onClick** | 按钮的点击事件 | [(event: ModalActionEvent) => void](#modalactionevent) | - | - | +| **loading** | 显示加载状态指示器 | `boolean` | - | `false` | | ... | 原生属性 | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | useModal