diff --git a/docs/examples-docs/nav-bar.md b/docs/examples-docs/nav-bar.md new file mode 100644 index 000000000..ad4577d2e --- /dev/null +++ b/docs/examples-docs/nav-bar.md @@ -0,0 +1,52 @@ +## NavBar 导航栏 + +### 使用指南 +``` javascript +import { NavBar } from 'vant'; + +Vue.component(NavBar.name, NavBar); +``` + +### 代码演示 + +#### 基础用法 + +:::demo 基础用法 +```html + +``` +::: + +#### 高级用法 +通过 slot 定制内容 + +:::demo 高级用法 +```html + + + +``` +::: + + +### API +| 参数 | 说明 | 类型 | 默认值 | 可选值 | +|-----------|-----------|-----------|-------------|-------------| +| title | 标题 | `String` | `''` | - | +| left-text | 左侧文案 | `String` | `''` | - | +| right-text | 右侧文案 | `String` | `''` | - | +| left-arrow | 是否显示左侧箭头 | `Boolean` | `false` | - | +| fixed | 是否固定在顶部 | `Boolean` | `false` | - | + +### Slot + +| name | 描述 | +|-----------|-----------| +| title | 自定义标题 | +| left | 自定义左侧区域内容 | +| right | 自定义右侧区域内容 | \ No newline at end of file diff --git a/docs/src/doc.config.js b/docs/src/doc.config.js index f57fddcf2..492844c19 100644 --- a/docs/src/doc.config.js +++ b/docs/src/doc.config.js @@ -82,6 +82,10 @@ module.exports = { "path": "/loading", "title": "Loading 加载" }, + { + "path": "/nav-bar", + "title": "NavBar 导航栏" + }, { "path": "/notice-bar", "title": "NoticeBar 通告栏" diff --git a/packages/index.js b/packages/index.js index e47352577..2129658e0 100644 --- a/packages/index.js +++ b/packages/index.js @@ -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, diff --git a/packages/nav-bar/index.vue b/packages/nav-bar/index.vue new file mode 100644 index 000000000..084fe672e --- /dev/null +++ b/packages/nav-bar/index.vue @@ -0,0 +1,38 @@ + + + diff --git a/packages/vant-css/src/index.css b/packages/vant-css/src/index.css index 25790dddb..140c245e2 100644 --- a/packages/vant-css/src/index.css +++ b/packages/vant-css/src/index.css @@ -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'; diff --git a/packages/vant-css/src/nav-bar.css b/packages/vant-css/src/nav-bar.css new file mode 100644 index 000000000..25932b595 --- /dev/null +++ b/packages/vant-css/src/nav-bar.css @@ -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; + } + } +} diff --git a/test/unit/specs/nav-bar.spec.js b/test/unit/specs/nav-bar.spec.js new file mode 100644 index 000000000..858ef9ffc --- /dev/null +++ b/test/unit/specs/nav-bar.spec.js @@ -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; + }); +});