index.js 1.03 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 9 10
import styles from './index.less';

// TODO: ζ·»εŠ ι€»θΎ‘

class EditableLinkGroup extends PureComponent {
  static defaultProps = {
    links: [],
偏右's avatar
偏右 committed
11 12
    onAdd: () => {},
    linkElement: 'a',
13 14
  };

偏右's avatar
偏右 committed
15 16 17 18 19
  static propTypes = {
    links: PropTypes.array,
    onAdd: PropTypes.func,
    linkElement: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  };
20 21

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

export default EditableLinkGroup;