@blueprintjs-formik/datetime
Version:
Bindings for using Formik and Blueprint.js
40 lines (37 loc) • 1.81 kB
JavaScript
import { __rest, __assign } from '../_virtual/_tslib.js';
import React from 'react';
import { Field, getIn } from 'formik';
import { Intent } from '@blueprintjs/core';
import { TimezoneSelect as TimezoneSelect$1 } from '@blueprintjs/datetime2';
/**
* Transforms field props to timezone select props.
* @param {FieldToTimezoneSelect} props - Field props
* @returns {TimezoneSelectProps}
*/
function fieldToTimezoneSelect(_a) {
var _b = _a.field; _b.onBlur; var field = __rest(_b, ["onBlur"]), _c = _a.form, touched = _c.touched, errors = _c.errors, form = __rest(_c, ["touched", "errors"]); _a.meta; var props = __rest(_a, ["field", "form", "meta"]);
var fieldError = getIn(errors, field.name);
var showError = getIn(touched, field.name) && !!fieldError;
return __assign(__assign(__assign({}, field), { onChange: function (timezone) {
form.setFieldValue(field.name, timezone);
}, buttonProps: __assign({ intent: showError ? Intent.DANGER : Intent.NONE }, props === null || props === void 0 ? void 0 : props.buttonProps), value: field.value || '' }), props);
}
/**
* Transforms field props to timezone select component.
* @param {FieldProps} props - Field props
* @returns {JSX.Element}
*/
function FieldToTimezoneSelectComponent(props) {
return (React.createElement(TimezoneSelect$1, __assign({}, fieldToTimezoneSelect(props))));
}
/**
* Timezone select Blueprint component binded with Formik.
* @param {TimezoneSelectProps} props - Timezone select props
* @returns {JSX.Element}
*/
function TimezoneSelect(_a) {
var props = __rest(_a, []);
return React.createElement(Field, __assign({}, props, { component: FieldToTimezoneSelectComponent }));
}
export { TimezoneSelect };
//# sourceMappingURL=TimezoneSelect.js.map