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

export default EditableLinkGroup;