-
Notifications
You must be signed in to change notification settings - Fork 140
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 (#1775)
BREAKING CHANGE: itemHeight is deprecated, use rowHeight instead BREAKING CHANGE: itemRender is deprecated, use rowRender instead
- Loading branch information
Showing
47 changed files
with
1,769 additions
and
398 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
20 changes: 10 additions & 10 deletions
20
packages/cdk/scroll/__tests__/__snapshots__/virtualScroll.spec.ts.snap
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`VirtualScroll > basic work > itemRender work 1`] = ` | ||
exports[`VirtualScroll > basic work > render work 1`] = ` | ||
"<div class=\\"cdk-virtual-scroll\\"> | ||
<div class=\\"cdk-virtual-scroll-holder\\" style=\\"max-height: 200px;\\"> | ||
<div class=\\"cdk-virtual-scroll-filler\\" style=\\"height: 400px;\\"> | ||
<div class=\\"cdk-virtual-scroll-content\\" style=\\"transform: translateY(0px); position: absolute; left: 0px; right: 0px; top: 0px;\\"><span class=\\"virtual-item\\">key-0 - 0</span><span class=\\"virtual-item\\">key-1 - 1</span><span class=\\"virtual-item\\">key-2 - 2</span><span class=\\"virtual-item\\">key-3 - 3</span><span class=\\"virtual-item\\">key-4 - 4</span><span class=\\"virtual-item\\">key-5 - 5</span><span class=\\"virtual-item\\">key-6 - 6</span><span class=\\"virtual-item\\">key-7 - 7</span><span class=\\"virtual-item\\">key-8 - 8</span><span class=\\"virtual-item\\">key-9 - 9</span><span class=\\"virtual-item\\">key-10 - 10</span><span class=\\"virtual-item\\">key-11 - 11</span></div> | ||
</div> | ||
<div class=\\"cdk-virtual-scroll-holder\\" style=\\"max-height: 200px; width: 100%;\\"> | ||
<!----> | ||
<div class=\\"cdk-virtual-scroll-filler-vertical\\" style=\\"height: 400px; width: 0px;\\"></div> | ||
<div class=\\"cdk-virtual-scroll-content\\" style=\\"margin-top: 0px; margin-left: 0px;\\"><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-0 - 0</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-1 - 1</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-2 - 2</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-3 - 3</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-4 - 4</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-5 - 5</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-6 - 6</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-7 - 7</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-8 - 8</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-9 - 9</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-10 - 10</span></div> | ||
</div> | ||
</div>" | ||
`; | ||
exports[`VirtualScroll > basic work > render work 1`] = ` | ||
exports[`VirtualScroll > basic work > rowRender work 1`] = ` | ||
"<div class=\\"cdk-virtual-scroll\\"> | ||
<div class=\\"cdk-virtual-scroll-holder\\" style=\\"max-height: 200px;\\"> | ||
<div class=\\"cdk-virtual-scroll-filler\\" style=\\"height: 400px;\\"> | ||
<div class=\\"cdk-virtual-scroll-content\\" style=\\"transform: translateY(0px); position: absolute; left: 0px; right: 0px; top: 0px;\\"><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-0 - 0</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-1 - 1</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-2 - 2</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-3 - 3</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-4 - 4</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-5 - 5</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-6 - 6</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-7 - 7</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-8 - 8</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-9 - 9</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-10 - 10</span><span class=\\"virtual-item\\" style=\\"height: 20px;\\">key-11 - 11</span></div> | ||
</div> | ||
<div class=\\"cdk-virtual-scroll-holder\\" style=\\"max-height: 200px; width: 100%;\\"> | ||
<!----> | ||
<div class=\\"cdk-virtual-scroll-filler-vertical\\" style=\\"height: 400px; width: 0px;\\"></div> | ||
<div class=\\"cdk-virtual-scroll-content\\" style=\\"margin-top: 0px; margin-left: 0px;\\"><span class=\\"virtual-item\\">key-0 - 0</span><span class=\\"virtual-item\\">key-1 - 1</span><span class=\\"virtual-item\\">key-2 - 2</span><span class=\\"virtual-item\\">key-3 - 3</span><span class=\\"virtual-item\\">key-4 - 4</span><span class=\\"virtual-item\\">key-5 - 5</span><span class=\\"virtual-item\\">key-6 - 6</span><span class=\\"virtual-item\\">key-7 - 7</span><span class=\\"virtual-item\\">key-8 - 8</span><span class=\\"virtual-item\\">key-9 - 9</span><span class=\\"virtual-item\\">key-10 - 10</span></div> | ||
</div> | ||
</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
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,77 @@ | ||
<template> | ||
<div class="demo-both-scroll-wrapper"> | ||
<CdkVirtualScroll | ||
ref="listRef" | ||
:dataSource="rowData" | ||
:height="200" | ||
:rowHeight="20" | ||
:colWidth="200" | ||
:virtual="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" | ||
:virtual="{ 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
Oops, something went wrong.