refactor(TreeSelect): use Sidebar as nav (#4383)

This commit is contained in:
neverland
2019-09-06 09:51:20 +08:00
committed by GitHub
parent ebf5a18eb9
commit 5b0feb58e8
5 changed files with 66 additions and 61 deletions
+21 -23
View File
@@ -1,6 +1,8 @@
import { createNamespace, addUnit } from '../utils';
import { emit, inherit } from '../utils/functional';
import Icon from '../icon';
import Sidebar from '../sidebar';
import SidebarItem from '../sidebar-item';
// Types
import { CreateElement, RenderContext } from 'vue/types';
@@ -52,28 +54,12 @@ function TreeSelect(
: activeId === id;
}
const Nav = items.map((item, index) => (
<div
key={index}
class={[
'van-ellipsis',
bem('nav-item', {
active: mainActiveIndex === index,
disabled: item.disabled
})
]}
onClick={() => {
if (!item.disabled) {
emit(ctx, 'click-nav', index);
emit(ctx, 'update:main-active-index', index);
// compatible for old usage, should be removed in next major version
emit(ctx, 'navclick', index);
}
}}
>
{item.text}
</div>
const Nav = items.map(item => (
<SidebarItem
title={item.text}
disabled={item.disabled}
class={bem('nav-item')}
/>
));
function Content() {
@@ -124,7 +110,19 @@ function TreeSelect(
return (
<div class={bem()} style={{ height: addUnit(height) }} {...inherit(ctx)}>
<div class={bem('nav')}>{Nav}</div>
<Sidebar
class={bem('nav')}
activeKey={mainActiveIndex}
onChange={(index: number) => {
emit(ctx, 'click-nav', index);
emit(ctx, 'update:main-active-index', index);
// compatible for old usage, should be removed in next major version
emit(ctx, 'navclick', index);
}}
>
{Nav}
</Sidebar>
<div class={bem('content')}>{Content()}</div>
</div>
);