feat(Dialog): add width prop (#2141)

This commit is contained in:
neverland 2019-10-11 19:44:10 +08:00 committed by GitHub
parent a1c01090f1
commit f7379bb6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -133,6 +133,7 @@ Page({
| 参数 | 说明 | 类型 | 默认值 | 版本 | | 参数 | 说明 | 类型 | 默认值 | 版本 |
|-----------|-----------|-----------|-------------|-------------| |-----------|-----------|-----------|-------------|-------------|
| title | 标题 | *string* | - | - | | title | 标题 | *string* | - | - |
| width | 弹窗宽度,默认单位为`px` | *string \| number* | `320px` | 1.0.0 |
| message | 文本内容,支持通过`\n`换行 | *string* | - | 1.0.0 | | message | 文本内容,支持通过`\n`换行 | *string* | - | 1.0.0 |
| messageAlign | 内容对齐方式,可选值为`left` `right` | *string* | `center` | - | | messageAlign | 内容对齐方式,可选值为`left` `right` | *string* | `center` | - |
| zIndex | z-index 层级 | *number* | `100` | - | | zIndex | z-index 层级 | *number* | `100` | - |
@ -174,7 +175,8 @@ Page({
|-----------|-----------|-----------|-------------| |-----------|-----------|-----------|-------------|
| show | 是否显示弹窗 | *boolean* | - | | show | 是否显示弹窗 | *boolean* | - |
| title | 标题 | *string* | - | | title | 标题 | *string* | - |
| message | 内容 | *string* | - | | width | 弹窗宽度,默认单位为`px` | *string \| number* | `320px` | 1.0.0 |
| message | 文本内容,支持通过`\n`换行 | *string* | - |
| message-align | 内容对齐方式,可选值为`left` `right` | *string* | `center` | | message-align | 内容对齐方式,可选值为`left` `right` | *string* | `center` |
| z-index | z-index 层级 | *number* | `100` | | z-index | z-index 层级 | *number* | `100` |
| class-name | 自定义类名dialog在自定义组件内时无效 | *string* | '' | | class-name | 自定义类名dialog在自定义组件内时无效 | *string* | '' |

View File

@ -5,6 +5,7 @@ type DialogOptions = {
lang?: string; lang?: string;
show?: boolean; show?: boolean;
title?: string; title?: string;
width?: string | number;
zIndex?: number; zIndex?: number;
context?: WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance; context?: WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
message?: string; message?: string;
@ -79,6 +80,7 @@ const Dialog: Dialog = options => {
Dialog.defaultOptions = { Dialog.defaultOptions = {
show: true, show: true,
title: '', title: '',
width: null,
message: '', message: '',
zIndex: 100, zIndex: 100,
overlay: true, overlay: true,

View File

@ -1,6 +1,7 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
import { addUnit } from '../common/utils';
import { GRAY, BLUE } from '../common/color'; import { GRAY, BLUE } from '../common/color';
type Action = 'confirm' | 'cancel' | 'overlay'; type Action = 'confirm' | 'cancel' | 'overlay';
@ -22,6 +23,10 @@ VantComponent({
showCancelButton: Boolean, showCancelButton: Boolean,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
confirmButtonOpenType: String, confirmButtonOpenType: String,
width: {
type: null,
observer: 'setWidthWithUnit'
},
zIndex: { zIndex: {
type: Number, type: Number,
value: 2000 value: 2000
@ -120,6 +125,12 @@ VantComponent({
if (callback) { if (callback) {
callback(this); callback(this);
} }
},
setWidthWithUnit(val) {
this.setData({
widthWithUnit: addUnit(val)
});
} }
} }
}); });

View File

@ -4,7 +4,7 @@
overlay="{{ overlay }}" overlay="{{ overlay }}"
transition="{{ transition }}" transition="{{ transition }}"
custom-class="van-dialog {{ className }}" custom-class="van-dialog {{ className }}"
custom-style="{{ customStyle }}" custom-style="{{ widthWithUnit ? 'width: ' + widthWithUnit + ';' : '' }}{{ customStyle }}"
overlay-style="{{ overlayStyle }}" overlay-style="{{ overlayStyle }}"
close-on-click-overlay="{{ closeOnClickOverlay }}" close-on-click-overlay="{{ closeOnClickOverlay }}"
bind:close="onClickOverlay" bind:close="onClickOverlay"