TreeSelect.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { FC, forwardRef } from 'react'
  21. import { TreeSelect as AntTreeSelect } from 'antd'
  22. import { TreeNode } from 'antd/lib/tree-select'
  23. import { IControl } from '../types'
  24. import { CONTROL_MAX_TAG_COUNT } from '../constants'
  25. import { filterTreeSelectOption } from 'app/utils/util'
  26. declare const SelectSizes: ['default', 'large', 'small']
  27. interface ITreeSelectProps {
  28. control: Omit<IControl, 'relatedItems' | 'relatedViews'>
  29. value?: string | string[]
  30. size?: typeof SelectSizes[number]
  31. onChange?: (value: string | string[]) => void
  32. options: TreeNode[]
  33. }
  34. const TreeSelect: FC<ITreeSelectProps> = (
  35. { control, value, size, onChange, options },
  36. ref
  37. ) => {
  38. const { multiple } = control
  39. return (
  40. <AntTreeSelect
  41. showSearch
  42. allowClear
  43. treeCheckable={multiple}
  44. treeDataSimpleMode
  45. placeholder="请选择"
  46. maxTagCount={CONTROL_MAX_TAG_COUNT}
  47. treeData={options}
  48. value={value}
  49. onChange={onChange}
  50. {...(size && { size })}
  51. filterTreeNode={filterTreeSelectOption}
  52. ref={ref}
  53. />
  54. )
  55. }
  56. export default forwardRef(TreeSelect)