UNPKG

colonel-kurtz

Version:
77 lines (58 loc) 2.07 kB
'use strict'; function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var React = _interopDefault(require('react')); /** * Field * A reuseable field element */ function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } function uid(len) { len = len || 7; return Math.random() .toString(35) .substr(2, len) } var defaultProps = { hint: null, element: 'input', type: 'text' }; var Field = /*@__PURE__*/(function (superclass) { function Field(props) { superclass.call(this, props); this.fieldId = "col-field-" + (uid()); this.hintId = (this.fieldId) + "-hint"; } if ( superclass ) Field.__proto__ = superclass; Field.prototype = Object.create( superclass && superclass.prototype ); Field.prototype.constructor = Field; Field.prototype.getHint = function getHint (hint) { return hint ? ( React.createElement( 'span', { id: this.hintId, className: "col-field-hint" }, hint ) ) : null }; Field.prototype.render = function render () { var this$1 = this; var ref = this.props; var hint = ref.hint; var Element = ref.element; var label = ref.label; var rest = objectWithoutProperties( ref, ["hint", "element", "label"] ); var props = rest; var id = 'id' in props ? props.id : this.fieldId; return ( React.createElement( 'label', { className: "col-field", htmlFor: id }, React.createElement( 'span', { className: "col-field-label" }, label), React.createElement( Element, Object.assign({}, { ref: function (el) { return (this$1.input = el); }, id: id, className: "col-field-input", 'aria-describedby': hint ? this.hintId : null }, props)), this.getHint(hint) ) ) }; return Field; }(React.Component)); Field.defaultProps = defaultProps; module.exports = Field; //# sourceMappingURL=field.js.map