mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Popup: add position default value
This commit is contained in:
parent
0288fb35a4
commit
70550a500f
@ -45,7 +45,7 @@ function ActionSheet(
|
|||||||
function Header() {
|
function Header() {
|
||||||
if (title) {
|
if (title) {
|
||||||
return (
|
return (
|
||||||
<div class={[bem('header'), 'van-hairline--top-bottom']}>
|
<div class={[bem('header'), 'van-hairline--bottom']}>
|
||||||
{title}
|
{title}
|
||||||
<Icon name="close" class={bem('close')} onClick={onCancel} />
|
<Icon name="close" class={bem('close')} onClick={onCancel} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -90,15 +90,6 @@ export default {
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
showDialog() {
|
|
||||||
this.$dialog.confirm({
|
|
||||||
title: 'confirm标题',
|
|
||||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -108,36 +99,25 @@ export default {
|
|||||||
|
|
||||||
.demo-popup {
|
.demo-popup {
|
||||||
.van-button {
|
.van-button {
|
||||||
margin: 10px 0 10px 15px;
|
margin-left: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.van-popup {
|
.van-popup {
|
||||||
width: 60%;
|
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
&--center {
|
||||||
|
width: 60%;
|
||||||
|
}
|
||||||
|
|
||||||
&--bottom {
|
&--bottom {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.van-tabs__content {
|
|
||||||
height: 156px;
|
|
||||||
overflow-y: scroll;
|
|
||||||
-webkit-overflow-scrolling: touch;
|
|
||||||
}
|
|
||||||
|
|
||||||
.van-tab__pane:not(:first-child) {
|
|
||||||
padding: 10px;
|
|
||||||
line-height: 1.4;
|
|
||||||
color: @gray-darker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&--top {
|
&--top {
|
||||||
color: @white;
|
color: @white;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 0;
|
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
background-color: rgba(0, 0, 0, 0.8);
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ Vue.use(Popup);
|
|||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
#### Basic Usage
|
#### Basic Usage
|
||||||
|
|
||||||
Popup is located in the middle of the screen by default
|
Popup is located in the middle of the screen by default
|
||||||
|
|
||||||
```html
|
```html
|
||||||
@ -27,6 +28,7 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### Position
|
#### Position
|
||||||
|
|
||||||
Use `position` prop to set popup display position
|
Use `position` prop to set popup display position
|
||||||
|
|
||||||
```html
|
```html
|
||||||
@ -41,7 +43,7 @@ Use `position` prop to set popup display position
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| v-model | Whether to show popup | `Boolean` | `false` |
|
| v-model | Whether to show popup | `Boolean` | `false` |
|
||||||
| overlay | Whether to show overlay | `Boolean` | `true` |
|
| overlay | Whether to show overlay | `Boolean` | `true` |
|
||||||
| position | Can be set to `top` `bottom` `right` `left` | `String` | - |
|
| position | Can be set to `top` `bottom` `right` `left` | `String` | `center` |
|
||||||
| overlay-class | Custom overlay class | `String` | - |
|
| overlay-class | Custom overlay class | `String` | - |
|
||||||
| overlay-style | Custom overlay style | `Object` | - |
|
| overlay-style | Custom overlay style | `Object` | - |
|
||||||
| close-on-click-overlay | Close popup when click overlay | `Boolean` | `true` |
|
| close-on-click-overlay | Close popup when click overlay | `Boolean` | `true` |
|
||||||
|
@ -7,8 +7,11 @@ export default sfc({
|
|||||||
mixins: [PopupMixin],
|
mixins: [PopupMixin],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
position: String,
|
|
||||||
transition: String,
|
transition: String,
|
||||||
|
position: {
|
||||||
|
type: String,
|
||||||
|
default: 'center'
|
||||||
|
},
|
||||||
overlay: {
|
overlay: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
@ -26,7 +29,9 @@ export default sfc({
|
|||||||
|
|
||||||
const { position } = this;
|
const { position } = this;
|
||||||
const emit = eventName => event => this.$emit(eventName, event);
|
const emit = eventName => event => this.$emit(eventName, event);
|
||||||
const transitionName = this.transition || (position ? `van-popup-slide-${position}` : 'van-fade');
|
const transitionName =
|
||||||
|
this.transition ||
|
||||||
|
(position === 'center' ? 'van-fade' : `van-popup-slide-${position}`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<transition
|
<transition
|
||||||
@ -34,7 +39,11 @@ export default sfc({
|
|||||||
onAfterEnter={emit('opened')}
|
onAfterEnter={emit('opened')}
|
||||||
onAfterLeave={emit('closed')}
|
onAfterLeave={emit('closed')}
|
||||||
>
|
>
|
||||||
<div vShow={this.value} class={bem({ [position]: position })} onClick={emit('click')}>
|
<div
|
||||||
|
vShow={this.value}
|
||||||
|
class={bem({ [position]: position })}
|
||||||
|
onClick={emit('click')}
|
||||||
|
>
|
||||||
{this.slots()}
|
{this.slots()}
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -7,20 +7,21 @@
|
|||||||
|
|
||||||
&-popup {
|
&-popup {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
background-color: @white;
|
background-color: @white;
|
||||||
transition: .3s ease-out;
|
transition: .3s ease-out;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
transform: translate3d(-50%, -50%, 0);
|
|
||||||
|
&--center {
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate3d(-50%, -50%, 0);
|
||||||
|
}
|
||||||
|
|
||||||
&--top {
|
&--top {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: auto;
|
|
||||||
bottom: auto;
|
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate3d(-50%, 0, 0);
|
transform: translate3d(-50%, 0, 0);
|
||||||
}
|
}
|
||||||
@ -28,24 +29,18 @@
|
|||||||
&--right {
|
&--right {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: auto;
|
|
||||||
left: auto;
|
|
||||||
transform: translate3d(0, -50%, 0);
|
transform: translate3d(0, -50%, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
&--bottom {
|
&--bottom {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: auto;
|
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
right: auto;
|
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate3d(-50%, 0, 0);
|
transform: translate3d(-50%, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
&--left {
|
&--left {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
right: auto;
|
|
||||||
bottom: auto;
|
|
||||||
left: 0;
|
left: 0;
|
||||||
transform: translate3d(0, -50%, 0);
|
transform: translate3d(0, -50%, 0);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`reset z-index 1`] = `<div class="van-popup" name="van-fade"></div>`;
|
exports[`reset z-index 1`] = `<div class="van-popup van-popup--center" name="van-fade"></div>`;
|
||||||
|
@ -10,7 +10,8 @@ Vue.use(Popup);
|
|||||||
### 代码演示
|
### 代码演示
|
||||||
|
|
||||||
#### 基础用法
|
#### 基础用法
|
||||||
`popup`默认从中间弹出
|
|
||||||
|
`Popup`默认从中间弹出
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-popup v-model="show">内容</van-popup>
|
<van-popup v-model="show">内容</van-popup>
|
||||||
@ -27,7 +28,8 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### 弹出位置
|
#### 弹出位置
|
||||||
通过`position`属性设置 Popup 弹出位置
|
|
||||||
|
通过`position`属性设置`Popup`弹出位置
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-popup v-model="show" position="top" :overlay="false">
|
<van-popup v-model="show" position="top" :overlay="false">
|
||||||
@ -41,7 +43,7 @@ export default {
|
|||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| v-model | 当前组件是否显示 | `Boolean` | `false` | - |
|
| v-model | 当前组件是否显示 | `Boolean` | `false` | - |
|
||||||
| overlay | 是否显示蒙层 | `Boolean` | `true` | - |
|
| overlay | 是否显示蒙层 | `Boolean` | `true` | - |
|
||||||
| position | 位置,可选值为 `top` `bottom` <br> `right` `left` | `String` | - | - |
|
| position | 位置,可选值为 `top` `bottom` <br> `right` `left` | `String` | `center` | - |
|
||||||
| overlay-class | 自定义蒙层类名 | `String` | - | - |
|
| overlay-class | 自定义蒙层类名 | `String` | - | - |
|
||||||
| overlay-style | 自定义蒙层样式 | `Object` | - | - |
|
| overlay-style | 自定义蒙层样式 | `Object` | - | - |
|
||||||
| transition | transition 名称 | `String` | - | - |
|
| transition | transition 名称 | `String` | - | - |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user