-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cascader): add virtual list support (#2577)
- Loading branch information
Showing
7 changed files
with
241 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
```yaml | ||
title: | ||
zh-CN: 虚拟列表 | ||
en-US: Virtual List | ||
``` | ||
## zh-CN | ||
虚拟列表的使用方法。 | ||
--- | ||
## en-US | ||
How to use the virtual list. | ||
--- | ||
```vue | ||
|
||
<template> | ||
<a-cascader :options="options" :style="{width:'320px'}" placeholder="Please select ..." | ||
:virtual-list-props="{height:200}" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
setup() { | ||
const options = [ | ||
{ | ||
value: 'beijing', | ||
label: 'Beijing', | ||
children: [ | ||
{ | ||
value: 'chaoyang', | ||
label: 'ChaoYang', | ||
children: [ | ||
{ | ||
value: 'datunli', | ||
label: 'Datunli', | ||
}, | ||
], | ||
}, | ||
{ | ||
value: 'haidian', | ||
label: 'Haidian', | ||
}, | ||
{ | ||
value: 'dongcheng', | ||
label: 'Dongcheng', | ||
}, | ||
{ | ||
value: 'xicheng', | ||
label: 'Xicheng', | ||
children: [ | ||
{ | ||
value: 'jinrongjie', | ||
label: 'Jinrongjie', | ||
}, | ||
{ | ||
value: 'tianqiao', | ||
label: 'Tianqiao', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
value: 'shanghai', | ||
label: 'Shanghai', | ||
children: Array(1000).fill(null).map((_, index) => { | ||
return { | ||
value: `Option ${index}`, | ||
label: `Option ${index}` | ||
} | ||
}) | ||
}, | ||
]; | ||
|
||
return { | ||
options | ||
} | ||
}, | ||
} | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/web-vue/components/cascader/cascader-column.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { defineComponent, inject, PropType, ref } from 'vue'; | ||
import { configProviderInjectionKey } from '../config-provider/context'; | ||
import { CascaderOptionInfo } from './interface'; | ||
import CascaderOption from './cascader-option'; | ||
import { getPrefixCls } from '../_utils/global-config'; | ||
import Empty from '../empty'; | ||
import Scrollbar from '../scrollbar'; | ||
import VirtualList from '../_components/virtual-list-v2'; | ||
import { VirtualListProps } from '../_components/virtual-list-v2/interface'; | ||
|
||
export default defineComponent({ | ||
name: 'CascaderColumn', | ||
props: { | ||
column: { | ||
type: Array as PropType<CascaderOptionInfo[]>, | ||
required: true, | ||
}, | ||
level: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
selectedPath: { | ||
type: Array as PropType<string[]>, | ||
required: true, | ||
}, | ||
activeKey: String, | ||
totalLevel: { | ||
type: Number, | ||
required: true, | ||
}, | ||
multiple: Boolean, | ||
checkStrictly: Boolean, | ||
virtualListProps: { | ||
type: Object as PropType<VirtualListProps>, | ||
}, | ||
}, | ||
setup(props, { slots }) { | ||
const prefixCls = getPrefixCls('cascader'); | ||
const configCtx = inject(configProviderInjectionKey, undefined); | ||
const virtualListRef = ref(); | ||
const isVirtual = ref(Boolean(props.virtualListProps)); | ||
|
||
const renderEmpty = () => { | ||
return ( | ||
slots.empty?.() ?? | ||
configCtx?.slots.empty?.({ component: 'cascader' }) ?? <Empty /> | ||
); | ||
}; | ||
|
||
return () => { | ||
return ( | ||
<div | ||
class={`${prefixCls}-panel-column`} | ||
style={{ zIndex: props.totalLevel - props.level }} | ||
> | ||
{isVirtual.value ? ( | ||
<VirtualList | ||
key={props.column?.length} | ||
{...props.virtualListProps} | ||
ref={virtualListRef} | ||
data={props.column} | ||
v-slots={{ | ||
item: ({ item }: { item: CascaderOptionInfo }) => { | ||
return ( | ||
<CascaderOption | ||
key={item.key} | ||
option={item} | ||
active={ | ||
props.selectedPath.includes(item.key) || | ||
item.key === props.activeKey | ||
} | ||
multiple={props.multiple} | ||
checkStrictly={props.checkStrictly} | ||
/> | ||
); | ||
}, | ||
}} | ||
/> | ||
) : ( | ||
<Scrollbar class={`${prefixCls}-column-content`}> | ||
{props.column.length === 0 ? ( | ||
<div class={`${prefixCls}-list-empty`}>{renderEmpty()}</div> | ||
) : ( | ||
<ul | ||
role="menu" | ||
class={[ | ||
`${prefixCls}-list`, | ||
{ | ||
[`${prefixCls}-list-multiple`]: Boolean(props?.multiple), | ||
[`${prefixCls}-list-strictly`]: Boolean( | ||
props?.checkStrictly | ||
), | ||
}, | ||
]} | ||
> | ||
{props.column.map((item) => { | ||
return ( | ||
<CascaderOption | ||
key={item.key} | ||
option={item} | ||
active={ | ||
props.selectedPath.includes(item.key) || | ||
item.key === props.activeKey | ||
} | ||
multiple={props.multiple} | ||
checkStrictly={props.checkStrictly} | ||
/> | ||
); | ||
})} | ||
</ul> | ||
)} | ||
</Scrollbar> | ||
)} | ||
</div> | ||
); | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters