forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alibaba-fusion#58 from alibaba-fusion/feat/virtual…
…-list Feat/virtual list
- Loading branch information
Showing
12 changed files
with
262 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# 无限滚动 | ||
|
||
- order: 15 | ||
|
||
select 配合无限滚动 | ||
|
||
:::lang=en-us | ||
# virtual-select | ||
|
||
- order: 15 | ||
|
||
select with virtual list | ||
::: | ||
--- | ||
|
||
````jsx | ||
import { Select } from '@alifd/next'; | ||
|
||
const Option = Select.Option; | ||
|
||
const onChange = function (value) { | ||
console.log(value); | ||
}; | ||
|
||
function generateItem(index) { | ||
return {label: `option${index}`, value: `option${index}`}; | ||
} | ||
|
||
function generateOption(index) { | ||
return <Option key={`option${index}`} value={`option${index}`}>{`option${index}`}</Option>; | ||
} | ||
|
||
function generateData(len, isOption) { | ||
const data = []; | ||
|
||
for (let i = 0; i < len; i++) { | ||
isOption ? data.push(generateOption(i)) : data.push(generateItem(i)); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Select dataSource={generateData(100)} useVirtual onChange={onChange} defaultValue="option0" /> | ||
| ||
<Select useVirtual onChange={onChange} defaultValue="option50"> | ||
{generateData(100, true)} | ||
</Select> | ||
</div> | ||
, mountNode); | ||
```` |
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,95 @@ | ||
# 不等高的item | ||
|
||
- order: 2 | ||
|
||
使用 jumpIndex 设置初始位置, 并设置 itemSizeGetter | ||
|
||
:::lang=en-us | ||
# Basic | ||
|
||
- order: 2 | ||
|
||
Use jumpIndex and itemSizeGetter to set first item in visual area. | ||
|
||
::: | ||
|
||
--- | ||
|
||
````jsx | ||
import { VirtualList } from '@alifd/next'; | ||
|
||
const dataSource = []; | ||
|
||
function generateLi(index) { | ||
if (index % 3 === 0) { | ||
return (<li key={`key-${index}`} style={{lineHeight: '30px', background: '#5f83ff', color: '#fff'}}>key-{index}</li>); | ||
} else { | ||
return (<li key={`key-${index}`} style={{lineHeight: '20px'}}>key-{index}</li>); | ||
} | ||
} | ||
function generateData(len) { | ||
for (let i = 0; i < len; i++) { | ||
dataSource.push(generateLi(i)); | ||
} | ||
} | ||
|
||
class App extends React.Component { | ||
state = { | ||
initial: 20, | ||
dataSource: generateData(1000) | ||
} | ||
|
||
componentDidMount() { | ||
setTimeout(()=> { | ||
const instance = this.refs.virtual.getInstance(); | ||
instance.scrollTo(50); | ||
}, 200); | ||
|
||
} | ||
|
||
getHeight(index) { | ||
return index % 3 === 0 ? 30 : 20; | ||
} | ||
|
||
onClick() { | ||
this.setState({ | ||
initial: this.state.initial + 20 | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button onClick={this.onClick.bind(this)}>jump to {this.state.initial + 20}</button> | ||
<br/> | ||
<br/> | ||
<div className={'virtual-box'}> | ||
<VirtualList ref="virtual" jumpIndex={this.state.initial} itemSizeGetter={this.getHeight.bind(this)}> | ||
{dataSource} | ||
</VirtualList> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(<App />, mountNode); | ||
```` | ||
|
||
````css | ||
.virtual-box { | ||
height: 200px; | ||
width: 200px; | ||
border: 1px solid #ddd; | ||
overflow: auto; | ||
} | ||
.virtual-box ul { | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
.virtual-box li { | ||
padding-left: 10px; | ||
border-bottom: 1px solid #333; | ||
} | ||
```` |
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
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.