index.js 1.5 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
import classNames from 'classnames';
4
import { Input, Tree, Divider, ConfigProvider, Skeleton } from 'antd';
涂茜's avatar
涂茜 committed
5
import { SearchOutlined } from '@ant-design/icons';
涂茜's avatar
涂茜 committed
6
import Empty from '@wisdom-components/empty';
7
import './index.less';
涂茜's avatar
涂茜 committed
8 9

const DeviceTree = (props) => {
10
  const { prefix, placeholder, treeData, first, onSearch } = props;
涂茜's avatar
涂茜 committed
11 12 13
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('device-tree');

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

DeviceTree.defaultProps = {
  prefix: <SearchOutlined />,
  placeholder: '搜索设备名称',
  treeData: [],
44
  onSearch: () => { },
涂茜's avatar
涂茜 committed
45 46 47 48 49 50 51 52 53 54
};

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

export default DeviceTree;