Skip to content

Commit 5fafc70

Browse files
committed
feat(dialog): the imperative call returns the trigger
1 parent f950b69 commit 5fafc70

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

src/dialog/README.en-US.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ t-class-content | \-
4747
### CSS Variables
4848

4949
The component provides the following CSS variables, which can be used to customize styles.
50-
Name | Default Value | Description
50+
51+
Name | Default Value | Description
5152
-- | -- | --
52-
--td-dialog-body-max-height | 912rpx | -
53-
--td-dialog-border-radius | @radius-extra-large | -
54-
--td-dialog-close-color | @text-color-placeholder | -
55-
--td-dialog-content-color | @text-color-secondary | -
56-
--td-dialog-content-font-size | 32rpx | -
57-
--td-dialog-content-line-height | 48rpx | -
58-
--td-dialog-title-color | @text-color-primary | -
59-
--td-dialog-title-font-size | 36rpx | -
60-
--td-dialog-title-line-height | 52rpx | -
61-
--td-dialog-width | 622rpx | -
53+
--td-dialog-body-max-height | 912rpx | -
54+
--td-dialog-border-radius | @radius-extra-large | -
55+
--td-dialog-close-color | @text-color-placeholder | -
56+
--td-dialog-content-color | @text-color-secondary | -
57+
--td-dialog-content-font-size | 32rpx | -
58+
--td-dialog-content-line-height | 48rpx | -
59+
--td-dialog-title-color | @text-color-primary | -
60+
--td-dialog-title-font-size | 36rpx | -
61+
--td-dialog-title-line-height | 52rpx | -
62+
--td-dialog-width | 622rpx | -

src/dialog/README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ isComponent: true
66
---
77

88
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-97%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-94%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-82%25-blue" /></span>
9+
910
## 引入
1011

1112
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
@@ -51,6 +52,7 @@ isComponent: true
5152
{{ status }}
5253

5354
### 组件用法
55+
5456
#### 命令调用
5557

5658
{{ command }}
@@ -108,15 +110,16 @@ t-class-content | 内容样式类
108110
### CSS Variables
109111

110112
组件提供了下列 CSS 变量,可用于自定义样式。
111-
名称 | 默认值 | 描述
113+
114+
名称 | 默认值 | 描述
112115
-- | -- | --
113-
--td-dialog-body-max-height | 912rpx | -
114-
--td-dialog-border-radius | @radius-extra-large | -
115-
--td-dialog-close-color | @text-color-placeholder | -
116-
--td-dialog-content-color | @text-color-secondary | -
117-
--td-dialog-content-font-size | 32rpx | -
118-
--td-dialog-content-line-height | 48rpx | -
119-
--td-dialog-title-color | @text-color-primary | -
120-
--td-dialog-title-font-size | 36rpx | -
121-
--td-dialog-title-line-height | 52rpx | -
122-
--td-dialog-width | 622rpx | -
116+
--td-dialog-body-max-height | 912rpx | -
117+
--td-dialog-border-radius | @radius-extra-large | -
118+
--td-dialog-close-color | @text-color-placeholder | -
119+
--td-dialog-content-color | @text-color-secondary | -
120+
--td-dialog-content-font-size | 32rpx | -
121+
--td-dialog-content-line-height | 48rpx | -
122+
--td-dialog-title-color | @text-color-primary | -
123+
--td-dialog-title-font-size | 36rpx | -
124+
--td-dialog-title-line-height | 52rpx | -
125+
--td-dialog-width | 622rpx | -

src/dialog/_example/command/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Component({
1313
};
1414

1515
Dialog.confirm(dialogConfig)
16-
.then(() => console.log('点击了确定'))
17-
.catch(() => console.log('点击了取消'));
16+
.then((data) => console.log('点击了确定', data))
17+
.catch((data) => console.log('点击了取消', data));
1818
},
1919
},
2020
});

src/dialog/dialog.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,30 @@ export default class Dialog extends SuperComponent {
110110

111111
onConfirm() {
112112
this.triggerEvent('confirm');
113+
113114
if (this._onConfirm) {
114-
this._onConfirm();
115+
this._onConfirm({ trigger: 'confirm' });
115116
this.close();
116117
}
117118
},
118119

119120
onCancel() {
120-
this.triggerEvent('close', { trigger: 'cancel' });
121+
const trigger = { trigger: 'cancel' };
122+
121123
this.triggerEvent('cancel');
124+
this.triggerEvent('close', trigger);
122125

123126
if (this._onCancel) {
124-
this._onCancel();
127+
this._onCancel(trigger);
125128
this.close();
126129
}
127130
},
128131

129132
onClose() {
130-
this.triggerEvent('close', { trigger: 'close-btn' });
133+
const trigger = { trigger: 'close-btn' };
134+
135+
this.triggerEvent('close', trigger);
136+
this._onCancel?.(trigger);
131137
this.close();
132138
},
133139

@@ -136,11 +142,15 @@ export default class Dialog extends SuperComponent {
136142
},
137143

138144
overlayClick() {
145+
this.triggerEvent('overlay-click');
146+
139147
if (this.properties.closeOnOverlayClick) {
140-
this.triggerEvent('close', { trigger: 'overlay' });
148+
const trigger = { trigger: 'overlay' };
149+
150+
this.triggerEvent('close', trigger);
151+
this._onCancel?.(trigger);
141152
this.close();
142153
}
143-
this.triggerEvent('overlay-click');
144154
},
145155

146156
onActionTap(index: number) {

0 commit comments

Comments
 (0)