-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk:scroll): virtual scroll supports horizontal
BREAKING CHANGE: itemHeight is deprecated, use rowHeight instead BREAKING CHANGE: itemRender is deprecated, use rowRender instead
- Loading branch information
Showing
32 changed files
with
1,227 additions
and
214 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
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,14 @@ | ||
--- | ||
title: | ||
zh: 横向&竖向虚拟滚动 | ||
en: Horizontal & vertical virtual scroll | ||
order: 3 | ||
--- | ||
|
||
## zh | ||
|
||
开启横向以及竖向虚拟滚动的场景。 | ||
|
||
## en | ||
|
||
Use horizontal and vertical virtual scroll. |
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,79 @@ | ||
<template> | ||
<div class="demo-both-scroll-wrapper"> | ||
<CdkVirtualScroll | ||
ref="listRef" | ||
:dataSource="rowData" | ||
:height="200" | ||
:rowHeight="20" | ||
:colWidth="200" | ||
:bufferSize="5" | ||
:bufferOffset="2" | ||
:enabled="true" | ||
:rowRender="rowRender" | ||
getKey="key" | ||
> | ||
<template #col="{ row, item, index }"> | ||
<span class="virtual-item" @click="onItemClick(item.key)">{{ row.key }} - {{ index }}</span> | ||
</template> | ||
</CdkVirtualScroll> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { h, ref } from 'vue' | ||
import { VirtualRowRenderFn, VirtualScrollInstance, VirtualScrollRowData } from '@idux/cdk/scroll' | ||
const listRef = ref<VirtualScrollInstance>() | ||
const colData: { key: string }[] = [] | ||
for (let index = 0; index < 1000; index++) { | ||
colData.push({ key: `col-key-${index}` }) | ||
} | ||
const rowData: VirtualScrollRowData[] = [] | ||
for (let index = 0; index < 1000; index++) { | ||
rowData.push({ | ||
key: `row-key-${index}`, | ||
data: colData, | ||
}) | ||
} | ||
const rowRender: VirtualRowRenderFn = ({ children }) => | ||
h( | ||
'div', | ||
{ | ||
class: 'virtual-row', | ||
}, | ||
children, | ||
) | ||
const onItemClick = (key: string) => { | ||
console.log('click:', key) | ||
} | ||
</script> | ||
|
||
<style lang="less"> | ||
.demo-both-scroll-wrapper { | ||
height: 240px; | ||
.cdk-virtual-scroll { | ||
border: 1px solid red; | ||
margin-bottom: 8px; | ||
} | ||
.virtual-row { | ||
flex-shrink: 0; | ||
display: flex; | ||
height: 20px; | ||
flex-wrap: nowrap; | ||
border: 1px solid gray; | ||
} | ||
.virtual-item { | ||
flex-shrink: 0; | ||
padding-left: 16px; | ||
border: 1px solid gray; | ||
height: 100%; | ||
width: 200px; | ||
line-height: 18px; | ||
} | ||
} | ||
</style> |
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,14 @@ | ||
--- | ||
title: | ||
zh: 横向虚拟滚动 | ||
en: Horizontal virtual scroll | ||
order: 2 | ||
--- | ||
|
||
## zh | ||
|
||
仅开启横向虚拟滚动的场景。 | ||
|
||
## en | ||
|
||
Only use horizontal virtual scroll. |
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,93 @@ | ||
<template> | ||
<div class="demo-horizontal-scroll-wrapper"> | ||
<CdkVirtualScroll | ||
ref="listRef" | ||
:dataSource="rowData" | ||
:height="200" | ||
:fullHeight="true" | ||
:colWidth="80" | ||
:bufferSize="20" | ||
:bufferOffset="5" | ||
:enabled="{ vertical: false, horizontal: true }" | ||
:rowRender="rowRender" | ||
getKey="key" | ||
@scroll="onScroll" | ||
@scrolledChange="onScrolledChange" | ||
@scrolledBottom="onScrolledBottom" | ||
> | ||
<template #col="{ item, index }"> | ||
<span class="virtual-item" @click="onItemClick(item.key)">{{ item.key }} - {{ index }}</span> | ||
</template> | ||
</CdkVirtualScroll> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { h, ref } from 'vue' | ||
import { VirtualRowRenderFn, VirtualScrollInstance } from '@idux/cdk/scroll' | ||
const listRef = ref<VirtualScrollInstance>() | ||
const data: { key: string }[] = [] | ||
for (let index = 0; index < 1000; index++) { | ||
data.push({ key: `key-${index}` }) | ||
} | ||
const rowData = [ | ||
{ | ||
key: 'row', | ||
data, | ||
}, | ||
] | ||
const rowRender: VirtualRowRenderFn = ({ children }) => | ||
h( | ||
'div', | ||
{ | ||
class: 'virtual-row', | ||
style: { display: 'flex', height: '100%', 'flex-wrap': 'nowrap' }, | ||
}, | ||
children, | ||
) | ||
const onScroll = (evt: Event) => { | ||
console.log('scroll:', evt) | ||
} | ||
const onScrolledChange = (startIndex: number, endIndex: number, visibleData: { key: string }[]) => | ||
console.log('onScrolledChange', startIndex, endIndex, visibleData) | ||
const onScrolledBottom = () => console.log('onScrolledBottom') | ||
const onItemClick = (key: string) => { | ||
console.log('click:', key) | ||
} | ||
</script> | ||
|
||
<style lang="less"> | ||
.demo-horizontal-scroll-wrapper { | ||
height: 240px; | ||
.cdk-virtual-scroll { | ||
border: 1px solid red; | ||
margin-bottom: 8px; | ||
} | ||
.cdk-virtual-scroll-content { | ||
height: 100%; | ||
} | ||
.virtual-row { | ||
display: flex; | ||
height: 100%; | ||
flex-wrap: nowrap; | ||
} | ||
.virtual-item { | ||
flex-shrink: 0; | ||
padding-left: 16px; | ||
border: 1px solid gray; | ||
height: 100%; | ||
width: 80px; | ||
line-height: 18px; | ||
} | ||
} | ||
</style> |
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
Oops, something went wrong.