Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<feat>: 让tabbar通过slot支持weui的icon组件。 #155

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tabbar/tabbar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Component({
options: {
addGlobalClass: true
addGlobalClass: true,
multipleSlots: true
},
properties: {
extClass: {
Expand Down
8 changes: 6 additions & 2 deletions src/tabbar/tabbar.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
<!-- 选中的时候往 weui-tabbar__item 加 class:weui-bar__item_on -->
<view data-index='{{index}}' bindtap="tabChange" wx:for="{{list}}" wx:key="index" class="weui-tabbar__item {{index === current ? 'weui-bar__item_on' : ''}}">
<view style="position: relative;display:inline-block;">
<image src="{{current === index ? item.selectedIconPath : item.iconPath}}" class="weui-tabbar__icon"></image>
<view wx:if="{{item.slotIcon !=undefined ||item.selectSlotIcon != undefined}}" class="weui-tabbar__icon">
<slot wx:if="{{current !== index}}" name="{{item.slotIcon}}"></slot>
<slot wx:if="{{current === index}}" name="{{item.selectSlotIcon}}"></slot>
</view>
<image wx:else src="{{current === index ? item.selectedIconPath : item.iconPath}}" class="weui-tabbar__icon"></image>
<mp-badge wx:if="{{item.badge || item.dot}}" content="{{item.badge}}" style="position: absolute;top:-2px;left:calc(100% - 3px)"></mp-badge>
</view>
<view class="weui-tabbar__label">{{item.text}}</view>
</view>
</view>
</view>
2 changes: 2 additions & 0 deletions tools/demo/example/tabbar/tabbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CustomPage({
list: [
{
text: '微信',
slotIcon: "wx",
selectSlotIcon: "selwx",
iconPath: app.globalData.iconTabbar,
selectedIconPath: app.globalData.iconTabbar,
badge: '8'
Expand Down
3 changes: 2 additions & 1 deletion tools/demo/example/tabbar/tabbar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"usingComponents": {
"mp-tabbar": "../../components/tabbar/tabbar"
"mp-tabbar": "../../components/tabbar/tabbar",
"mp-icon": "../../components/icon/icon"
}
}
7 changes: 6 additions & 1 deletion tools/demo/example/tabbar/tabbar.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
<view class="page__title">Tabbar</view>
<view class="page__desc">类似小程序原生tabbar的组件,可用于自定义tabbar</view>
</view>
<mp-tabbar class="tabbar" list="{{list}}" bindchange="tabChange"></mp-tabbar>
<mp-tabbar class="tabbar" list="{{list}}" bindchange="tabChange">
<block wx:for="{{list}}" wx:key="index">
<mp-icon slot="{{item.slotIcon}}" color="white" icon="add"></mp-icon>
<mp-icon slot="{{item.selectSlotIcon}}" color="green" icon="add"></mp-icon>
</block>
</mp-tabbar>
</view>