Demo.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react';
  2. import TreeSelect, { TreeSelectProps } from '../index';
  3. const Demo = (props: TreeSelectProps): React.ReactElement => {
  4. const treeData = [
  5. {
  6. label: 'Asia',
  7. value: 'Asia',
  8. key: '0',
  9. children: [
  10. {
  11. label: 'China',
  12. value: 'China',
  13. key: '0-0',
  14. children: [
  15. {
  16. label: 'Beijing',
  17. value: 'Beijing',
  18. key: '0-0-0',
  19. },
  20. {
  21. label: 'Shanghai',
  22. value: 'Shanghai',
  23. key: '0-0-1',
  24. },
  25. ],
  26. },
  27. {
  28. label: 'Japan',
  29. value: 'Japan',
  30. key: '0-1',
  31. children: [
  32. {
  33. label: 'Osaka',
  34. value: 'Osaka',
  35. key: '0-1-0'
  36. }
  37. ]
  38. },
  39. ],
  40. },
  41. {
  42. label: 'North America',
  43. value: 'North America',
  44. key: '1',
  45. children: [
  46. {
  47. label: 'United States',
  48. value: 'United States',
  49. key: '1-0'
  50. },
  51. {
  52. label: 'Canada',
  53. value: 'Canada',
  54. key: '1-1'
  55. }
  56. ]
  57. }
  58. ];
  59. return (
  60. <div>
  61. <TreeSelect
  62. style={{ width: 300 }}
  63. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  64. treeData={treeData}
  65. filterTreeNode
  66. placeholder="单选可搜索的"
  67. />
  68. <TreeSelect
  69. style={{ width: 300 }}
  70. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  71. treeData={treeData}
  72. multiple
  73. filterTreeNode
  74. maxTagCount={2}
  75. placeholder="多选可搜索的"
  76. searchPlaceholder="请输入关键字开始搜索"
  77. />
  78. </div>
  79. );
  80. };
  81. export default Demo;