UNPKG

cjd-parkball

Version:

> 中后台业务组件库,中后台就像公园,进入需要买门票(登录),所以以 Parkball(公园球) 命名,公园内必定捕获!作为一个组件库,提供使用方法文档,方便开发者的调用

70 lines (56 loc) 1.45 kB
--- category: 2 title: 自定义建议 title_en: Customize Suggestion --- zh-CN 自定义建议 注意,自定义建议时,onSearchChange 必须不能为空。 en-US Customize suggestions. ````jsx import { Mention } from 'parkball'; const Nav = Mention.Nav; const webFrameworks = [ { name: 'React', type: 'JavaScript' }, { name: 'Angular', type: 'JavaScript' }, { name: 'Laravel', type: 'PHP', disabled: true }, { name: 'Flask', type: 'Python' }, { name: 'Django', type: 'Python' }, ]; function onSelect(suggestion, data) { console.log('onSelect', suggestion, data); } class CustomNavMention extends React.Component { state = { suggestions: [], } onSearchChange = (value) => { const searchValue = value.toLowerCase(); const filtered = webFrameworks.filter(item => item.name.toLowerCase().indexOf(searchValue) !== -1 ); const suggestions = filtered.map(suggestion => ( <Nav value={suggestion.name} data={suggestion} > <span>{suggestion.name} - {suggestion.type}</span> </Nav> )); this.setState({ suggestions }); } render() { const { suggestions } = this.state; return ( <Mention placeholder="@someone" style={{ width: '100%' }} suggestions={suggestions} onSearchChange={this.onSearchChange} onSelect={onSelect} /> ); } } ReactDOM.render(<CustomNavMention />, mountNode); ````