elemental
Version:
React UI Framework
42 lines (36 loc) • 1.53 kB
JavaScript
;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var React = require('react');
var blacklist = require('blacklist');
var classNames = require('classnames');
module.exports = React.createClass({
displayName: 'FormField',
propTypes: {
className: React.PropTypes.string,
htmlFor: React.PropTypes.string,
id: React.PropTypes.string,
label: React.PropTypes.string,
offsetAbsentLabel: React.PropTypes.bool,
width: React.PropTypes.oneOf(['one-half', 'two-quarters', 'three-sixths', 'one-quarter', 'three-quarters', 'one-third', 'two-sixths', 'two-thirds', 'four-sixths', 'one-fifth', 'two-fifths', 'three-fifths', 'four-fifths', 'one-sixth', 'five-sixths'])
},
render: function render() {
// classes
var componentClass = classNames('FormField', {
'offset-absent-label': this.props.offsetAbsentLabel
}, this.props.width, this.props.className);
// props
var props = blacklist(this.props, 'className', 'label', 'offsetAbsentLabel', 'width');
// elements
var componentLabel = this.props.label ? React.createElement(
'label',
{ className: 'FormLabel', htmlFor: this.props.id || this.props.htmlFor },
this.props.label
) : null;
return React.createElement(
'div',
_extends({ className: componentClass }, props),
componentLabel,
this.props.children
);
}
});