cosmo-ui
Version:
Common React components
62 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var form_field_1 = require("../abstract/form-field");
var cx = require("classnames");
// import { Row } from './row'
// import { Column } from './column'
var styles = require('../../src/styles/components/forms.scss');
var borderStyles = require('../../src/styles/common/borders.scss');
var WebFormField = (function (_super) {
tslib_1.__extends(WebFormField, _super);
function WebFormField() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Initialize the field
* this will also trigger the validation
* but will not mark the field as dirty (only onFocus does that)
*/
WebFormField.prototype.componentDidMount = function () {
// console.log('FORM FIELD DID MOUNT', this)
this.init();
if (this.props.autofocus) {
this.field.focus();
}
};
WebFormField.prototype.render = function () {
// console.log('RENDER FORM FIELD', this)
// the field may not be initialized yet
if (!this.props.field) {
return null;
}
return null;
// return (
// <Column className={styles.fieldset}>
// {this.renderField()}
// <Row align="flex-start" className={styles.errorText}>
// {this.renderErrors()}
// </Row>
// </Column>
// )
};
WebFormField.prototype.classNames = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _a = this.props.field, valid = _a.valid, errors = _a.errors, focused = _a.focused, required = _a.required;
var res = cx.apply(void 0, [styles.field].concat(args, [this.props.className, (_b = {},
_b[styles.disabled] = this.props.disabled === true,
_b[borderStyles.error] = !this.props.disabled && this.shouldShowErrors(),
_b[borderStyles.success] = this.shouldShowValid(),
_b[borderStyles.info] = !this.props.disabled && focused && !valid,
_b)]));
// console.log('classnames', this.props, res)
return res;
var _b;
};
return WebFormField;
}(form_field_1.BaseFormField));
exports.WebFormField = WebFormField;
//# sourceMappingURL=form-field.js.map