Skip to content

Commit

Permalink
Merge pull request alibaba-fusion#60 from alibaba-fusion/feature/1.10.0
Browse files Browse the repository at this point in the history
Feature/1.10.0
  • Loading branch information
youluna authored Nov 28, 2018
2 parents f2c64dd + cee30f7 commit 0ce4e34
Show file tree
Hide file tree
Showing 35 changed files with 1,165 additions and 78 deletions.
52 changes: 52 additions & 0 deletions docs/select/demo/virtual-select.md
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" />
&nbsp;&nbsp;&nbsp;&nbsp;
<Select useVirtual onChange={onChange} defaultValue="option50">
{generateData(100, true)}
</Select>
</div>
, mountNode);
````
2 changes: 1 addition & 1 deletion docs/select/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This is because the layer's animation of the overlay is implemented by `classNam
|Size | selector size<br><br>**optional values**:<br>'small', 'medium', 'large' | Enum | 'medium' |
| value | Current value for controlled mode | any | - |
| defaultValue | initial default | any | - |
| onChange | Callback that fires when Select changes <br><br> **Signature**:<br>Function(value: mixed, actionType: String) => void<br>**Parameters**:<br> _value_: {mixed} Selected value <br>_actionType_: {String} Triggered, 'itemClick', 'enter', 'tag' | Function | func.noop |
| onChange | Callback that fires when Select changes <br><br> **Signature**:<br>Function(value: mixed, actionType: String) => void<br>**Parameters**:<br> _value_: {mixed} Selected value <br>_actionType_: {String} Triggered, 'itemClick', 'enter', 'tag' <br> _item_: {mixed} value in dataSource(only useDetailValue=false) | Function | func.noop |
| placeholder | placeholder when there is no value | ReactNode | - |
| autoWidth | Drop-down menu to align with selector | Boolean | true |
| label | custom inline label | ReactNode | - |
Expand Down
39 changes: 33 additions & 6 deletions docs/tag/theme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,32 @@ function render(i18n) {
<Demo title="Normal">
<DemoHead cols={['L', 'M', 'S']} />
<DemoGroup label="Normal">
<Tag.Selectable type="normal" size="large">{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium">{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small">{i18n.small}</Tag.Selectable>
</DemoGroup>

<DemoGroup label="Hover">
<Tag.Selectable type="normal" size="large" className="hover">{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium" className="hover">{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small" className="hover">{i18n.small}</Tag.Selectable>
</DemoGroup>
<DemoGroup label="Selected">
<Tag.Selectable type="normal" size="large" checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium" checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small" checked>{i18n.small}</Tag.Selectable>
</DemoGroup>

<DemoGroup label="Hover">
<DemoGroup label="Selected & Hover">
<Tag.Selectable type="normal" size="large" className="hover" checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium" className="hover" checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small" className="hover" checked>{i18n.small}</Tag.Selectable>
</DemoGroup>

<DemoGroup label="Disabled">
<Tag.Selectable type="normal" size="large" disabled>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium" disabled>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small" disabled>{i18n.small}</Tag.Selectable>
</DemoGroup>
<DemoGroup label="Selected & Disabled">
<Tag.Selectable type="normal" size="large" disabled checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="normal" size="medium" disabled checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="normal" size="small" disabled checked>{i18n.small}</Tag.Selectable>
Expand All @@ -94,18 +108,31 @@ function render(i18n) {
<Demo title="Primary">
<DemoHead cols={['L', 'M', 'S']} />
<DemoGroup label="Normal">
<Tag.Selectable type="primary" size="large">{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium">{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small">{i18n.small}</Tag.Selectable>
</DemoGroup>
<DemoGroup label="Hover">
<Tag.Selectable type="primary" size="large" className="hover">{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium" className="hover">{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small" className="hover">{i18n.small}</Tag.Selectable>
</DemoGroup>
<DemoGroup label="Selected">
<Tag.Selectable type="primary" size="large" checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium" checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small" checked>{i18n.small}</Tag.Selectable>
</DemoGroup>

<DemoGroup label="Hover">
<DemoGroup label="Selected & Hover">
<Tag.Selectable type="primary" size="large" className="hover" checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium" className="hover" checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small" className="hover" checked>{i18n.small}</Tag.Selectable>
</DemoGroup>

<DemoGroup label="Disabled">
<Tag.Selectable type="primary" size="large" disabled>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium" disabled>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small" disabled>{i18n.small}</Tag.Selectable>
</DemoGroup>
<DemoGroup label="Disabled & Selected">
<Tag.Selectable type="primary" size="large" disabled checked>{i18n.large}</Tag.Selectable>
<Tag.Selectable type="primary" size="medium" disabled checked>{i18n.medium}</Tag.Selectable>
<Tag.Selectable type="primary" size="small" disabled checked>{i18n.small}</Tag.Selectable>
Expand Down
3 changes: 3 additions & 0 deletions docs/transfer/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ Move the items in two panels in an intuitive way to select.
| listStyle | custom list style | Object | - |
| sortable | whether to allow drag and drop sort | Boolean | false |
| onSort | callback function triggered when dragging sort<br><br>**signatures**:<br>Function(value: Array, position: String) => void<br>**params**:<br>_value_: {Array} sorted value<br>_position_: {String} position of the sorted panel, 'left' or 'right' | Function | - |
| disabled | disable operations on transfer | Boolean | false |
| leftDisabled | disable left panel | Boolean | false |
| rightDisabled | disable right panel | Boolean | false |
3 changes: 3 additions & 0 deletions docs/transfer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
| value | (用于受控)当前值 | Array&lt;String> | - |
| defaultValue | (用于非受控)初始值 | Array&lt;String> | \[] |
| onChange | 值发生改变的时候触发的回调函数<br><br>**签名**:<br>Function(value: Array, data: Array, extra: Object) => void<br>**参数**:<br>_value_: {Array} 右面板值<br>_data_: {Array} 右面板数据<br>_extra_: {Object} 额外参数<br>_extra.leftValue_: {Array} 左面板值<br>_extra.leftData_: {Array} 左面板数据<br>_extra.movedValue_: {Array} 发生移动的值<br>_extra.movedData_: {Object} 发生移动的数据<br>_extra.direction_: {String} 移动的方向,值为'left'或'right' | Function | - |
| disabled | 是否禁用 | Boolean | false |
| leftDisabled | 是否禁用左侧面板 | Boolean | false |
| rightDisabled | 是否禁用右侧面板 | Boolean | false |
| itemRender | 列表项渲染函数<br><br>**签名**:<br>Function(data: Object) => ReactNode<br>**参数**:<br>_data_: {Object} 数据<br>**返回值**:<br>{ReactNode} 列表项内容<br> | Function | data => data.label |
| showSearch | 是否显示搜索框 | Boolean | false |
| filter | 自定义搜索函数<br><br>**签名**:<br>Function(searchedValue: String, data: Object) => Boolean<br>**参数**:<br>_searchedValue_: {String} 搜索的内容<br>_data_: {Object} 数据<br>**返回值**:<br>{Boolean} 是否匹配到<br> | Function | 根据 label 属性匹配 |
Expand Down
64 changes: 64 additions & 0 deletions docs/virtual-list/demo/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 简单用法

- order: 0

使用 VirtualList 最简单的例子。

:::lang=en-us
# Basic

- order: 0

A simple case.

:::

---

````jsx
import { VirtualList } from '@alifd/next';

const dataSource = [];

const generateLi = (index = 'index') => {
const data = [];
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>;
}
};

for (let i = 0; i < 1000; i++) {
dataSource.push(generateLi(i));
}

const demo = (
<div className={'virtual-box'}>
<VirtualList>
{dataSource}
</VirtualList>
</div>
);


ReactDOM.render(demo, 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;
}
````
77 changes: 77 additions & 0 deletions docs/virtual-list/demo/initial-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 设置初始位置

- order: 1

使用 jumpIndex 设置初始位置

:::lang=en-us
# Basic

- order: 1

Use jumpIndex to set first item.

:::

---

````jsx
import { VirtualList } from '@alifd/next';

const dataSource = [];

function generateLi(index) {
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: 50,
dataSource: generateData(1000)
}
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}>
{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;
}
````
95 changes: 95 additions & 0 deletions docs/virtual-list/demo/item-size-getter.md
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;
}
````
Loading

0 comments on commit 0ce4e34

Please sign in to comment.