import React from 'react';
import classNames from 'classnames';
function ieGT9() {
if (typeof document === 'undefined') {
return false;
}
const documentMode = document.documentMode || 0;
return documentMode > 9;
}
function fixControlledValue(value) {
if (typeof value === 'undefined' || value === null) {
return '';
}
return value;
}
export default class Input extends React.Component {
static defaultProps = {
defaultValue: '',
disabled: false,
prefixCls: 'ant-input',
type: 'text',
}
static propTypes = {
type: React.PropTypes.string,
id: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number,
]),
size: React.PropTypes.oneOf(['small', 'default', 'large']),
disabled: React.PropTypes.bool,
value: React.PropTypes.any,
defaultValue: React.PropTypes.any,
className: React.PropTypes.string,
addonBefore: React.PropTypes.node,
addonAfter: React.PropTypes.node,
prefixCls: React.PropTypes.string,
}
renderLabledInput(children) {
const props = this.props;
const wrapperClassName = `${props.prefixCls}-group`;
const addonClassName = `${wrapperClassName}-addon`;
const addonBefore = props.addonBefore ? (
{props.addonBefore}
) : null;
const addonAfter = props.addonAfter ? (
{props.addonAfter}
) : null;
const className = classNames({
[`${props.prefixCls}-wrapper`]: true,
[wrapperClassName]: (addonBefore || addonAfter),
});
return (
{addonBefore}
{children}
{addonAfter}
);
}
renderInput() {
const props = { ...this.props };
const prefixCls = props.prefixCls;
if (!props.type) {
return props.children;
}
const inputClassName = classNames({
[prefixCls]: true,
[`${prefixCls}-sm`]: props.size === 'small',
[`${prefixCls}-lg`]: props.size === 'large',
[props.className]: !!props.className,
});
let placeholder = props.placeholder;
if (placeholder && ieGT9()) {
placeholder = null;
}
if ('value' in props) {
props.value = fixControlledValue(props.value);
}
switch (props.type) {
case 'textarea':
return ;
default:
return ;
}
}
render() {
return this.renderLabledInput(this.renderInput());
}
}