index.js 1.05 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { PureComponent, createElement } from 'react';
2
import PropTypes from 'prop-types';
afc163's avatar
afc163 committed
3
import { Button } from 'antd';
4 5 6 7 8
import styles from './index.less';

// TODO: 添加逻辑

class EditableLinkGroup extends PureComponent {
偏右's avatar
偏右 committed
9 10 11 12 13
  static propTypes = {
    links: PropTypes.array,
    onAdd: PropTypes.func,
    linkElement: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  };
14

jim's avatar
jim committed
15 16 17 18 19
  static defaultProps = {
    links: [],
    onAdd: () => {},
    linkElement: 'a',
  };
陈帅's avatar
陈帅 committed
20

21
  render() {
偏右's avatar
偏右 committed
22
    const { links, linkElement, onAdd } = this.props;
23 24
    return (
      <div className={styles.linkGroup}>
jim's avatar
jim committed
25 26 27 28
        {links.map(link =>
          createElement(
            linkElement,
            {
偏右's avatar
偏右 committed
29 30 31
              key: `linkGroup-item-${link.id || link.title}`,
              to: link.href,
              href: link.href,
jim's avatar
jim committed
32 33 34 35
            },
            link.title
          )
        )}
36
        {
afc163's avatar
afc163 committed
37 38
          <Button size="small" type="primary" ghost onClick={onAdd} icon="plus">
            添加
39 40 41 42 43 44 45 46
          </Button>
        }
      </div>
    );
  }
}

export default EditableLinkGroup;