2016-07-04 10:31:27 +08:00
|
|
|
|
---
|
|
|
|
|
order: 3
|
2017-02-20 21:39:07 +08:00
|
|
|
|
title:
|
2016-09-23 09:40:32 +08:00
|
|
|
|
zh-CN: 头像
|
|
|
|
|
en-US: Icon Image
|
2016-07-04 10:31:27 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
|
|
自定义建议(含头像)
|
|
|
|
|
|
|
|
|
|
注意,自定义建议时,onSearchChange 必须不能为空。
|
|
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
2017-11-06 21:28:51 +08:00
|
|
|
|
Customize suggestions.
|
2016-07-04 10:31:27 +08:00
|
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
|
````jsx
|
2017-11-06 21:28:51 +08:00
|
|
|
|
import { Mention, Avatar } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
|
2016-07-04 10:31:27 +08:00
|
|
|
|
const Nav = Mention.Nav;
|
|
|
|
|
|
|
|
|
|
const webFrameworks = [
|
|
|
|
|
{ name: 'React', type: 'JavaScript', icon: 'https://zos.alipayobjects.com/rmsportal/LFIeMPzdLcLnEUe.svg' },
|
|
|
|
|
{ name: 'Angular', type: 'JavaScript', icon: 'https://zos.alipayobjects.com/rmsportal/PJTbxSvzYWjDZnJ.png' },
|
2016-10-31 15:39:03 +08:00
|
|
|
|
{ name: 'Dva', type: 'Javascript', icon: 'https://zos.alipayobjects.com/rmsportal/EYPwSeEJKxDtVxI.png' },
|
2016-07-04 10:31:27 +08:00
|
|
|
|
{ name: 'Flask', type: 'Python', icon: 'https://zos.alipayobjects.com/rmsportal/xaypBUijfnpAlXE.png' },
|
|
|
|
|
];
|
|
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
|
class CustomNavMention extends React.Component {
|
2017-02-20 21:47:57 +08:00
|
|
|
|
state = {
|
|
|
|
|
suggestions: [],
|
2017-02-20 21:39:07 +08:00
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
|
onSearchChange = (value) => {
|
2016-07-04 10:31:27 +08:00
|
|
|
|
const searchValue = value.toLowerCase();
|
2018-06-27 15:55:04 +08:00
|
|
|
|
const filtered = webFrameworks.filter(item => item.name.toLowerCase().indexOf(searchValue) !== -1
|
2016-07-04 10:31:27 +08:00
|
|
|
|
);
|
2017-05-15 14:37:22 +08:00
|
|
|
|
const suggestions = filtered.map(suggestion => (
|
|
|
|
|
<Nav
|
|
|
|
|
value={suggestion.name}
|
|
|
|
|
data={suggestion}
|
|
|
|
|
disabled={suggestion.disabled}
|
|
|
|
|
>
|
2017-11-06 21:28:51 +08:00
|
|
|
|
<Avatar
|
|
|
|
|
src={suggestion.icon}
|
|
|
|
|
size="small"
|
|
|
|
|
style={{ width: 14, height: 14, marginRight: 8, top: 2, position: 'relative' }}
|
|
|
|
|
/>
|
|
|
|
|
{suggestion.name} - {suggestion.type}
|
2017-05-15 14:37:22 +08:00
|
|
|
|
</Nav>
|
|
|
|
|
));
|
2017-02-20 21:39:07 +08:00
|
|
|
|
this.setState({ suggestions });
|
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
|
2016-07-04 10:31:27 +08:00
|
|
|
|
render() {
|
2016-08-29 14:46:31 +08:00
|
|
|
|
const { suggestions } = this.state;
|
2016-07-21 15:40:13 +08:00
|
|
|
|
return (
|
|
|
|
|
<Mention
|
2017-09-25 22:42:07 +08:00
|
|
|
|
style={{ width: '100%' }}
|
2016-07-21 15:40:13 +08:00
|
|
|
|
suggestions={suggestions}
|
|
|
|
|
onSearchChange={this.onSearchChange}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2017-02-20 21:39:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 10:31:27 +08:00
|
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
|
ReactDOM.render(<CustomNavMention />, mountNode);
|
2016-07-04 10:31:27 +08:00
|
|
|
|
````
|