UNPKG

@navinc/base-react-components

Version:
37 lines 1.88 kB
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 { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef } from 'react'; import { DATE_FORMAT_ISO8601_DATE, createProxyWithOverrides, formatDate } from '@navinc/utils'; const defaultMinDate = '1900-01-01'; const defaultMaxDate = '9999-12-31'; const resolveUncontrolled = (uncontrolled) => (uncontrolled ? undefined : ''); const updateEvent = (e) => { // appending 'T12:00:00' to the date string to prevent timezone shifting issues const value = e.target.value ? new Date(`${e.target.value}T12:00:00`) : undefined; const updatedEvent = e; updatedEvent.target = createProxyWithOverrides(updatedEvent.target, { value, }); return updatedEvent; }; export const BaseDateInput = forwardRef((_a, ref) => { var { value, uncontrolled, onChange, min, max } = _a, props = __rest(_a, ["value", "uncontrolled", "onChange", "min", "max"]); return (_jsx("input", Object.assign({ ref: ref, type: "date", min: min !== null && min !== void 0 ? min : defaultMinDate, max: max !== null && max !== void 0 ? max : defaultMaxDate, onChange: onChange ? (e) => { onChange(updateEvent(e)); } : undefined, value: value && !isNaN(value.getTime()) ? formatDate(value, DATE_FORMAT_ISO8601_DATE) : resolveUncontrolled(uncontrolled) }, props))); }); //# sourceMappingURL=base-date-input.js.map