index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React, { PureComponent, createElement } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Button } from 'antd';
  4. import styles from './index.less';
  5. // TODO: 添加逻辑
  6. class EditableLinkGroup extends PureComponent {
  7. static propTypes = {
  8. links: PropTypes.array,
  9. onAdd: PropTypes.func,
  10. linkElement: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  11. };
  12. static defaultProps = {
  13. links: [],
  14. onAdd: () => {},
  15. linkElement: 'a',
  16. };
  17. render() {
  18. const { links, linkElement, onAdd } = this.props;
  19. return (
  20. <div className={styles.linkGroup}>
  21. {links.map(link =>
  22. createElement(
  23. linkElement,
  24. {
  25. key: `linkGroup-item-${link.id || link.title}`,
  26. to: link.href,
  27. href: link.href,
  28. },
  29. link.title
  30. )
  31. )}
  32. {
  33. <Button size="small" type="primary" ghost onClick={onAdd} icon="plus">
  34. 添加
  35. </Button>
  36. }
  37. </div>
  38. );
  39. }
  40. }
  41. export default EditableLinkGroup;