List 列表

单个连续模块垂直排列,显示当前的内容、状态和可进行的操作。eg:联系人列表。

规则

  • 一般由主要信息、主要操作、次要信息、次要操作组成。

  • 主要信息和主要操作放在列表的左边,次要信息和次要操作放在列表的右边。

代码演示

基本

  1. import { List } from 'antd-mobile';
  2. const Item = List.Item;
  3. const Brief = Item.Brief;
  4. class ListExample extends React.Component {
  5. state = {
  6. disabled: false,
  7. }
  8. handleLongPress = (e) => {
  9. console.log('longpress toggled', e);
  10. }
  11. render() {
  12. return (<div>
  13. <List renderHeader={() => 'Basic Style'} className="my-list">
  14. <Item extra={'extra content'} onLongPress={this.handleLongPress}>Title</Item>
  15. </List>
  16. <List renderHeader={() => 'Subtitle'} className="my-list">
  17. <Item arrow="horizontal" multipleLine>
  18. Title <Brief>subtitle</Brief>
  19. </Item>
  20. <Item
  21. arrow="horizontal"
  22. multipleLine
  23. onClick={() => {}}
  24. platform="android"
  25. >
  26. ListItem Android)<Brief>There may have water ripple effect of <br /> material if you set the click event.</Brief>
  27. </Item>
  28. <Item
  29. arrow="horizontal"
  30. thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
  31. multipleLine
  32. onClick={() => {}}
  33. >
  34. Title <Brief>subtitle</Brief>
  35. </Item>
  36. </List>
  37. <List renderHeader={() => 'Customized Right Side(Empty Content / Text / Image)'} className="my-list">
  38. <Item>Title</Item>
  39. <Item arrow="horizontal" onClick={() => {}}>Title</Item>
  40. <Item extra="extra content" arrow="horizontal" onClick={() => {}}>Title</Item>
  41. <Item extra="10:30" align="top" thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png" multipleLine>
  42. Title <Brief>subtitle</Brief>
  43. </Item>
  44. </List>
  45. <List renderHeader={() => 'Align Vertical Center'} className="my-list">
  46. <Item multipleLine extra="extra content">
  47. Title <Brief>subtitle</Brief>
  48. </Item>
  49. </List>
  50. <List renderHeader={() => 'Icon in the left'}>
  51. <Item
  52. thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
  53. arrow="horizontal"
  54. onClick={() => {}}
  55. >My wallet</Item>
  56. <Item thumb="https://zos.alipayobjects.com/rmsportal/UmbJMbWOejVOpxe.png" arrow="horizontal">My Cost Ratio</Item>
  57. </List>
  58. <List renderHeader={() => 'Text Wrapping'} className="my-list">
  59. <Item data-seed="logId">Single linelong text will be hidden with ellipsis;</Item>
  60. <Item wrap>Multiple linelong text will wrapLong Text Long Text Long Text Long Text Long Text Long Text</Item>
  61. <Item extra="extra content" multipleLine align="top" wrap>
  62. Multiple line and long text will wrap. Long Text Long Text Long Text
  63. </Item>
  64. <Item extra="no arrow" arrow="empty" className="spe" wrap>
  65. In rare cases, the text of right side will wrap in the single line with long text. long text long text long text
  66. </Item>
  67. </List>
  68. <List renderHeader={() => 'Other'} className="my-list">
  69. <Item disabled={this.state.disabled} extra="" onClick={() => { console.log('click', this.state.disabled); this.setState({ disabled: true }); }}>Click to disable</Item>
  70. <Item>
  71. <select defaultValue="1">
  72. <option value="1">html select element</option>
  73. <option value="2" disabled>Unable to select</option>
  74. <option value="3">option 3</option>
  75. </select>
  76. </Item>
  77. </List>
  78. </div>);
  79. }
  80. }
  81. ReactDOM.render(<ListExample />, mountNode);
  1. .my-list .spe .am-list-extra {
  2. flex-basis: initial;
  3. }

