index.js 1.03 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { PureComponent, createElement } from 'react';
2 3 4 5 6 7 8 9 10
import PropTypes from 'prop-types';
import { Button, Icon } from 'antd';
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
        }
        {
偏右's avatar
偏右 committed
35
          <Button size="small" onClick={onAdd}>
niko's avatar
niko committed
36
            <Icon type="plus" />添加
37 38 39 40 41 42 43 44
          </Button>
        }
      </div>
    );
  }
}

export default EditableLinkGroup;