[Max Red] - Added error property to Input tag :D

This commit is contained in:
Ivan Diaz 2016-07-01 19:27:20 -03:00
parent 2f88162256
commit b59ebc48bd
3 changed files with 31 additions and 5 deletions

View File

@ -35,7 +35,7 @@ let DemoPage = React.createClass({
{ {
title: 'Input', title: 'Input',
render: ( render: (
<Input placeholder="placeholder"/> <Input placeholder="placeholder" error="No anda"/>
) )
}, },
{ {

View File

@ -13,7 +13,8 @@ const Input = React.createClass({
inputType: React.PropTypes.string, inputType: React.PropTypes.string,
password: React.PropTypes.bool, password: React.PropTypes.bool,
required: React.PropTypes.bool, required: React.PropTypes.bool,
icon: React.PropTypes.string icon: React.PropTypes.string,
error: React.PropTypes.string
}, },
getDefaultProps() { getDefaultProps() {
@ -28,10 +29,21 @@ const Input = React.createClass({
<span className="input__label">{this.props.label}</span> <span className="input__label">{this.props.label}</span>
{this.renderIcon()} {this.renderIcon()}
<input {...this.getInputProps()} className="input__text" /> <input {...this.getInputProps()} className="input__text" />
{this.renderError()}
</label> </label>
); );
}, },
renderError() {
let error = null;
if (this.props.error){
error = <span className="input__error"> {this.props.error} </span>;
}
return error;
},
renderIcon() { renderIcon() {
let icon = null; let icon = null;
@ -57,6 +69,7 @@ const Input = React.createClass({
let classes = { let classes = {
'input': true, 'input': true,
'input_with-icon': (this.props.icon), 'input_with-icon': (this.props.icon),
'input_with-error': (this.props.error),
['input_' + this.props.inputType]: true, ['input_' + this.props.inputType]: true,
[this.props.className]: (this.props.className) [this.props.className]: (this.props.className)

View File

@ -42,13 +42,26 @@
position: absolute; position: absolute;
margin: 1px; margin: 1px;
padding: 8px 12px; padding: 8px 12px;
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
background-color: #eee; background-color: #eee;
} }
.input__text { .input__text {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 40px; padding-left: 40px;
} }
} }
&_with-error {
.input__error {
color: red;
font-size: $font-size--sm;
display: block;
position: absolute;
}
.input__text {
border: 1px solid red;
}
}
} }