improve demo code style

This commit is contained in:
afc163 2017-02-19 15:06:37 +08:00
parent e289ce8b31
commit f5b0536d42

View File

@ -43,38 +43,37 @@ class NumericInput extends React.Component {
// '.' at the end or only '-' in the input box.
onBlur = () => {
const { value } = this.props;
const { value, onBlur, onChange } = this.props;
if (value.charAt(value.length - 1) === '.' || value === '-') {
this.props.onChange({ value: value.slice(0, -1) });
onChange({ value: value.slice(0, -1) });
}
if (this.props.onBlur) {
this.props.onBlur();
if (onBlur) {
onBlur();
}
}
render() {
const { value } = this.props;
const title = (value ?
(<span className="numeric-input-title">
const title = value ? (
<span className="numeric-input-title">
{value !== '-' ? formatNumber(value) : '-'}
</span>) : '');
</span>
) : '';
return (
<div>
<Tooltip
trigger={['focus']}
title={title}
placement="topLeft"
overlayClassName="numeric-input"
>
<Input
{...this.props}
onChange={this.onChange}
onBlur={this.onBlur}
placeholder="input a number"
maxLength="25"
/>
</Tooltip>
</div>
<Tooltip
trigger={['focus']}
title={title}
placement="topLeft"
overlayClassName="numeric-input"
>
<Input
{...this.props}
onChange={this.onChange}
onBlur={this.onBlur}
placeholder="input a number"
maxLength="25"
/>
</Tooltip>
);
}
}
@ -89,11 +88,7 @@ class NumericInputDemo extends React.Component {
}
render() {
const { value } = this.state;
return (
<div className="numeric-input-demo">
<NumericInput value={value} onChange={this.onChange} />
</div>
);
return <NumericInput style={{ width: 120 }} value={value} onChange={this.onChange} />;
}
}
@ -111,8 +106,4 @@ or the height is not enough when content is empty */
.numeric-input .numeric-input-title {
font-size: 14px;
}
.numeric-input-demo {
width: 120px;
}
````