index.js 1.21 KB
Newer Older
涂茜's avatar
涂茜 committed
1
import React, { useContext } from 'react';
涂茜's avatar
涂茜 committed
2
import PropTypes from 'prop-types';
涂茜's avatar
涂茜 committed
3 4
import classNames from 'classnames';
import { Input, Tree, Divider, ConfigProvider } from 'antd';
涂茜's avatar
涂茜 committed
5
import { SearchOutlined } from '@ant-design/icons';
涂茜's avatar
涂茜 committed
6
import Empty from '@wisdom-components/empty';
涂茜's avatar
涂茜 committed
7
import './index.less';
涂茜's avatar
涂茜 committed
8 9 10 11

const DeviceTree = (props) => {
  const { prefix, placeholder, treeData, onSearch } = props;

涂茜's avatar
涂茜 committed
12 13 14
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('device-tree');

涂茜's avatar
涂茜 committed
15
  return (
涂茜's avatar
涂茜 committed
16
    <div className={classNames(prefixCls)}>
涂茜's avatar
涂茜 committed
17 18 19 20 21 22 23 24
      <Input
        prefix={prefix}
        placeholder={placeholder}
        bordered={false}
        onChange={onSearch}
        onPressEnter={onSearch}
      />
      <Divider />
涂茜's avatar
涂茜 committed
25 26 27 28
      <div className={classNames(`${prefixCls}-content`)}>
        {!!treeData.length && <Tree {...props} />}
        {!treeData.length && <Empty />}
      </div>
涂茜's avatar
涂茜 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    </div>
  );
};

DeviceTree.defaultProps = {
  prefix: <SearchOutlined />,
  placeholder: '搜索设备名称',
  treeData: [],
  onSearch: () => {},
};

DeviceTree.propTypes = {
  prefix: PropTypes.node,
  placeholder: PropTypes.string,
  treeData: PropTypes.array,
  onSearch: PropTypes.func,
};

export default DeviceTree;