[new feature] NoticeBar: add new prop wrapable

fix #1568
This commit is contained in:
rex 2019-05-09 13:58:32 +08:00 committed by GitHub
parent 34d5750e3b
commit a1ca50d003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 21 deletions

View File

@ -5,11 +5,15 @@
/> />
</demo-block> </demo-block>
<demo-block title="禁用滚动">
<van-notice-bar scrollable="{{ false }}" text="{{ text }}" />
</demo-block>
<demo-block title="通告栏模式"> <demo-block title="通告栏模式">
<van-notice-bar mode="closeable" text="{{ text }}" custom-class="demo-margin-bottom" /> <van-notice-bar mode="closeable" text="{{ text }}" custom-class="demo-margin-bottom" />
<van-notice-bar mode="link" text="{{ text }}" /> <van-notice-bar mode="link" text="{{ text }}" />
</demo-block> </demo-block>
<demo-block title="禁用滚动">
<van-notice-bar scrollable="{{ false }}" text="{{ text }}" />
</demo-block>
<demo-block title="文本换行">
<van-notice-bar wrapable scrollable="{{ false }}" text="{{ text }}" />
</demo-block>

View File

@ -6,15 +6,31 @@
line-height: 24px; line-height: 24px;
align-items: center; align-items: center;
&--within-icon { &--withicon {
position: relative; position: relative;
padding-right: 40px; padding-right: 40px;
} }
&--wrapable {
height: auto;
padding: 8px 15px;
.van-notice-bar {
&__wrap {
height: auto;
}
&__content {
position: relative;
white-space: normal;
}
}
}
&__left-icon { &__left-icon {
display: flex;
margin-right: 4px; margin-right: 4px;
vertical-align: middle; vertical-align: middle;
display: flex;
align-items: center; align-items: center;
} }
@ -25,7 +41,7 @@
font-size: 16px; font-size: 16px;
} }
&__content-wrap { &__wrap {
position: relative; position: relative;
height: 24px; height: 24px;
overflow: hidden; overflow: hidden;

View File

@ -23,7 +23,7 @@ VantComponent({
}, },
delay: { delay: {
type: Number, type: Number,
value: 0 value: 1
}, },
speed: { speed: {
type: Number, type: Number,
@ -44,12 +44,12 @@ VantComponent({
backgroundColor: { backgroundColor: {
type: String, type: String,
value: BG_COLOR value: BG_COLOR
} },
wrapable: Boolean
}, },
data: { data: {
show: true, show: true
hasRightIcon: false
}, },
watch: { watch: {
@ -59,12 +59,6 @@ VantComponent({
}, },
created() { created() {
if (this.data.mode) {
this.set({
hasRightIcon: true
});
}
this.resetAnimation = wx.createAnimation({ this.resetAnimation = wx.createAnimation({
duration: 0, duration: 0,
timingFunction: 'linear' timingFunction: 'linear'
@ -79,7 +73,7 @@ VantComponent({
init() { init() {
Promise.all([ Promise.all([
this.getRect('.van-notice-bar__content'), this.getRect('.van-notice-bar__content'),
this.getRect('.van-notice-bar__content-wrap') this.getRect('.van-notice-bar__wrap')
]).then((rects: wx.BoundingClientRectCallbackResult[]) => { ]).then((rects: wx.BoundingClientRectCallbackResult[]) => {
const [contentRect, wrapRect] = rects; const [contentRect, wrapRect] = rects;
if ( if (

View File

@ -1,6 +1,8 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<view <view
wx:if="{{ show }}" wx:if="{{ show }}"
class="custom-class van-notice-bar {{ hasRightIcon ? 'van-notice-bar--within-icon' : '' }}" class="custom-class {{ utils.bem('notice-bar', { withicon: mode, wrapable }) }}"
style="color: {{ color }}; background-color: {{ backgroundColor }};" style="color: {{ color }}; background-color: {{ backgroundColor }};"
bind:tap="onClick" bind:tap="onClick"
> >
@ -11,8 +13,8 @@
class="van-notice-bar__left-icon" class="van-notice-bar__left-icon"
/> />
<view class="van-notice-bar__content-wrap"> <view class="van-notice-bar__wrap">
<view class="van-notice-bar__content {{ scrollable ? '' : 'van-ellipsis' }}" animation="{{ animationData }}"> <view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}" animation="{{ animationData }}">
{{ text }} {{ text }}
</view> </view>
</view> </view>