可输入列表

Form Collection. (Use rc-form to validate form fields)

  1. import { List, InputItem, Switch, Stepper, Range, Button, createTooltip } from 'antd-mobile';
  2. import { createForm } from 'rc-form';
  3. const Item = List.Item;
  4. const RangeWithTooltip = createTooltip(Range);
  5. class BasicInput extends React.Component {
  6. state = {
  7. value: 1,
  8. }
  9. onSubmit = () => {
  10. this.props.form.validateFields({ force: true }, (error) => {
  11. if (!error) {
  12. console.log(this.props.form.getFieldsValue());
  13. } else {
  14. alert('Validation failed');
  15. }
  16. });
  17. }
  18. onReset = () => {
  19. this.props.form.resetFields();
  20. }
  21. validateAccount = (rule, value, callback) => {
  22. if (value && value.length > 4) {
  23. callback();
  24. } else {
  25. callback(new Error('At least four charactors for account'));
  26. }
  27. }
  28. render() {
  29. const { getFieldProps, getFieldError } = this.props.form;
  30. return (<form>
  31. <List renderHeader={() => 'Form Validation'}
  32. renderFooter={() => getFieldError('account') && getFieldError('account').join(',')}
  33. >
  34. <InputItem
  35. {...getFieldProps('account', {
  36. // initialValue: 'little ant',
  37. rules: [
  38. { required: true, message: 'Please input account' },
  39. { validator: this.validateAccount },
  40. ],
  41. })}
  42. clear
  43. error={!!getFieldError('account')}
  44. onErrorClick={() => {
  45. alert(getFieldError('account').join('、'));
  46. }}
  47. placeholder="Please input account"
  48. >Account</InputItem>
  49. <InputItem {...getFieldProps('password')} placeholder="Please input password" type="password">
  50. Password
  51. </InputItem>
  52. <Item
  53. extra={<Switch {...getFieldProps('1', { initialValue: true, valuePropName: 'checked' })} />}
  54. >Confirm Infomation</Item>
  55. <Item><div style={{ position: 'relative', top: '-0.14rem' }}><RangeWithTooltip defaultValue={[20, 80]} /></div></Item>
  56. <Item extra={<Stepper style={{ width: '100%', minWidth: '2rem' }} showNumber size="small" defaultValue={20} />}>Number of Subscribers</Item>
  57. <Item>
  58. <Button type="primary" onClick={this.onSubmit} inline>Submit</Button>
  59. <Button onClick={this.onReset} inline style={{ marginLeft: 5 }}>Reset</Button>
  60. </Item>
  61. </List>
  62. </form>);
  63. }
  64. }
  65. const BasicInputWrapper = createForm()(BasicInput);
  66. ReactDOM.render(<BasicInputWrapper />, mountNode);

List列表 - 图1

API

适用平台:WEB、React-Native

List

属性说明类型默认值
renderHeaderlist heder(): void
renderFooterlist footer(): void

List.Item

属性说明类型默认值
thumb缩略图(当为 string 类型时作为 img src)String/React.Element
extra右边内容String/React.Element
arrow箭头方向(右,上,下), 可选horizontal,up,down,empty,如果是empty则存在对应的dom,但是不显示String
alignFlex 子元素垂直对齐,可选top,middle,bottomStringmiddle
onClick点击事件的回调函数(): void
onLongPress长按事件的回调函数(): void
error(web only)报错样式,右侧文字颜色变成橙色Booleanfalse
multipleLine多行Booleanfalse
wrap是否换行,默认情况下,文字超长会被隐藏,Booleanfalse
activeStyle(web only)自定义active的样式Object
platform (web only)设定组件的平台特有样式, 可选值为 android, ios, 默认为 cross, 即组件会自动检测设备 UA 应用不同平台的样式String'cross'

List.Item.Brief

辅助说明