UNPKG

@blueprintjs-formik/datetime

Version:
41 lines (38 loc) 1.93 kB
import { __rest, __assign } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@2.80.0_tslib@2.8.1_typescript@4.9.5/node_modules/tslib/tslib.es6.js'; import React from 'react'; import { getIn } from 'formik'; import { Intent } from '@blueprintjs/core'; import { TimezoneSelect as TimezoneSelect$1 } from '@blueprintjs/datetime2'; import { Field } from '@blueprintjs-formik/core'; /** * 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