index.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { ScrollList, ScrollItem, Button } from '@douyinfe/semi-ui';
  2. import React from 'react';
  3. class ScrollListDemo extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. selectIndex1: 1,
  8. selectIndex2: 1,
  9. selectIndex3: 1,
  10. };
  11. this.ampms = [
  12. {
  13. value: '上午',
  14. },
  15. {
  16. value: '下午',
  17. },
  18. ];
  19. this.hours = new Array(12).fill(0).map((itm, index) => {
  20. return {
  21. value: index + 1,
  22. };
  23. });
  24. this.minutes = new Array(60).fill(0).map((itm, index) => {
  25. return {
  26. value: index,
  27. disabled: index % 2 === 1 ? true : false,
  28. };
  29. });
  30. this.onSelectAP = this.onSelectAP.bind(this);
  31. this.onSelectHour = this.onSelectHour.bind(this);
  32. this.onSelectMinute = this.onSelectMinute.bind(this);
  33. this.handleClose = this.handleClose.bind(this);
  34. this.renderFooter = this.renderFooter.bind(this);
  35. }
  36. onSelectAP(data) {
  37. this.setState({
  38. ['selectIndex' + data.type]: data.index,
  39. });
  40. }
  41. onSelectHour(data) {
  42. console.log('You have choose the hour for: ', data.value);
  43. this.setState({
  44. ['selectIndex' + data.type]: data.index,
  45. });
  46. }
  47. onSelectMinute(data) {
  48. console.log('You have choose the minute for: ', data.value);
  49. this.setState({
  50. ['selectIndex' + data.type]: data.index,
  51. });
  52. }
  53. handleClose() {
  54. console.log('close');
  55. }
  56. renderFooter() {
  57. return (
  58. <Button size="small" type="primary" onClick={this.handleClose}>
  59. Ok
  60. </Button>
  61. );
  62. }
  63. render() {
  64. let list = this.list;
  65. const scrollStyle = {
  66. border: 'unset',
  67. boxShadow: 'unset',
  68. };
  69. const commonProps = {
  70. // mode: 'normal',
  71. mode: 'wheel',
  72. cycled: false,
  73. motion: true,
  74. };
  75. return (
  76. <div>
  77. <ScrollList style={scrollStyle} header={'无限滚动列表'} footer={this.renderFooter()}>
  78. <ScrollItem
  79. {...commonProps}
  80. list={this.ampms}
  81. type={1}
  82. selectedIndex={this.state.selectIndex1}
  83. onSelect={this.onSelectAP}
  84. aria-label="时段"
  85. />
  86. <ScrollItem
  87. {...commonProps}
  88. list={this.hours}
  89. type={2}
  90. selectedIndex={this.state.selectIndex2}
  91. onSelect={this.onSelectHour}
  92. aria-label="小时"
  93. />
  94. <ScrollItem
  95. {...commonProps}
  96. list={this.minutes}
  97. type={3}
  98. selectedIndex={this.state.selectIndex3}
  99. onSelect={this.onSelectMinute}
  100. aria-label="分钟"
  101. />
  102. </ScrollList>
  103. </div>
  104. );
  105. }
  106. }
  107. export default ScrollListDemo;