transfer.stories.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react';
  2. import { storiesOf } from '@storybook/react';
  3. import Transfer from '../index';
  4. const stories = storiesOf('Transfer', module);
  5. const commonProps = {
  6. onSelect: (...args: any) => {
  7. console.log('onSelect');
  8. console.log(...args);
  9. },
  10. onChange: (...args: any) => {
  11. console.log('onChange');
  12. console.log(...args);
  13. },
  14. onDeselect: (...args: any) => {
  15. console.log('onDeselect');
  16. console.log(...args);
  17. },
  18. onSearch: (...args: any) => {
  19. console.log('onSearch');
  20. console.log(...args);
  21. },
  22. };
  23. const data = Array.from({ length: 100 }, (v, i) => {
  24. return {
  25. label: `选项名称${i}`,
  26. value: i,
  27. disabled: false,
  28. key: i,
  29. };
  30. });
  31. const dataWithGroup = [
  32. {
  33. title: '类别A',
  34. children: [
  35. { label: '选项名称1', value: 1, disabled: false, key: 1 },
  36. { label: '选项名称2', value: 2, disabled: false, key: 2 },
  37. { label: '选项名称3', value: 3, disabled: false, key: 3 },
  38. ],
  39. },
  40. {
  41. title: '类别B',
  42. children: [
  43. { label: '选项名称1', value: 4, disabled: true, key: 4 },
  44. { label: '选项名称2', value: 5, disabled: false, key: 5 },
  45. { label: '选项名称3', value: 6, disabled: false, key: 6 },
  46. ],
  47. },
  48. {
  49. title: '类别C',
  50. children: [
  51. { label: '选项名称1', value: 7, disabled: false, key: 7 },
  52. { label: '选项名称2', value: 8, disabled: false, key: 8 },
  53. { label: '选项名称3', value: 9, disabled: false, key: 9 },
  54. { label: '选项名称3', value: 10, disabled: false, key: 10 },
  55. { label: '选项名称3', value: 11, disabled: false, key: 11 },
  56. { label: '选项名称3', value: 12, disabled: false, key: 12 },
  57. { label: '选项名称3', value: 13, disabled: false, key: 13 },
  58. ],
  59. },
  60. ];
  61. stories.add('Transfer', () => (
  62. <>
  63. <div style={{ margin: 10, padding: 10, width: 600 }}>
  64. <Transfer {...commonProps} dataSource={data} defaultValue={[2, 4]} emptyContent={{right: 123}}/>
  65. </div>
  66. </>
  67. ));
  68. stories.add('分组Transfer', () => (
  69. <div style={{ margin: 10, padding: 10, width: 600 }}>
  70. <Transfer onChange={(values,items) => console.log(values)} dataSource={dataWithGroup} type="groupList" />
  71. <Transfer {...commonProps} dataSource={dataWithGroup} defaultValue={[2, 4]} type="groupList" />
  72. </div>
  73. ));