DeepSelect: rename to TreeSelect

This commit is contained in:
陈嘉涵 2017-09-08 14:02:14 +08:00
parent 6ec9d9852a
commit 025133b172
8 changed files with 52 additions and 58 deletions

View File

@ -21,7 +21,7 @@
**合并的 Pull Request (可能有不兼容改动):** **合并的 Pull Request (可能有不兼容改动):**
- Add deep-select component and fix a popup bug. [\#103](https://github.com/youzan/vant/pull/103) ([Tinysymphony](https://github.com/Tinysymphony)) - Add tree-select component and fix a popup bug. [\#103](https://github.com/youzan/vant/pull/103) ([Tinysymphony](https://github.com/Tinysymphony))
- Doc: update Step/Loading/Tag/Badge documents [\#101](https://github.com/youzan/vant/pull/101) ([chenjiahan](https://github.com/chenjiahan)) - Doc: update Step/Loading/Tag/Badge documents [\#101](https://github.com/youzan/vant/pull/101) ([chenjiahan](https://github.com/chenjiahan))
## [v0.8.7](https://github.com/youzan/vant/tree/v0.8.7) (2017-08-29) ## [v0.8.7](https://github.com/youzan/vant/tree/v0.8.7) (2017-08-29)

View File

@ -74,13 +74,13 @@ export default {
} }
</script> </script>
## DeepSelect 分类选择 ## TreeSelect 分类选择
### 使用指南 ### 使用指南
``` javascript ``` javascript
import { DeepSelect } from 'vant'; import { TreeSelect } from 'vant';
Vue.component(DeepSelect.name, DeepSelect); Vue.component(TreeSelect.name, TreeSelect);
``` ```
### 代码演示 ### 代码演示
@ -89,13 +89,13 @@ Vue.component(DeepSelect.name, DeepSelect);
:::demo 基础用法 :::demo 基础用法
```html ```html
<van-deep-select <van-tree-select
:items="items" :items="items"
:main-active-index="mainActiveIndex" :main-active-index="mainActiveIndex"
:active-id="activeId" :active-id="activeId"
@navclick="onNavClick" @navclick="onNavClick"
@itemclick="onItemClick" @itemclick="onItemClick"
></van-deep-select> ></van-tree-select>
``` ```
```javascript ```javascript

View File

@ -98,6 +98,10 @@ module.exports = {
"path": "/progress", "path": "/progress",
"title": "Progress 进度条" "title": "Progress 进度条"
}, },
{
"path": "/search",
"title": "Search 搜索"
},
{ {
"path": "/stepper", "path": "/stepper",
"title": "Stepper 步进器" "title": "Stepper 步进器"
@ -106,6 +110,10 @@ module.exports = {
"path": "/steps", "path": "/steps",
"title": "Steps 步骤条" "title": "Steps 步骤条"
}, },
{
"path": "/swipe",
"title": "Swipe 轮播"
},
{ {
"path": "/tab", "path": "/tab",
"title": "Tab 标签" "title": "Tab 标签"
@ -114,14 +122,6 @@ module.exports = {
"path": "/tag", "path": "/tag",
"title": "Tag 标记" "title": "Tag 标记"
}, },
{
"path": "/swipe",
"title": "Swipe 轮播"
},
{
"path": "/search",
"title": "Search 搜索"
},
{ {
"path": "/waterfall", "path": "/waterfall",
"title": "Waterfall 瀑布流" "title": "Waterfall 瀑布流"
@ -192,7 +192,11 @@ module.exports = {
{ {
"path": "/switch-cell", "path": "/switch-cell",
"title": "SwitchCell 开关单元格" "title": "SwitchCell 开关单元格"
} },
{
"path": "/tree-select",
"title": "TreeSelect 分类选择"
},
] ]
}, },
{ {
@ -203,17 +207,13 @@ module.exports = {
"title": "Area 省市区选择" "title": "Area 省市区选择"
}, },
{ {
"path": "/deep-select", "path": "/coupon",
"title": "DeepSelect 分类选择" "title": "Coupon 优惠券选择器"
}, },
{ {
"path": "/goods-action", "path": "/goods-action",
"title": "GoodsAction 商品页行动点" "title": "GoodsAction 商品页行动点"
}, },
{
"path": "/coupon",
"title": "Coupon 优惠券选择器"
},
{ {
"path": "/pay-order", "path": "/pay-order",
"title": "PayOrder 提交订单栏" "title": "PayOrder 提交订单栏"

View File

@ -13,7 +13,6 @@ import Col from './col';
import CouponCell from './coupon-cell'; import CouponCell from './coupon-cell';
import CouponList from './coupon-list'; import CouponList from './coupon-list';
import DatetimePicker from './datetime-picker'; import DatetimePicker from './datetime-picker';
import DeepSelect from './deep-select';
import Dialog from './dialog'; import Dialog from './dialog';
import Field from './field'; import Field from './field';
import GoodsAction from './goods-action'; import GoodsAction from './goods-action';
@ -30,12 +29,12 @@ import Picker from './picker';
import Popup from './popup'; import Popup from './popup';
import Progress from './progress'; import Progress from './progress';
import PullRefresh from './pull-refresh'; import PullRefresh from './pull-refresh';
import Stepper from './stepper';
import Radio from './radio'; import Radio from './radio';
import RadioGroup from './radio-group'; import RadioGroup from './radio-group';
import Row from './row'; import Row from './row';
import Search from './search'; import Search from './search';
import Step from './step'; import Step from './step';
import Stepper from './stepper';
import Steps from './steps'; import Steps from './steps';
import Swipe from './swipe'; import Swipe from './swipe';
import SwipeItem from './swipe-item'; import SwipeItem from './swipe-item';
@ -45,6 +44,7 @@ import Tab from './tab';
import Tabs from './tabs'; import Tabs from './tabs';
import Tag from './tag'; import Tag from './tag';
import Toast from './toast'; import Toast from './toast';
import TreeSelect from './tree-select';
import Uploader from './uploader'; import Uploader from './uploader';
import Waterfall from './waterfall'; import Waterfall from './waterfall';
@ -65,7 +65,6 @@ const components = [
CouponCell, CouponCell,
CouponList, CouponList,
DatetimePicker, DatetimePicker,
DeepSelect,
Field, Field,
GoodsAction, GoodsAction,
GoodsActionBigBtn, GoodsActionBigBtn,
@ -79,12 +78,12 @@ const components = [
Popup, Popup,
Progress, Progress,
PullRefresh, PullRefresh,
Stepper,
Radio, Radio,
RadioGroup, RadioGroup,
Row, Row,
Search, Search,
Step, Step,
Stepper,
Steps, Steps,
Swipe, Swipe,
SwipeItem, SwipeItem,
@ -93,6 +92,7 @@ const components = [
Tab, Tab,
Tabs, Tabs,
Tag, Tag,
TreeSelect,
Uploader Uploader
]; ];
@ -127,7 +127,6 @@ export {
CouponCell, CouponCell,
CouponList, CouponList,
DatetimePicker, DatetimePicker,
DeepSelect,
Dialog, Dialog,
Field, Field,
GoodsAction, GoodsAction,
@ -144,12 +143,12 @@ export {
Popup, Popup,
Progress, Progress,
PullRefresh, PullRefresh,
Stepper,
Radio, Radio,
RadioGroup, RadioGroup,
Row, Row,
Search, Search,
Step, Step,
Stepper,
Steps, Steps,
Swipe, Swipe,
SwipeItem, SwipeItem,
@ -159,6 +158,7 @@ export {
Tabs, Tabs,
Tag, Tag,
Toast, Toast,
TreeSelect,
Uploader, Uploader,
Waterfall Waterfall
}; };

View File

@ -1,26 +1,26 @@
<template> <template>
<div class="van-deep-select" :style="{ height: mainHeight + 'px' }"> <div class="van-tree-select" :style="{ height: mainHeight + 'px' }">
<div class="van-deep-select__nav"> <div class="van-tree-select__nav">
<div <div
v-for="(item, index) in items" v-for="(item, index) in items"
class="van-deep-select__nitem" class="van-tree-select__nitem"
:class="{ 'van-deep-select__nitem--active': mainActiveIndex === index }" :class="{ 'van-tree-select__nitem--active': mainActiveIndex === index }"
@click="onNavClick(index)"> @click="$emit('navclick', index)">
{{ item.text }} {{ item.text }}
</div> </div>
</div> </div>
<div class="van-deep-select__content" :style="{ height: itemHeight + 'px' }"> <div class="van-tree-select__content" :style="{ height: itemHeight + 'px' }">
<div <div
v-for="item in subItems" v-for="item in subItems"
:key="item.id" :key="item.id"
class="van-deep-select__item" class="van-tree-select__item"
:class="{ 'van-deep-select__item--active': activeId === item.id }" :class="{ 'van-tree-select__item--active': activeId === item.id }"
@click="onItemSelect(item)"> @click="onItemSelect(item)">
{{ item.text }} {{ item.text }}
<van-icon <van-icon
v-if="activeId === item.id" v-if="activeId === item.id"
name="success" name="success"
class="van-deep-select__selected" class="van-tree-select__selected"
></van-icon> ></van-icon>
</div> </div>
</div> </div>
@ -31,7 +31,7 @@
import Icon from 'packages/icon'; import Icon from 'packages/icon';
export default { export default {
name: 'van-deep-select', name: 'van-tree-select',
components: { components: {
'van-icon': Icon 'van-icon': Icon
@ -40,9 +40,7 @@ export default {
props: { props: {
items: { items: {
type: Array, type: Array,
default () { default: () => []
return [];
}
}, },
mainActiveIndex: { mainActiveIndex: {
type: Number, type: Number,
@ -73,12 +71,8 @@ export default {
}, },
methods: { methods: {
onNavClick(index) {
this.$emit('navclick', index);
},
onItemSelect(data) { onItemSelect(data) {
const exportData = Object.assign({}, data); this.$emit('itemclick', { ...data });
this.$emit('itemclick', exportData);
} }
} }
}; };

View File

@ -12,7 +12,6 @@
@import './badge.css'; @import './badge.css';
@import './button.css'; @import './button.css';
@import './cell.css'; @import './cell.css';
@import './cell-swipe.css';
@import './card.css'; @import './card.css';
@import './icon.css'; @import './icon.css';
@import './loading.css'; @import './loading.css';
@ -42,10 +41,11 @@
@import './toast.css'; @import './toast.css';
/* high order components */ /* high order components */
@import './cell-swipe.css';
@import './switch-cell.css'; @import './switch-cell.css';
@import './tree-select.css';
/* business components */ /* business components */
@import './deep-select.css';
@import './goods-action.css'; @import './goods-action.css';
@import './notice-bar.css'; @import './notice-bar.css';
@import './coupon.css'; @import './coupon.css';

View File

@ -2,7 +2,7 @@
@import "./mixins/clearfix.css"; @import "./mixins/clearfix.css";
@import './common/var.css'; @import './common/var.css';
.van-deep-select { .van-tree-select {
user-select: none; user-select: none;
position: relative; position: relative;
@mixin clearfix; @mixin clearfix;

View File

@ -1,19 +1,19 @@
import DeepSelect from 'packages/deep-select'; import TreeSelect from 'packages/tree-select';
import { mount } from 'avoriaz'; import { mount } from 'avoriaz';
describe('DeepSelect', () => { describe('TreeSelect', () => {
let wrapper; let wrapper;
afterEach(() => { afterEach(() => {
wrapper && wrapper.destroy(); wrapper && wrapper.destroy();
}); });
it('create an empty deep-select', () => { it('create an empty tree-select', () => {
wrapper = mount(DeepSelect); wrapper = mount(TreeSelect);
expect(wrapper.hasStyle('height', '0px')).to.be.true; expect(wrapper.hasStyle('height', '0px')).to.be.true;
}); });
it('create a deep-select correctly', () => { it('create a tree-select correctly', () => {
wrapper = mount(DeepSelect, { wrapper = mount(TreeSelect, {
propsData: { propsData: {
items: [{ items: [{
text: 'A', text: 'A',
@ -25,13 +25,13 @@ describe('DeepSelect', () => {
maxHeight: 200 maxHeight: 200
} }
}); });
expect(wrapper.hasClass('van-deep-select')).to.be.true; expect(wrapper.hasClass('van-tree-select')).to.be.true;
expect(wrapper.hasStyle('height', '44px')).to.be.true; expect(wrapper.hasStyle('height', '44px')).to.be.true;
expect(wrapper.vm.maxHeight).to.equal(200); expect(wrapper.vm.maxHeight).to.equal(200);
}); });
it('interact with this component', () => { it('interact with this component', () => {
wrapper = mount(DeepSelect, { wrapper = mount(TreeSelect, {
propsData: { propsData: {
items: [{ items: [{
text: 'A', text: 'A',
@ -58,10 +58,10 @@ describe('DeepSelect', () => {
wrapper.vm.$on('itemclick', item => { wrapper.vm.$on('itemclick', item => {
wrapper.vm.activeId = item.id; wrapper.vm.activeId = item.id;
}); });
const secondNav = wrapper.find('.van-deep-select__nitem')[1]; const secondNav = wrapper.find('.van-tree-select__nitem')[1];
secondNav.trigger('click'); secondNav.trigger('click');
expect(wrapper.vm.mainActiveIndex).to.equal(1); expect(wrapper.vm.mainActiveIndex).to.equal(1);
const target = wrapper.find('.van-deep-select__item')[0]; const target = wrapper.find('.van-tree-select__item')[0];
target.trigger('click'); target.trigger('click');
expect(wrapper.vm.activeId).to.equal(345); expect(wrapper.vm.activeId).to.equal(345);
}); });