mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 02:16:12 +08:00
feat(Popup): add close-icon prop (#4366)
This commit is contained in:
parent
f43be4dd86
commit
7b66aef056
@ -58,6 +58,15 @@ Use `position` prop to set popup display position
|
|||||||
position="bottom"
|
position="bottom"
|
||||||
:style="{ height: '20%' }"
|
:style="{ height: '20%' }"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Custom Icon -->
|
||||||
|
<van-popup
|
||||||
|
v-model="show"
|
||||||
|
closeable
|
||||||
|
close-icon="close"
|
||||||
|
position="bottom"
|
||||||
|
:style="{ height: '20%' }"
|
||||||
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Round Corner
|
### Round Corner
|
||||||
@ -121,9 +130,11 @@ export default {
|
|||||||
| lock-scroll | Whether to lock background scroll | *boolean* | `true` | - |
|
| lock-scroll | Whether to lock background scroll | *boolean* | `true` | - |
|
||||||
| lazy-render | Whether to lazy render util appeared | *boolean* | `true` | - |
|
| lazy-render | Whether to lazy render util appeared | *boolean* | `true` | - |
|
||||||
| close-on-click-overlay | Whether to close when click overlay | *boolean* | `true` | - |
|
| close-on-click-overlay | Whether to close when click overlay | *boolean* | `true` | - |
|
||||||
|
| closeable | Whether to show close icon | *boolean* | `false` | 2.2.0 |
|
||||||
|
| close-icon | Close icon name | *string* | `cross` | 2.2.0 |
|
||||||
| transition | Transition | *string* | `popup-slide` | - |
|
| transition | Transition | *string* | `popup-slide` | - |
|
||||||
| get-container | Return the mount node for Popup | *string \| () => HTMLElement* | - | - |
|
| get-container | Return the mount node for Popup | *string \| () => HTMLElement* | - | - |
|
||||||
| closeable | Whether to show close icon | *boolean* | `false` | 2.2.0 |
|
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export default {
|
|||||||
|
|
||||||
### 关闭图标
|
### 关闭图标
|
||||||
|
|
||||||
设置`closeable`属性后,会在弹出层的右上角显示关闭图标
|
设置`closeable`属性后,会在弹出层的右上角显示关闭图标,并且可以通过`close-icon`属性自定义图标
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-popup
|
<van-popup
|
||||||
@ -66,6 +66,15 @@ export default {
|
|||||||
position="bottom"
|
position="bottom"
|
||||||
:style="{ height: '20%' }"
|
:style="{ height: '20%' }"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 自定义图标 -->
|
||||||
|
<van-popup
|
||||||
|
v-model="show"
|
||||||
|
closeable
|
||||||
|
close-icon="close"
|
||||||
|
position="bottom"
|
||||||
|
:style="{ height: '20%' }"
|
||||||
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
### 圆角弹窗
|
### 圆角弹窗
|
||||||
@ -133,6 +142,7 @@ export default {
|
|||||||
| lazy-render | 是否在显示弹层时才渲染节点 | *boolean* | `true` | - |
|
| lazy-render | 是否在显示弹层时才渲染节点 | *boolean* | `true` | - |
|
||||||
| close-on-click-overlay | 是否在点击遮罩层后关闭 | *boolean* | `true` | - |
|
| close-on-click-overlay | 是否在点击遮罩层后关闭 | *boolean* | `true` | - |
|
||||||
| closeable | 是否显示关闭图标 | *boolean* | `false` | 2.2.0 |
|
| closeable | 是否显示关闭图标 | *boolean* | `false` | 2.2.0 |
|
||||||
|
| close-icon | 关闭图标名称或图片链接 | *string* | `cross` | 2.2.0 |
|
||||||
| transition | 动画类名,用法与 Vue 原生`transtion`组件的`name`属性一致 | *string* | - | - |
|
| transition | 动画类名,用法与 Vue 原生`transtion`组件的`name`属性一致 | *string* | - | - |
|
||||||
| get-container | 指定挂载的节点,可以传入选择器,<br>或一个返回节点的函数 | *string \| () => HTMLElement* | - | - |
|
| get-container | 指定挂载的节点,可以传入选择器,<br>或一个返回节点的函数 | *string \| () => HTMLElement* | - | - |
|
||||||
|
|
||||||
|
@ -28,6 +28,15 @@
|
|||||||
<demo-block v-if="!$attrs.weapp" :title="$t('closeIcon')">
|
<demo-block v-if="!$attrs.weapp" :title="$t('closeIcon')">
|
||||||
<van-button type="primary" @click="showCloseIcon = true">{{ $t('closeIcon') }}</van-button>
|
<van-button type="primary" @click="showCloseIcon = true">{{ $t('closeIcon') }}</van-button>
|
||||||
<van-popup v-model="showCloseIcon" closeable position="bottom" :style="{ height: '20%' }" />
|
<van-popup v-model="showCloseIcon" closeable position="bottom" :style="{ height: '20%' }" />
|
||||||
|
|
||||||
|
<van-button type="primary" @click="showCustomCloseIcon = true">{{ $t('customCloseIcon') }}</van-button>
|
||||||
|
<van-popup
|
||||||
|
v-model="showCustomCloseIcon"
|
||||||
|
closeable
|
||||||
|
close-icon="close"
|
||||||
|
position="bottom"
|
||||||
|
:style="{ height: '20%' }"
|
||||||
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block v-if="!$attrs.weapp" :title="$t('roundCorner')">
|
<demo-block v-if="!$attrs.weapp" :title="$t('roundCorner')">
|
||||||
@ -54,7 +63,8 @@ export default {
|
|||||||
buttonRight: '右侧弹出',
|
buttonRight: '右侧弹出',
|
||||||
getContainer: '指定挂载节点',
|
getContainer: '指定挂载节点',
|
||||||
roundCorner: '圆角弹窗',
|
roundCorner: '圆角弹窗',
|
||||||
closeIcon: '关闭图标'
|
closeIcon: '关闭图标',
|
||||||
|
customCloseIcon: '自定义图标'
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
position: 'Position',
|
position: 'Position',
|
||||||
@ -65,7 +75,8 @@ export default {
|
|||||||
buttonRight: 'From Right',
|
buttonRight: 'From Right',
|
||||||
getContainer: 'Get Container',
|
getContainer: 'Get Container',
|
||||||
roundCorner: 'Round Corner',
|
roundCorner: 'Round Corner',
|
||||||
closeIcon: 'Close Icon'
|
closeIcon: 'Close Icon',
|
||||||
|
customCloseIcon: 'Custom Icon'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -78,7 +89,8 @@ export default {
|
|||||||
showRight: false,
|
showRight: false,
|
||||||
showCloseIcon: false,
|
showCloseIcon: false,
|
||||||
showRoundCorner: false,
|
showRoundCorner: false,
|
||||||
showGetContainer: false
|
showGetContainer: false,
|
||||||
|
showCustomCloseIcon: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,10 @@ export default createComponent({
|
|||||||
duration: Number,
|
duration: Number,
|
||||||
closeable: Boolean,
|
closeable: Boolean,
|
||||||
transition: String,
|
transition: String,
|
||||||
|
closeIcon: {
|
||||||
|
type: String,
|
||||||
|
default: 'cross'
|
||||||
|
},
|
||||||
position: {
|
position: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'center'
|
default: 'center'
|
||||||
@ -64,7 +68,7 @@ export default createComponent({
|
|||||||
>
|
>
|
||||||
{this.slots()}
|
{this.slots()}
|
||||||
{this.closeable && (
|
{this.closeable && (
|
||||||
<Icon name="cross" class={bem('close-icon')} onClick={this.close} />
|
<Icon name={this.closeIcon} class={bem('close-icon')} onClick={this.close} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -89,6 +89,10 @@
|
|||||||
right: @popup-close-icon-margin;
|
right: @popup-close-icon-margin;
|
||||||
color: @popup-close-icon-color;
|
color: @popup-close-icon-color;
|
||||||
font-size: @popup-close-icon-size;
|
font-size: @popup-close-icon-size;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: .6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<!---->
|
<!---->
|
||||||
</div>
|
</div>
|
||||||
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">关闭图标</span></button>
|
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">关闭图标</span></button>
|
||||||
|
<!----> <button class="van-button van-button--primary van-button--normal"><span class="van-button__text">自定义图标</span></button>
|
||||||
<!---->
|
<!---->
|
||||||
</div>
|
</div>
|
||||||
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">圆角弹窗</span></button>
|
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">圆角弹窗</span></button>
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`close-icon prop 1`] = `
|
||||||
|
<div class="van-popup van-popup--center" name="van-fade"><i class="van-icon van-icon-success van-popup__close-icon">
|
||||||
|
<!----></i></div>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`duration prop 1`] = `<div class="van-popup van-popup--center" style="transition-duration: 0.5s;" name="van-fade"></div>`;
|
exports[`duration prop 1`] = `<div class="van-popup van-popup--center" style="transition-duration: 0.5s;" name="van-fade"></div>`;
|
||||||
|
|
||||||
exports[`reset z-index 1`] = `<div class="van-popup van-popup--center" name="van-fade"></div>`;
|
exports[`reset z-index 1`] = `<div class="van-popup van-popup--center" name="van-fade"></div>`;
|
||||||
|
@ -239,3 +239,15 @@ test('closeable prop', () => {
|
|||||||
wrapper.find('.van-popup__close-icon').trigger('click');
|
wrapper.find('.van-popup__close-icon').trigger('click');
|
||||||
expect(wrapper.emitted('input')[0][0]).toEqual(false);
|
expect(wrapper.emitted('input')[0][0]).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('close-icon prop', () => {
|
||||||
|
const wrapper = mount(Popup, {
|
||||||
|
propsData: {
|
||||||
|
value: true,
|
||||||
|
closeable: true,
|
||||||
|
closeIcon: 'success'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user