index.js
1.03 KB
1
2
3
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
33
34
35
36
37
38
39
40
41
42
43
44
import React, { PureComponent, createElement } from 'react';
import PropTypes from 'prop-types';
import { Button } from 'antd';
import styles from './index.less';
// TODO: 添加逻辑
class EditableLinkGroup extends PureComponent {
static defaultProps = {
links: [],
onAdd: () => {},
linkElement: 'a',
};
static propTypes = {
links: PropTypes.array,
onAdd: PropTypes.func,
linkElement: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
};
render() {
const { links, linkElement, onAdd } = this.props;
return (
<div className={styles.linkGroup}>
{
links.map(link => (
createElement(linkElement, {
key: `linkGroup-item-${link.id || link.title}`,
to: link.href,
href: link.href,
}, link.title)
))
}
{
<Button size="small" type="primary" ghost onClick={onAdd} icon="plus">
添加
</Button>
}
</div>
);
}
}
export default EditableLinkGroup;