[Ivan Diaz y Maxi] - Added property icon to Input tag :D

This commit is contained in:
Ivan Diaz 2016-07-01 18:25:13 -03:00
parent e039162025
commit 2f88162256
3 changed files with 38 additions and 6 deletions

View File

@ -41,7 +41,7 @@ let DemoPage = React.createClass({
{ {
title: 'Input wrapped in a label', title: 'Input wrapped in a label',
render: ( render: (
<Input placeholder="placeholder" label="This is a label" /> <Input placeholder="placeholder" label="This is a label" icon="user" />
) )
}, },
{ {

View File

@ -2,6 +2,8 @@ const React = require('react');
const classNames = require('classnames'); const classNames = require('classnames');
const _ = require('lodash'); const _ = require('lodash');
const Icon = require('core-components/icon');
const Input = React.createClass({ const Input = React.createClass({
propTypes: { propTypes: {
@ -10,7 +12,8 @@ const Input = React.createClass({
onChange: React.PropTypes.func, onChange: React.PropTypes.func,
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
}, },
getDefaultProps() { getDefaultProps() {
@ -22,12 +25,23 @@ const Input = React.createClass({
render() { render() {
return ( return (
<label className={this.getClass()}> <label className={this.getClass()}>
<span className="input--label">{this.props.label}</span> <span className="input__label">{this.props.label}</span>
<input {...this.getInputProps()} className="input--text" /> {this.renderIcon()}
<input {...this.getInputProps()} className="input__text" />
</label> </label>
); );
}, },
renderIcon() {
let icon = null;
if (this.props.icon) {
icon = <span className="input__icon"><Icon name={this.props.icon} /></span>
}
return icon;
},
getInputProps() { getInputProps() {
let props = _.clone(this.props); let props = _.clone(this.props);
@ -42,6 +56,7 @@ const Input = React.createClass({
getClass() { getClass() {
let classes = { let classes = {
'input': true, 'input': true,
'input_with-icon': (this.props.icon),
['input_' + this.props.inputType]: true, ['input_' + this.props.inputType]: true,
[this.props.className]: (this.props.className) [this.props.className]: (this.props.className)

View File

@ -3,7 +3,7 @@
.input { .input {
display: block; display: block;
&--text { &__text {
border: 1px solid $grey; border: 1px solid $grey;
border-radius: 3px; border-radius: 3px;
padding: 8px; padding: 8px;
@ -19,7 +19,7 @@
} }
} }
&--label { &__label {
color: $primary-black; color: $primary-black;
font-size: 15px; font-size: 15px;
display: block; display: block;
@ -34,4 +34,21 @@
&_secondary { &_secondary {
width: 250px; width: 250px;
} }
&_with-icon {
position: relative;
.input__icon {
position: absolute;
margin: 1px;
padding: 8px 12px;
background-color: #eee;
}
.input__text {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 40px;
}
}
} }