Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-input

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-input - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

LICENSE

119

index.js
var React = require('react/addons');
var classes = require('react-classes');
var Input = React.createClass({
mixins: [React.addons.LinkedStateMixin],
mixins: [React.addons.LinkedStateMixin, classes],
/**
* @function focus
* @description Focus on the element.
*/
focus: function () {
if (this.isMounted()) {
this.refs.input.getDOMNode().focus();
}
},
/**
* @function value
* @returns {string} The value of the input.
*/
value: function () {
return this.state.value;
},
/**
* @function clear
* @description Clear the value of the element.
*/
clear: function() {
this.setState({
value: ''
});
},
/**
* @private
* @function onChange
* @descriptin When the value of the input changes, update the state.
*/
_onChange: function (event) {
this.getValueLink(this.props).requestChange(event.target.value);
// Get the value from the input
var value = event.target.value;
// Set the state
this.setState({
value: value
});
// Run the onChange function if it exists
if (this.props.onChange) {
this.props.onChange(event, value);
}
},

@@ -14,35 +61,34 @@

type: React.PropTypes.string,
value: React.PropTypes.string,
onChange: React.PropTypes.func,
valueLink: React.PropTypes.shape({
value: React.PropTypes.string.isRequired,
requestChange: React.PropTypes.func.isRequired
})
name: React.PropTypes.string,
placeholder: React.PropTypes.string,
defaultValue: React.PropTypes.string,
error: React.PropTypes.string,
disabled: React.PropTypes.bool,
onChange: React.PropTypes.func
},
getInitialState: function () {
return {
value: this.props.defaultValue || ''
}
},
getDefaultProps: function () {
return {
label: '',
type: 'text',
value: '',
onChange: function () {
return;
},
valueLink: null
onChange: this._onChange
}
},
getValueLink: function(props) {
return props.valueLink || {
value: props.value,
requestChange: props.onChange
};
},
render: function () {
var Label; // the form label
var classes = this.getClass('input-group', {
'input-group-error': this.props.error || false,
'input-group-disabled': this.props.disabled || false
});
var label; // the form label
if (this.props.label) {
Label = (
label = (
<label className="input-group-label" for={this.props.name}>{this.props.label}</label>

@@ -52,13 +98,30 @@ );

/**
* Create the span element used for containing messages
* related to the element.
*/
var span;
if (this.props.error) {
span = (
<span className="input-group-span">{this.props.error}</span>
);
} else if (this.props.message) {
span = (
<span className="input-group-span">{this.props.message}</span>
);
}
return (
<div className="input-group">
<Label />
<div className={classes} ref={this.props.ref}>
{label}
<input
ref="input"
className="input-group-field"
type={this.props.type}
className="input-group-field"
name={this.props.name}
label={this.props.label}
placeholder={this.props.placeholder}
value={this.getValueLink(this.props).value}
value={this.state.value}
onChange={this._onChange}/>
{span}
</div>

@@ -65,0 +128,0 @@ )

{
"name": "react-input",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple input component for React.",

@@ -26,4 +26,5 @@ "main": "index.js",

"dependencies": {
"react": "^0.12.2"
"react": "^0.12.2",
"react-classes": "^1.0.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc