[new feature] Tab: 增加新属性 dot、info、title-style

re #1059 #1153
This commit is contained in:
rex 2019-01-04 10:57:37 +08:00 committed by GitHub
parent cf5922aacc
commit ab1b07ec8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 23 deletions

View File

@ -12,6 +12,23 @@
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block title="自定义标题">
<van-tabs active="{{ 1 }}" bind:change="onChange">
<van-tab
wx:for="1234"
wx:key="index"
title="{{ '标签' + item }}"
title-style="font-size: 16px; font-weight: bold; {{ index === 0 ? 'text-decoration: line-through;' : '' }}"
dot="{{ index === 1 }}"
info="{{ index === 2 ? 99 : null }}"
>
<view class="content">
{{ '内容' + item }}
</view>
</van-tab>
</van-tabs>
</demo-block>
<demo-block title="横向滚动"> <demo-block title="横向滚动">
<van-tabs> <van-tabs>
<van-tab <van-tab

View File

@ -187,6 +187,9 @@ Page({
|-----------|-----------|-----------|-------------| |-----------|-----------|-----------|-------------|
| title | 标题 | `String` | - | | title | 标题 | `String` | - |
| disabled | 是否禁用标签 | `Boolean` | `false` | | disabled | 是否禁用标签 | `Boolean` | `false` |
| dot | 是否显示小红点 | `Boolean` | - |
| info | 图标右上角提示信息 | `String | Number` | - |
| title-style | 自定义标题样式 | `String` | - |
### Tab Slot ### Tab Slot

View File

@ -8,7 +8,10 @@ VantComponent({
props: { props: {
title: String, title: String,
disabled: Boolean disabled: Boolean,
dot: Boolean,
info: null,
titleStyle: String
}, },
data: { data: {
@ -20,7 +23,10 @@ VantComponent({
watch: { watch: {
title: 'update', title: 'update',
disabled: 'update' disabled: 'update',
dot: 'update',
info: 'update',
titleStyle: 'update'
}, },
methods: { methods: {

View File

@ -1,6 +1,8 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<view <view
wx:if="{{ animated || inited }}" wx:if="{{ animated || inited }}"
class="custom-class van-tab__pane {{ active ? 'van-tab__pane--active' : 'van-tab__pane--inactive' }}" class="custom-class utils.bem('tab__pane', { active, inactive: !active }) }}"
style="{{ animated || active ? '' : 'display: none;' }} {{ width ? 'width:' + width + 'px;' : '' }}" style="{{ animated || active ? '' : 'display: none;' }} {{ width ? 'width:' + width + 'px;' : '' }}"
> >
<slot /> <slot />

View File

@ -1,3 +1,6 @@
{ {
"component": true "component": true,
"usingComponents": {
"van-info": "../info/index"
}
} }

View File

@ -8,10 +8,10 @@
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
&__wrap { &__wrap {
top: 0;
left: 0;
right: 0;
position: absolute; position: absolute;
top: 0;
right: 0;
left: 0;
&--page-top { &--page-top {
position: fixed; position: fixed;
@ -35,10 +35,10 @@
} }
&__nav { &__nav {
display: flex;
user-select: none;
position: relative; position: relative;
display: flex;
background-color: @white; background-color: @white;
user-select: none;
&--line { &--line {
height: 100%; height: 100%;
@ -48,9 +48,9 @@
height: @tabs-card-height; height: @tabs-card-height;
.van-tab { .van-tab {
line-height: @tabs-card-height;
color: @red; color: @red;
border-right: 1px solid @red; border-right: 1px solid @red;
line-height: @tabs-card-height;
&:last-child { &:last-child {
border-right: none; border-right: none;
@ -65,11 +65,11 @@
} }
&__line { &__line {
z-index: 1;
left: 0;
bottom: 0;
height: 2px;
position: absolute; position: absolute;
bottom: 0;
left: 0;
z-index: 1;
height: 2px;
background-color: @red; background-color: @red;
border-radius: 2px; border-radius: 2px;
} }
@ -101,17 +101,17 @@
} }
.van-tab { .van-tab {
flex: 1; position: relative;
cursor: pointer; min-width: 0; /* hack for flex ellipsis */
padding: 0 5px; padding: 0 5px;
font-size: 14px; font-size: 14px;
position: relative;
color: @gray-darker;
line-height: @tabs-line-height; line-height: @tabs-line-height;
color: @gray-darker;
text-align: center; text-align: center;
box-sizing: border-box; cursor: pointer;
background-color: @white; background-color: @white;
min-width: 0; /* hack for flex ellipsis */ box-sizing: border-box;
flex: 1;
&--active { &--active {
font-weight: 500; font-weight: 500;
@ -121,4 +121,25 @@
&--disabled { &--disabled {
color: @gray; color: @gray;
} }
&__title {
&--dot {
&::after {
display: inline-block;
width: 8px;
height: 8px;
vertical-align: middle;
background-color: @red;
border-radius: 100%;
content: '';
}
}
&__info {
position: relative !important;
top: -1px !important;
display: inline-block;
transform: translateX(0) !important;
}
}
} }

View File

@ -1,3 +1,5 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<view class="custom-class van-tabs van-tabs--{{ type }}"> <view class="custom-class van-tabs van-tabs--{{ type }}">
<view style="z-index: {{ zIndex }}; {{ wrapStyle }}" class="van-tabs__wrap {{ scrollable ? 'van-tabs__wrap--scrollable' : '' }} {{ type === 'line' && border ? 'van-hairline--top-bottom' : '' }}"> <view style="z-index: {{ zIndex }}; {{ wrapStyle }}" class="van-tabs__wrap {{ scrollable ? 'van-tabs__wrap--scrollable' : '' }} {{ type === 'line' && border ? 'van-hairline--top-bottom' : '' }}">
<scroll-view <scroll-view
@ -13,12 +15,17 @@
wx:for="{{ tabs }}" wx:for="{{ tabs }}"
wx:key="index" wx:key="index"
data-index="{{ index }}" data-index="{{ index }}"
class="van-ellipsis van-tab {{ index === active ? 'van-tab--active' : '' }} {{ item.disabled ? 'van-tab--disabled' : '' }}" class="van-ellipsis {{ utils.bem('tab', { active: index === active, disabled: item.disabled }) }}"
style="{{ color && index !== active && type === 'card' && !item.disabled ? 'color: ' + color : '' }} {{ color && index === active && type === 'card' ? ';background-color:' + color : '' }} {{ color ? ';border-color: ' + color : '' }} {{ scrollable ? ';flex-basis:' + (88 / swipeThreshold) + '%' : '' }}" style="{{ color && index !== active && type === 'card' && !item.disabled ? 'color: ' + color : '' }} {{ color && index === active && type === 'card' ? ';background-color:' + color : '' }} {{ color ? ';border-color: ' + color : '' }} {{ scrollable ? ';flex-basis:' + (88 / swipeThreshold) + '%' : '' }}"
bind:tap="onTap" bind:tap="onTap"
> >
<view class="van-ellipsis van-tab__title"> <view class="van-ellipsis {{ utils.bem('tab__title', { dot: item.dot }) }}" style="{{ item.titleStyle }}">
{{ item.title }} {{ item.title }}
<van-info
wx:if="{{ item.info !== null }}"
info="{{ item.info }}"
custom-class="van-tab__title__info"
/>
</view> </view>
</view> </view>
</view> </view>