2016-05-02 14:50:50 +05:30
|
|
|
import React, { PropTypes } from 'react';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import { uniqueId } from 'functions';
|
|
|
|
import icons from 'components/ui/icons.scss';
|
2016-05-30 10:10:59 +05:30
|
|
|
import { colors, skins, SKIN_DARK, COLOR_GREEN } from 'components/ui';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
import styles from './form.scss';
|
2016-05-02 14:50:50 +05:30
|
|
|
import FormInputComponent from './FormInputComponent';
|
2016-05-02 12:45:42 +05:30
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
export default class Input extends FormInputComponent {
|
2016-05-02 12:45:42 +05:30
|
|
|
static displayName = 'Input';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
placeholder: PropTypes.oneOfType([
|
|
|
|
PropTypes.shape({
|
|
|
|
id: PropTypes.string
|
|
|
|
}),
|
|
|
|
PropTypes.string
|
|
|
|
]),
|
|
|
|
label: PropTypes.oneOfType([
|
|
|
|
PropTypes.shape({
|
|
|
|
id: PropTypes.string
|
|
|
|
}),
|
|
|
|
PropTypes.string
|
2016-05-02 14:50:50 +05:30
|
|
|
]),
|
2016-05-02 12:45:42 +05:30
|
|
|
error: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
2016-05-30 10:10:59 +05:30
|
|
|
skin: PropTypes.oneOf(skins),
|
2016-06-16 18:41:55 +05:30
|
|
|
color: PropTypes.oneOf(colors),
|
|
|
|
center: PropTypes.bool
|
2016-05-30 10:10:59 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
color: COLOR_GREEN,
|
|
|
|
skin: SKIN_DARK
|
2016-05-02 12:45:42 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2016-06-16 18:41:55 +05:30
|
|
|
const { color, skin, center } = this.props;
|
2016-05-30 10:10:59 +05:30
|
|
|
let { icon, label } = this.props;
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
const props = {
|
|
|
|
type: 'text',
|
|
|
|
...this.props
|
|
|
|
};
|
|
|
|
|
|
|
|
if (label) {
|
|
|
|
if (!props.id) {
|
|
|
|
props.id = uniqueId('input');
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
label = this.formatMessage(label);
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
label = (
|
|
|
|
<label className={styles.textFieldLabel} htmlFor={props.id}>
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
props.placeholder = this.formatMessage(props.placeholder);
|
2016-05-02 12:45:42 +05:30
|
|
|
|
|
|
|
let baseClass = styles.formRow;
|
|
|
|
if (icon) {
|
|
|
|
baseClass = styles.formIconRow;
|
|
|
|
icon = (
|
2016-06-16 18:41:55 +05:30
|
|
|
<span className={classNames(styles.textFieldIcon, icons[icon])} />
|
2016-05-02 12:45:42 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={baseClass}>
|
|
|
|
{label}
|
|
|
|
<div className={styles.textFieldContainer}>
|
2016-05-02 14:50:50 +05:30
|
|
|
<input ref={this.setEl}
|
|
|
|
className={classNames(
|
|
|
|
styles[`${skin}TextField`],
|
2016-06-16 18:41:55 +05:30
|
|
|
styles[`${color}TextField`],
|
|
|
|
{
|
|
|
|
[styles.textFieldCenter]: center
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
)}
|
|
|
|
{...props}
|
|
|
|
/>
|
2016-05-02 12:45:42 +05:30
|
|
|
{icon}
|
|
|
|
</div>
|
2016-05-02 14:50:50 +05:30
|
|
|
{this.renderError()}
|
2016-05-02 12:45:42 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.el.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
this.el.focus();
|
|
|
|
setTimeout(this.el.focus.bind(this.el), 10);
|
|
|
|
}
|
|
|
|
}
|