mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
commit
37bbd9e42c
52
docs/examples-docs/nav-bar.md
Normal file
52
docs/examples-docs/nav-bar.md
Normal 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 | 自定义右侧区域内容 |
|
@ -82,6 +82,10 @@ module.exports = {
|
|||||||
"path": "/loading",
|
"path": "/loading",
|
||||||
"title": "Loading 加载"
|
"title": "Loading 加载"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "/nav-bar",
|
||||||
|
"title": "NavBar 导航栏"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "/notice-bar",
|
"path": "/notice-bar",
|
||||||
"title": "NoticeBar 通告栏"
|
"title": "NoticeBar 通告栏"
|
||||||
|
@ -22,6 +22,7 @@ import Icon from './icon';
|
|||||||
import ImagePreview from './image-preview';
|
import ImagePreview from './image-preview';
|
||||||
import Lazyload from './lazyload';
|
import Lazyload from './lazyload';
|
||||||
import Loading from './loading';
|
import Loading from './loading';
|
||||||
|
import NavBar from './nav-bar';
|
||||||
import NoticeBar from './notice-bar';
|
import NoticeBar from './notice-bar';
|
||||||
import Panel from './panel';
|
import Panel from './panel';
|
||||||
import Picker from './picker';
|
import Picker from './picker';
|
||||||
@ -71,6 +72,7 @@ const components = [
|
|||||||
GoodsActionMiniBtn,
|
GoodsActionMiniBtn,
|
||||||
Icon,
|
Icon,
|
||||||
Loading,
|
Loading,
|
||||||
|
NavBar,
|
||||||
NoticeBar,
|
NoticeBar,
|
||||||
Panel,
|
Panel,
|
||||||
Picker,
|
Picker,
|
||||||
@ -136,6 +138,7 @@ export {
|
|||||||
ImagePreview,
|
ImagePreview,
|
||||||
Lazyload,
|
Lazyload,
|
||||||
Loading,
|
Loading,
|
||||||
|
NavBar,
|
||||||
NoticeBar,
|
NoticeBar,
|
||||||
Panel,
|
Panel,
|
||||||
Picker,
|
Picker,
|
||||||
|
38
packages/nav-bar/index.vue
Normal file
38
packages/nav-bar/index.vue
Normal 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>
|
@ -15,6 +15,8 @@
|
|||||||
@import './card.css';
|
@import './card.css';
|
||||||
@import './icon.css';
|
@import './icon.css';
|
||||||
@import './loading.css';
|
@import './loading.css';
|
||||||
|
@import './nav-bar.css';
|
||||||
|
@import './notice-bar.css';
|
||||||
@import './popup.css';
|
@import './popup.css';
|
||||||
@import './search.css';
|
@import './search.css';
|
||||||
@import './panel.css';
|
@import './panel.css';
|
||||||
@ -48,5 +50,4 @@
|
|||||||
/* business components */
|
/* business components */
|
||||||
@import './coupon-list.css';
|
@import './coupon-list.css';
|
||||||
@import './goods-action.css';
|
@import './goods-action.css';
|
||||||
@import './notice-bar.css';
|
|
||||||
@import './submit-bar.css';
|
@import './submit-bar.css';
|
||||||
|
60
packages/vant-css/src/nav-bar.css
Normal file
60
packages/vant-css/src/nav-bar.css
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
test/unit/specs/nav-bar.spec.js
Normal file
43
test/unit/specs/nav-bar.spec.js
Normal 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;
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user