[breaking change] Badge: rename to sidebar

This commit is contained in:
陈嘉涵
2019-04-29 20:06:20 +08:00
parent a84d93869c
commit baf309c33a
25 changed files with 288 additions and 284 deletions
-5
View File
@@ -1,5 +0,0 @@
@import '../style/var';
.badge-group {
width: @badge-group-width;
}
-65
View File
@@ -1,65 +0,0 @@
## Badge
### Install
``` javascript
import { Badge, BadgeGroup } from 'vant';
Vue.use(Badge);
Vue.use(BadgeGroup);
```
### Usage
#### Basic Usage
Use `active-key` prop to set index of chosen 'badge'
```html
<van-badge-group :active-key="activeKey" @change="onChange">
<van-badge title="Title" />
<van-badge title="Title" info="8" />
<van-badge title="Title" info="99" />
<van-badge title="Title" info="99+" />
</van-badge-group>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onChange(key) {
this.activeKey = key;
}
}
};
```
### BadgeGroup API
| Attribute | Description | Type | Default |
|------|------|------|------|
| active-key | Index of chosen badge | `String | Number` | `0` |
### BadgeGroup Event
| Event | Description | Arguments |
|------|------|------|
| change | Triggered when badge changed | key: index of current badge |
### Badge API
| Attribute | Description | Type | Default |
|------|------|------|------|
| title | Content | `String` | `''` |
| info | Info Message | `String | Number` | `''` |
| url | Link | `String` | - |
### Badge Event
| Event | Description | Arguments |
|------|------|------|
| click | Triggered when click badge | key: index of current badge |
-46
View File
@@ -1,46 +0,0 @@
@import '../style/var';
.van-badge {
display: block;
overflow: hidden;
user-select: none;
word-break: break-all;
box-sizing: border-box;
color: @badge-text-color;
padding: @badge-padding;
font-size: @badge-font-size;
line-height: @badge-line-height;
background-color: @badge-background-color;
border-left: 3px solid transparent;
&__text {
position: relative;
}
&:active {
background-color: @badge-active-color;
}
&:not(:last-child)::after {
border-bottom-width: 1px;
}
&--select {
color: @badge-selected-text-color;
font-weight: @badge-selected-font-weight;
border-color: @badge-selected-border-color;
&::after {
border-right-width: 1px;
}
&,
&:active {
background-color: @badge-selected-background-color;
}
}
.van-info {
right: 4px;
}
}
@@ -1,22 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders demo correctly 1`] = `
<div>
<div>
<div class="van-badge-group van-hairline--top-bottom"><a class="van-badge van-badge--select van-hairline">
<div class="van-badge__text">标签名称
<!---->
</div>
</a> <a class="van-badge van-hairline">
<div class="van-badge__text">标签名称<div class="van-info van-badge__info">8</div>
</div>
</a> <a class="van-badge van-hairline">
<div class="van-badge__text">标签名称<div class="van-info van-badge__info">99</div>
</div>
</a> <a class="van-badge van-hairline">
<div class="van-badge__text">标签名称<div class="van-info van-badge__info">99+</div>
</div>
</a></div>
</div>
</div>
`;
-66
View File
@@ -1,66 +0,0 @@
## Badge 徽章
### 使用指南
``` javascript
import { Badge, BadgeGroup } from 'vant';
Vue.use(Badge);
Vue.use(BadgeGroup);
```
### 代码演示
#### 基础用法
通过在`van-badge-group`上设置`active-key`属性来控制选中的`badge`
```html
<van-badge-group :active-key="activeKey" @change="onChange">
<van-badge title="标签名称" />
<van-badge title="标签名称" info="8" />
<van-badge title="标签名称" info="99" />
<van-badge title="标签名称" info="99+" />
</van-badge-group>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onChange(key) {
this.activeKey = key;
}
}
};
```
### BadgeGroup API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|------|------|------|------|------|
| active-key | 选中`badge`的索引 | `String | Number` | `0` | - |
### BadgeGroup Event
| 事件名 | 说明 | 参数 |
|------|------|------|
| change | 切换徽章时触发 | key: 当前选中徽章的索引 |
### Badge API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|------|------|------|------|------|
| title | 内容 | `String` | `''` | - |
| info | 提示消息 | `String | Number` | `''` | - |
| url | 跳转链接 | `String` | - | - |
### Badge Event
| 事件名 | 说明 | 参数 |
|------|------|------|
| click | 点击徽章时触发 | key: 当前徽章的索引 |
+2 -2
View File
@@ -8,8 +8,6 @@
/* common components */
@import './col/index';
@import './row/index';
@import './badge/index';
@import './badge-group/index';
@import './circle/index';
@import './collapse-item/index';
@import './list/index';
@@ -30,6 +28,8 @@
@import './image-preview/index';
@import './stepper/index';
@import './progress/index';
@import './sidebar/index';
@import './sidebar-item/index';
@import './swipe/index';
@import './swipe-item/index';
@import './slider/index';
+6 -6
View File
@@ -5,8 +5,6 @@ import ActionSheet from './action-sheet';
import AddressEdit from './address-edit';
import AddressList from './address-list';
import Area from './area';
import Badge from './badge';
import BadgeGroup from './badge-group';
import Button from './button';
import Card from './card';
import Cell from './cell';
@@ -53,6 +51,8 @@ import RadioGroup from './radio-group';
import Rate from './rate';
import Row from './row';
import Search from './search';
import Sidebar from './sidebar';
import SidebarItem from './sidebar-item';
import Sku from './sku';
import Slider from './slider';
import Step from './step';
@@ -85,8 +85,6 @@ const components = [
AddressEdit,
AddressList,
Area,
Badge,
BadgeGroup,
Button,
Card,
Cell,
@@ -131,6 +129,8 @@ const components = [
Rate,
Row,
Search,
Sidebar,
SidebarItem,
Sku,
Slider,
Step,
@@ -170,8 +170,6 @@ export {
AddressEdit,
AddressList,
Area,
Badge,
BadgeGroup,
Button,
Card,
Cell,
@@ -218,6 +216,8 @@ export {
Rate,
Row,
Search,
Sidebar,
SidebarItem,
Sku,
Slider,
Step,
@@ -1,7 +1,7 @@
import { use } from '../utils';
import Info from '../info';
const [sfc, bem] = use('badge');
const [sfc, bem] = use('sidebar-item');
export default sfc({
props: {
@@ -10,32 +10,32 @@ export default sfc({
title: String
},
inject: ['vanBadgeGroup'],
inject: ['vanSidebar'],
created() {
this.parent.badges.push(this);
this.parent.items.push(this);
},
beforeDestroy() {
this.parent.badges = this.parent.badges.filter(item => item !== this);
this.parent.items = this.parent.items.filter(item => item !== this);
},
computed: {
parent() {
if (process.env.NODE_ENV !== 'production' && !this.vanBadgeGroup) {
console.error('[Vant] Badge needs to be child of BadgeGroup');
if (process.env.NODE_ENV !== 'production' && !this.vanSidebar) {
console.error('[Vant] SidebarItem needs to be child of Sidebar');
}
return this.vanBadgeGroup;
return this.vanSidebar;
},
select() {
return this.parent.badges.indexOf(this) === +this.parent.activeKey;
return this.parent.items.indexOf(this) === +this.parent.activeKey;
}
},
methods: {
onClick() {
const index = this.parent.badges.indexOf(this);
const index = this.parent.items.indexOf(this);
this.$emit('click', index);
this.parent.$emit('change', index);
}
+46
View File
@@ -0,0 +1,46 @@
@import '../style/var';
.van-sidebar-item {
display: block;
overflow: hidden;
user-select: none;
word-break: break-all;
box-sizing: border-box;
color: @sidebar-text-color;
padding: @sidebar-padding;
font-size: @sidebar-font-size;
line-height: @sidebar-line-height;
background-color: @sidebar-background-color;
border-left: 3px solid transparent;
&__text {
position: relative;
}
&:active {
background-color: @sidebar-active-color;
}
&:not(:last-child)::after {
border-bottom-width: 1px;
}
&--select {
color: @sidebar-selected-text-color;
font-weight: @sidebar-selected-font-weight;
border-color: @sidebar-selected-border-color;
&::after {
border-right-width: 1px;
}
&,
&:active {
background-color: @sidebar-selected-background-color;
}
}
.van-info {
right: 4px;
}
}
@@ -1,24 +1,24 @@
<template>
<demo-section>
<demo-block :title="$t('basicUsage')">
<van-badge-group
<van-sidebar
:active-key="activeKey"
@change="onChange"
>
<van-badge :title="$t('title')" />
<van-badge
<van-sidebar-item :title="$t('title')" />
<van-sidebar-item
:title="$t('title')"
info="8"
/>
<van-badge
<van-sidebar-item
:title="$t('title')"
info="99"
/>
<van-badge
<van-sidebar-item
:title="$t('title')"
info="99+"
/>
</van-badge-group>
</van-sidebar>
</demo-block>
</demo-section>
</template>
@@ -48,8 +48,8 @@ export default {
<style lang="less">
@import '../../style/var';
.demo-badge {
.van-badge-group {
.demo-sidebar {
.van-sidebar {
width: auto;
margin: 0 15px;
padding: 20px 0;
@@ -60,7 +60,7 @@ export default {
}
}
.van-badge {
.van-sidebar-item {
width: 85px;
margin: 0 auto;
}
+67
View File
@@ -0,0 +1,67 @@
## Sidebar
### Install
``` javascript
import { Sidebar, SidebarItem } from 'vant';
Vue.use(Sidebar);
Vue.use(SidebarItem);
```
### Usage
#### Basic Usage
Use `active-key` prop to set index of chosen item
```html
<van-sidebar :active-key="activeKey" @change="onChange">
<van-sidebar-item title="Title" />
<van-sidebar-item title="Title" info="8" />
<van-sidebar-item title="Title" info="99" />
<van-sidebar-item title="Title" info="99+" />
</van-sidebar>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onChange(key) {
this.activeKey = key;
}
}
};
```
### Sidebar API
| Attribute | Description | Type | Default |
|------|------|------|------|
| active-key | Index of chosen item | `String | Number` | `0` |
### Sidebar Event
| Event | Description | Arguments |
|------|------|------|
| change | Triggered when item changed | key: index of current item |
### SidebarItem API
| Attribute | Description | Type | Default |
|------|------|------|------|
| title | Content | `String` | `''` |
| info | Info Message | `String | Number` | `''` |
| url | Link | `String` | - |
### SidebarItem Event
| Event | Description | Arguments |
|------|------|------|
| click | Triggered when click item | key: index of current item |
@@ -1,6 +1,6 @@
import { use } from '../utils';
const [sfc, bem] = use('badge-group');
const [sfc, bem] = use('sidebar');
export default sfc({
props: {
@@ -12,13 +12,13 @@ export default sfc({
provide() {
return {
vanBadgeGroup: this
vanSidebar: this
};
},
data() {
return {
badges: []
items: []
};
},
+5
View File
@@ -0,0 +1,5 @@
@import '../style/var';
.van-sidebar {
width: @sidebar-width;
}
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders demo correctly 1`] = `
<div>
<div>
<div class="van-sidebar van-hairline--top-bottom"><a class="van-sidebar-item van-sidebar-item--select van-hairline">
<div class="van-sidebar-item__text">标签名称
<!---->
</div>
</a> <a class="van-sidebar-item van-hairline">
<div class="van-sidebar-item__text">标签名称<div class="van-info van-sidebar-item__info">8</div>
</div>
</a> <a class="van-sidebar-item van-hairline">
<div class="van-sidebar-item__text">标签名称<div class="van-info van-sidebar-item__info">99</div>
</div>
</a> <a class="van-sidebar-item van-hairline">
<div class="van-sidebar-item__text">标签名称<div class="van-info van-sidebar-item__info">99+</div>
</div>
</a></div>
</div>
</div>
`;
@@ -1,19 +1,19 @@
import { mount } from '../../../test/utils';
import Badge from '..';
import BadgeGroup from '../../badge-group';
import Sidebar from '..';
import SidebarItem from '../../sidebar-item';
test('event', () => {
const onClick = jest.fn();
const onChange = jest.fn();
const wrapper = mount({
template: `
<badge-group @change="onChange">
<badge @click="onClick">Text</badge>
</badge-group>
<sidebar @change="onChange">
<sidebar-item @click="onClick">Text</sidebar-item>
</sidebar>
`,
components: {
Badge,
BadgeGroup
Sidebar,
SidebarItem
},
methods: {
onClick,
@@ -21,7 +21,7 @@ test('event', () => {
}
});
wrapper.find('.van-badge').trigger('click');
wrapper.find('.van-sidebar-item').trigger('click');
expect(onClick).toHaveBeenCalledWith(0);
expect(onChange).toHaveBeenCalledWith(0);
wrapper.vm.$destroy();
@@ -31,7 +31,7 @@ test('without parent', () => {
const consoleError = console.error;
try {
console.error = jest.fn();
mount(Badge);
mount(Sidebar);
} catch (err) {
console.error = consoleError;
expect(err).toBeTruthy();
+67
View File
@@ -0,0 +1,67 @@
## Sidebar 侧边导航
### 使用指南
``` javascript
import { Sidebar, SidebarItem } from 'vant';
Vue.use(Sidebar);
Vue.use(SidebarItem);
```
### 代码演示
#### 基础用法
通过在`van-sidebar`上设置`active-key`属性来控制选中项
```html
<van-sidebar :active-key="activeKey" @change="onChange">
<van-sidebar-item title="标签名称" />
<van-sidebar-item title="标签名称" info="8" />
<van-sidebar-item title="标签名称" info="99" />
<van-sidebar-item title="标签名称" info="99+" />
</van-sidebar>
```
``` javascript
export default {
data() {
return {
activeKey: 0
};
},
methods: {
onChange(key) {
this.activeKey = key;
}
}
};
```
### Sidebar API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|------|------|------|------|------|
| active-key | 当前导航项的索引 | `String | Number` | `0` | - |
### Sidebar Event
| 事件名 | 说明 | 参数 |
|------|------|------|
| change | 切换当前导航项时触发 | key: 当前导航项的索引 |
### SidebarItem API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|------|------|------|------|------|
| title | 内容 | `String` | `''` | - |
| info | 提示消息 | `String | Number` | `''` | - |
| url | 跳转链接 | `String` | - | - |
### SidebarItem Event
| 事件名 | 说明 | 参数 |
|------|------|------|
| click | 点击时触发 | key: 当前导航项的索引 |
+15 -15
View File
@@ -32,21 +32,6 @@
@action-sheet-close-icon-size: 18px;
@action-sheet-close-icon-color: @gray-dark;
// Badge
@badge-font-size: 14px;
@badge-line-height: 1.4;
@badge-text-color: @gray-darker;
@badge-padding: 20px 12px 20px 9px;
@badge-active-color: @active-color;
@badge-background-color: @background-color;
@badge-selected-font-weight: 500;
@badge-selected-text-color: @text-color;
@badge-selected-border-color: @red;
@badge-selected-background-color: @white;
// BadgeGroup
@badge-group-width: 85px;
// Button
@button-mini-height: 22px;
@button-mini-min-width: 50px;
@@ -235,6 +220,21 @@
// Rate
@rate-horizontal-padding: 2px;
// Sidebar
@sidebar-width: 85px;
// SidebarItem
@sidebar-font-size: 14px;
@sidebar-line-height: 1.4;
@sidebar-text-color: @gray-darker;
@sidebar-padding: 20px 12px 20px 9px;
@sidebar-active-color: @active-color;
@sidebar-background-color: @background-color;
@sidebar-selected-font-weight: 500;
@sidebar-selected-text-color: @text-color;
@sidebar-selected-border-color: @red;
@sidebar-selected-background-color: @white;
// Slider
@slider-active-background-color: @blue;
@slider-inactive-background-color: @gray-light;