mirror of https://github.com/ElemeFE/element
MessageBox: add chalk theme (#7029)
* Message Box: add chalk theme * Message Box: doc fix * Message Box: change prop name into centerpull/7041/head
parent
43ecb8818c
commit
7e365e244c
|
@ -97,6 +97,25 @@
|
||||||
this.$alert('<strong>This is <i>HTML</i> string</strong>', 'HTML String', {
|
this.$alert('<strong>This is <i>HTML</i> string</strong>', 'HTML String', {
|
||||||
dangerouslyUseHTMLString: true
|
dangerouslyUseHTMLString: true
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
open6() {
|
||||||
|
this.$confirm('This will permanently delete the file. Continue?', 'Warning', {
|
||||||
|
confirmButtonText: 'OK',
|
||||||
|
cancelButtonText: 'Cancel',
|
||||||
|
type: 'warning',
|
||||||
|
center: true
|
||||||
|
}).then(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Delete completed'
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: 'Delete canceled'
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -292,6 +311,43 @@ Can be customized to show various content.
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Align in center
|
||||||
|
Align the content in center
|
||||||
|
|
||||||
|
:::demo set `center` to `true` will align the content in center
|
||||||
|
|
||||||
|
```html
|
||||||
|
<template>
|
||||||
|
<el-button type="text" @click="open6">Click to open Message Box</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
open6() {
|
||||||
|
this.$confirm('This will permanently delete the file. Continue?', 'Warning', {
|
||||||
|
confirmButtonText: 'OK',
|
||||||
|
cancelButtonText: 'Cancel',
|
||||||
|
type: 'warning',
|
||||||
|
center: true
|
||||||
|
}).then(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Delete completed'
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: 'Delete canceled'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content.
|
Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content.
|
||||||
:::
|
:::
|
||||||
|
@ -345,3 +401,5 @@ Although `message` property supports HTML strings, dynamically rendering arbitra
|
||||||
| inputPattern | regexp for the input | regexp | — | — |
|
| inputPattern | regexp for the input | regexp | — | — |
|
||||||
| inputValidator | validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage | function | — | — |
|
| inputValidator | validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage | function | — | — |
|
||||||
| inputErrorMessage | error message when validation fails | string | — | Illegal input |
|
| inputErrorMessage | error message when validation fails | string | — | Illegal input |
|
||||||
|
| center | whether to align the content in center | boolean | — | false |
|
||||||
|
| roundButton | whether to use round button | boolean | — | false |
|
|
@ -98,6 +98,25 @@
|
||||||
this.$alert('<strong>这是 <i>HTML</i> 片段</strong>', 'HTML 片段', {
|
this.$alert('<strong>这是 <i>HTML</i> 片段</strong>', 'HTML 片段', {
|
||||||
dangerouslyUseHTMLString: true
|
dangerouslyUseHTMLString: true
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
open6() {
|
||||||
|
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
center: true
|
||||||
|
}).then(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: '删除成功!'
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: '已取消删除'
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -290,6 +309,43 @@
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### 居中布局
|
||||||
|
内容支持居中布局
|
||||||
|
|
||||||
|
:::demo 将 `center` 为 `true` 将采用居中布局
|
||||||
|
|
||||||
|
```html
|
||||||
|
<template>
|
||||||
|
<el-button type="text" @click="open6">点击打开 Message Box</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
open6() {
|
||||||
|
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
center: true
|
||||||
|
}).then(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: '删除成功!'
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: '已取消删除'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
:::warning
|
:::warning
|
||||||
`message` 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。因此在 `dangerouslyUseHTMLString` 打开的情况下,请确保 `message` 的内容是可信的,**永远不要**将用户提交的内容赋值给 `message` 属性。
|
`message` 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。因此在 `dangerouslyUseHTMLString` 打开的情况下,请确保 `message` 的内容是可信的,**永远不要**将用户提交的内容赋值给 `message` 属性。
|
||||||
:::
|
:::
|
||||||
|
@ -339,3 +395,5 @@ import { MessageBox } from 'element-ui';
|
||||||
| inputPattern | 输入框的校验表达式 | regexp | — | — |
|
| inputPattern | 输入框的校验表达式 | regexp | — | — |
|
||||||
| inputValidator | 输入框的校验函数。可以返回布尔值或字符串,若返回一个字符串, 则返回结果会被赋值给 inputErrorMessage | function | — | — |
|
| inputValidator | 输入框的校验函数。可以返回布尔值或字符串,若返回一个字符串, 则返回结果会被赋值给 inputErrorMessage | function | — | — |
|
||||||
| inputErrorMessage | 校验未通过时的提示文本 | string | — | 输入的数据不合法! |
|
| inputErrorMessage | 校验未通过时的提示文本 | string | — | 输入的数据不合法! |
|
||||||
|
| center | 是否居中布局 | boolean | — | false |
|
||||||
|
| roundButton | 是否使用圆角按钮 | boolean | — | false |
|
||||||
|
|
|
@ -25,7 +25,9 @@ const defaults = {
|
||||||
cancelButtonClass: '',
|
cancelButtonClass: '',
|
||||||
customClass: '',
|
customClass: '',
|
||||||
beforeClose: null,
|
beforeClose: null,
|
||||||
dangerouslyUseHTMLString: false
|
dangerouslyUseHTMLString: false,
|
||||||
|
center: false,
|
||||||
|
roundButton: false
|
||||||
};
|
};
|
||||||
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<transition name="msgbox-fade">
|
<transition name="msgbox-fade">
|
||||||
<div class="el-message-box__wrapper" tabindex="-1" v-show="visible" @click.self="handleWrapperClick">
|
<div class="el-message-box__wrapper" tabindex="-1" v-show="visible" @click.self="handleWrapperClick">
|
||||||
<div class="el-message-box" :class="customClass">
|
<div class="el-message-box" :class="[customClass, center && 'el-message-box--center']">
|
||||||
<div class="el-message-box__header" v-if="title !== undefined">
|
<div class="el-message-box__header" v-if="title !== undefined">
|
||||||
<div class="el-message-box__title">{{ title }}</div>
|
<div class="el-message-box__title">
|
||||||
|
<div class="el-message-box__status" :class="[ typeClass ]" v-if="typeClass && center"></div>
|
||||||
|
<span>{{ title }}</span>
|
||||||
|
</div>
|
||||||
<button type="button" class="el-message-box__headerbtn" aria-label="Close"
|
<button type="button" class="el-message-box__headerbtn" aria-label="Close"
|
||||||
v-if="showClose" @click="handleAction('cancel')">
|
v-if="showClose" @click="handleAction('cancel')">
|
||||||
<i class="el-message-box__close el-icon-close"></i>
|
<i class="el-message-box__close el-icon-close"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="el-message-box__content" v-if="message !== ''">
|
<div class="el-message-box__content" v-if="message !== ''">
|
||||||
<div class="el-message-box__status" :class="[ typeClass ]"></div>
|
<div class="el-message-box__status" :class="[ typeClass ]" v-if="typeClass && !center"></div>
|
||||||
<div class="el-message-box__message" :style="{ 'margin-left': typeClass ? '50px' : '0' }">
|
<div class="el-message-box__message">
|
||||||
<slot>
|
<slot>
|
||||||
<p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
|
<p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
|
||||||
<p v-else v-html="message"></p>
|
<p v-else v-html="message"></p>
|
||||||
|
@ -27,6 +30,8 @@
|
||||||
:loading="cancelButtonLoading"
|
:loading="cancelButtonLoading"
|
||||||
:class="[ cancelButtonClasses ]"
|
:class="[ cancelButtonClasses ]"
|
||||||
v-show="showCancelButton"
|
v-show="showCancelButton"
|
||||||
|
:round="roundButton"
|
||||||
|
size="small"
|
||||||
@click.native="handleAction('cancel')">
|
@click.native="handleAction('cancel')">
|
||||||
{{ cancelButtonText || t('el.messagebox.cancel') }}
|
{{ cancelButtonText || t('el.messagebox.cancel') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -35,6 +40,8 @@
|
||||||
ref="confirm"
|
ref="confirm"
|
||||||
:class="[ confirmButtonClasses ]"
|
:class="[ confirmButtonClasses ]"
|
||||||
v-show="showConfirmButton"
|
v-show="showConfirmButton"
|
||||||
|
:round="roundButton"
|
||||||
|
size="small"
|
||||||
@click.native="handleAction('confirm')">
|
@click.native="handleAction('confirm')">
|
||||||
{{ confirmButtonText || t('el.messagebox.confirm') }}
|
{{ confirmButtonText || t('el.messagebox.confirm') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -81,6 +88,14 @@
|
||||||
},
|
},
|
||||||
closeOnHashChange: {
|
closeOnHashChange: {
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
center: {
|
||||||
|
default: false,
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
|
roundButton: {
|
||||||
|
default: false,
|
||||||
|
type: Boolean
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ $--fill-base: $--color-white;
|
||||||
-------------------------- */
|
-------------------------- */
|
||||||
$--font-size-base: 14px;
|
$--font-size-base: 14px;
|
||||||
$--font-size-small: 13px;
|
$--font-size-small: 13px;
|
||||||
|
$--font-size-large: 18px;
|
||||||
$--font-color-base: #5a5e66;
|
$--font-color-base: #5a5e66;
|
||||||
$--font-color-disabled-base: #bbb;
|
$--font-color-disabled-base: #bbb;
|
||||||
$--font-weight-primary: 500;
|
$--font-weight-primary: 500;
|
||||||
|
@ -251,11 +252,12 @@ $--alert-icon-large-size: 28px;
|
||||||
/* Message Box
|
/* Message Box
|
||||||
-------------------------- */
|
-------------------------- */
|
||||||
$--msgbox-width: 420px;
|
$--msgbox-width: 420px;
|
||||||
$--msgbox-border-radius: 3px;
|
$--msgbox-border-radius: 4px;
|
||||||
$--msgbox-font-size: 16px;
|
$--msgbox-font-size: $--font-size-large;
|
||||||
$--msgbox-content-font-size: 14px;
|
$--msgbox-content-font-size: $--font-size-base;
|
||||||
$--msgbox-content-color: $--link-color;
|
$--msgbox-content-color: $--color-text-regular;
|
||||||
$--msgbox-error-font-size: 12px;
|
$--msgbox-error-font-size: 12px;
|
||||||
|
$--msgbox-padding-primary: 15px;
|
||||||
|
|
||||||
$--msgbox-success-color: $--color-success;
|
$--msgbox-success-color: $--color-success;
|
||||||
$--msgbox-info-color: $--color-info;
|
$--msgbox-info-color: $--color-info;
|
||||||
|
|
|
@ -5,15 +5,19 @@
|
||||||
@import "input";
|
@import "input";
|
||||||
|
|
||||||
@include b(message-box) {
|
@include b(message-box) {
|
||||||
text-align: left;
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
width: $--msgbox-width;
|
||||||
|
padding-bottom: 10px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
background-color: $--color-white;
|
background-color: $--color-white;
|
||||||
width: $--msgbox-width;
|
|
||||||
border-radius: $--msgbox-border-radius;
|
border-radius: $--msgbox-border-radius;
|
||||||
|
border: 1px solid $--border-color-lighter;
|
||||||
font-size: $--msgbox-font-size;
|
font-size: $--msgbox-font-size;
|
||||||
|
box-shadow: $--box-shadow-light;
|
||||||
|
text-align: left;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
|
|
||||||
@include e(wrapper) {
|
@include e(wrapper) {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -21,6 +25,7 @@
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
content: "";
|
content: "";
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -32,21 +37,31 @@
|
||||||
|
|
||||||
@include e(header) {
|
@include e(header) {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 20px 20px 0;
|
padding: $--msgbox-padding-primary;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(title) {
|
||||||
|
padding-left: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
font-size: $--msgbox-font-size;
|
||||||
|
line-height: 1;
|
||||||
|
color: $--color-text-primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
@include e(headerbtn) {
|
@include e(headerbtn) {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 19px;
|
top: $--msgbox-padding-primary;
|
||||||
right: 20px;
|
right: $--msgbox-padding-primary;
|
||||||
background: transparent;
|
padding: 0;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
padding: 0;
|
background: transparent;
|
||||||
|
font-size: 12px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
.el-message-box__close {
|
.el-message-box__close {
|
||||||
color: #999;
|
color: $--color-info;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus, &:hover {
|
&:focus, &:hover {
|
||||||
|
@ -58,14 +73,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@include e(content) {
|
@include e(content) {
|
||||||
padding: 30px 20px;
|
position: relative;
|
||||||
|
padding: 10px $--msgbox-padding-primary;
|
||||||
color: $--msgbox-content-color;
|
color: $--msgbox-content-color;
|
||||||
font-size: $--msgbox-content-font-size;
|
font-size: $--msgbox-content-font-size;
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@include e(input) {
|
@include e(input) {
|
||||||
padding-top: 15px;
|
padding-top: 15px;
|
||||||
|
|
||||||
& input.invalid {
|
& input.invalid {
|
||||||
border-color: $--color-danger;
|
border-color: $--color-danger;
|
||||||
&:focus {
|
&:focus {
|
||||||
|
@ -74,49 +90,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@include e(errormsg) {
|
|
||||||
color: $--color-danger;
|
|
||||||
font-size: $--msgbox-error-font-size;
|
|
||||||
min-height: 18px;
|
|
||||||
margin-top: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include e(title) {
|
|
||||||
padding-left: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
font-size: $--msgbox-font-size;
|
|
||||||
font-weight: bold;
|
|
||||||
height: 18px;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include e(message) {
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
& p {
|
|
||||||
margin: 0;
|
|
||||||
line-height: 1.4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@include e(btns) {
|
|
||||||
padding: 10px 20px 15px;
|
|
||||||
text-align: right;
|
|
||||||
|
|
||||||
& button:nth-child(2) {
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@include e(btns-reverse) {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include e(status) {
|
@include e(status) {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
font-size: 36px !important;
|
font-size: 24px !important;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
// 防止图标切割
|
||||||
|
padding-left: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ .el-message-box__message {
|
||||||
|
padding-left: 36px;
|
||||||
|
padding-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
&.el-icon-circle-check {
|
&.el-icon-circle-check {
|
||||||
color: $--msgbox-success-color;
|
color: $--msgbox-success-color;
|
||||||
|
@ -134,6 +122,74 @@
|
||||||
color: $--msgbox-danger-color;
|
color: $--msgbox-danger-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@include e(message) {
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
& p {
|
||||||
|
margin: 0;
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(errormsg) {
|
||||||
|
color: $--color-danger;
|
||||||
|
font-size: $--msgbox-error-font-size;
|
||||||
|
min-height: 18px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(btns) {
|
||||||
|
padding: 5px 15px 0;
|
||||||
|
text-align: right;
|
||||||
|
|
||||||
|
& button:nth-child(2) {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(btns-reverse) {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// centerAlign 布局
|
||||||
|
@include m(center) {
|
||||||
|
padding-bottom: 30px;
|
||||||
|
|
||||||
|
@include e(header) {
|
||||||
|
padding-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(title) {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(status) {
|
||||||
|
position: relative;
|
||||||
|
top: auto;
|
||||||
|
padding-right: 5px;
|
||||||
|
text-align: center;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(message) {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e((btns, content)) {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include e(content) {
|
||||||
|
$padding-horizontal: $--msgbox-padding-primary + 12px;
|
||||||
|
|
||||||
|
padding-left: $padding-horizontal;
|
||||||
|
padding-right: $padding-horizontal;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.msgbox-fade-enter-active {
|
.msgbox-fade-enter-active {
|
||||||
|
|
Loading…
Reference in New Issue