Merge pull request #121 from chenjiahan/dev

add NavBar component
This commit is contained in:
neverland 2017-09-08 03:15:30 -05:00 committed by GitHub
commit 37bbd9e42c
7 changed files with 202 additions and 1 deletions

View File

@ -0,0 +1,52 @@
## NavBar 导航栏
### 使用指南
``` javascript
import { NavBar } from 'vant';
Vue.component(NavBar.name, NavBar);
```
### 代码演示
#### 基础用法
:::demo 基础用法
```html
<van-nav-bar
title="标题"
left-text="返回"
right-text="按钮"
left-arrow
/>
```
:::
#### 高级用法
通过 slot 定制内容
:::demo 高级用法
```html
<van-nav-bar title="标题" left-text="返回" left-arrow>
<van-icon name="search" slot="right" />
</van-nav-bar>
```
:::
### API
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| title | 标题 | `String` | `''` | - |
| left-text | 左侧文案 | `String` | `''` | - |
| right-text | 右侧文案 | `String` | `''` | - |
| left-arrow | 是否显示左侧箭头 | `Boolean` | `false` | - |
| fixed | 是否固定在顶部 | `Boolean` | `false` | - |
### Slot
| name | 描述 |
|-----------|-----------|
| title | 自定义标题 |
| left | 自定义左侧区域内容 |
| right | 自定义右侧区域内容 |

View File

@ -82,6 +82,10 @@ module.exports = {
"path": "/loading",
"title": "Loading 加载"
},
{
"path": "/nav-bar",
"title": "NavBar 导航栏"
},
{
"path": "/notice-bar",
"title": "NoticeBar 通告栏"

View File

@ -22,6 +22,7 @@ import Icon from './icon';
import ImagePreview from './image-preview';
import Lazyload from './lazyload';
import Loading from './loading';
import NavBar from './nav-bar';
import NoticeBar from './notice-bar';
import Panel from './panel';
import Picker from './picker';
@ -71,6 +72,7 @@ const components = [
GoodsActionMiniBtn,
Icon,
Loading,
NavBar,
NoticeBar,
Panel,
Picker,
@ -136,6 +138,7 @@ export {
ImagePreview,
Lazyload,
Loading,
NavBar,
NoticeBar,
Panel,
Picker,

View File

@ -0,0 +1,38 @@
<template>
<div :class="['van-nav-bar van-hairline--top-bottom', { 'van-nav-bar--fixed': fixed }]">
<div class="van-nav-bar__left" @click="$emit('clickLeft')">
<slot name="left">
<van-icon v-if="leftArrow" class="van-nav-bar__arrow" name="arrow" />
<span v-if="leftText" v-text="leftText" class="van-nav-bar__text" />
</slot>
</div>
<div class="van-nav-bar__title">
<slot name="title">{{ title }}</slot>
</div>
<div class="van-nav-bar__right" @click="$emit('clickRight')">
<slot name="right">
<span v-if="rightText" v-text="rightText" class="van-nav-bar__text" />
</slot>
</div>
</div>
</template>
<script>
import Icon from '../icon';
export default {
name: 'van-nav-bar',
components: {
[Icon.name]: Icon
},
props: {
title: String,
leftText: String,
rightText: String,
leftArrow: Boolean,
fixed: Boolean
}
};
</script>

View File

@ -15,6 +15,8 @@
@import './card.css';
@import './icon.css';
@import './loading.css';
@import './nav-bar.css';
@import './notice-bar.css';
@import './popup.css';
@import './search.css';
@import './panel.css';
@ -48,5 +50,4 @@
/* business components */
@import './coupon-list.css';
@import './goods-action.css';
@import './notice-bar.css';
@import './submit-bar.css';

View File

@ -0,0 +1,60 @@
@import './common/var.css';
.van-nav-bar {
height: 46px;
position: relative;
user-select: none;
text-align: center;
line-height: 46px;
background-color: #fff;
.van-icon {
color: $blue;
}
&__arrow {
transform: rotate(180deg);
+ .van-nav-bar__text {
margin-left: -20px;
padding-left: 25px;
}
}
&--fixed {
top: 0;
left: 0;
width: 100%;
position: fixed;
}
&__title {
font-size: 16px;
}
&__left,
&__right {
bottom: 0;
font-size: 14px;
position: absolute;
}
&__left {
left: 15px;
}
&__right {
right: 15px;
}
&__text {
color: $blue;
margin: 0 -15px;
padding: 0 15px;
display: inline-block;
&:active {
background-color: $active-color;
}
}
}

View File

@ -0,0 +1,43 @@
import NavBar from 'packages/nav-bar';
import { mount } from 'avoriaz';
import { DOMChecker } from '../utils';
describe('NavBar', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('create a NavBar', () => {
wrapper = mount(NavBar, {
propsData: {
title: '标题',
leftText: '返回',
rightText: '按钮',
leftArrow: true
}
});
DOMChecker(wrapper, {
text: {
'.van-nav-bar__title': '标题',
'.van-nav-bar__left .van-nav-bar__text': '返回',
'.van-nav-bar__right .van-nav-bar__text': '按钮'
},
count: {
'.van-nav-bar__arrow': 1
}
});
expect(wrapper.hasClass('van-nav-bar')).to.be.true;
});
it('NavBar fixed', () => {
wrapper = mount(NavBar, {
propsData: {
fixed: true
}
});
expect(wrapper.hasClass('van-nav-bar')).to.be.true;
});
});