Created
May 22, 2018 07:36
-
-
Save irrigator/e65fe5e57eaa5fb1a097ee01b64636db to your computer and use it in GitHub Desktop.
reproduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import * as ReactDOM from 'react-dom' | |
import { Icon, Input, AutoComplete } from 'antd' | |
const Option = AutoComplete.Option | |
const OptGroup = AutoComplete.OptGroup | |
const dataSource = [ | |
{ | |
title: '话题', | |
children: [ | |
{ | |
title: 'AntDesign', | |
count: 10000, | |
}, | |
{ | |
title: 'AntDesign UI', | |
count: 10600, | |
}, | |
], | |
}, | |
{ | |
title: '问题', | |
children: [ | |
{ | |
title: 'AntDesign UI 有多好', | |
count: 60100, | |
}, | |
{ | |
title: 'AntDesign 是啥', | |
count: 30010, | |
}, | |
], | |
}, | |
{ | |
title: '文章', | |
children: [ | |
{ | |
title: 'AntDesign 是一个设计语言', | |
count: 100000, | |
}, | |
], | |
}, | |
] | |
function renderTitle(title: string) { | |
return ( | |
<span> | |
{title} | |
<a | |
style={{ float: 'right' }} | |
href="https://www.google.com/search?q=antd" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
更多 | |
</a> | |
</span> | |
) | |
} | |
const options = dataSource | |
.map(group => ( | |
<OptGroup key={group.title} label={renderTitle(group.title)}> | |
{group.children.map(opt => ( | |
<Option key={opt.title} value={opt.title}> | |
{opt.title} | |
<span className="certain-search-item-count">{opt.count} 人 关注</span> | |
</Option> | |
))} | |
</OptGroup> | |
)) | |
.concat([ | |
<Option disabled key="all"> | |
<a | |
href="https://www.google.com/search?q=antd" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
查看所有结果 | |
</a> | |
</Option>, | |
]) | |
function Complete() { | |
return ( | |
<div className="certain-category-search-wrapper" style={{ width: 250 }}> | |
<AutoComplete | |
className="certain-category-search" | |
dropdownClassName="certain-category-search-dropdown" | |
dropdownMatchSelectWidth={false} | |
dropdownStyle={{ width: 300 }} | |
size="large" | |
style={{ width: '100%' }} | |
dataSource={options} | |
placeholder="input here" | |
optionLabelProp="value" | |
> | |
<Input | |
suffix={<Icon type="search" className="certain-category-icon" />} | |
/> | |
</AutoComplete> | |
</div> | |
) | |
} | |
ReactDOM.render(<Complete />, document.getElementById('root')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment