@blueprintjs-formik/core
Version:
Bindings for using Formik and Blueprint.js
56 lines • 2.31 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React from 'react';
import { Checkbox as BPCheckbox, } from '@blueprintjs/core';
import { Field } from './FieldBase';
/**
* Transformes the field props to checkbox props.
* @param {CheckboxToFieldProps}
* @returns {CheckboxProps}
*/
function fieldToCheckbox(_a) {
var disabled = _a.disabled, _b = _a.field, fieldOnBlur = _b.onBlur, field = __rest(_b, ["onBlur"]), form = _a.form, type = _a.type, onBlur = _a.onBlur, props = __rest(_a, ["disabled", "field", "form", "type", "onBlur"]);
var indeterminate = !Array.isArray(field.value) && field.value == null;
return __assign(__assign({ indeterminate: indeterminate, onBlur: onBlur !== null && onBlur !== void 0 ? onBlur : function (e) {
fieldOnBlur(e !== null && e !== void 0 ? e : field.name);
} }, field), props);
}
/**
* Transformes the Formik field props to checkbox group component.
* @param {CheckboxToFieldProps}
* @returns {JSX.Element}
*/
function FieldToCheckboxGroup(_a) {
var props = __rest(_a, []);
return React.createElement(BPCheckbox, __assign({}, fieldToCheckbox(props)));
}
/**
* Checkbox BP wrappeed component to bind with Formik.
* @param {CheckboxProps}
* @returns {JSX.Element}
*/
export function Checkbox(_a) {
var props = __rest(_a, []);
return (React.createElement(Field, __assign({}, props, { type: 'checkbox', component: FieldToCheckboxGroup })));
}
//# sourceMappingURL=Checkbox.js.map