feat: Add option for component: 'mention'

This commit is contained in:
转二 2017-09-25 21:12:43 +08:00
parent 91b97d7b25
commit 20dae8f33e
4 changed files with 48 additions and 2 deletions

View File

@ -0,0 +1,37 @@
---
order: 0
title:
zh-CN: 向上展开
en-US: Expand up
---
## zh-CN
向上展开建议。
## en-US
Expand the suggestions up.
````jsx
import { Mention } from 'antd';
const { toString } = Mention;
function onChange(contentState) {
console.log(toString(contentState));
}
function onSelect(suggestion) {
console.log('onSelect', suggestion);
}
ReactDOM.render(
<Mention
style={{ width: '100%', height: 100 }}
onChange={onChange}
suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
onSelect={onSelect}
placement="top"
/>
, mountNode);
````

View File

@ -4,6 +4,8 @@ import classNames from 'classnames';
import shallowequal from 'shallowequal'; import shallowequal from 'shallowequal';
import Icon from '../icon'; import Icon from '../icon';
export type MentionPlacement = 'top' | 'bottom';
export interface MentionProps { export interface MentionProps {
prefixCls?: string; prefixCls?: string;
suggestionStyle?: React.CSSProperties; suggestionStyle?: React.CSSProperties;
@ -24,6 +26,7 @@ export interface MentionProps {
onBlur?: Function; onBlur?: Function;
readOnly?: boolean; readOnly?: boolean;
disabled?: boolean; disabled?: boolean;
placement?: MentionPlacement;
} }
export interface MentionState { export interface MentionState {
@ -38,6 +41,7 @@ export default class Mention extends React.Component<MentionProps, MentionState>
notFoundContent: '无匹配结果,轻敲空格完成输入', notFoundContent: '无匹配结果,轻敲空格完成输入',
loading: false, loading: false,
multiLines: false, multiLines: false,
placement: 'bottom',
}; };
static Nav = Nav; static Nav = Nav;
static toString = toString; static toString = toString;
@ -117,10 +121,11 @@ export default class Mention extends React.Component<MentionProps, MentionState>
this.mentionEle = ele; this.mentionEle = ele;
} }
render() { render() {
const { className = '', prefixCls, loading } = this.props; const { className = '', prefixCls, loading, placement } = this.props;
const { suggestions, focus } = this.state; const { suggestions, focus } = this.state;
const cls = classNames(className, { const cls = classNames(className, {
[`${prefixCls}-active`]: focus, [`${prefixCls}-active`]: focus,
[`${prefixCls}-placement-top`]: placement === 'top',
}); });
const notFoundContent = loading const notFoundContent = loading

View File

@ -61,6 +61,10 @@
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
&-placement-top {
margin-top: -0.1em;
}
&-notfound&-item { &-notfound&-item {
color: @disabled-color; color: @disabled-color;

View File

@ -56,7 +56,7 @@
"rc-collapse": "~1.7.5", "rc-collapse": "~1.7.5",
"rc-dialog": "~6.5.10", "rc-dialog": "~6.5.10",
"rc-dropdown": "~1.5.0", "rc-dropdown": "~1.5.0",
"rc-editor-mention": "~0.6.12", "rc-editor-mention": "^1.0.2",
"rc-form": "~1.4.0", "rc-form": "~1.4.0",
"rc-input-number": "~3.6.0", "rc-input-number": "~3.6.0",
"rc-menu": "~5.1.0", "rc-menu": "~5.1.0",