mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] NoticeBar: add right-icon prop
This commit is contained in:
parent
152ee6a90d
commit
dec1e4cee8
@ -54,6 +54,7 @@
|
|||||||
## NoticeBar
|
## NoticeBar
|
||||||
|
|
||||||
- 新增`left-icon`插槽
|
- 新增`left-icon`插槽
|
||||||
|
- 新增`right-icon`插槽
|
||||||
|
|
||||||
### Sku
|
### Sku
|
||||||
|
|
||||||
|
@ -77,9 +77,7 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
const { mode } = this;
|
const { slots, mode, leftIcon, onClickIcon } = this;
|
||||||
|
|
||||||
const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : '';
|
|
||||||
|
|
||||||
const barStyle = {
|
const barStyle = {
|
||||||
color: this.color,
|
color: this.color,
|
||||||
@ -92,20 +90,41 @@ export default sfc({
|
|||||||
animationDuration: this.duration + 's'
|
animationDuration: this.duration + 's'
|
||||||
};
|
};
|
||||||
|
|
||||||
const LeftIcon =
|
function LeftIcon() {
|
||||||
this.slots('left-icon') ||
|
const slot = slots('left-icon');
|
||||||
(this.leftIcon && <Icon class={bem('left-icon')} name={this.leftIcon} />);
|
|
||||||
|
if (slot) {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftIcon) {
|
||||||
|
return <Icon class={bem('left-icon')} name={leftIcon} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function RightIcon() {
|
||||||
|
const slot = slots('right-icon');
|
||||||
|
|
||||||
|
if (slot) {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : '';
|
||||||
|
if (iconName) {
|
||||||
|
return <Icon class={bem('right-icon')} name={iconName} onClick={onClickIcon} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
vShow={this.showNoticeBar}
|
vShow={this.showNoticeBar}
|
||||||
class={bem({ withicon: mode, wrapable: this.wrapable })}
|
class={bem({ wrapable: this.wrapable })}
|
||||||
style={barStyle}
|
style={barStyle}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.$emit('click');
|
this.$emit('click');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{LeftIcon}
|
{LeftIcon()}
|
||||||
<div ref="wrap" class={bem('wrap')}>
|
<div ref="wrap" class={bem('wrap')}>
|
||||||
<div
|
<div
|
||||||
ref="content"
|
ref="content"
|
||||||
@ -121,9 +140,7 @@ export default sfc({
|
|||||||
{this.slots() || this.text}
|
{this.slots() || this.text}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{iconName && (
|
{RightIcon()}
|
||||||
<Icon class={bem('right-icon')} name={iconName} onClick={this.onClickIcon} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,14 @@
|
|||||||
color: @orange-dark;
|
color: @orange-dark;
|
||||||
background-color: @orange-light;
|
background-color: @orange-light;
|
||||||
|
|
||||||
&__left-icon {
|
&__left-icon,
|
||||||
|
&__right-icon {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
min-width: 22px;
|
min-width: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__right-icon {
|
&__right-icon {
|
||||||
top: 50%;
|
text-align: right;
|
||||||
right: 15px;
|
|
||||||
font-size: 16px;
|
|
||||||
position: absolute;
|
|
||||||
margin-top: -0.5em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__wrap {
|
&__wrap {
|
||||||
@ -63,11 +60,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&--withicon {
|
|
||||||
position: relative;
|
|
||||||
padding-right: 40px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`left-icon slot 1`] = `
|
exports[`icon slot 1`] = `
|
||||||
<div class="van-notice-bar">Custom Left Icon<div class="van-notice-bar__wrap">
|
<div class="van-notice-bar">Custom Left Icon<div class="van-notice-bar__wrap">
|
||||||
<div class="van-notice-bar__content" style="padding-left: 0px; animation-delay: 1s; animation-duration: 0s;">
|
<div class="van-notice-bar__content" style="padding-left: 0px; animation-delay: 1s; animation-duration: 0s;">
|
||||||
Content
|
Content
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>Custom Right Icon</div>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
|
@ -13,12 +13,13 @@ test('close event', () => {
|
|||||||
expect(wrapper.emitted('close')).toBeTruthy();
|
expect(wrapper.emitted('close')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('left-icon slot', () => {
|
test('icon slot', () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
template: `
|
template: `
|
||||||
<notice-bar>
|
<notice-bar>
|
||||||
Content
|
Content
|
||||||
<template v-slot:left-icon>Custom Left Icon</template>
|
<template v-slot:left-icon>Custom Left Icon</template>
|
||||||
|
<template v-slot:right-icon>Custom Right Icon</template>
|
||||||
</notice-bar>
|
</notice-bar>
|
||||||
`,
|
`,
|
||||||
components: {
|
components: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user