UNPKG

@blueprintjs-formik/core

Version:
38 lines (35 loc) 1.4 kB
import { __rest, __assign } from '../_virtual/_tslib.js'; import React__default from 'react'; import { Switch as Switch$1 } from '@blueprintjs/core'; import { Field } from './FieldBase.js'; /** * Transforms the field props to switch props. * @param {SwitchToFieldProps} * @returns {SwitchProps} */ function fieldToSwitch(_a) { _a.disabled; var _b = _a.field, fieldOnBlur = _b.onBlur, field = __rest(_b, ["onBlur"]); _a.form; _a.type; var onBlur = _a.onBlur, props = __rest(_a, ["disabled", "field", "form", "type", "onBlur"]); return __assign(__assign({ id: field.name, onBlur: onBlur !== null && onBlur !== void 0 ? onBlur : function (e) { fieldOnBlur(e !== null && e !== void 0 ? e : field.name); } }, field), props); } /** * Transforms the field props to Switch BP properties. * @param {SwitchToFieldProps} * @returns {JSX.Element} */ function FieldToSwitchGroup(_a) { var props = __rest(_a, []); return React__default.createElement(Switch$1, __assign({}, fieldToSwitch(props))); } /** * Switch BP wrapped component to bind with Formik. * @param {SwitchProps} * @returns {JSX.Element} */ function Switch(_a) { var props = __rest(_a, []); return React__default.createElement(Field, __assign({}, props, { type: 'checkbox', component: FieldToSwitchGroup })); } export { Switch }; //# sourceMappingURL=Switch.js.map