@blueprintjs-formik/core
Version:
Bindings for using Formik and Blueprint.js
41 lines (38 loc) • 1.68 kB
JavaScript
import { __rest, __assign } from '../_virtual/_tslib.js';
import React__default from 'react';
import { getIn } from 'formik';
import { TextArea as TextArea$1, Intent } from '@blueprintjs/core';
import { Field } from './FieldBase.js';
/**
* Transforms the field props to textarea props.
* @param {Omit<FieldToTextAreaProps, 'children'>}
* @returns {TextAreaProps}
*/
function fieldToTextarea(_a) {
var _b = _a.field, onFieldBlur = _b.onBlur, field = __rest(_b, ["onBlur"]), _c = _a.form, touched = _c.touched, errors = _c.errors, onBlur = _a.onBlur, props = __rest(_a, ["field", "form", "onBlur"]);
var fieldError = getIn(errors, field.name);
var showError = getIn(touched, field.name) && !!fieldError;
return __assign(__assign({ id: field.name, intent: showError ? Intent.DANGER : Intent.NONE, onBlur: onBlur !== null && onBlur !== void 0 ? onBlur : function (e) {
onFieldBlur(e !== null && e !== void 0 ? e : field.name);
} }, field), props);
}
/**
* Transforms the field props to textarea props.
* @param {FieldToTextAreaProps}
* @returns {JSX.Element}
*/
function FieldToTextArea(_a) {
var children = _a.children, props = __rest(_a, ["children"]);
return React__default.createElement(TextArea$1, __assign({}, fieldToTextarea(props), { children: children }));
}
/**
* Textarea Blurprint component bound with Formik.
* @param {TextAreaProps}
* @returns {JSX.Element}
*/
function TextArea(_a) {
var props = __rest(_a, []);
return React__default.createElement(Field, __assign({}, props, { component: FieldToTextArea }));
}
export { TextArea };
//# sourceMappingURL=Textarea.js.map