index.js 988 Bytes
Newer Older
1 2
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
3
import { Link } from 'react-router';
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import { Button, Icon } from 'antd';
import styles from './index.less';

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

class EditableLinkGroup extends PureComponent {
  static defaultProps = {
    links: [],
    onAdd: () => {
    },
  }
  state = {
    links: this.props.links,
  };

  handleOnClick() {
    const { onAdd } = this.props;
    onAdd();
  }

  render() {
    const { links } = this.state;
    return (
      <div className={styles.linkGroup}>
        {
          links.map(link => <Link key={`linkGroup-item-${link.id || link.title}`} to={link.href}>{link.title}</Link>)
        }
        {
          <Button size="small" onClick={() => this.handleOnClick()}>
niko's avatar
niko committed
33
            <Icon type="plus" />添加
34 35 36 37 38 39 40 41 42 43 44 45 46
          </Button>
        }
      </div>
    );
  }
}

EditableLinkGroup.propTypes = {
  links: PropTypes.array,
  onAdd: PropTypes.func,
};

export default EditableLinkGroup;